DbVisualizer is a database tool for developers and database administrators, helping you with both the development and maintenance of your databases.
It is the perfect solution since the same tool can be used on all major operating systems accessing a wide range of databases.
http://www.minq.se/products/dbvis/download/install.jsp
Friday, December 19, 2008
Thursday, December 18, 2008
Firefox Add-ons - Web Developer
Web Developer is the number one add-on for Firefox. It’s an essential for web developers and has a huge array of tools for making web development easier. We use it the most for on-the-fly validation of CSS and HTML as well as inspecting HTML and CSS.
https://addons.mozilla.org/en-US/firefox/addon/60
https://addons.mozilla.org/en-US/firefox/addon/60
Tuesday, December 16, 2008
Tuesday, November 25, 2008
Creating simple web project using maven
we can use mvn archetype:generate command to generate java web appication using maven. Afterthat,
cd testweb
mvn idea:idea
useful link:
http://books.sonatype.com/maven-book/reference/web.html
cd testweb
mvn idea:idea
useful link:
http://books.sonatype.com/maven-book/reference/web.html
Friday, November 14, 2008
JSF (JavaServer Faces)
JavaServer Faces technology simplifies building user interfaces for JavaServer applications.
JavaServer Faces technology includes:
* A set of APIs for representing UI components and managing their state, handling events and input validation, defining page navigation, and supporting internationalization and accessibility.
* A JavaServer Pages (JSP) custom tag library for expressing a JavaServer Faces interface within a JSP page.
Links:
http://java.sun.com/javaee/javaserverfaces/overview.html
http://en.wikipedia.org/wiki/JavaServer_Faces
JavaServer Faces technology includes:
* A set of APIs for representing UI components and managing their state, handling events and input validation, defining page navigation, and supporting internationalization and accessibility.
* A JavaServer Pages (JSP) custom tag library for expressing a JavaServer Faces interface within a JSP page.
Links:
http://java.sun.com/javaee/javaserverfaces/overview.html
http://en.wikipedia.org/wiki/JavaServer_Faces
log4j
This is the way of using log4j in java.
import org.apache.log4j.Logger;
private static Logger log = Logger.getLogger(ExternalAdvertiserAccountAssembler.class);
if (log.isDebugEnabled()) {
log.debug("User [id:"+ currentUser.getId() + "] is authorized to set the Trusted state.");
}
Links:
http://logging.apache.org/log4j/1.2/index.html
import org.apache.log4j.Logger;
private static Logger log = Logger.getLogger(ExternalAdvertiserAccountAssembler.class);
if (log.isDebugEnabled()) {
log.debug("User [id:"+ currentUser.getId() + "] is authorized to set the Trusted state.");
}
Links:
http://logging.apache.org/log4j/1.2/index.html
Wednesday, October 22, 2008
Reformat and Optimise code in IDEA
These are the shortcuts to reformat and optimize the code.
Alt+Ctrl+L / Alt+Ctrl+O
Alt+Ctrl+L / Alt+Ctrl+O
Sunday, October 12, 2008
hessian binary web service protocol
The Hessian binary web service protocol makes web services usable without requiring a large framework, and without learning yet another alphabet soup of protocols. Because it is a binary protocol, it is well-suited to sending binary data without any need to extend the protocol with attachments.
http://hessian.caucho.com/#Java
In our project i needed to write a test client in C# to use Exposed java API methods.For that I used HessianC#. I added hessiancsharp.dll to the .NET project.
http://www.hessiancsharp.org/
in Java , its like this.
bean id="advertisementService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean"
description Proxy for the user service using HTTP. /description
property name="serviceUrl" value="${admanager.url}remoting/secured/advertisementService"/
property name="serviceInterface" value="com.fastsearch.admomentum.admanager.advertisement.client.ExposedAdvertisementService"/
property name="serializerFactory" ref="hessianSerializer"/
property name="username" value="advertiser@test.com"/
property name="password" value="password"/
/bean
http://hessian.caucho.com/#Java
In our project i needed to write a test client in C# to use Exposed java API methods.For that I used HessianC#. I added hessiancsharp.dll to the .NET project.
http://www.hessiancsharp.org/
in Java , its like this.
bean id="advertisementService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean"
description Proxy for the user service using HTTP. /description
property name="serviceUrl" value="${admanager.url}remoting/secured/advertisementService"/
property name="serviceInterface" value="com.fastsearch.admomentum.admanager.advertisement.client.ExposedAdvertisementService"/
property name="serializerFactory" ref="hessianSerializer"/
property name="username" value="advertiser@test.com"/
property name="password" value="password"/
/bean
Thursday, October 2, 2008
XSLT
XSL stands for EXtensible Stylesheet Language. The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML-based style sheet language. XSLT stands for XSL Transformations. We can use XSLT to transform XML documents into other formats, like XHTML.
http://www.w3schools.com/xsl/default.asp
In my project i used it to transform xml document to csv file.
TransformBillingXmlToCsv.xml
xsl:template name="amount"
xsl:text " /xsl:text
xsl:value-of select="currencySymbol"/
xsl:text /xsl:text
xsl:choose
xsl:when test="currencySymbol = 'JPY'"
xsl:value-of select='format-number(value, "#.")'/
/xsl:when
xsl:otherwise
xsl:value-of select='format-number(value, "#.00")'/
/xsl:otherwise
/xsl:choose
xsl:text " /xsl:text
/xsl:template
(tag characters are removed from above sample code)
Here i had to use XSLT format-number() Function and XSLT Element.
http://www.w3schools.com/XSL/func_formatnumber.asp
http://www.w3schools.com/xsl/el_when.asp
http://www.w3schools.com/xsl/default.asp
In my project i used it to transform xml document to csv file.
TransformBillingXmlToCsv.xml
xsl:template name="amount"
xsl:text " /xsl:text
xsl:value-of select="currencySymbol"/
xsl:text /xsl:text
xsl:choose
xsl:when test="currencySymbol = 'JPY'"
xsl:value-of select='format-number(value, "#.")'/
/xsl:when
xsl:otherwise
xsl:value-of select='format-number(value, "#.00")'/
/xsl:otherwise
/xsl:choose
xsl:text " /xsl:text
/xsl:template
(tag characters are removed from above sample code)
Here i had to use XSLT format-number() Function and XSLT
http://www.w3schools.com/XSL/func_formatnumber.asp
http://www.w3schools.com/xsl/el_when.asp
Friday, September 26, 2008
Credit card numbers
I had to work with wrong credit numbers but valid numbers for testing purpose. These are two links which was useful for me.
http://www.darkcoding.net/credit-card-numbers/
http://www.auricsystems.com/support-center/sample-credit-card-numbers
http://www.darkcoding.net/credit-card-numbers/
http://www.auricsystems.com/support-center/sample-credit-card-numbers
Joda Time
Joda-Time provides a quality replacement for the Java date and time classes. The design allows for multiple calendar systems, while still providing a simple API. The 'default' calendar is the ISO8601 standard which is used by XML. The Gregorian, Julian, Buddhist, Coptic, Ethiopic and Islamic systems are also included, and are welcomed further additions. Supporting classes include time zone, duration, format and parsing.
http://joda-time.sourceforge.net/
http://apidoc.org/docset/62
http://apidoc.org/view/35865
Common Era (also known as Christian Era and Current Era; abbreviated CE)is a designation for the period of time beginning with year 1 of the proleptic Gregorian calendar.
http://en.wikipedia.org/wiki/BCE
http://joda-time.sourceforge.net/
http://apidoc.org/docset/62
http://apidoc.org/view/35865
Common Era (also known as Christian Era and Current Era; abbreviated CE)is a designation for the period of time beginning with year 1 of the proleptic Gregorian calendar.
http://en.wikipedia.org/wiki/BCE
Monday, September 22, 2008
Speed up the cargo start
To speed up the cargo start, I added these text to setenv.sh ,source it and put apache-tomcat-5.5.25.zip file to relevant path mentioned here.
export MAVEN_OPTS="-Djava.net.preferIPv4Stack=true -Djava.rmi.server.ignoreStubClasses=true -Dtomcat.installer.url=file:///home/chanaka/admo/bin-3.x/apache-tomcat-5.5.25.zip -Dtomcat.alternate.installer.url=file:///home/chanaka/admo/bin-3.x/apache-tomcat-5.5.25.zip $ADMO_OPTS"
export MAVEN_OPTS="-Djava.net.preferIPv4Stack=true -Djava.rmi.server.ignoreStubClasses=true -Dtomcat.installer.url=file:///home/chanaka/admo/bin-3.x/apache-tomcat-5.5.25.zip -Dtomcat.alternate.installer.url=file:///home/chanaka/admo/bin-3.x/apache-tomcat-5.5.25.zip $ADMO_OPTS"
Thursday, September 18, 2008
Remotely debug your app in Eclipse or Idea
When i needed to debug the app remotely, i needed to put
-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y
in cargo.jvmArguments -Xmx512M -XX:MaxPermSize=128m -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y /cargo.jvmArguments
line in pom.xml. (I'm using InteliJIdea).
useful links:
http://raibledesigns.com/rd/entry/remotely_debug_your_app_in
http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html
http://lists.nuxeo.com/pipermail/ecm-checkins/2006-December/002644.html
-Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y
in cargo.jvmArguments -Xmx512M -XX:MaxPermSize=128m -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y /cargo.jvmArguments
line in pom.xml. (I'm using InteliJIdea).
useful links:
http://raibledesigns.com/rd/entry/remotely_debug_your_app_in
http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html
http://lists.nuxeo.com/pipermail/ecm-checkins/2006-December/002644.html
Sunday, September 14, 2008
JSTL
I had to format a date to dispaly in the jsp page. For that, i used JSTL. The JavaServer Pages Standard Tag Library (JSTL) encapsulates as simple tags the core functionality common to many Web applications. JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags. It also provides a framework for integrating existing custom tags with JSTL tags.
http://java.sun.com/products/jsp/jstl/
I used JSTL Format Library — Tag. This tag has pattern attribute.
http://download-west.oracle.com/otn_hosted_doc/jdeveloper/905/working_with_html_pages/f1_html_xsql_jsp/f1_jspfmtformatdate.html
For that patten, we can give the pattern we need.
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
eg:
fmt:formatDate timeZone="${definedTimeZone}" value="${value}" pattern="EEE MMM dd HH:mm:ss z yyyy"
http://java.sun.com/products/jsp/jstl/
I used JSTL Format Library —
http://download-west.oracle.com/otn_hosted_doc/jdeveloper/905/working_with_html_pages/f1_html_xsql_jsp/f1_jspfmtformatdate.html
For that patten, we can give the pattern we need.
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
eg:
fmt:formatDate timeZone="${definedTimeZone}" value="${value}" pattern="EEE MMM dd HH:mm:ss z yyyy"
Friday, August 22, 2008
Skip execution of method in specific time of day
/* this test fails if the current time is between 12:00am and 3:00am*/
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
String timeCheck = "Current time not between 12:00am and 3:00am";
String timeDescription = "Current time" + ((hour < 3) ? "" : " not") + " between 12:00am and 3:00am";
Assume.assumeThat(timeDescription, equalTo(timeCheck));
Assume is package org.junit;(public class Assume )
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
String timeCheck = "Current time not between 12:00am and 3:00am";
String timeDescription = "Current time" + ((hour < 3) ? "" : " not") + " between 12:00am and 3:00am";
Assume.assumeThat(timeDescription, equalTo(timeCheck));
Assume is package org.junit;(public class Assume )
Thursday, August 21, 2008
ANTLR
Today i worked with some text character parsing. In our project, they have used ANTLR parser. ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages. ANTLR provides excellent support for tree construction, tree walking, translation, error recovery, and error reporting.
http://www.antlr.org/
We have used both Class LLkParser and Class Parser.Alos one important interface that provides is Interface AST in antlr.collections.
http://www.antlr2.org/javadoc/antlr/LLkParser.html
http://www.antlr2.org/javadoc/antlr/Parser.html#LA(int)
http://www.antlr2.org/javadoc/antlr/collections/AST.html
http://www.antlr.org/
We have used both Class LLkParser and Class Parser.Alos one important interface that provides is Interface AST in antlr.collections.
http://www.antlr2.org/javadoc/antlr/LLkParser.html
http://www.antlr2.org/javadoc/antlr/Parser.html#LA(int)
http://www.antlr2.org/javadoc/antlr/collections/AST.html
Thursday, August 14, 2008
Payment gateway
A payment gateway is an e-commerce application service provider service that authorizes payments for e-businesses, online retailers, bricks and clicks, or traditional brick and mortar. Paypal and SecurePay are two common payment gateways. Following are the list of gateways.
http://www.paymentgatewaydirectory.com/
In our project we use saferpay payment gateway. In billing-services.xml,
< bean id="billing.paymentService"
class="com.fastsearch.admomentum.billing.service.DefaultPaymentService">
. . .
< !-- this bean is defined in fast-admomentum-paymentgateway.jar -->
< property name="paymentGateway" ref="saferpayPaymentGateway" />
. . .
< /bean>
and in base-configuration.properties, there are lots of configurations.
one of them are,
# The merchant account id with Saferpay
com.fastsearch.admomentum.paymentgateway.saferpay.accountId=XXXXX-XXXXXXXXX
Wednesday, August 13, 2008
Java Unit testing
This is a simple test class i wrote to test following method.
package com.fastsearch.admomentum.common.time;
import java.io.Serializable;
import java.util.Calendar;
........
public class DateRange implements Serializable {
.....
public boolean isBetween(Calendar date) {
if (getEnd() != null) {
return (date.after(getStart()) && date.before(getEnd()))
|| date.equals(getStart()) || date.equals(getEnd());
} else {
return date.after(getStart()) || date.equals(getStart());
}
}
}
----------------------------------------------
package com.fastsearch.admomentum.common.time;
import junit.framework.TestCase;
import java.util.Calendar;
public class DateRangeUnitTest extends TestCase {
private DateRange dateRange;
public void testIsBetween()
{
assertFalse(isBetweenOutOfBoundTest());
}
private boolean isBetweenOutOfBoundTest()
{
Calendar testDate = Calendar.getInstance();
testDate.clear();
testDate.set(Calendar.YEAR,2007);
testDate.set(Calendar.MONTH,4);
testDate.set(Calendar.DATE,1);
Calendar startDate = Calendar.getInstance();
startDate.clear();
startDate.set(Calendar.YEAR,2007);
startDate.set(Calendar.MONTH,5);
startDate.set(Calendar.DATE,1);
Calendar endDate = Calendar.getInstance();
endDate.clear();
endDate.set(Calendar.YEAR,2007);
endDate.set(Calendar.MONTH,7);
endDate.set(Calendar.DATE,1);
dateRange = new DateRange(startDate, endDate);
return dateRange.isBetween(testDate);
}
}
package com.fastsearch.admomentum.common.time;
import java.io.Serializable;
import java.util.Calendar;
........
public class DateRange implements Serializable {
.....
public boolean isBetween(Calendar date) {
if (getEnd() != null) {
return (date.after(getStart()) && date.before(getEnd()))
|| date.equals(getStart()) || date.equals(getEnd());
} else {
return date.after(getStart()) || date.equals(getStart());
}
}
}
----------------------------------------------
package com.fastsearch.admomentum.common.time;
import junit.framework.TestCase;
import java.util.Calendar;
public class DateRangeUnitTest extends TestCase {
private DateRange dateRange;
public void testIsBetween()
{
assertFalse(isBetweenOutOfBoundTest());
}
private boolean isBetweenOutOfBoundTest()
{
Calendar testDate = Calendar.getInstance();
testDate.clear();
testDate.set(Calendar.YEAR,2007);
testDate.set(Calendar.MONTH,4);
testDate.set(Calendar.DATE,1);
Calendar startDate = Calendar.getInstance();
startDate.clear();
startDate.set(Calendar.YEAR,2007);
startDate.set(Calendar.MONTH,5);
startDate.set(Calendar.DATE,1);
Calendar endDate = Calendar.getInstance();
endDate.clear();
endDate.set(Calendar.YEAR,2007);
endDate.set(Calendar.MONTH,7);
endDate.set(Calendar.DATE,1);
dateRange = new DateRange(startDate, endDate);
return dateRange.isBetween(testDate);
}
}
mvn commands
- clean
mvn clean
- build
mvn install
- skip all the test
mvn install -P test-unit -Dmaven.test.skip=true
mvn install -o -P test-unit -Dmaven.test.skip=true
- run all the tests including selenium tests
mvn -Ptest-all install
- run specific tests (unit test or selenium test)
mvn install -Ptest-all -Dtest=com.fastsearch.admomentum..ClassName
mvn install -P test-all -Dtest=AdvertisementSeleniumTest
mvn install -Dtest=com.fastsearch.admomentum.common.time.DateRangeUnitTest -o -Ptest-all
- run specific tests (unit test or selenium test) with degugging
mvn install -Dtest=com.fastsearch.admomentum.admanager.webapp.selenium.campaign.CampaignSeleniumTest -o -Dmaven.surefire.debug -Ptest-all
mvn install -Dtest=com.fastsearch.admomentum.admanager.reporting.DefaultReportingServiceUnitTest -o -Dmaven.surefire.debug -Ptest-all
mvn clean
- build
mvn install
- skip all the test
mvn install -P test-unit -Dmaven.test.skip=true
mvn install -o -P test-unit -Dmaven.test.skip=true
- run all the tests including selenium tests
mvn -Ptest-all install
- run specific tests (unit test or selenium test)
mvn install -Ptest-all -Dtest=com.fastsearch.admomentum.
mvn install -P test-all -Dtest=AdvertisementSeleniumTest
mvn install -Dtest=com.fastsearch.admomentum.common.time.DateRangeUnitTest -o -Ptest-all
- run specific tests (unit test or selenium test) with degugging
mvn install -Dtest=com.fastsearch.admomentum.admanager.webapp.selenium.campaign.CampaignSeleniumTest -o -Dmaven.surefire.debug -Ptest-all
mvn install -Dtest=com.fastsearch.admomentum.admanager.reporting.DefaultReportingServiceUnitTest -o -Dmaven.surefire.debug -Ptest-all
Tuesday, August 12, 2008
Cargo
Cargo is a thin wrapper around existing containers (e.g. J2EE containers). It provides different APIs to easily manipulate containers.
Cargo provides the following APIs:
* A Java API to start/stop/configure Java Containers and deploy modules into them. Also Ant tasks, Maven 1, Maven 2 plugins. Intellij IDEA and Netbeans plugins are offered.
* A Java API to parse/create/merge J2EE Modules
Following are some containers.
* Geronimo 1.x
* JBoss 3.x
* JBoss 4.x
* Jetty 4.x
* Jetty 5.x
* Jetty 6.x
* jo 1.x
* Oc4J 9.x
* Orion 1.x
* Orion 2.x
* Resin 2.x
* Resin 3.x
* Tomcat 3.x
* Tomcat 4.x
* Tomcat 5.x
* WebLogic 8.x
Cargo provides the following APIs:
* A Java API to start/stop/configure Java Containers and deploy modules into them. Also Ant tasks, Maven 1, Maven 2 plugins. Intellij IDEA and Netbeans plugins are offered.
* A Java API to parse/create/merge J2EE Modules
Following are some containers.
* Geronimo 1.x
* JBoss 3.x
* JBoss 4.x
* Jetty 4.x
* Jetty 5.x
* Jetty 6.x
* jo 1.x
* Oc4J 9.x
* Orion 1.x
* Orion 2.x
* Resin 2.x
* Resin 3.x
* Tomcat 3.x
* Tomcat 4.x
* Tomcat 5.x
* WebLogic 8.x
Difference between 'vi' and 'vim' editors
vim is 'vi improved'
More powerful, etc
http://www.dc.turkuamk.fi/docs/soft/vim/vim_diff.html
More powerful, etc
http://www.dc.turkuamk.fi/docs/soft/vim/vim_diff.html
Thursday, August 7, 2008
Job scheduling with Quartz
Quartz is an open source job scheduling framework that provides simple but powerful mechanisms for job scheduling in Java applications. Quartz allows developers to schedule jobs by time interval or by time of day. The two fundamental units of Quartz's scheduling package are jobs and triggers. A job is an executable task that can be scheduled, while a trigger provides a schedule for a job.
Also, any singular job can have many triggers associated with it.
A CronTrigger allows for more specific scheduling than a SimpleTrigger and is still not very complex. Based on cron expressions, CronTriggers allow for calendar-like repeat intervals rather than uniform repeat intervals -- a major improvement over SimpleTriggers.
A "Cron-Expression" is a string comprised of 6 or 7 fields separated by white space. There are 6 mandatory and 1 optional fields.
Field Name
Seconds
Minutes
Hours
Day-of-month
Month
Day-of-Week
Year (Optional)
Expression Meaning
"0 0 12 * * ?" Fire at 12pm (noon) every day
useful links:
http://www-128.ibm.com/developerworks/java/library/j-quartz/
http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html
Also, any singular job can have many triggers associated with it.
A CronTrigger allows for more specific scheduling than a SimpleTrigger and is still not very complex. Based on cron expressions, CronTriggers allow for calendar-like repeat intervals rather than uniform repeat intervals -- a major improvement over SimpleTriggers.
A "Cron-Expression" is a string comprised of 6 or 7 fields separated by white space. There are 6 mandatory and 1 optional fields.
Field Name
Seconds
Minutes
Hours
Day-of-month
Month
Day-of-Week
Year (Optional)
Expression Meaning
"0 0 12 * * ?" Fire at 12pm (noon) every day
useful links:
http://www-128.ibm.com/developerworks/java/library/j-quartz/
http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html
Tuesday, August 5, 2008
Daylight saving time
Daylight saving time (DST; also summer time in British English; see Terminology) is the convention of advancing clocks so that afternoons have more daylight and mornings have less. Typically clocks are adjusted forward one hour near the start of spring and are adjusted backward in autumn.
http://en.wikipedia.org/wiki/Daylight_saving_time
In Java, there are two ways to create days. One method is using Calender object.
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR,2007);
c.set(Calendar.MONTH,9);
c.set(Calendar.DATE,31);
System.out.println(c.getTime());
c.add(Calendar.DATE,1);
System.out.println(c.getTime());
private List calculateIntervals(DateRange dateRange) {
Date date = dateRange.getStart().getTime();
Calendar c = Calendar.getInstance();
c.clear();
c.setTimeZone(dateRange.getStart().getTimeZone());
c.setTime(dateRange.getStart().getTime());
List dates = new ArrayList();
while (c.getTime().compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(c.getTime());
Calendar nextDate = (Calendar) c.clone();
nextDate.add(Calendar.DATE,1);
c = nextDate;
}
return dates;
}
This timezone don't work with daylight saving time. The other way is using Date object.
private List calculateIntervals(DateRange dateRange) {
Date date = dateRange.getStart().getTime();
List dates = new ArrayList();
while (date.compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(date);
Date nextDate = (Date) date.clone();
nextDate = DateUtils.addDays(nextDate, 1);
date = nextDate;
}
return dates;
}
This Date object time zone cater with daylight-saving time. In date object->cdate->daylightSaving parameter contains the time in milisecond that should add to the date for daylight-saving changes.
http://en.wikipedia.org/wiki/Daylight_saving_time
In Java, there are two ways to create days. One method is using Calender object.
Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR,2007);
c.set(Calendar.MONTH,9);
c.set(Calendar.DATE,31);
System.out.println(c.getTime());
c.add(Calendar.DATE,1);
System.out.println(c.getTime());
private List
Date date = dateRange.getStart().getTime();
Calendar c = Calendar.getInstance();
c.clear();
c.setTimeZone(dateRange.getStart().getTimeZone());
c.setTime(dateRange.getStart().getTime());
List
while (c.getTime().compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(c.getTime());
Calendar nextDate = (Calendar) c.clone();
nextDate.add(Calendar.DATE,1);
c = nextDate;
}
return dates;
}
This timezone don't work with daylight saving time. The other way is using Date object.
private List
Date date = dateRange.getStart().getTime();
List
while (date.compareTo(dateRange.getEnd().getTime()) <= 0) {
dates.add(date);
Date nextDate = (Date) date.clone();
nextDate = DateUtils.addDays(nextDate, 1);
date = nextDate;
}
return dates;
}
This Date object time zone cater with daylight-saving time. In date object->cdate->daylightSaving parameter contains the time in milisecond that should add to the date for daylight-saving changes.
Wednesday, July 30, 2008
Generics
Generics allow you to abstract over types. The most common examples are container types, such as those in the Collection hierarchy.
When you take an element out of a Collection, you must cast it to the type of element that is stored in the collection. Besides being inconvenient, this is unsafe. The compiler does not check that your cast is the same as the collection's type, so the cast can fail at run time.
Generics provides a way for you to communicate the type of a collection to the compiler, so that it can be checked. Once the compiler knows the element type of the collection, the compiler can check that you have used the collection consistently and can insert the correct casts on values being taken out of the collection.
Here is a simple example taken from the existing Collections tutorial:
// Removes 4-letter words from c. Elements must be strings
static void expurgate(Collection c) {
for (Iterator i = c.iterator(); i.hasNext(); )
if (((String) i.next()).length() == 4)
i.remove();
}
Here is the same example modified to use generics:
// Removes the 4-letter words from c
static void expurgate(Collection c) {
for (Iterator i = c.iterator(); i.hasNext(); )
if (i.next().length() == 4)
i.remove();
}
When you take an element out of a Collection, you must cast it to the type of element that is stored in the collection. Besides being inconvenient, this is unsafe. The compiler does not check that your cast is the same as the collection's type, so the cast can fail at run time.
Generics provides a way for you to communicate the type of a collection to the compiler, so that it can be checked. Once the compiler knows the element type of the collection, the compiler can check that you have used the collection consistently and can insert the correct casts on values being taken out of the collection.
Here is a simple example taken from the existing Collections tutorial:
// Removes 4-letter words from c. Elements must be strings
static void expurgate(Collection c) {
for (Iterator i = c.iterator(); i.hasNext(); )
if (((String) i.next()).length() == 4)
i.remove();
}
Here is the same example modified to use generics:
// Removes the 4-letter words from c
static void expurgate(Collection
for (Iterator
if (i.next().length() == 4)
i.remove();
}
Monday, July 28, 2008
Firefox Add-ons - Fire bug
Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page...
Firebug 1.2 requires Firefox 3. Firefox 2 users should install the older 1.05 version of Firebug.
https://addons.mozilla.org/en-US/firefox/addon/1843
Firebug 1.2 requires Firefox 3. Firefox 2 users should install the older 1.05 version of Firebug.
https://addons.mozilla.org/en-US/firefox/addon/1843
Thursday, July 24, 2008
Linux BASH command line
These are several useful Linux commands.
df ----Display free disk space
gzip ----Compress or decompress named file(s)
history ----Command History
ifconfig ----See the ip address of the machine
This is the url:
http://www.ss64.com/bash/
df ----Display free disk space
gzip ----Compress or decompress named file(s)
history ----Command History
ifconfig ----See the ip address of the machine
This is the url:
http://www.ss64.com/bash/
Wednesday, July 23, 2008
Selenium IDE
Selenium is a test tool for web applications. Selenium tests run directly in a browser, just like real users do. It runs in Internet Explorer, Mozilla and Firefox on Windows, Linux, and Macintosh, Safari on the Mac.I tested it in Firefox on Linux.The quickest way to learn Selenium is via a Firefox plugin called Selenium IDE.
http://selenium.openqa.org/
We can download it from
http://selenium-ide.openqa.org/download.jsp
I used Version 0.8.7
This is a good link for learning about selenium.
http://blog.taragana.com/index.php/archive/5-minute-guide-to-selenium-ide-and-selenium-rc-test-tools/
Our project(Admomentum) uses Selenium Remote Control rather than Selenium IDE. The Selenium Remote Control allows you to develop test cases and test suites in Java (supports JUnit & NGUnit), PHP, Ruby, Python, Perl and even .NET. It is the most flexible setup but requires some development knowledge to set up and use.
How To Raise a "File Download" Dialog Box
When you serve a document from a Web server, you might want to immediately prompt the user to save the file directly to the user's disk, without opening it in the browser. However, for known MIME (Multipurpose Internet Mail Extensions) types such as Microsoft Word ("application/ms-word"), the default behavior is to open the document in Internet Explorer.You can use the content-disposition header to override this default behavior. Its format is:
Content-disposition: attachment; filename=fname.ext
Content-disposition is an extension to the MIME protocol that instructs a MIME user agent on how it should display an attached file.When Internet Explorer receives the header, It raises a File Download dialog box whose file name box is automatically populated with the file name that is specified in the header.
To apply the header dynamically, create an Active Server Pages (ASP) file that writes the document out to the browser. Use the Response.AddHeader method to add the content-disposition header. For example:
Response.AddHeader "content-disposition","attachment; filename=fname.ext"
in Java
response.addHeader(CONTENT_DISPOSITION, conditionalParse(contentDisposition, invocation));
Content-disposition: attachment; filename=fname.ext
Content-disposition is an extension to the MIME protocol that instructs a MIME user agent on how it should display an attached file.When Internet Explorer receives the header, It raises a File Download dialog box whose file name box is automatically populated with the file name that is specified in the header.
To apply the header dynamically, create an Active Server Pages (ASP) file that writes the document out to the browser. Use the Response.AddHeader method to add the content-disposition header. For example:
Response.AddHeader "content-disposition","attachment; filename=fname.ext"
in Java
response.addHeader(CONTENT_DISPOSITION, conditionalParse(contentDisposition, invocation));
Tuesday, July 22, 2008
UTF-8 and shift-jis
UTF-8 (8-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode. It is able to represent any character in the Unicode standard, yet the initial encoding of byte codes and character assignments for UTF-8 is backwards compatible with ASCII. For these reasons, it is steadily becoming the preferred encoding for e-mail, web pages.
Shift JIS is a character encoding for the Japanese language.
This is a sample example of using encoding in Java.
filename = new StringBuilder();
private static final String DEFAULT_CHARSET = "ISO-8859-1";
try {
filename.append(new String(getText("campaign.download.filename.prefix").getBytes("UTF-8"), DEFAULT_CHARSET))
.append("-")
.append(sdf.format(now))
.append("-")
.append(new String(getCampaign().getName().toLowerCase().replace(" ", "-").getBytes("UTF-8"), DEFAULT_CHARSET))
.append(".csv");
} catch (UnsupportedEncodingException e) {
addActionError(getText("error.advertisementCsv.failedToDownload"));
return INPUT;
}
Shift JIS is a character encoding for the Japanese language.
This is a sample example of using encoding in Java.
filename = new StringBuilder();
private static final String DEFAULT_CHARSET = "ISO-8859-1";
try {
filename.append(new String(getText("campaign.download.filename.prefix").getBytes("UTF-8"), DEFAULT_CHARSET))
.append("-")
.append(sdf.format(now))
.append("-")
.append(new String(getCampaign().getName().toLowerCase().replace(" ", "-").getBytes("UTF-8"), DEFAULT_CHARSET))
.append(".csv");
} catch (UnsupportedEncodingException e) {
addActionError(getText("error.advertisementCsv.failedToDownload"));
return INPUT;
}
Monday, July 21, 2008
CSS float Property
The float property allows two div elements to display in same line.The float property sets where an image or a text will appear in another element.Note: If there is too little space on a line for the floating element, it will jump down on the next line, and continue until a line has enough space.
img
{
float: left
}
img
{
float: left
}
Remote Access in PostgreSQL databases
When we need to allow to someone to access our PostgreSQL database in our machine, we need to put following code in our pg_hba.conf file.
# Allow a user from host 192.168.12.10 to connect to database
# "postgres" if the user's password is correctly supplied.
#
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host postgres all 192.168.12.10/32 md5
This is a useful site regarding that.
http://developer.postgresql.org/pgdocs/postgres/auth-pg-hba-conf.html
# Allow a user from host 192.168.12.10 to connect to database
# "postgres" if the user's password is correctly supplied.
#
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host postgres all 192.168.12.10/32 md5
This is a useful site regarding that.
http://developer.postgresql.org/pgdocs/postgres/auth-pg-hba-conf.html
Friday, July 18, 2008
Remote login in Ubuntu
When you need to remote login to a another machine, first you need to change the remote desktop preferences of the machine which you need to connect and then run following command withing your machine.
vncviewer 172.23.69.90
or
vncviewer -fullscreen 172.23.69.90
change the ip address as u need. This is remote login with user interface.
The command for remote login in command pront is:
eg:
ssh silsaj@cmb1u119.cmb1.fast.no
vncviewer 172.23.69.90
or
vncviewer -fullscreen 172.23.69.90
change the ip address as u need. This is remote login with user interface.
The command for remote login in command pront is:
eg:
ssh silsaj@cmb1u119.cmb1.fast.no
Thursday, July 17, 2008
md5sum in Linux
A checksum is a form of redundancy check, a simple way to protect the integrity of data by detecting errors in data that are sent through space (telecommunications) or time (storage). It works by adding up the basic components of a message, typically the assorted bits, and storing the resulting value.
These types of redundancy check are useful in detecting accidental modification such as corruption to stored data or errors in a communication channel. However, they provide no security against a malicious agent as their simple mathematical structure makes them trivial to circumvent. To provide this level of integrity, the use of a cryptographic hash function, such as SHA-256,MD5 is necessary. In cryptography, MD5 (Message-Digest algorithm 5) is a widely used, partially insecure cryptographic hash function with a 128-bit hash value.
md5sum is a computer program that calculates and verifies 128-bit MD5 hashes, as described in RFC 1321. The MD5 hash (or checksum) functions as a compact digital fingerprint of a file. It is extremely unlikely that any two non-identical files existing in the real world will have the same MD5 hash (although as with all such hashing algorithms, in theory there is an unlimited number of files that will have any given MD5 hash).
In Linux, we use following command to check the checksum of a file.
md5sum -b ojdbc14.jar
These types of redundancy check are useful in detecting accidental modification such as corruption to stored data or errors in a communication channel. However, they provide no security against a malicious agent as their simple mathematical structure makes them trivial to circumvent. To provide this level of integrity, the use of a cryptographic hash function, such as SHA-256,MD5 is necessary. In cryptography, MD5 (Message-Digest algorithm 5) is a widely used, partially insecure cryptographic hash function with a 128-bit hash value.
md5sum is a computer program that calculates and verifies 128-bit MD5 hashes, as described in RFC 1321. The MD5 hash (or checksum) functions as a compact digital fingerprint of a file. It is extremely unlikely that any two non-identical files existing in the real world will have the same MD5 hash (although as with all such hashing algorithms, in theory there is an unlimited number of files that will have any given MD5 hash).
In Linux, we use following command to check the checksum of a file.
md5sum -b ojdbc14.jar
Wednesday, July 9, 2008
Regular Expression
This is a simple java application for using regular expressions in Java.
import java.util.regex.*;
public class Regex {
public static void main(String[] args) throws Exception {
Pattern p = Pattern.compile("[,\\s]+");
String[] result = p.split("one,two, three four , five");
for (int i=0; i System.out.println(result[i]);
String textSubject = "aasasa2323";
Pattern brackets = Pattern.compile(".*\\{[h][e][l][l][o]\\}.*");
Matcher fit = brackets.matcher(textSubject);
if (fit.find()) {
System.out.println ("Found");
} else {
System.out.println ("Not found");
}
}
}
import java.util.regex.*;
public class Regex {
public static void main(String[] args) throws Exception {
Pattern p = Pattern.compile("[,\\s]+");
String[] result = p.split("one,two, three four , five");
for (int i=0; i
String textSubject = "aasasa2323";
Pattern brackets = Pattern.compile(".*\\{[h][e][l][l][o]\\}.*");
Matcher fit = brackets.matcher(textSubject);
if (fit.find()) {
System.out.println ("Found");
} else {
System.out.println ("Not found");
}
}
}
Thursday, July 3, 2008
Download accelerator for Ubuntu
I'm using Ubuntu 7.10 (Gutsy Gibbon) in the working place. This link was useful for me to find details about it.
http://ubuntuguide.org/wiki/Ubuntu:Gutsy
Axel is a lightweight command line download accelerator for ubuntu. This link provides the procedure to use it.
http://blog.codefront.net/2007/04/29/axel-lightweight-command-line-download-accelerator/
Web developer 1.1.6 is an add-on to Firefox which is a very useful tool for web developers. This is the url:
https://addons.mozilla.org/en-US/firefox/addon/60
Today when I'm giving permissions to files and folders, this article was useful for me.
http://www.freeos.com/articles/4440/
http://ubuntuguide.org/wiki/Ubuntu:Gutsy
Axel is a lightweight command line download accelerator for ubuntu. This link provides the procedure to use it.
http://blog.codefront.net/2007/04/29/axel-lightweight-command-line-download-accelerator/
Web developer 1.1.6 is an add-on to Firefox which is a very useful tool for web developers. This is the url:
https://addons.mozilla.org/en-US/firefox/addon/60
Today when I'm giving permissions to files and folders, this article was useful for me.
http://www.freeos.com/articles/4440/
Subscribe to:
Posts (Atom)