Wednesday 2 December 2009

Java: Sorting a Map by Values

Here's a simple (TestNG) test to demonstrate getting a List of values out of a Map where you'd like the contents to be ordered by Value (not Key)

Tuesday 17 November 2009

Configuring Console 2 and bash with cygwin on Windows XP

One of my biggest issues with Windows XP has always been with cmd.exe. To make Windows XP much more enjoyable to use (from a command-line perspective), two excellent applications can be installed:

Cygwin: http://www.cygwin.com
Console 2: http://sourceforge.net/projects/console/files/

Once cygwin is set up and you've installed any other necessary applications (e.g. vim etc), open Console 2 and select Settings > Tabs. Create a new tab (e.g. "Bash") and for the Shell: input set the following:


You should now be able to use Console 2 to create new bash sessions by going to: File > New Tab > Bash

For a great file manager replacement, I'd also recommend installing KDE 4 for Windows:
http://windows.kde.org/
And using Dolphin.

Saturday 14 November 2009

Getting Google's "go" language compiler set up on OSX (Snow Leopard)

Here are my rough notes for getting google's go compiler set up on Snow Leopard (applies to any 64 bit macbook). These steps are mostly outlined on http://golang.org/doc/install.html, although there are a couple of extra steps I needed to make, which I'm listing here:

1. If you haven't already, install XCode so you have the gcc compiler:
http://developer.apple.com/technology/xcode.html

2. Install mercurial (if you don't already have it):


3. Configure your environment variables and run the setup - open the terminal and in your home directory edit .profile and add the following:

Run source .profile if you want to use those values without restarting (otherwise just close the terminal and reopen it)

4. check out go from the mercurial repository


5. run the setup:


6. Write out the obligatory hello world code (hello.go):


7. Compile, link and run:


Adapted from: http://golang.org/doc/install.html

Monday 9 November 2009

PrintScreen in Windows using a Mac keyboard...

If you want to capture the active window as a screengrab:

Shift + Ctrl + Alt and F14

is what you need.

Wednesday 4 November 2009

Get Eclipse, EGit and github all working together on OSX

I've managed to get all the pieces working for this. It's not an especially neat solution, but I should be able to give you enough information to enable you to create a project in github, install and configure EGit and then import the project.

Creating a github account

If you don't already have a github account, start here: https://github.com/signup/free

Fill in your username, email address and password (you can ignore the public key right now if you like) and hit submit to go to your dashboard.

Create ssh key and test your connection to github

These instructions are for OS X, although Linux users will probably be able to follow these instructions closely, there are instructions for all operating systems at http://help.github.com. Probably the link marked Generating SSH Keys is the place to go first.

The notes for the section below are discussed in detail at http://help.github.com/mac-key-setup/

Open the terminal and type:



The default file location will probably be something like: (/Users/%your_username%/.ssh/id_rsa) and then it will ask you for a passphrase.

To copy your key to the clipboard:



You can now go to your github accpunt page and select "add another public key" to paste your public key into the textarea.

You should now be able to confirm everything works by testing the following:



Once you've entered your passphrase, you should see a message saying something like: "You've successfully authenticated, but GitHub does not provide shell access".

Create a config file for the EGit plugin

In the terminal



and create a file called config containing the following line:



Installing EGit

I'm guessing you already have Eclipse installed at this stage;

Go to Help > Install New Software and select Add to add a new site:

Add this as the location

http://www.jgit.org/updates/

And select the Plugin, then Next, then restart when Eclipse prompts you to.

Create a github repository

On your github home page, you can now create a new repository, give it a name, fill in the details and when done, you should see your Clone URL - should look something like this:


There will be a link next to it to copy it to your clipboard.

It will also provide step-by-step instructions for you to install and configure git, check out the project and make the first commit. Once this is done, you should be able to work with the project within EGit.

At the install stage, you may need to execute the script "setup PATH for non-terminal programs.sh" by selecting Open With, Other, select Enable All Applications, then go into Utilities and select terminal. Close all instances of the terminal and reopen, you should now be able to use git from the terminal.

Import the repository into Eclipse as a project

I used this as a starting point and would highly recommend you check it out if you want a more visual walk-through of the steps involved: http://github.com/guides/using-the-egit-eclipse-plugin-with-github

Right click on the project Explorer, select Import, expand the Git folder and select Git Repository and next.

Paste your Clone URL into the First field (URI) and it should complete most other fields for you.

Change the protocol to git+ssh and do not enter anything for the Authentication section (leave the User pre-filled as "git").

If everything is set up properly, you should get a prompt for a password - this is your passphrase from the earlier stage.

It should now locate the master branch you created when you followed the "Next Steps" section. Select it if you need to, then select Next. As there are no eclipse files in the project, uncheck "import projects after clone" and Finish.

Right click on the Project Explorer, New > General > Project, give it the same name as your repository. It should "create" your project in the Project Explorer (you should now see the README you created and committed).

Right click on your project folder in the Project Explorer, select "Team" and "Share Project". Select Git as the repository type and then next. Highlight your project and select Finish.

You should now be able to open the README in eclipse, make a change, save it and commit your changes.


Other related reading:
http://support.github.com/discussions/accounts/23-egit-github-auth-fail

Sunday 1 November 2009

VirtualBox - Changing the UUID of a .vdi file

Open the terminal, and:

Friday 2 October 2009

JQuery Example: Search and replace on a specific html attribute value

This snippet can be used to query for an element with a specific attribute value and replace that value. In the example below (for shadowbox), a rel attribute was set with "player=flv".

We were using swfobject to detect for the presence of a flash player [(swfobject.hasFlashPlayerVersion("8"))] in the event of flash player not being installed and javascript being enabled, I needed to be able to rewrite the rel attributes to get shadowbox to use a different player. This JQuery example worked nicely by allowing us to query the DOM for all anchor elements containing rel attributes which contained "flv" - and to replace all instances of "flv" with "qt":

Tuesday 29 September 2009

JQuery Example: Hiding alt attribute tooltips in Internet Explorer

Snippet to hide alt tooltips using Javascript:

JQuery Example: Showing and hiding form elements based on user input

Here's a quick example of how something close to XForm relevancy binding can be achieved using an html form and JQuery:

Thursday 24 September 2009

Daisy CMS - Javascript Document Task for setting all draft content to "PUBLISH"

Once you have your query, as an administrator, create a document task and use this to publish everything:

Tuesday 1 September 2009

Java note: Traversing a Map

I use this snippet quite a bit:



Here's the JSTL way:

Tuesday 18 August 2009

JSF - panelGrid syntax

If you have a list of items and you want to display them in a grid structure (e.g. a table), here's an example of usage for the h:panelGrid for a 4-column layout:

Wednesday 5 August 2009

Java Reflections API (example)

Looping through Objects in a list, checking whether each Object contains a method called getId(). If so, invoke the method and show the result:

Tuesday 4 August 2009

Glassfish and Eclipse : Cutting down the number of "out of PermGen space" errors

We've run into an issue where making and re-deploying several changes to a webapp on glassfish causes PermGen space errors. This behaviour has been observed when using the glassfish adapter in Eclipse whilst working on a JSF(1.2) application.

For a quick fix, edit your domains\{domain-name}\config\domain.xml and look for a line specifying the -XX:MaxPermSize. Try upping the value somewhat:

Tuesday 23 June 2009

Daisy CMS - connecting a JMS listener to the repository

The following information may be useful for anyone wanting to write an application that connects to the Daisy repository using a JMS connection. The port is tcp://[your_name_or_ip]:61616 and the username and password can be found in $DAISY_HOME/daisydata/conf/myconfig.xml

Look for this:


And the username and password are listed as attributes in the credentials element

Daisy CMS - customising the footer of the editor pages.

Brief note:

$DAISY_HOME/daisywiki/webapp/daisy/resources/xml/documenteditor.xml contains all the formatting logic for the footer of the editor page(s).

Search for: (about 2/3 down the file)

Monday 22 June 2009

Daisy CMS - allowing attributes in the SimpleDocument Editor

We had noticed that when using the SimpleDocument Editor in Daisy, although attributes can be added freehand (using the html view), there was a process that seemed to be running after save that removed many attributes.

I have since discovered that editing $DAISY_HOME/dasiywiki/webapp/daisy/resources/conf/htmlcleaner.xml will allow for modifications to be made to these "cleaning" rules. For example: we wanted to be able to write out 'a' tags with class attributes within the editor. This change was made possible by editing htmlcleaner and making the following adjustments (for example):

JSF - ensuring your [xhtml] pages load with a text/html contentType

We were having a problem with Safari and Chrome rendering our JSF pages; all the content was available, but for some reason they refused to load any of the external links to stylesheets, javascript etc. They also refused to render any markup; in fact, all they would show was all the page "content" in the default text.

Further investigation (using fiddler) made it apparent that the pages were being served with the "application/xhtml+xml" when our page templates all had an html 4.01 strict doctype. This caused the WebKit browsers to ignore any links to external assets while Firefox and IE seemed to render the page as expected.

We discovered that creating templates that looked like (where the contentType is specified inside the f:view tag as early as possible) seemed to solve the issue:

Sunday 21 June 2009

Eclipse Galileo (3.5): Creating and running a JSF Project

These notes follow on from my previous posting regarding getting Eclipse Galileo and glassfish v3 configured on OSX

In this post, I'm going to quickly outline the necessary steps for getting a very simple JSF project running within Galileo.

First, you'll need to download Mojarra and unpack it somewhere.

Go to the Java EE perspective and create a new project to get the "New Project" wizard to appear. Expand out "Web" and select "Dynamic Web Project". Give the project a name.

The "Target Runtime" should be GlassFish v3 Prelude, The Dynamic web module version should be 2.5 and select JavaServer Faces v1.2 Project as your configuration option.

Choose "Next" for the Source folders option and "Next" for the Web Module settings.

For the JSF Implementation Library settings, click on the "Manage Libraries" link (it's the icon on the right, just below the "Type" dropdown list), Select "New", create a name (e.g. "Mojarra") and check the System Library checkbox. Select OK and then highlight the library you just created and select "Add JARs". Navigate to the folder where you unpacked Mojarra and go to its lib folder. Select both jsf-impl.jar and jsf-api.jar and then select "Open".

Both JARs should be visible under the library you created. Select "OK" and now check the library you just created and select "Finish". You should now be ready to start coding.

To create a simple JSF example project:

1. Right-click on your Java Resources:src folder and select New > Other. Expand out "General" and select "File" and select "Next". If it asks you to select a "parent folder", just select the src folder for the project you just created. The file should be called messages.properties. In that file, add a line: greeting=JSF is working and save the file.

2. in WebContent/WEB-INF/web.xml, find the <servlet-mapping> and make sure it looks like this:



3. Right-click on WebContent and select "New" and "JSP". Name it "index.jsp". You should have a basic html template page.

In the body of the template, paste in:



4. Create a folder called "faces" under "WebContent"

5. Create a New JSP file inside the "faces" folder. Call it greeting.jsp (note the file extension is jsp, *not* jsf)

Below the doctype of greeting.jsp, paste in:



And in between the body tags, paste in:


Right-click on the project and select Run As > Run on Server. Ensure you're running it on GlassFish Prelude v3 (if you are working from my previous post). You should now be able to go to localhost:8080/%the_name_of_your_project% and you should see the message from the config file: "JSF is working".

The project can be found here: http://jsf-examples.googlecode.com/files/jsf-greeting.zip if anyone wants to check out the folder structure

Saturday 20 June 2009

Using Eclipse Galileo to develop JSF applications on Glassfish (OS X)

These are rough notes for getting Eclipse Galileo (3.5) and GlassFish 3 Prelude to work together for deploying and developing JSF applications. I've encountered a few issues still with both of these things but am pleased to say that once you're up and running, you can be very productive, so it's worth taking the steps to get the environment set up.

If you're happy using a build of Ganymede (3.4), I'd recommend installing the Glassfish bundle instead: http://download.java.net/glassfish/eclipse/


I'm working on the premise that the user has the JDK1.6 already installed in OSX - to confirm this, you can check for the presence of this folder: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

I'm also writing these notes before Galileo is released (should be released 4 days from time of writing)

Here are the steps required:

1. Go to http://www.eclipse.org/downloads/ and select the "Development Builds" tab. Download the Eclipse IDE for Java EE Developers (188 MB) and I'd recommend getting the one for Mac OS X (Cocoa).

2. Download Glassfish Prelude from here: http://download.java.net/glassfish/v3-preview/release/glassfish-v3-web-preview-unix.sh. You'll probably need to run it from the command line (chmod a+x glassfish-v3-web-preview-unix.sh followed by ./glassfish-v3-web-preview-unix.sh)

3. Once the glassfish installer has completed, start Eclipse and confirm that you have a Java 1.6 JDK registered. To do this, go to Eclipse > Preferences > Java > Installed JREs. If you can't see anything that says something like "JVM 1.6.0" select "Add..." and choose MacOS X VM then Next.

The JRE Home should be /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

And the choice of name is up to you.

4. Next you will need to install the GlassFish adapter. Go to Help > Install new Software. Select "Add" and add this location: https://ajax.dev.java.net/eclipse. Once that's done, you should see an option for "Glassfish Java EE5 and Java EE6 support". Select that and Next or Finish. Eclipse will require a restart.

5. To add the GlassFish server, first ensure you're in the Java EE perspective and locate the tab marked "Servers", right click, select New > Server. Open out the GlassFish options and select GlassFish v3 Prelude.

For the JRE, make sure you're choosing the 1.6.0 JVM and your application directory should be something like: /Users/%yourusername%/glassfishv3/glassfish. I had to select Install Server too.

6. Once that's completed, you can highlight the listed server and hit the green start button. A brief visit to localhost:8080 should confirm this.

I've posted up a simple jsf example project here: http://jsf-examples.googlecode.com/files/simple-jsf-example.zip if you'd like to test your GlassFish installation, import it into eclipse and right-click and Run as > Run on Server and select your recently created instance of GlassFish v3 Prelude

Wednesday 17 June 2009

SVN Web view - looking at older revisions

Quick comment here:

Adding something like this:

/!svn/bc/123/

Into your browser in between the repository name and location will allow you to view older revisions of project code (e.g. this should show revision 123)

http://your.ip.address/svn/repositoryname/!svn/bc/123/projectname

Tuesday 16 June 2009

Notes on setting up mod_proxy on apache 2.2 for proxying a servlet container (like glassfish)

Just wanted to make these notes before I forget - the aim here was to create a vhost (or potentially several vhosts) which map to different projects hosted on (some kind) of servlet container like glassfish:

1. Install or upgrade to the latest version of Apache http server (Apache 2.2)
2. edit your hosts file (C:\WINDOWS\system32\drivers\etc) to add the name for whatever you need to proxy (as per usual vhost settings):



3. edit httpd.conf (For Windows, it should be in C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf):

ensure both

Are uncommented in order for proxying to work correctly.

Also ensure the httpd-vhosts.conf include is being "Included" by uncommenting:



4. edit C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf

Delete (or uncomment) any of the default install stuff in there... If you're using a different folder, you'll have to configure the permissions (OSX):

# This block sets the permissions for apache (n.b. these differ from the OS file permissions)


# setting localhost's "starting point"; in this case, it's my workspace folder, so I can see all my projects


#setting the rewrite / proxy rules for your hostname


Restart apache and mod_proxy should be working.

Tuesday 9 June 2009

Addressing stability issues when running Eclipse 3.5 on JDK1.6 in OSX

Since running Eclipse Galileo (3.5), I've had problems with Eclipse frequently quitting out - this was happening so regularly it was almost unusable.

There was an issue with DataTreeNode in the error report; if this sounds familiar to you, try adding this to eclipse.ini:



The workaround has been outlined in this bug posting:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=214092

Friday 5 June 2009

Forcing glassfish 2.1 to start-up with JDK1.6 (OSX)

We were having a problem where we were trying to deploy a webapp on glassfish 2.1; the app itself was compiled with Java 1.6 and glassfish was being launched with Java 1.5. It should be noted that in this case we were trying to launch glassfish from within IntelliJ IDEA.

If you're having the same problem, go into your {glassfish home}/config/asenv.conf and check to see whether this value is pointing to an earlier version of the JDK. It should be:

Hope this helps someone

Wednesday 27 May 2009

ColdFusion (JRun) and JNDI mapping for JDBC and Mail Sessions

We have a situation where we're working on a ColdFusion project that will be deployed on glassfish (in production). Glassfish will use JNDI to manage all the connections to external resources (namely the databases and the mail server).

By default, ColdFusion ships with its own J2EE container (JRun) - so as the project began to take shape, we wanted to be able to create similar JNDI bindings within JRun - so we could closely mimic how the application would behave when deployed on glassfish.

I think I'm being fair saying the documentation for ColdFusion's JRun config files isn't exactly what you'd call the most comprehensive, so here's a rough list of the steps we took to set up JNDI mappings in ColdFusion for a JDBC[JNDI] datasource and for a mail server and what was required to get it all working:

Configuring ColdFusion to work with a JDBC datasource

1. Get the relevant Java JDBC driver for the database you're trying to use (for example, MS SQL Server would use sqljdbc4.jar) and put that jar into your Coldfusion lib folder (e.g. ColdFusion8/lib)

2. In the jrun-web.xml (/Applications/ColdFusion8/wwwroot/WEB-INF/jrun-web.xml), you need to declare the JNDI bindings before you can configure them, so the last few lines of your xml document should look like this:



N.B. make sure this is just above the closing tag (</jrun-web-app>)

3. In your jrun-resources.xml (/Applications/ColdFusion8/runtime/servers/coldfusion/SERVER-INF/jrun-resources.xml)



N.B. This should be just before the closing tag (</jrun-resources>)

An important note here should be that there should be a match between the names in the two files on:
<jndi-name>your-jndi-db-ref-name</jndi-name>
and
<jndi-name>your-jndi-db-ref-name</jndi-name>
respectively.

This should complete the binding for Coldfusion/JRun - restart ColdFusion and you should be good to go.

Configuring ColdFusion to work with a MailServer via JNDI

1. In the jrun-web.xml:



2. In your jrun-resources.xml:



As before, restart ColdFusion to test whether these changes worked.

Useful References:
http://www.adobe.com/support/jrun/working_jrun/jrun4_jndi_and_j2ee_enc/jrun4_jndi_and_j2ee_enc03.html
http://livedocs.adobe.com/jrun/4/descriptordocs/jrun-resources/jrun-resources.htm

Tuesday 5 May 2009

Daisy CMS - Notes on updating Links as part of a Document Task

This needs to be expanded upon, but:



Works in Java... -1, -1 args seem to work for ensuring proper linkage between variant and branch ids


But if you're creating a Document Task using Javascript, get your document using:



This updates a load of link fields with the id of the specified linked Document (by Id).

Ref: http://www.nabble.com/Programmatically-create-a-link-%28VariantKey%29-td7687320.html#a7687320

Monday 20 April 2009

XSLT, text-transform:captialize and Excel workbooks

Quick note on parsing an Excel Workbook using XSLT. In this case, there was a requirement to transform a column of upper-case city names into capitalized city names in much the same style as using the text-transform:capitalize css property:

(This example put together with some significant guidance from this link: http://www.biglist.com/lists/xsl-list/archives/200509/msg00542.html)

Source XML document:


XSL Stylesheet:

Structure for Regular Expressions in Javascript

Quick note on using Javascript to perform basic RegExp pattern matching - it had been a while since I last tried to do this and I spent some time trying to recall everything. Listed is a (hopefully) functional example demonstrating "trimming" the first part of a URL so only the path is returned - while also serving as a reminder for the syntax:

Wednesday 8 April 2009

SQL Server : Granting EXEC on Stored Procedures

Syntax for this is:

Sunday 5 April 2009

Eclipse : Save Actions for autoformatting code and updating imports

If you want Eclipse to automatically tidy up your list of import statements and indent your code each time you save:

1. Open Preferences

2. Go to Java > Editor > Save Actions

Select (tick) Perform the selected actions on save and choose "Format Source Code", "Organize imports" and [any] "Additional actions"

Eclipse : Display heap status (like IntelliJ IDEA)

If you want to keep track of the heap status for eclipse (like IntelliJ IDEA does), go to Preferences then to General and tick "Show heap Status".

Eclipse : Display Java Type Indicator for classes

One of the many things I liked about IntelliJ IDEA was the fact that the Project pane would show whether a class was an interface or not. I'd been trying to find out whether Eclipse could do the same thing and it can:

1. Open the Preferences panel

2. Tick the checkbox at: General > Appearance > Label Decorations/Java Type Indicator

When you return to your project view in the package explorer, you should see a purple (I) icon next to your interfaces.

Friday 20 February 2009

XCode - iPhone SDK - CoreGraphics Library issue

If you're creating an iPhone app and want to use the CoreGraphics framework (and you're having trouble finding it anywhere), it seems to be located in:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/System/Library/Frameworks/CoreGraphics.framework
(See: http://forums.pragprog.com/forums/83/topics/1032)

You can also try this (and check to make sure it's set as a target):

- expand Targets in Xcode
- double click on you app
- select general tab
- in the bottom left corner click "+"
- scroll through the list and select "CoreGraphics.framework"

(See: http://www.iphonedevsdk.com/forum/iphone-sdk-development/2981-error-i-am-having-xcode.html)

If you're getting build errors that start with _GG, try:

1) XCode Menu: ->Project -> Edit Active Target
2) Select Build Tab
3) Find "Framework Search Paths" under Search Paths section
4) Double Click to Edit
5) Delete all lines.
6) Rebuild Project

(See: http://discussions.apple.com/message.jspa?messageID=7428822)

This fix worked for me.

Wednesday 18 February 2009

Merging SVN Repositories using svn-merge-repos.pl

Note on syntax for svn-merge-repos.pl:

Deleting .svn folders from a project

Useful tip(s):



Thanks to: http://antcooper.com/2007/11/21/remove-hidden-svn-folders/ for the original posting on this



Thanks to: http://www.techiecorner.com/154/how-to-delete-all-svn-folder-in-linux-mac/

Friday 6 February 2009

FlexUnit and IntelliJ

Here are my notes regarding creating a flex project in IntelliJ and configuring it to work with FlexUnit:

- Create a new Flex project, give it a name and uncheck 'create html wrapper' and 'Create HelloWorld form'

- Create a bin folder in your project and place FlexUnit.swc in /bin

- Go to module settings > Modules > Dependencies and select 'Add' (I opted for Single-Entry Module Library). Browse to the FlexUnit.swc in the bin folder and check the 'Export' checkbox when it appears in the list.

compiler-config.xml should look like this:




And in the /src folder, you'll need to create a file called TestRunner.mxml:




Right click and Run (or use Shift + F10). If all is good, you should see an empty FlexUnit shell.

Friday 23 January 2009

Flash Player - Output all trace statements to a log file (OSX).

to enable trace to log file:



In this folder, edit a file called mm.cfg (you will probably need to create it).


This file should contain:





or



to add some colour.

Blog Archive