Dec 282011
 

Doctrine – a very famous and strong ORM library for PHP web app development now can be easily integrated into CodeIgniter. (this post is assumed that you already know about PHP, CodeIgniter, ORM, Doctrine… so I just do the rest: to integrate them together)

1. Create CodeIgniter application ready to integrate Doctrine

You will need a folder name codeigniter-doctrine and copy the codeigniter application, system and index.php file into it. The result should look like this.

codeigniter doctrine integration thumb1 CodeIgniter 2 Doctrine 2 Integration

2. Download Doctrine library for CodeIgniter

Just download Doctrine ORM from it homepage, extract it and you will see the following:

image thumb7 CodeIgniter 2 Doctrine 2 Integration

We will need that Doctrine lib folder, copy it into CodeIgniter application libraries folder, and create a file name Doctrine.php just like this.

codeigniter doctrine integration 2 thumb1 CodeIgniter 2 Doctrine 2 Integration

3. Doctrine and CodeIgniter Integration

Now you’re ready to configure the Doctrine library for CodeIgniter, open the file Doctrine.php in your text editor and replace it with the following content:

<?php
use DoctrineCommonClassLoader,
DoctrineORMConfiguration,
DoctrineORMEntityManager,
DoctrineCommonCacheArrayCache,
DoctrineDBALLoggingEchoSQLLogger;

class Doctrine {

	public $em = null;

	public function __construct()
	{
		// load database configuration from CodeIgniter
		require_once APPPATH.'config/database.php';	

		// Set up class loading. You could use different autoloaders, provided by your favorite framework,
		// if you want to.
		require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php';

		$doctrineClassLoader = new ClassLoader('Doctrine',  APPPATH.'libraries');
		$doctrineClassLoader->register();
		$entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/" ));
		$entitiesClassLoader->register();
		$proxiesClassLoader = new ClassLoader('Proxies', APPPATH.'models/proxies');
		$proxiesClassLoader->register();

		// Set up caches
		$config = new Configuration;
		$cache = new ArrayCache;
		$config->setMetadataCacheImpl($cache);
		$driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH.'models/Entities'));
		$config->setMetadataDriverImpl($driverImpl);
		$config->setQueryCacheImpl($cache);

		$config->setQueryCacheImpl($cache);

		// Proxy configuration
		$config->setProxyDir(APPPATH.'/models/proxies');
		$config->setProxyNamespace('Proxies');

		$config->setAutoGenerateProxyClasses( TRUE );

		// Database connection information				

		$connectionOptions = array( 
        'driver' => 'pdo_mysql',		
        'user' =>     'webapp',
        'password' => 'webapp',
        'host' =>     'localhost',
        'dbname' =>   'mydb'
		);

		// Create EntityManager
		$this->em = EntityManager::create($connectionOptions, $config);
	}
}

As you can see from the above, we do most Doctrine config in this file, please change the $connectionOptions to the right database information you’re using.

Continue reading »

Dec 282011
 

In this post I will show you how to integrate Smarty 3 (I use the current version Smarty 3.1.3 ) with CodeIgniter 2 (2.0.3).

1. Create CodeIgniter application ready to integrate Smarty

Create a folder name codeigniter-smarty and copy codeigniter lib folder to it. You will make something like this.

codeigniter smarty integration thumb CodeIgniter 2 Smarty 3 integration

2. Download Smarty and prepare library for CodeIgniter

Now you will need to download Smarty and copy its libs folder.

smarty lib for codeigniter thumb CodeIgniter 2 Smarty 3 integration

In your CodeIgniter application folder, find the libraries folder and create a folder name “smarty” and a file name smarty.php. Don’t worry about their content, we will complete it softly, now just paste your libs folder copy from Smarty to libraries > smarty folder

codeigniter smarty integration folder thumb CodeIgniter 2 Smarty 3 integration

You will also need a cache and a config folder, please create them in the librariessmarty as following:

image thumb3 CodeIgniter 2 Smarty 3 integration

Continue reading »

Dec 282011
 

In this tutorial, I will guide you to integrate 2 power frameworks for Java EE application: Struts 2 and Hibernate 3 (I used the latest library version of them to the time I wrote this post). The example we will use is a simple blog, here is how it looks

struts hibernate integration blogging example thumb Struts 2 Hibernate 3 Integration Blogging Example

We will develop some main features of a blogging application:

  • To Create New Post
  • To List All Posts in One Page
  • To Manage Post: Edit/Remove Posts.

Software and Library needed:

  • Eclipse Indigo 3.7
  • Apache Tomcat 7.0
  • MySQL 5
  • MySQL Workbench
  • Struts 2.2.3.1
  • Hibernate Core 3.6.7
  • slf4j-1.6.2
  • apache-log4j-1.2.16
  • JSTL 1.2

Note: All of these are the latest up to October 2011.

1. Setup Eclipse, Tomcat and New Struts-Hibernate Project Lib

In Eclipse, select Java EE perspective. image thumb Struts 2 Hibernate 3 Integration Blogging Example

In the Server view, right click and select New to create a new Instance of Tomcat 7 (if you don’t have one).

Now from Eclipse, right click in Project Explorer then select New > Web > Dynamic Web Project

new struts hibernate project thumb Struts 2 Hibernate 3 Integration Blogging Example

Enter struts-hibernate-integration as the project name, select Tomcat 7 as the Runtime Server and you’ll be ready with a project structure like this.

image thumb1 Struts 2 Hibernate 3 Integration Blogging Example

Now you need to configure library for the application.

struts hibernate library thumb Struts 2 Hibernate 3 Integration Blogging Example

Please find the above jar file in these location:

  • struts-2.2.3.1lib
  • hibernate-distribution-3.6.7.Final
  • hibernate-distribution-3.6.7.Finallibrequired
  • hibernate-distribution-3.6.7.Finallibjpa
  • slf4j-1.6.2
  • apache-log4j-1.2.16
  • jstl-1.2

Now if you collect all of the above jar files, please copy them all to the folder WebContent > WEB-INF > lib

2. Configure Struts 2 Application

Your next step is to configure Struts 2 Application and to make sure it will work.

First thing to do is to configure Struts 2 Filter in web.xml file (find this file under WebContent > WEB-INF folder. Configure it like this: web.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">
	<display-name>struts-hibernate-integration</display-name>
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

Create an XML file with name: struts.xml and put it under your src folder (to make sure it will visible in build folder when we deploy), with the following content.

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
	<package name="default" extends="struts-default" namespace="/blog">
		<action name="listBlog" method="listBlog"
			class="com.googlecode.frameworksintegration.action.BlogAction">
			<result name="success">/blog_listing.jsp</result>
		</action>
		<action name="newBlog" method="renderAddBlog"
			class="com.googlecode.frameworksintegration.action.BlogAction">
			<result name="success">/blog_adding.jsp</result>
		</action>

		<action name="addBlog" method="addBlog"
			class="com.googlecode.frameworksintegration.action.BlogAction">
			<result name="success">/notifications.jsp</result>
		</action>

		<action name="manageBlog" method="manageBlog"
			class="com.googlecode.frameworksintegration.action.BlogAction">
			<result name="success">/blog_manage.jsp</result>
		</action>

		<action name="deleteBlog" method="deleteBlog"
			class="com.googlecode.frameworksintegration.action.BlogAction">
			<result name="success">/notifications.jsp</result>
		</action>
	</package>
</struts>

You can see in the above struts config file that all the action we use in this example is point to BlogAction class, here is its content:

package com.googlecode.frameworksintegration.action;

import java.util.List;

import com.googlecode.frameworksintegration.dao.BlogDAO;
import com.googlecode.frameworksintegration.dao.BlogDAOImpl;
import com.googlecode.frameworksintegration.domain.Blog;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Struts 2 Integrated with Hibernate 3 blogging example.
 * http://java.searchdaily.net
 * @author namnvhue
 *
 */
public class BlogAction extends ActionSupport {
	private BlogDAO blogDAO = null;
	private List<Blog> blogs;
	private Blog blog;
	private String message;
	private String blogId;

	/**
	 *
	 */
	public BlogAction() {
		this.blogDAO = new BlogDAOImpl();
	}

	private static final long serialVersionUID = -4901097198092626247L;

	public String listBlog() {
		this.blogs = blogDAO.listBlogs();

		return SUCCESS;
	}

	public String manageBlog() {
		this.blogs = blogDAO.listBlogs();

		return SUCCESS;
	}

	public String renderAddBlog() {
		this.blog = new Blog();
		return SUCCESS;
	}

	public String addBlog() {
		blogDAO.save(this.blog);
		this.message = "Blog has been created successfully.";
		return SUCCESS;
	}

	public String deleteBlog() {
		this.blog = this.blogDAO.find(Integer.parseInt(blogId));
		this.blogDAO.delete(blog);
		this.message = "Blog has been removed successfully.";
		return SUCCESS;
	}

	public String editBlog() {
		return SUCCESS;
	}

	public String detail(String id) {
		return SUCCESS;
	}

	public List<Blog> getBlogs() {
		return blogs;
	}

	public void setBlogs(List<Blog> blogs) {
		this.blogs = blogs;
	}

	public Blog getBlog() {
		return blog;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getBlogId() {
		return blogId;
	}

	public void setBlogId(String blogId) {
		this.blogId = blogId;
	}

}

If you enter all the above code now, Eclipse will give you some compiling error, but don’t worry, we will fix it softly.

3. Prepare MySQL database and Configure JPA persistence unit

We will use MySQL 5 as the database and JPA over Hibernate 3, first thing to do is to create a new schema named blog and create a blog table with the following structure:

CREATE TABLE `blog` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `CONTENT` text,
  `POSTED_BY` varchar(255) DEFAULT NULL,
  `POSTED_DATE` datetime DEFAULT NULL,
  `TITLE` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

Now in the src folder of the project, create a folder name: META-INF and create inside it a file name: persistence.xml.

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="blogds">
		<class>com.googlecode.frameworksintegration.domain.Blog</class>
		<properties>
			<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/blog" />
			<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
			<property name="hibernate.connection.password" value="mysql_password" />
			<property name="hibernate.connection.username" value="mysql_user" />
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
		</properties>
	</persistence-unit>
</persistence>
4. Configure Hibernate and DAO layer for Struts Application.

Now you will see how to configure an entity for using Hibernate. Here is the Blog class you see as the domain object in BlogAction action before.

package com.googlecode.frameworksintegration.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Struts 2 Integrated with Hibernate 3 blogging example.
 * http://java.searchdaily.net
 * @author namnvhue
 *
 */
@Entity
@Table(name = "BLOG")
public class Blog {

	private Integer id;
	private String title;
	private String content;
	private Date postedDate;
	private String postedBy;

	@Id
	@GeneratedValue
	@Column(name = "ID")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "CONTENT")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "POSTED_DATE")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getPostedDate() {
		return postedDate;
	}

	public void setPostedDate(Date postedDate) {
		this.postedDate = postedDate;
	}

	@Column(name = "POSTED_BY")
	public String getPostedBy() {
		return postedBy;
	}

	public void setPostedBy(String postedBy) {
		this.postedBy = postedBy;
	}

	@Column(name = "TITLE")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

}

The blogDAO interface:

package com.googlecode.frameworksintegration.dao;

import java.util.List;

import com.googlecode.frameworksintegration.domain.Blog;

/**
 * Struts 2 Integrated with Hibernate 3 blogging example.
 * http://java.searchdaily.net
 *
 * @author namnvhue
 *
 */
public interface BlogDAO {
	public Blog find(Integer id);

	public List listBlogs();

	public void save(Blog blog);

	public void delete(Blog blog);
}

The implementation of blogDAO using Hibernate

package com.googlecode.frameworksintegration.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import com.googlecode.frameworksintegration.domain.Blog;
/**
 * Struts 2 Integrated with Hibernate 3 blogging example.
 * http://java.searchdaily.net
 * @author namnvhue
 *
 */
public class BlogDAOImpl implements BlogDAO {
	private EntityManagerFactory entityManagerFactory;
	private EntityManager entityManager;

	public BlogDAOImpl() {
		this.entityManagerFactory = Persistence
				.createEntityManagerFactory("blogds");
		this.entityManager = entityManagerFactory.createEntityManager();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List listBlogs() {
		Query q = entityManager.createQuery("select blog from Blog blog");
		return q.getResultList();

	}

	@Override
	public void save(Blog blog) {
		entityManager.getTransaction().begin();
		entityManager.persist(blog);
		entityManager.flush();
		entityManager.getTransaction().commit();
	}

	@Override
	public void delete(Blog blog) {
		entityManager.getTransaction().begin();
		entityManager.remove(blog);
		entityManager.flush();
		entityManager.getTransaction().commit();
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}

	@Override
	public Blog find(Integer id) {
		return entityManager.find(Blog.class, id);

	}

}

You won’t see any import from Hibernate here, because we use Hibernate as a Persistence Provider to JPA and for a standard rule, more and more projects are using it this way.

 Posted by at 3:20 pm
Sep 172011
 

Today I do a simple test of new HTML5 Input Types on Different Browsers and here I will show you some interesting results.

image thumb34 HTML5 Input Types on Different Browsers

Firefox, Chrome, Safari, Opera and Internet Explorer are as much major browser as I can get. The test will run on the following input types:

No. Type Description
1. tel The input value is of type telephone number
2. search The input field is a search field
3. url The input value is a URL
4. email The input value is one or more email addresses
5. datetime The input value is a date and/or time
6. date The input value is a date
7. month The input value is a month
8. week The input value is a week
9. time The input value is of type time
10. datetime-local The input value is a local date/time
11. number The input value is a number
12. range The input value is a number in a given range
13. color The input value is a hexadecimal color, like #FF8800

In the past you will see only <input type=”text”… /> or <input type=”button”…/> Now HTML5 comes with these types new types of input to help you simplify the process of designing and coding web application. I only need design a simple source code for the test, here it goes:

<form action="input-test.html" method="get">
		<table>
			<tr>
				<td><strong>Input Type</strong></td>
				<td><strong>Result</strong></td>
			</tr>
			<tr>
				<td>Telephone</td>
				<td><input type="tel" name="tel" value="12345" /></td>
			</tr>

			<tr>
				<td>Search</td>
				<td><input type="search" name="search" value="type in keyword" />
				</td>
			</tr>

			<tr>
				<td>URL</td>
				<td><input type="URL" name="url" value="http://searchdaily.net" />
				</td>
			</tr>

			<tr>
				<td>Email</td>
				<td><input type="email" name="email"
					value="nam@searchdaily.net" /></td>
			</tr>

			<tr>
				<td>Datetime</td>
				<td><input type="datetime" name="datetime" value="2011-09-17" />
				</td>
			</tr>


			<tr>
				<td>Datetime-Local</td>
				<td><input type="datetime-local" name="datetime_local"
					value="2011-09-17" /></td>
			</tr>

			<tr>
				<td>Date</td>
				<td><input type="date" name="date" value="2011-09-17" /></td>
			</tr>

			<tr>
				<td>Time</td>
				<td><input type="time" name="time" value="16:40" /></td>
			</tr>

			<tr>
				<td>Month</td>
				<td><input type="month" name="month" value="08" /></td>
			</tr>

			<tr>
				<td>Week</td>
				<td><input type="week" name="week" /></td>
			</tr>

			<tr>
				<td>Number</td>
				<td><input type="number" name="number" value="1234" /></td>
			</tr>

			<tr>
				<td>Range</td>
				<td><input type="range" name="range" min="1" max="100"
					value="70" /></td>
			</tr>

			<tr>
				<td>Color</td>
				<td><input type="color" name="color" /></td>
			</tr>
		</table>
	</form>

Which eventually should look like this:

image thumb35 HTML5 Input Types on Different Browsers

Now I will run the test file through various browser to see its result.

First is Chrome (13.0), because I know it best supports HTML5 at the moment.

HTML5 Input Types support in Google Chrome

chrome html5 input compatible thumb HTML5 Input Types on Different Browsers

Most of input are supported now by Chrome, but datepicker is not visible yet, we can only change date/time by input it manually or to increase/decrease it.

HTML5 Colorpicker is not supported as well, not like what I can see later on Opera.

Now let’s move to the latest Opera (11.50)

HTML5 Input Types supports in Opera

opera html5 input compatible thumb HTML5 Input Types on Different Browsers

You won’t see Opera can suggest URL like Chrome can do and Opera doesn’t support Search either, but It can support great Color Picker, let see what I can capture from Opera if I click on the Color:

image thumb36 HTML5 Input Types on Different Browsers

And here is what it can give if you want the full color picker.

Continue reading »

Sep 142011
 

Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. You’ll never neend to email yourself a file again!

Your files, anywhere

Any file you save to Dropbox also instantly saves to your computers, phones, and the Dropbox website.

  • 091411 1547 Dropboxagoo1 Dropbox – a Good and Free Portable Disk for hitech er2GB of Dropbox for free, with subscriptions up to 100GB available.
  • Your files are always available from the secure Dropbox website.
  • Dropbox works with Windows, Mac, Linux, iPad, iPhone, Android and BlackBerry.
  • Works even when offline. You always have your files, whether or not you have a connection.
  • Dropbox transfers just the parts of a file that change (not the whole thing).
  • Manually set bandwidth limits — Dropbox won’t hog your connection.

Simple sharing

Shared folders allow people to work together on the same projects and documents.

  • 091411 1547 Dropboxagoo2 Dropbox – a Good and Free Portable Disk for hitech erInvite friends, family or teammates to a folder. It’ll be as if you saved the folder to their computers.
  • See other people’s changes instantly.
  • Create photo galleries viewable by anyone you choose.
  • Send a link to any file in your Dropbox using your Public folder.

Continue reading »

Sep 142011
 
Model

Battery

Charger

CANON G12

NB-7L

CB-2LZE

CANON G11

NB-7L

CB-2LZE

CANON G10

NB-7L

CB-2LZE

CANON G9

NB-2L / 2LH

CB-2LW

CANON G7

NB-2L / 2LH

CB-2LW

CANON G6

BP-511A

CG-580

CANON G5

BP-511A

CG-580

CANON G3

BP-511A

CG-580

CANON G2

BP-511A

CG-580

CANON SX30 IS

NB-7L

CB-2LZE

CANON SX20 IS

AA

AA charger

CANON SX10 IS

AA

AA charger

CANON SX1 IS

AA

AA charger

CANON SX210 IS

NB-5L

CB-2LXE

CANON SX200 IS

NB-5L

CB-2LXE

CANON SX100 IS

AA

AA charger

CANON SX110 IS

AA

AA charger

CANON SX120 IS

AA

AA charger

CANON SX130 IS

AA

AA charger

CANON E1

AA

AA charger

CANON D10

NB-6L

CB-2LYE

CANON S95

NB-6L

CB-2LYE

CANON S90

NB-6L

CB-2LYE

CANON S80

NB-2L / 2LH

CB-2LW

CANON S70

NB-2L / 2LH

CB-2LW

CANON S60

NB-2L / 2LH

CB-2LW

CANON S50

NB-2L / 2LH

CB-2LW

CANON S45

NB-2L / 2LH

CB-2LW

CANON S40

NB-2L / 2LH

CB-2LW

CANON IXY 50S (IXUS 1000 HS  – SD4500 IS)

NB-6L

CB-2LYE

CANON IXY 30S (IXUS 300 HS – SD4000 IS)

NB-6L

CB-2LYE

CANON IXY 10S (IXUS 210 IS – SD3500 IS)

NB-6L

CB-2LYE

CANON IXY 200F (IXUS 105 IS – SD1300 IS)

NB-6L

CB-2LYE

CANON IXY 400F (IXUS 130 IS – SD1400 IS)

NB-4L

CB-2LVE

CANON IXY 220 IS (IXUS 120 IS – SD940 IS)

NB-4L

CB-2LVE

CANON IXY 930 IS (IXUS 200 IS – SD980 IS)

NB-6L

CB-2LYE

CANON IXY 510 IS (IXUS 110 IS – SD960 IS)

NB-4L

CB-2LVE

CANON IXY 210 IS (IXUS 100 IS – SD780 IS)

NB-4L

CB-2LVE

CANON IXY 110 IS (IXUS 95 IS – SD1200 IS)

NB-6L

CB-2LYE

CANON IXY 920 IS (IXUS 870 IS – SD880 IS)

NB-5L

CB-2LXE

CANON IXY 910 IS (IXUS 860 IS – SD870 IS)

NB-5L

CB-2LXE

CANON IXY 900 IS (IXUS 850 IS – SD800 IS)

NB-5L

CB-2LXE

CANON IXY 830 IS (IXUS 990 IS – SD970 IS)

NB-5L

CB-2LXE

CANON IXY 820 IS (IXUS 970 IS – SD890 IS)

NB-5L

CB-2LXE

CANON IXY 810 IS (IXUS 950 IS – SD850 IS)

NB-5L

CB-2LXE

CANON IXY 800 IS (IXUS 800 IS – SD700 IS)

NB-5L

CB-2LXE

CANON IXY 700 (IXUS 750 – SD550 )

NB-3L

CB-2LUE

CANON IXY 600 (IXUS 700 – SD500 )

NB-3L

CB-2LUE

CANON IXY 400 (IXUS 400 – SD400 )

NB-4L

CB-2LVE

CANON IXY 25 IS (IXUS 85 IS – SD770 IS)

NB-6L

CB-2LYE

CANON IXY 20 IS (IXUS 80 IS – SD1100 IS)

NB-4L

CB-2LVE

CANON IXY 10 IS (IXUS 70 IS – SD1000 IS)

NB-4L

CB-2LVE

CANON IXY 95 IS (IXUS 90 IS – SD790 IS)

NB-5L

CB-2LXE

CANON IXY 90 IS (IXUS 75 – SD750 )

NB-4L

CB-2LVE

CANON IXY 80 IS (IXUS 65 – SD630 )

NB-4L

CB-2LVE

CANON IXY 70 IS (IXUS 60 – SD600 )

NB-4L

CB-2LVE

CANON IXY 60 (IXUS 55 – SD450 )

NB-4L

CB-2LVE

CANON IXY 55 (IXUS 50 – SD400 )

NB-4L

CB-2LVE

CANON IXY 50 (IXUS 40 – SD300 )

NB-4L

CB-2LVE

CANON IXY 40 (IXUS 30 – SD200 )

NB-4L

CB-2LVE

(IXUS IIs – SD110 )

NB-3L

CB-2LUE

CANON IXY 3000 IS (IXUS 980 IS – SD990 IS)

NB-5L

CB-2LXE

CANON IXY 2000 IS (IXUS 960 IS – SD950 IS)

NB-5L

CB-2LXE

CANON IXY 1000 (IXUS 900 Ti – SD900 )

NB-5L

CB-2LXE

CANON IXY L3 (IXUS izoom – SD30 )

NB-4L

CB-2LVE

CANON IXY L4 (IXUS I7 zoom – SD40 )

NB-4L

CB-2LVE

CANON IXY Wireless (IXUS wireless – SD430 )

NB-4L

CB-2LVE

CANON S5 IS

AA

AA charger

CANON S3 IS

AA

AA charger

CANON S2 IS

AA

AA charger

CANON A3100 IS

NB-8L

CB-2LAE

CANON A3000 IS

NB-8L

CB-2LAE

CANON A2000 IS

AA

AA charger

CANON A1100 IS

AA

AA charger

CANON A1000 IS

AA

AA charger

CANON A495

AA

AA charger

CANON A490

AA

AA charger

CANON A480

AA

AA charger

CANON A470

AA

AA charger

CANON A450

AA

AA charger

CANON A590 IS

AA

AA charger

CANON A580

AA

AA charger

CANON A570 IS

AA

AA charger

CANON A720 IS

AA

AA charger

CANON A710 IS

AA

AA charger

CANON A700

AA

AA charger

CANON A460

AA

AA charger

CANON A430

AA

AA charger

CANON A420

AA

AA charger

CANON A410

AA

AA charger

CANON A400

AA

AA charger

CANON A310

AA

AA charger

CANON A300

AA

AA charger

CANON A200

AA

AA charger

CANON A560

AA

AA charger

CANON A550

AA

AA charger

CANON A540

AA

AA charger

CANON A530

AA

AA charger

CANON A520

AA

AA charger

CANON A510

AA

AA charger

CANON TX1

NB-4L

CB-2LVE

CANON A650 IS

AA

AA charger

CANON A640

AA

AA charger

CANON A630

AA

AA charger

CANON A620

AA

AA charger

CANON A610

AA

AA charger

CANON PRO1

BP-511A

CG-580

CANON A100

AA

AA charger

CANON A95

AA

AA charger

CANON A90

AA

AA charger

CANON A85

AA

AA charger

CANON A75

AA

AA charger

CANON A70

AA

AA charger

CANON A60

AA

AA charger

CANON A40

AA

AA charger

CANON A30

AA

AA charger

CANON SD40

NB-4L

CB-2LVE

CANON SD20

NB-3L

CB-2LUE

CANON SD10

NB-3L

CB-2LUE

CANON S500

NB-1L / 1LH

CB-2LSE

CANON S410

NB-1L / 1LH

CB-2LSE

CANON S400

NB-1L / 1LH

CB-2LSE

CANON S330

NB-1L / 1LH

CB-2LSE

CANON S300

NB-1L / 1LH

CB-2LSE

CANON S230

NB-1L / 1LH

CB-2LSE

CANON S200

NB-1L / 1LH

CB-2LSE

CANON S110

NB-1L / 1LH

CB-2LSE

CANON S100

NB-1L / 1LH

CB-2LSE

CANON EOS 10D

BP-511A

CG-580

CANON EOS 20D

BP-511A

CG-580

CANON EOS 30D

BP-511A

CG-580

CANON EOS 40D

BP-511A

CG-580

CANON EOS 50D

BP-511A

CG-580

CANON EOS 60D

BP-511A

CG-580

CANON EOS KISS (REBEL – 300D)

BP-511A

CG-580

CANON EOS KISS N (REBEL XT – 350D)

NB-2LH

CB-2LW

CANON EOS KISS X (REBEL XTI – 400D)

NB-2LH

CB-2LW

CANON EOS KISS F (REBEL XS – 1000D)

LP-E5

LC-E5E

CANON EOS KISS X2 (REBEL XSI – 450D)

LP-E5

LC-E5E

CANON EOS KISS X3 (REBEL T1I – 500D)

LP-E5

LC-E5E

CANON EOS KISS X4 (REBEL T2I – 550D)

LP-E8

LC-E8E

NIKON D7000

EN-EL15

MH-25

NIKON D3100

EN-EL14

MH-24

NIKON D3S

EN-EL4a

MH-21

NIKON D300S

EN-EL3e

MH-18a

NIKON D3000

EN-EL9a

MH-23

NIKON D5000

EN-EL9a

MH-23

NIKON D3X

EN-EL4a

MH-21

NIKON D90

EN-EL3e

MH-18a

NIKON D700

EN-EL3e

MH-18

NIKON D60

EN-EL9

MH-23

NIKON D300

EN-EL3e

MH-18a

NIKON D3

EN-EL4a

MH-21

NIKON D40X

EN-EL9

MH-23

NIKON D40

EN-EL9

MH-23

NIKON D80

EN-EL3e

MH-18a

NIKON D2Xs

EN-EL4a

MH-21

NIKON D200

EN-EL3e

MH-18a

NIKON D70S

EN-EL3a

MH-18a

NIKON D50

EN-EL3a

MH-18a

NIKON D2Hs

EN-EL4

MH-21

NIKON D2X

EN-EL4

MH-21

NIKON D70

EN-EL3a

MH-18a

NIKON D2H

EN-EL4

MH-21

NIKON D100

EN-EL3a

MH-18a

NIKON D1X

EN-4

MH-21

NIKON D1H

EN-4

MH-21

NIKON D1

EN-4

MH-21

NIKON S8100

EN-EL12

MH-65

NIKON S1100pj

EN-EL12

MH-65

NIKON L110

AA

AA charger

NIKON L22

AA

AA charger

NIKON L21

AA

AA charger

NIKON S4000

EN-EL10

MH-63

NIKON S3000

EN-EL10

MH-63

NIKON S8000

EN-EL12

MH-65

NIKON S6000

EN-EL12

MH-65

NIKON S1000pj

EN-EL12

MH-65

NIKON S70

EN-EL12

MH-65

NIKON S640

EN-EL12

MH-65

NIKON S570

EN-EL10

MH-63

NIKON S230

EN-EL10

MH-63

NIKON L20

AA

AA charger

NIKON L19

AA

AA charger

NIKON S220

EN-EL10

MH-63

NIKON P90
NIKON S620

EN-EL12

MH-65

NIKON L100

AA

AA charger

NIKON S630

EN-EL12

MH-65

NIKON S610

EN-EL12

MH-65

NIKON S60

EN-EL10

MH-63

NIKON S560

EN-EL11

MH-64

NIKON S710

EN-EL12

MH-65

NIKON S610c

EN-EL12

MH-65

NIKON P6000
NIKON P80
NIKON S52
NIKON S52c
NIKON S550

EN-EL11

MH-64

NIKON S600

EN-EL10

MH-63

NIKON S520

EN-EL10

MH-63

NIKON L16

AA

AA charger

NIKON L18

AA

AA charger

NIKON P60
NIKON S210

EN-EL10

MH-63

NIKON S510

EN-EL10

MH-63

NIKON P50
NIKON L15

AA

AA charger

NIKON L14

AA

AA charger

NIKON P5100
NIKON S700

EN-EL10

MH-63

NIKON S51
NIKON S51c
NIKON S200

EN-EL10

MH-63

NIKON S500

EN-EL10

MH-63

NIKON S50
NIKON P5000
NIKON L12

AA

AA charger

NIKON L11

AA

AA charger

NIKON L10

AA

AA charger

NIKON S50c
NIKON S10
NIKON S9
NIKON S7c
NIKON L6

AA

AA charger

NIKON L5

AA

AA charger

NIKON L4

AA

AA charger

NIKON P3
NIKON P4
NIKON L3

AA

AA charger

NIKON L2

AA

AA charger

NIKON L1

AA

AA charger

Continue reading »

Sep 132011
 

In this post I will share some frequently use methods for Date/Time processing. These methods are needed for almost every project or project starters. Feel free to use and add more features to my class.

First are some Date Time Formatter like date formatter, 24h time formatter, 24h date time formatter…

public static final SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
public static final SimpleDateFormat monthYearFormater = new SimpleDateFormat("MM/yyyy");
public static final SimpleDateFormat timeFormatter = new SimpleDateFormat("hh:mm:ss");
public static final SimpleDateFormat datetimeFormatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
public static final SimpleDateFormat datetimeFormatterNoSecond = new SimpleDateFormat("dd/MM/yyyy HH:mm");
public static final SimpleDateFormat hourMinuteFormater = new SimpleDateFormat("HH:mm");
public static final SimpleDateFormat timeStampFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

You will use these formatters to parse String into Date so that you can use for calculation. Or you can use these formatters to format a Date into String so that you can use it to print out a console or notify user via a message.

Next is methods needed to get a Calendar instance, to operate with Date object, you definitely will need Calendar object.

public static Calendar getCalendar(Date date) {
	Calendar c = Calendar.getInstance();
	c.setTime(date);
	return c;
}

public static Calendar getCalendar() {
	Calendar c = Calendar.getInstance();
	c.setTime(new Date());
	return c;
}

Now what if you know date/month/year and want to have a Date object? The following methods will help you to build Date

	/**
	 * Build Date from date/month/year. Zero-based for Month (0=January).
	 * 
	 * @return
	 */
	public static Date buildDate(int year, int month, int date) {
		Calendar calendar = getCalendar();
		calendar.set(year, month, date);
		return calendar.getTime();
	}

	/**
	 * Build Datetime from date/month/year/hour/minute/second. Zero-based for
	 * Month (0=January).
	 * 
	 * @param year
	 * @param month
	 * @param date
	 * @param hour
	 * @param minute
	 * @param second
	 * @return
	 */
	public static Date buildDateTime(int year, int month, int date, int hour, int minute, int second) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(year, month, date, hour, minute, second);
		return calendar.getTime();
	}

Sometime you will also need to remove the Time part from a Datetime object, here is the method for that purpose

	/**
	 * Delete time from Date.
	 * 
	 * @param date
	 * @return
	 */
	public static Date removeTime(Date date) {		
		if (date == null) {
			return null;
		}

		// Obtain an instance of the Calendar.
		Calendar calendar = getCalendar(date);

		// Mark no automatic correction
		calendar.setLenient(false);

		// Remove the hours, minutes, seconds and milliseconds.
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);

		// Return the date again.
		return calendar.getTime();
	}

And not only to build a new Date object, you can use the following methods to adjust date, like get the previous date or get the next date or get yesterday or get tomorrow date

Continue reading »

Sep 102011
 

Like most of Linux OS, Mac OS X has a great feature names Spaces that lets you group applications/opened files and keep your working space uncluttered and organized.

spaces mac 7 thumb Bring Mac OS X Spaces Feature to Windows 7Sadly, Windows doesn’t have this feature but there’s good alternative for Windows users to keep their desktop organized and clean.

1. Use WindowsPager as Virtual Desktop to make more spaces for Windows 7

windowspagerscreenshot2 thumb Bring Mac OS X Spaces Feature to Windows 7

windowspager thumb Bring Mac OS X Spaces Feature to Windows 7

It lets you manage and group your desktop into multiple desktop spaces for different purpose (like working desktop, entertainment desktop, personal desktop…). This is very useful for advanced Windows users.

Continue reading »

Sep 102011
 

You’ve seen the Observer Pattern where subscriber get notified from publisher about events when something happened. It’s about the Listener/ Observer, how about another famous pattern named “Callback Pattern”?

What is Callback Pattern?

I can tell you that there’s some similarity about the notification, but the Callback Pattern is very much “Architectural Pattern” and only these diagram and definition can help you to distinguish.

image thumb20 Callback Pattern with RMI Client Callback

Callback Pattern is an Architectural Pattern that allows a client to register with a server for extended operations. This enables the server to notify the client when the operation has been completed.

image thumb21 Callback Pattern with RMI Client Callback

What can Callback Pattern help you?

Use the Callback pattern for a client-server system with time-consuming client operations, and when one or both of the following are true:

  • You want to conserve server resources for active communication.
  • The client can and should continue work until the information becomes available. This can be accomplished with simple threading in the client.
Callback Pattern Example

This Design Pattern is an architectural pattern and needs a server/client application to apply, so I will use the same example in my previous post about Proxy Pattern using RMI for the demo. To save your time, I won’t tell the story again but you should read and run the RMI example first before taking the next step.

First, I will define a BankClientCallback interface, which will act as a standardized channel for the server to interact with the client.

package net.searchdaily.java.design.pattern.callback;

import java.rmi.Remote;
import java.rmi.RemoteException;
/**
 * Callback Pattern with RMI tutorial by http://java.searchdaily.net
 * 
 * @author namnvhue
 * 
 */
public interface BankClientCallback extends Remote {
	public void notifyAction(String action) throws RemoteException;
}

As you can see to allow the server to interact with the client, the client’s now actually a server, so it’s much like server-to-server conversation. Next is for the Server interface

Continue reading »