Simple Introduction to Reflection

Reflection is a mechanism in java that allows to to get information about a class without needing to know the type of the class. The program below takes a java class name as a command line argument and shows you all of the methods and field names that are in the class.

You call the sample program like this:
java ReflectionTest java.util.Calendar

ReflectionTest takes the string you pass in on the command line and attempts to find a class by that name. If it finds one it gets an array of all the fields and displays their name and their values. It then gets an array of all the methods and displays their name and their return type.
Continue reading “Simple Introduction to Reflection”

CheckStyle

I’ve been using Eclipse and it is a very nice IDE. I’m very impressed with the number of plugin’s available for it. One of the plugins I’ve been using is called CheckStyle. Basically it can check your code for errors whenever you save it. The errors are configurable and it comes with a default implementation of the Sun Java coding style. It can be very annoying to apply it to code that you have already written, but if you use it as you are writing code it makes it much easier to make sure you are coding in a consistent way.
Continue reading “CheckStyle”

Emailing a webpage from the command line

There are many situations whey you have information on a web page that needs to be emailed to individuals on a regular basis. Often times all that is needed is some type of script that will grab a URL, put it in an email and send it to the correct person. This article is going to look at some of the tools that can be used to do this. I’m testing it on OS X, but it should work under Linux, Unix and possibly Cygwin as well.
Continue reading “Emailing a webpage from the command line”

Using Javascript to Refresh Parent

First let me say that I’m not a huge fan of Javascript. I understand the need for Javascript, but generally I prefer to program for a server environment instead of worrying about the client. However I ran into an issue this week that required Javascript, so here is what I learned about refreshing a parent window.

I had a web page that would list a bunch of items. Users needed to be able to click the “add” button and open a pop-up window that would let them choose an item to add to the list. The pop-up window displayed a hierarchy of choices so users had to click on it several times in order to make their selection.
Continue reading “Using Javascript to Refresh Parent”

Dealing with Slow XSLT Transformations

I have some XSLT stylesheets that I use to integrate information from Amazon with my reading list on my website. This weekend I decided to create another list using Amazon’s “People Who Bought this Book also Bought” feature. After a couple generations of downloading books that were related to books I read, I ended up with an XML file with about 1,500 books in it. I tried running the transform using Xerces and it took 13 hours.

Obviously this wasn’t going to work, so I refactored parts of the XSLT and was able to cut that time in half. 6 hours still seemed like it was taking far too long. I considered doing away with the stylesheets and doing the transforms manually using Java to write directly to a file. After doing some searches I discovered that apache.org has a good solutions for this problem that is part of the Xalan-J project. Basically it allows you to take an XSLT stylesheet and compile it into java byte code called a “translet”. You can then run the transform using Xalan and the compiled java translet. This makes things run much quicker. It appears that this is because the transform doesn’t need to deal with the XSLT file and because of other optimizations.
Continue reading “Dealing with Slow XSLT Transformations”