Showing posts with label Jill's work. Show all posts
Showing posts with label Jill's work. Show all posts

Monday, May 11, 2009

Java Time and Daylight Savings

I wanted to create a Java based clock which can show timings of London and Newyork. I got stuck at the point of handling DayLight savings. Searched over Google and found out that Java on its own is not handling DayLight Savings.

For ex:

Calendar londonCal = Calendar.getInstance(TimeZone.getTimeZone("Europe/London"));
String londonTime = londonCal.get(Calendar.HOUR_OF_DAY)+":"+londonCal.get(Calendar.MINUTE)+":"+londonCal.get(Calendar.SECOND);

Calendar newyorkCal = Calendar.getInstance(TimeZone.getTimeZone("US/Central"));
String newyorkTime = newyorkCal.get(Calendar.HOUR_OF_DAY)+":"+newyorkCal.get(Calendar.MINUTE)+":"+newyorkCal.get(Calendar.SECOND);

System.out.println("London: "+londonTime+"\nNewYork: "+newyorkTime);

I thought the above code would have handled DayLight savings but to my surprise i got below result in console:

London: 12:23:17
Newyork: 6:23:17

stating diff in time to be:6 hours

wherein currently its daylight savings so it should have been 5 hours and i should have got a result of

London: 12:23:17
Newyork: 7:23:17

hmm either i am not finding a way to get java calendar handle daylight saving or there isnt one which does tht?

Wednesday, March 11, 2009

Ubuntu Eclipse Subverion Stored Password delete

In Ubuntu, To clear stored cached passwords.

1. If eclipse is running, close your eclipse instance.
2. sudo rm -rf /home/%user%/.subversion/auth
3. Open your eclipse installation.
4. Open Configurations.
5. Open org.eclipse.core.runtime folder.
6. ls -a
7. sudo rm -rf .keyring
8. sudo gedit /home/%user%/.subversion/config
9. Uncomment 'store-passwords' inside 'auth'.
10. modify store-passwords=yes.
11. Restart eclipse, add your repository location and see that you are prompted with user/password dialog box.

Tuesday, May 20, 2008

Eclipse Plugins: A Common Library / jars Plugin

How to create a Plugin which holds all the libraries (jars) required by a RCP Application?

Plugin:
1. test.core.lib
2. testPluginA

Library: junit.jar

Procedure:
1. Create Plugin: test.core.lib - A non-UI contributing plugin. This plugin would have only one class: Activator.
2. Create folder:lib on test.core.lib project. Copy junit.jar to lib folder.
3. Modify Plugin.xml of test.core.lib, Open Runtime tab, add this jar in classpath and expose all the packages of this jar.
4. Create Plugin: testPluginA - A UI contributing plugin. This plugin would have a default view, perspective and application classes.
5. Modify Plugin.xml of testPluginA - Open Dependency tab, add dependency on test.core.lib plugin.
6. Create a ViewTest class which extends junit.framework.TestCase. Add a test method like :

public static void testMessageHelloWorld(){
System.out.println("Test Class invoked showing message: Hello World");
}
7. Open View class, call this method in View's createPartControl() method.
8. Run testPluginA as eclipse application.
9. The following message should be displayed in console:
"Test Class invoked showing message: Hello World".

Thursday, May 15, 2008

Simple Steps to create and work with Eclipse Extension Point

Follwing is a sample extension point which shows simple steps to define and work with Extension Points/define custom Extension Points.

Requirement: A simple Hello World message display when an event is triggered.

Plugins:
testcore - defines a plugin extension point called eventhandler.
testplugin1 - contributes to the extension point - eventhandler.
testplugin2 - contributes to the extension point - eventhandler.

Step A: Create Extension Point: EventHandler
open plugin.xml of plugin:testcore.
1. Open Extension points tab, Click Add, which opens a New Extension Point Dialog, Give the following entries as shown in the below picture.

2. Click Enter and u will be opened eventhandler.exsd. Click on Definition tab and u should be opened with the below screen.

fig 2: ExtenionPoint eventhandler definition

fig 3: Extension Point Attribute: "id" definition

fig 4: Extension Point Attribute: "class" definition

2a) Add a sequence for eventhandler extension point to element: extension. This is mandatory otherwise eventhandler extension point will not be visible for other plugins to define id and class values.

fig 5: Extension Sequence for eventhandler extension point.

2b. Create IEventHandler class in package testcore.eventhandler with following details:

package testcore.eventhandler;

public interface IEventHandler {

public void handleEvent(String message);

}

2c) Open Runtime tab, Add testcore.eventhandler package for IEventHandler to be visible to other plugins

3. Open plugin.xml of Plugin: testplugin1.
3a) Open Dependencies tab, Add testcore plugin as a dependency.
3b) Open Extensions tab, Add testcore.eventhandler extension point. And edit id and class values for the event handler as shown in picture below:

fig 6: Add testcore.eventhandler extensionpoint in testplugin1.

3c) Create Plugin1EventHandler class in testplugin1.eventhandler package.

package testplugin1.eventhandler;

import testcore.eventhandler.IEventHandler;

public class Plugin1EventHandler implements IEventHandler {

public Plugin1EventHandler() {
// TODO Auto-generated constructor stub
}

public void handleEvent(String message) {
// TODO Auto-generated method stub
System.out.println("in Plugin1EventHandler:"+message);
}

}

4. Open plugin.xml of Plugin: testplugin2.
4a) Open Dependencies tab, Add testcore plugin as a dependency.
4b) Open Extensions tab, Add testcore.eventhandler extension point. And edit id and class values for the event handler as shown in picture below:

fig 7: Add testcore.eventhandler extensionpoint in testplugin2.

4c) Create Plugin2EventHandler class in testplugin1.eventhandler package.

package testplugin2.eventhandler;

import testcore.eventhandler.IEventHandler;

public class Plugin2EventHandler implements IEventHandler {

public Plugin2EventHandler() {
// TODO Auto-generated constructor stub
}

public void handleEvent(String message) {
// TODO Auto-generated method stub
System.out.println("in Plugin2EventHandler:"+message);
}

}

5. Open Activator class of testcore plugin and do the following in start method.

public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;

IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint point = registry.getExtensionPoint("testcore.eventhandler");
if (point == null) return;
IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; i++){
IConfigurationElement[] configElements = extensions[i]
.getConfigurationElements();
for(IConfigurationElement configElement : configElements){
System.out.println(configElement.getAttribute("class"));

IEventHandler eventHandler = (IEventHandler) configElement
.createExecutableExtension("class");
eventHandler.handleEvent("Hello World");

}
}
}

6. Run testcore as Eclipse Application. Add testplugin1 and testplugin2 to its run time class path. You should see the following messages:

testplugin1.eventhandler.Plugin1EventHandler
in Plugin1EventHandler:Hello World
testplugin2.eventhandler.Plugin2EventHandler
in Plugin2EventHandler:Hello World

which shows the contributor plugins : testplugin1 and testplugin2 's EventHandler's getting called.

Tuesday, May 6, 2008

Basic Authentication in Sun AppServer

Follow the below steps to configure a particular user with https enabled web app:
1. In the sun-web.xml of the webapp:

<sun-web-app>
<context-root>/test</context-root>
<security-role-mapping>
<role-name>my-role</role-name>
<principal-name>user1</principal-name>
<group-name>my-group</group-name>
</security-role-mapping>
</sun-web-app>


2. In the web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<display-name>Archetype Created Web Application</display-name>

<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>

<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Site</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>my-role</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

<login-config>
<auth-method>BASIC</auth-method>
<realm-name>file</realm-name>
</login-config>

<security-role>
<role-name>my-role</role-name>
</security-role>

</web-app>

3. In Sun App Server admin console:
Under Configuration-->Security-->Realms-->File --> Manage Users
User: user1
Password: xxxx
Confirm Password: xxxx
Group List: my-role

Under Configuration-->Security-->Realms-->Certificate
Property: assign-groups : my-role

Under Configuration-->HTTP Listeners
Add new https listener with port 443 and enable all authentication and ssl'S in that.

Now launch your web app. It should pop up a username and pwd dialog box for basic authentication.

Sunday, March 30, 2008

Easy Creation, Export and Import of SSL Certificates for Sun AppServer

Following are the easy steps to create, export and import SSL Certificates.

1. Open Command Prompt, Point to ${Sun_HOME}/AppServer9/Domains/Domain1/config folder.

2. Run: keytool -genkey -alias aliasname -keyalg RSA -keystore keystore.jks

2. Create "aliasname.cer" in Sun/AppServer9/Domains/Domain1/config folder.

3. Run: keytool -export -alias aliasname-file aliasname.cer -keystore keystore.jks

4. Run: keytool -import -v -trustcacerts -alias aliasname -file aliasname.cer -keystore cacerts.jks

Sunday, February 3, 2008

SWT Editable Dialog Cell Editor

A SWT Editable Dialog Cell Editor with Cut, Copy, Paste and Delete Editor, A Dialog Button[File Dialog] and A Clear Cell button.

File Dialog Button - Clicking this would pop up a file Dialog.
Clear Cell Button - Clicking this would clear the field.



Available for Download: Download

Thursday, January 3, 2008

JAXB - XJC Task Cannot Resolve '' to a(n) element declaration component

JAXB XJC Task ignores the second import statement in xsds. Hence multiple imports would not get read and hence classes would not be generated. Once the reference of those non-generated classes are invoked, XJC throws "Cannot resolve '' to a(n) element declaration component".

Solution:
1. Pass "-nv" argument to XJC Task
For Ant:

For Maven:

Wednesday, September 12, 2007

Simple Steps for Product Branding - Eclipse

Chk out the doc for achieving Eclipse Product Branding - an easy way to create executable for plugin project

http://docs.google.com/Doc?id=dhctpzz_33hjz243

Jaret Table

Jaret Table is a full functional SWT Table with Sorting, Flitering, Editable Functionalities. A doc introducing Jaret Table is uploaded in http://docs.google.com/Doc?id=dhctpzz_21g6thwp

How to go with Spring

A basic tutorial document to help anyone to start up with Spring is uploaded in
http://docs.google.com/Doc?id=dhctpzz_0dxpkvx

Thursday, September 6, 2007

MySQL Windows Instal Error

MySQL 4.1.22 installs itself, but fails to start MySQL service in Windows XP x86.

Download MySQL 5.0.45, install, this has no issues with Windows XP x86.

Create/Remove Service from Windows

To Create A Service
  • Start | Run and type cmd in the Open: line. Click OK.
  • Type: sc create
  • Reboot the system
To Delete A Service
  • Start | Run and type cmd in the Open: line. Click OK.
  • Type: sc delete
  • Reboot the system
f you prefer to work in the registry rather than through the command prompt to delete services;
  • Click Start | Run and type regedit in the Open: line. Click OK.

  • Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

  • Scroll down the left pane, locate the service name, right click it and select Delete.

  • Reboot the system

Tuesday, September 4, 2007

Spring

The following link gives a basic understanding about Spring to startup with.

http://www.roseindia.net/search/showtutorials.php?id=6463

Issues:
1. NoClassDefFoundError thrown for commons-logging for the deployed war,
Place the commons-logging used by Spring.jar in the lib folder inside WEB-INF
2. Weblogic closing of becoz of Java HOTSPOT
Check in which java version all the classes have been compiled. compile in the same java version as of weblogic

Tuesday, July 17, 2007

Hibernate Tutorial

To start up with hibernate can check the link for the tutorial : http://www.roseindia.net/hibernate/

Tuesday, June 26, 2007

Wednesday, June 13, 2007

Getting started with Struts 2.0

Following link gives u a initial basic approach of going abt creating ur first Struts 2.0 App

http://www.roseindia.net/strutsshtml/struts2/struts-2-hello-world-files.shtml

http://www.roseindia.net/strutsshtml/struts2/struts-xml.shtml

New updated links
http://www.roseindia.net/struts/struts2/
struts-2-hello-world-files.shtml

http://www.roseindia.net/struts/struts2/struts-xml.shtml

RCP and Java Web Start - Creating JNLP

The following link gives a detailed explanation for how to create jnlp for an RCP application 
http://www.i-proving.ca/space/RCP+and+Java+Web+Start

You will face
java.lang.NullPointerException 
at java.util.Hashtable.put(Unknown Source) 
at org.eclipse.core.launcher.WebStartMain.basicRun(WebStartMain.java:58) 
at org.eclipse.core.launcher.Main.run(Main.java:977) 
at org.eclipse.core.launcher.WebStartMain.main(WebStartMain.java:40)

Issue: The problem is that the code relies on underscore as a delimiter between plugin name and plugin version. However, some plugins have underscore even in their version number (e.g. '...../org.eclipse.osgi_3.2.1.R32x_v20060919.jar') and these plugins fail to load. Not loading the org.eclipse.osgi causes the whole app fail to start.

Solution: use org.eclipse.osgi_3.2.1.v20060919.jar, sign this jar and change in all its references in ur jnlp.

Monday, June 11, 2007

SWT TreeTable

Me and my friend were looking for a good Tree Table widget in SWT. But we couldnt find a stable one. So, we ended up creating our own stable SWT Sortable Editable TreeTable widget.

A stable SWT TreeTable widget has been uploaded at:
http://tools.assembla.com/svn/j3widgets

Editable / Clearable Dialog Cell Editor

This is a swt widget for a table cell which comes with
a text box, a file dialog button and a clear button.

This widget comes with
- Cut, Copy, Paste and Delete options [which are the default SWT.Text options].
- Clear Button on click clears the content of text.
- File Dialog button on click of which, as the name says : a File dialog would pop up allowing the user to load a file.

If you want have this widget then you can have a peep in : http://tools.assembla.com/svn/j3widgets