Software Development in Brisbane

Swing Text APIs

August 29th, 2008

At Ephox we are pretty heavy users of the Java text APIs. In some respects the EditLive! team probably knows more about them than anyone in the world. In a Creative Coding Afternoon recently, I was doing some work on a cool plugin for EditLive! (it might make it into a future release of Enterprise Edition), and after spending time getting angry with the Swing document (some of the anger was justified). I had an epiphany. I expect that the actual revelation will not matter to any outside of Ephox (ok so people who want to work for ephox might be interested), but I'm going to share it anyway.

The Swing Document model != the DOM. Don't expect it to look like the DOM. Don't expect it to be the HTML DOM. The subclass HTMLDocument is not the DOM. While you can access all the information in the DOM, you should not expect there to be a direct mapping between concepts in the DOM and in the Swing Document model. You can expect all the information in the DOM to be available in the Swing Document model, but it isn't going to look exactly like the DOM. The Swing Document model is a generic model for presenting a document for us in a rich text editor, which means the DOM is transformed to work with the Swing Document model.

Once you can get your head around this, the Swing Text APIs can begin to make more sense (although I'm still grumpy about the lack of working with the java.util.collections properly).


JWhich in a line of code

August 20th, 2008

Old skool java programmers will have almost certainly come across the tool JWhich (http://www.javaworld.com/javaworld/javatips/jw-javatip105.html).  It's the classic tool for finding out which jar file contains a class.  The following line of code has the same effect, and is slightly better than just trying to grep jar files.

com.ibm.websphere.management.AdminService.class. getClassLoader(). getResource( "com/ibm/websphere/management/AdminService.class");1

1 – after reading the source for JWhich I realised that I have just copied it exactly :)


Programmatic Check for WebSphere Portal iFixes and Fixpacks

August 20th, 2008

As the internet didn't seem to know how to programatically lookup the installed iFixes and Fixpacks for a PortalServer, I'm going to share my solution, it the hope that someone can point me to a better way.

What I was able to work out from trawling the net and poking around at the WebSphere portal installation is that the install history for iFixes and Fixpacks for Portal are stored in the directory %PORTAL_HOME%/version/history. This makes the process of finding the fix level a case of: 

  1.  Lookup the Portal home. 
  2. List the files in the version history directory.

Lookup the Portal Home

To lookup the portal home, use the fact that there is a WPS_HOME environment variable set in the WebSphere environment. Unfortunately looking up values in the WebSphere environment is non-trivial. The WebSphere environment is not made directly available, to access it you need to go through the WebSphere Admin service, and the WebSphere management mbeans.

The code to do this is:

com.ibm.websphere.management.AdminService as =
	com.ibm.websphere.management.AdminServiceFactory.getAdminService();
String server = as.getProcessName();
javax.management.ObjectName serverName =
    new javax.management.ObjectName("*:*,type=AdminOperations,process=" + server);
Set objectNames = as.queryNames(servName, null);
javax.management.ObjectName objectName =
    (javax.management.ObjectName) objectNames.iterator().next();
Object[] args = new Object[] {"${WPS_HOME}"};
String[] signature = new String[] {"java.lang.String"};
String wpsHome = as.invoke(objectName,"expandVariable",args, signature);

The wpsHome variable will contain the string path to the websphere portal home directory.

List the Files in the Version History Directory

After retrieving the portal home, it is possible to lookup the fixpacks in the ${WPS_HOME}/version/history directory.

The following code does this:

File f = new File(wpsHome + File.separatorChar +
    "version" + File.separatorChar + "history");
String[] children = f.list();
for (int i=0;i<children.length;i++){
	out.println(children[i]);
}

In summary the full code snippet for this is:

com.ibm.websphere.management.AdminService as =
	com.ibm.websphere.management.AdminServiceFactory.getAdminService();
String server = as.getProcessName();
javax.management.ObjectName serverName =
    new javax.management.ObjectName("*:*,type=AdminOperations,process=" + server);
Set objectNames = as.queryNames(servName, null);
javax.management.ObjectName objectName =
    (javax.management.ObjectName) objectNames.iterator().next();
Object[] args = new Object[] {"${WPS_HOME}"};
String[] signature = new String[] {"java.lang.String"};
String wpsHome = as.invoke(objectName,"expandVariable",args, signature);

File f = new File(wpsHome + File.separatorChar +
    "version" + File.separatorChar + "history");
String[] children = f.list();
for (int i=0;i<children.length;i++){
	out.println(children[i]);
}

The work of mapping file names to the installed fix packs/iFixes is left as an exercise for the reader.

Does anyone know if there is a better way of dong this?


Web Character Encoding

July 11th, 2008

Making character encoding work well on the web can be a bit of a tricky task. There are many different layers to get right, and many different places in which things can go wrong.

At Ephox we have seen many of our clients experience problems with character encoding, and different fonts. We've actually created a variety of different articles to help people make there content editing environment work better:

http://liveworks.ephox.com/2007/05/15/why-international-characters-display-as-boxes/
http://liveworks.ephox.com/2007/05/08/solving-character-set-issues-with-legacy-systems/
http://liveworks.ephox.com/2007/09/03/character-encoding-and-special-characters/
http://liveworks.ephox.com/2008/03/11/url-encoding-and-character-sets/
http://liveworks.ephox.com/2008/02/05/controlling-entity-encoding

More recently I have been seeing some issues with encoding without EditLive! included. Sun proved to have a decent article talking about Character Conversions: http://java.sun.com/developer/technicalArticles/Intl/HTTPCharset/.  This articles includes good details on how to setup your JSP/Servlet layers to support encodings well.

This proved to be the answer to my problems, and well worth viewing if you are having encoding related problems in a Java Web application.


ACT Split in two

June 25th, 2008

The Australian Capital Territory can be considered to have two parts. The first (well known) part is halway between Sydney and Melbourne, and is the site of Canberra (see below map of the ACT).


View Larger Map

The second is Jervis Bay. (see below map of Jervis Bay).


View Larger Map


Can the Government be Agile? – discussion with a PMP PM

June 22nd, 2008

I’ve enjoyed my relationship with my brother-in-law for a long time. We’ve often talked about business and career, sharing where we are at, and the directions we are taking.

Over the past few years Paul has been doing a great job as a project manager in Canberra, in particular his involvement with the Department of Defence in the successful and ambitious e-voting project (Remote Electronic Voting Federal Election 2007). It has been great hearing about his work, and some of the stories around it. He has also been sharing his growing understanding of project management, and some of the courses and information he has been collecting, and applying. I have been listening with interest, and a degree of skepticism, thinking that much of what he has been learning would not apply directly to me, as it seems to be focused on heavyweight/rigorous methods, and I very much prefer working in Agile environments, where good smart people are encouraged to do great work.

So it was with great interest that I was recently listening to him discussing and presenting some of his recent thinking and work around scrum. Paul has been looking at how to apply scrum to government projects, and has some great ideas about this. I was particularly interested to hear what he saw as the strengths that scrum would bring, and the advantages he saw in outcome based results (delivery of working software that meets outcomes) versus delivery based results (traditional waterfall delivery of documentation is part of the results).

I look forward to seeing Paul’s work going forward, and to seeing how he continues to apply agile techniques to his work. If you are in Canberra, and are looking for a great contract or consultant project management, it is well worth talking to Paul and the team at Barton Institute of Management.


Howto Learn an API

June 20th, 2008

I recently have been learning a number of different APIs. After reflecting on my process for learning I have ended up with the following strategy for working with APIs.

  1. Find someone who has used the API in the past and get a brief introduction.
  2. Read documentation about the product (starting at the central documentation site for the product, include any tutorials and getting started guides). The goal from this first step is to get a general background understanding of what the product is about, the core concepts and jargon and principles of the product.
  3. Use the product without the APIs. If there is a gui to access to product that is available, ensure that you know this, and the jargon around the product. Try and ensure that the information you have from step 1 is grounded in reality.
  4. Read more documentation around the APIs. Make the top goal for this round to get enough of an understanding of what you can do.
  5. Explore the APIs to see what they expose of the feature. The set of features exposed by APIs often do not match up with what is exposed through the GUI. The most important spot to aim for is the subset of features that are supported by both the API and the GUI.
  6. Google (as usual it’s your friend). Sometimes there are some useful results in google that are missed elsewhere. Start with searching for the product name, try adding in API/howto/tutorial/getting started keywords to filter down content if you get too many results.
  7. Write some exploratory code to see how the APIs work, and what they do. This should enable you to know enough to actually write the code that you need.

All steps are required, as there are often features which are not easily discovered by just taking one of the above paths. One of the most important steps is ensure that you do understand the subset of what is supported by the API and the front-end. This helps to ensure that you are actually hitting the right part of the API.

From time to time there are options which are not well documented at all, and are only alluded to in technical documents. It can be worth contacting authors of documents if the feature is not clear. The coding and exploration of the system will need to continue after this. It should be expected to continue learning the APIs. At every stage there is value in talking to whatever experts/more experienced people you have available. Being able to quickly pickup a technology and move from no knowledge to confidence in using the API is a valuable tool for developers. Learning new technologies has been an important part of my job as a software engineer, and I expect that it will continue to be for many years to come.


Facebook Phishing Scams

June 18th, 2008

 

It was only a matter of time, but facebook phishing scams have hit the wild in a big way.

At work we saw a number of emails from a facebookmail.com address (that’s where facebook e-mails come from), suggesting that you might want to add a friend.

facebook-phising.png

The add a friend link actually sent you off to an isgreat.org domain, which had a facebook look-alike login page.

This was the closest that I’ve ever come to clicking on a phising link. I only stopped for two reasons

  1. my work e-mail isn’t associated with facebook at all.
  2. the name didn’t tempt me at all.

If it went to my real facebook account I might have been tempted (but sure won’t now).

The security adage – Don’t click on links in e-mails is definitely true. Even for facebook sending nice helpful e-mails with links.

This isn’t the only way that phishing is happening for facebook. See here, and techcrunch


Empty Tags in Internet Explorer

June 16th, 2008

In Case you were wondering…. <span class="replaceMe"></span> does not behave the same as <span class="replaceMe"/>  in ie, even though they are semantically equivalent. The second option will cause sites to crash, and not render if using ajax calls to update them (in particular with Prototype, with the use of Element.replace, or event innerHTML).

So, even though <span class="replaceMe"></span> should be equivalent to <span class="replaceMe"/>. Don't use the later if you want dom manipulation to work (which is pretty much the main reason to use an empty span tag in the first place.  The real moral to the story is Don't use empty span tags if you want to support the most popular browser on the planet.


Finding Large Files on OSX

June 16th, 2008

After a recent security push at ephox (highlighted by a stolen laptop, and then me forgetting that I left my laptop in the office overnight), I've been working on freeing up some space on my laptop so I can turn on FileVault. A quick search of the internet found some great tools for doing this. My weapon of choice was Disk Inventory X. It presents your drive as a tree map, coloured by file type. I was quickly able to find the large files to kill (a couple of 1 GByte hprof files, and some large logs were the guilty parties on my machine).

Disk Inventory X is a good little utility for helping to cleanup up your machine.  If you are ever in need of a tool for OSX to find large files, it is well worth using.