Sunday, September 28, 2008

HTML&Applet reminder

It was painful but necessary to explain this history. Someone can think I'm a newbie and maybe he/she is right.

Many people has knowledge about HTML but ,like me, not everydoby is updated about what tags are in use and what are deprecated.

I started working in a simple HTML using DreamWeaver like this:





As you can see, the basic template includes a DTD line specifying XHTML1.0.

My problem comes when I tried to add an APPLET to the page. I spent near an hour comparing my code with other pages: maybe my applet 'codebase' is wrong? maybe the libraries needed by the applet has a wrong path? ...

Finally I found the problem. Here is a copy&paste extracted from w3schools
:
The applet element was deprecated in HTML 4.01.
The applet element is not supported in XHTML 1.0 Strict DTD.

Friday, September 26, 2008

Swing Application Framework & Beans Binding

This is a short post related to two Java project that can be very useful.

Swing Application Framework (https://appframework.dev.java.net) is a small set of Java classes that simplify building desktop applications. I recommned it because it can be viewed as a set of good practices programming with Java. Also take a look at this article.

On the other hand, lately working with NetBeans I make use fo BeansBinding. It could be a bit confusing at the begining but to work with tables and bind values to DB tables, Lists or other objects, is very poweful

Saturday, August 09, 2008

Visual words definition

Today I know the existence of this amazing page: Visuwords.
I think it is one of the most original things I can see in many time.

Thursday, August 07, 2008

Using JAXB to generate KML Java classes

Some days ago I write a post about using JAXB with the KML's XSD file.
Due to a comment I would like to write more explicitly how I generated the Java files.

First of all, what you need is the XSD files which defines the KML syntax (http://schemas.opengis.net/kml).
Also, you need the xjc utility, included in the JDK6 (or download the JAXB project files).

Uncompress the XSD zip file and go into the uncompressed folder. Execute:
xjc -xmlschema -verbose -extension ogckml22.xsd
and get an error similar to this:

[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 1058 of file:kml_files/ogckml22.xsd

[ERROR] (Related to above error) This is the other declaration.
line 255 of file:kml_files/ogckml22.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
line 350 of file:kml_files/ogckml22.xsd

[ERROR] (Related to above error) This is the other declaration.
line 261 of file:kml_files/ogckml22.xsd


The problem is there are two scale elements defined, one like 'scale' and the other with upper case 'Scale'. And the same for the snippet element.
By default, JAXB uses case insensitive which will produce duplicated class names.

To resolve this there are some solutions. One is to customize the JAXB specifying the class name to be generated for some elements. The later is a workaround (that I used) that consist to change the name for one of the duplicated elements.
In line 255 change:




by




and in line 1391 chage:



by




The same for the snippet element.

Now you can re-execute the xjc command and a set of Java classes will be generated. The only difference is the change in the scale element which produces a different class name.

Sunday, July 27, 2008

Eastwood Charts

Today, via Dave Gilbert's blog, I know the existence of Eastwood Charts.

If you know about Google Chart API, Eastwood are the same thing but based in the powerful JFreeChart library. Here is a comparison.



The interesting part of Eastwood is it can be used as a servlet installed on your own server and thus you don't need to send your data to Google.

Remove too much files...

Sometimes (in Linux) if you try to delete all files in a directory (that contains a lot files) you get an:

> rm -rf * 
Argument list too long

Via DZone I found this tip to avoid this problem. Basically it used find command to get the list of interested files and remove it one by one.

Friday, July 18, 2008

JAXB for KML

Yesterday, I take a look at KML 2.2 specification.
To avoid create a million of classes to parse XML (KML) documents I put on my hands JAXB. After a while to resolve a duplicate element name (due to case insensitive in JAXB), finally I get a bunch of classes representing the KML element types.

After a couple of little test it seems is all right and now I need to spend some time (that I haven't) to integrate KML2.2 support into Balloon ;)

Thursday, July 17, 2008

Design Patterns

Today I would like to point to this post Design Patterns - Command Pattern.
Via DZone I can see David Cumps is written a series of post about design patterns.
Very interesting for all programmers.

Thursday, July 10, 2008

Quote

Everyone is as God has made him, and oftentimes a great deal worse.
Miguel de Cervantes
Spanish adventurer, author, & poet (1547 - 1616)

Friday, June 27, 2008

Working with time

It can seem trivial but sometimes working with time can become a real headache.
Here I present a short code snippet showing one common but confusing situation:
if you create two different Calendar objects and print it getting its Date and using 'println()' method they can seem the same.

Please read code comments which clarifies every situation.


import java.util.Calendar;
import java.util.TimeZone;

public class utc {

/**
* @param args
*/
public static void main(String[] args) {
Calendar c1 = Calendar.getInstance(TimeZone
.getTimeZone("Europe/Madrid"));

Calendar c2 = (Calendar) c1.clone();
c2.setTimeZone(TimeZone.getTimeZone("UTC"));

// Print Calendars. By default the toString() Calendar method is called
// and gets a String version of the objects.
// As you can see the String version shows the time zone of the Calendar.
System.out.println("Cal1: " + c1);
System.out.println("Cal2: " + c2);

// Print the Date objects of each Calendar.
// Here the toString method of the Date objects are invoked and this method
// by default translates the Date to the default system timezone. Thus both Dates
// seems equal.
System.out.println("Cal1: " + c1.getTime());
System.out.println("Cal2: " + c2.getTime());

// Finally we get the value of HOUR, MINUTE and SECOND of each calendar and
// prints it on the screen.
int h1 = c1.get(Calendar.HOUR_OF_DAY);
int m1 = c1.get(Calendar.MINUTE);
int s1 = c1.get(Calendar.SECOND);

int h2 = c2.get(Calendar.HOUR_OF_DAY);
int m2 = c2.get(Calendar.MINUTE);
int s2 = c2.get(Calendar.SECOND);

System.out.println("Cal1: " + h1 + ":" + m1 + ":" + s1);
System.out.println("Cal2: " + h2 + ":" + m2 + ":" + s2);
}
}