Friday, 29 June 2007

Viewing Posted Xform instance and Environment Variables

Here's a cgi-bin script that you can use to echo posted form information back to yourself:

Monday, 18 June 2007

Using XSLT 2 (Saxon 8) with Ant...

Update: I had this problem again today, my notes from last time didn't work. To get saxon 8 working with ANT (1.7), first get the most up-to-date jars (important!) from sourceforge (8.9.0.4 at the time of writing):

http://sourceforge.net/project/showfiles.php?group_id=29872

Unpack them somewhere (e.g. a /lib directory)

Saxon is called in ANT using something like this:



I hope this helps someone :)

Ok - this is a short post; although I might extend it later on with some examples. If you're having a problem with Ant not using saxon to run the transforms (say, using xalan instead).. But you've added the classpath and you're sure it knows it's supposed to be using saxon, adding this line between your xslt tags might just help...

Friday, 15 June 2007

Eclipse, Ant and SSH

Getting Ant to work with a secure (SSH) connection requires a few more steps in the process.

Here's some guidelines which may help anyone wanting to run ant builds using SSH:

1. Once you've installed Eclipse, Ant and all the other bits, go and grab this:

http://www.sshtools.com/downloadProduct.do?productCode=MAVERICK-ANT

2. Copy the jar files in the archive over to wherever you installed Ant (in Windows, could be something like C:/Apps/apache-ant-1.6.5/lib/; on Linux it could be something like /home/{YOUR_USER_NAME}/apps/apache-ant-1.6.5/lib/)

3. Add maverick-ant.jar to your classpath in Eclipse (Window > Preferences > Ant > Editor > Runtime > Add External Jars) OR set the Ant Home (using the Ant Home button) and point to the base folder {YOUR_LOCATION}/apps/apache-ant-1.6.5

4. Go and get puttygen from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

5. Select 'Generate' and move the mouse around; this will create a random key pair.

6. Create (and confirm) a key passphrase to add another layer of security

7. Copy the Public key information Putty Key Generator has returned

8. Log into your server (wherever you're SSHing to) using the normal method (we're using Putty here)

9. edit /home/YOUR_USER_ID/.ssh/authorized_keys using your favourite editor and append the key information to that file, write the file and quit.

(I put an empty line in between the entries and this worked fine)

10. Save the private key locally using the save private key button in puttygen (you'll need to be able to refer to this in your ANT xml below)

11. Test it out in eclipse - create a build.xml file in your project, use the information below as a template and run the xml as an Ant build.

i. A basic ANT script for authentication should look like this - I've added the ls command in to show it working, so the ant file will authenticate (and show you the stages of authentication) and will then execute 'ls' to retrieve a directory listing:

<?xml version="1.0" encoding="UTF-8"?>

<project name="ssh" default="files" basedir=".">


<taskdef name="ssh"
classname="com.sshtools.ant.Ssh"
classpath="{THE_PATH_TO_YOUR_ANT_FOLDER}/lib/maverick-ant.jar" />

<target name="files">
<ssh host="{THE_NAME_OR_IP_ADDRESS_OF_YOUR_SERVER}"
username="YOUR_USER_NAME"
passphrase="YOUR_PASSWORD"
keyfile="{THE_NAME_AND_PATH_OF_YOUR_PRIVATE_KEY_FILE}.ppk">
<exec cmd="ls" />

</ssh>
</target>
</project>

Hope this helps. More information (as a tutorial) regarding ANT can be found here:
http://en.wikibooks.org/wiki/Programming:Apache_Ant

And check the documentation that came with Maverick Ant for more information:
http://www.sshtools.com/downloadProduct.do?productCode=MAVERICK-ANT

Sunday, 10 June 2007

Mp3 Playback in Java

Setting this up took a while and I can't really be sure exactly what I did to get all the things working; if I ever do a clean install, I'll try and document the process. Here's a very quick outline before I post the code -

I grabbed all the jars from here:
http://java.sun.com/products/java-media/jmf/2.1.1/download.html
And grabbed the mp3 handler here:
http://java.sun.com/products/java-media/jmf/mp3/download.html

The jars you'll need to drop into eclipse are (I think):
mp3plugin.jar
mediaplayer.jar
jmf.jar
multiplayer.jar

Here were some other links I found handy:
http://java.sun.com/products/java-media/jmf/2.1.1/setup-linux.html
http://java.sun.com/products/java-media/jmf/2.1.1/jmfdiagnostics.html
http://ubuntuforums.org/showthread.php?t=436053
http://weblogs.java.net/blog/jonathansimon/archive/2004/11/suns_mp3_plugin.html
http://forum.java.sun.com/thread.jspa?threadID=686681&messageID=3996185

Just a prewarning:
I kept getting errors that looked like this -
Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo,
LittleEndian, Signed, 16000.0 frame rate, FrameSize=32768 bits
Failed to realize: com.sun.media.PlaybackEngine@12dd76
Error: Unable to realize com.sun.media.PlaybackEngine@12dd76
Failed to realize: input media not supported: mpeglayer3 audio

If you keep seeing these, try a number of different mp3 files; I had to try 3 before I had something working. I found testing the mp3 files using jmstudio was a reliable way to test - if jmstudio can open and play the file automatically, then it should work fine with the code listed below.

You can see a forum discussion regarding some of the common problems here:
http://www.velocityreviews.com/forums/t149533-mp3-playback-using-java-sound-and-sun-mp3-plugin.html

A common alternative to the sun offering seems to be:
http://www.tritonus.org/plugins.html

-----------------------------------------------------
Ok - if everything is set up and appears to be working, you can try some of these classes. I found the original examples by looking around on forums, but had to make some changes to get them to work completely.

The simplest example I could find of a java class able to play an mp3 file:




Another example I found in a few forums used this code as a base:
http://forum.java.sun.com/thread.jspa?threadID=625352&messageID=3565801

I had to make a few modifications to get the code to work. Here is the class:



To test the class, I created a calling class called TestPlayMp3Thread:



Hope this is useful for someone else.

Wednesday, 6 June 2007

Simple Saxon Java example

I'd been wanting to create the *simplest* class possible to enable me to transform xsl files within a java application.

I looked around for a really simple example of this process. After a bit of digging around, I "ripped" these bits from the very comprehensive TraxExamples.java file provided within saxon-resources8-9.zip (the original file authored by Scott Boag) and now I have a class containing something like this:



The "void main" bit:



For this to work, you can get the real handleException method from the TraxExamples.java, or for the minimal amount of code to make it work (and not necessarily to make it too useful):



Using eclipse, all the imports were pulled in via Source > Organize Imports (Ctrl + Shift + O)

Does the trick for me :)

Viewing XForms and (x)html from the SVN web viewer

So we had a problem the other day, we wanted to be able to view html / xhtml examples as working pages direct from the SVN repository using a browser.

If you've committed a load of xhtml files (e.g. xforms) and you want to be able to view them as "applications" (or rendered html) from within svn, you need to set a property called svn:mime-type for all of the relevant files.

For old-skool html - you can use this mime-type:
text/html *.html (and any other extensions)

And in order to make xforms work properly - you can use this mime-type:
application/xhtml+xml *.xhtml

------------------------------
Within eclipse, right-click on the file (e.g. index.xhtml), go to Team > Set property, select svn:mime-type from the dropdown (or just type it) and enter the text property in the box below (e.g. application/xhtml+xml *.xhtml).

Eclipse/Subclipse also has a "Set property recursively) checkbox, selecting this should change the properties where there are several folders.

You can also select show properties to display the properties in a panel within the perspective.

For eclipse instructions - remember that you need subclipse installed (see my previous post)...

Tuesday, 5 June 2007

Using google's free SVN repository with Eclipse

Ok - here are some very quick notes on getting a google svn hosting account set up with eclipse; as google is offering us all such an amazing resource, I have a feeling I'll be doing this again some time whilst working on other projects...

If you already have a gmail account, make sure you're logged in (that way, your repository and your account will be linked).

Start here:
http://code.google.com/hosting/
Go to the 'Create a new Project' link and create your project...

Install eclipse if you haven't already (current recent version is 3.5):
http://www.eclipse.org/downloads/

Now you need to install the subclipse plugin from within eclipse..
Here are some step-by-step instructions:
http://subclipse.tigris.org/install.html

Once that's done you should be able to open your repository as a new project within eclipse.

Within the package explorer (the panel on the left if you're in the java developer perspective), right click to get the context menu and go to 'New' and 'Other...'

expand the SVN folder and select 'Checkout Projects from SVN' and select Next

Select the Create a new repository location and select Next

The URL will be:

https://[YOUR_PROJECT_NAME].googlecode.com/svn

If you don't use https:// you'll check out the repository as read only

Select (highlight) the folder to check out as an eclipse project (e.g. trunk) and select Next.

Select the check out as a project configured using the New Project Wizard and select 'Finish'

For this exercise, I'm checking mine out as a java project, so I'm selecting Java Project and Next on the wizard box.

Give the Project a name (e.g. myProject), select Finish and OK

Let it check out your project...

You should see something like myProject [trunk] in the package explorer.
You can now right click on the folder and go to New > Folder and create a new folder

When you're ready, right click on the folder you've created, go to the Team context menu and select 'Add to Version Control'; you'll probably need to do this for any new files you subsequently add...

From then, commit will add new changes and update will refresh a stale repository.

One other note: to check out the project, I used my gmail username. The svn password isn't the same as your gmail password though.

I found the password for the code repository (when logged in) here - so hopefully this will help:

http://code.google.com/hosting/settings

NB: I've seen situations where subclipse (or subversion) would keep asking for a password; I managed to stop it from doing this by going into the Eclipse > Window > Preferences, expanding the Team folder, selecting SVN and ensuring that the SVN interface was selection was set to SVNKit (Pure Java).