about:config trick for window.close() In Firefox

July 7th, 2010 kumarasamy No comments
This article is from my exp. on turning on the configuration in FF after each release.The script window.close() won’t work after every release from mozilla. The reason i found was “dom.allow_scripts_to_close_windows” in all.js will be set to false by default. I was trying to do it in the hard way,i.e Go to the location of all.js and change it manually. But i found a another easy method we can call the about:config page in FireFox, we can toggle it easier. The following shows how to do it.
Enter about:config in location bar
Openingabtcnfg
Shows all the options available
options
Search for dom.allow_script
allow_scripts
Highlight the entry dom.allow_scripts_to_close_windows and double click to toggle to true
Then write a simple script to check window.close()
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Categories: General, Open Source Tags: , ,

Integrating Hibernate with Struts1.x

July 2nd, 2010 kumarasamy No comments
We have got list of post(s) about Hibernate. Today as a next step we’ll try to intergrate with MVC framework. We’ll take the most used one which Struts1.3. For example we’ll take the same Singer Example and we’ll work with that for intergrating with struts also.Since we have the domain object generated already, we can make use of the same domain object to populate the values from DB, when we use the Hibernate.
We just take the examples of listing all the Singers from Singers table. Since we are using Struts1.x, we may need to write the action class and form class. The following code shows Form Class. Since we are going to list all the Singers, then our Form looks like the following.
		package com.techmaddy.form;

		/*
		*  Copyright 2010 - Kumarasamy
		*	kumarasamy@techmaddy.com
		*/

		import javax.servlet.http.HttpServletRequest;

		import org.apache.struts.action.ActionForm;
		import org.apache.struts.action.ActionMapping;

		import com.techmaddy.singer.Singer;

		public class SingerForm extends ActionForm {

			private static final long serialVersionUID = 1L;

			private Singer[] singer =  new Singer[0];

			public Singer[] getSinger() {
				return singer;
			}

			public void setSinger(Singer[] singer) {
				this.singer = singer;
			}

			public void reset(ActionMapping mapping, HttpServletRequest request) {
				singer =  new Singer[0];
			}

		}
	
The DAO class will make a call to DB and returns the results. This is almost very similar to the class CRUDTest.java in Simple CRUD Operation With Hibernate. Instead of my CRUDTest class, we have an DAO Class which gets the data from DB.
My DAO Class looks like the following.
			package com.techmaddy.bo;

			/*
			*  Copyright 2010 - Kumarasamy
			*	kumarasamy@techmaddy.com
			*/

			import java.util.ArrayList;
			import java.util.Iterator;
			import java.util.List;

			import org.hibernate.Session;
			import org.hibernate.Transaction;
			import org.hibernate.Query;

			import com.techmaddy.singer.HibernateSessionFactory;
			import com.techmaddy.singer.Singer;

			public class SingerManager {

				public Singer[] getAllSingers() {
					List singer = new ArrayList();
					Session session = null;
					Transaction tx = null;

					session = HibernateSessionFactory.getSession();

					tx = session.beginTransaction();
					Query qry = session.createQuery("from Singer");
					for (Iterator iterator = qry.iterate(); iterator.hasNext();) {
						singer.add(iterator.next());
					}

					return (Singer[]) singer.toArray(new Singer[0]);
				}

			}
	
The same way, based in the action performed from the screen, we can make a call to Editing and deleting the Singers.The following Images shows the result screen.
Struts-Hibernate Integration
Download
To download the War file for Singer with Struts Integration Click Here
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Categories: Java, ORM Tags: , ,

Simple File Upload Script in PHP

June 30th, 2010 kumarasamy No comments
Here goes my file upload component in PHP. It just uploads the file into the specified directory.Other thing i have added as of now is it’ll upload the files into the folder on the current month and checks for the file exists already or not, if it already exists then it’ll prefix the time in milliseconds in the file name.
	<?php

		/*
		*		Copyright 2010 - Kumarasamy
		*		kumarasamy@techmaddy.com
		*/

		class DocumentHandler {

			var $uploadDir;// Directory where the documents to be uploaded

			function prepateForUpload() {
				$this->uploadDir = '/var/www/uploads';
				$this->uploadDir = $this->uploadDir . "/" . date("Y_m");

				//Check the month folder is available, if not then create it.
				if(!is_dir($this->uploadDir))
					mkdir($this->uploadDir);

			} //End of setDetails

			function copyFile($_FILES,$fileCntrlName) {
				$resultArray = array();
				$uploadfile = $this->uploadDir . "/" . basename($_FILES[$fileCntrlName]['name']);

				//If the file exists already in the folder, append the millisecond in the file name.
				if(is_file($uploadfile)) {
					list($msec, $sec) = explode(".", microtime(true));
					$uploadfile = $this->uploadDir . "/" . $msec . $sec . basename($_FILES[$fileCntrlName]['name']);
				}

				if (move_uploaded_file($_FILES[$fileCntrlName]['tmp_name'], $uploadfile)) {
					$resultArray['error'] = '';
					$resultArray['displayMessage'] = 'File Uploaded Successfully!!!';
				}

				return $resultArray;
			} //End of copyFile

		} //End of DocumentHandler
	?>
	
The following things can be added,

  • Check for the file type
  • Check for the file Size
  • Scan the document using the shell commands
  • Check for the special chars in the file name
  • File name length check also can be added
Idea’s are accepted!!!
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Get Adobe Flash playerPlugin by wpburn.com wordpress themes