Monday, December 12, 2011

Table of Contents with subsections using XSL-FO

In Table of Contents using XSL-FO I explored creating table of contents using XSL-FO.

I needed to list subsections too. The way to do it is to loop through all subsections after you have listed the section in the TOC:
<xsl:for-each select="section">
<!-- Code to show TOC line for section -->
<xsl:for-each select="subsection">
<fo:block margin-left="10pt" text-align-last="justify">
<xsl:value-of select="subsectionheader" />
<fo:leader leader-pattern="dots" leader-length.maximum="100%" />
<fo:page-number-citation ref-id="{@subsectionid}" />

Notice the margin-left="10pt" which makes an indent to show that the line represents a subsection.

Also remember to add a block in the subsection with id corresponding to the @subsectionid attribute which XSL 'retrieves' from XML above.
<fo:block id="{@subsectionid}" />

If you have subsections that you dont want to list you can wrap the block above in the following code:
<xsl:if test="@subsectionid">

which checks if the 'subsection' attribute has been set in XML, if not, it enter a line in the TOC.


Friday, December 9, 2011

Java Enum from value

There are different levels of using Enums in Java. From the simplest one:
public enum Color {

to using constructor, values and methods:
public enum Color {
WHITE(21), BLACK(22), RED(23), YELLOW(24), BLUE(25);

private int code;

private Color(int c) {
code = c;

public int getCode() {
return code;

Note that the constructor can only be private or package default, to 'create' an Enum follow below:

To get an Enum from a value (e.g. after storing the value in DB) you can use valueOf() which looks up an Enum based on the given string. Or use values() to look it up directly in the array of possible values, e.g.:Color.values()[2];

Note: valueOf() may throw IllegalArgumentException so, check for that if you don't want a runtime exception.

Edit: From pk's comment and link below I discovered the correct way to use the valueOf() method is to pass the enum name, not the value. E.g. Color.valueOf("WHITE") would give the Color enum WHITE, instead of Color.valueOf("21") which would not. Thanks. :)

Code and thoughts found at:

Java abstract classes

Pretty basic stuff, but nicely explained:

In Java:
- Abstract classes have one or more abstract method.
- Cannot be instantiated, but can:
  - Have a constructor (callable from subclasses using super()).
  - Be referenced (Figure f = new Rectangle()).
- Subclasses of abstract classes (Rectangle extends Figure) must implement the abstract methods or must themselves be abstract.

Read the tutorial:

Tuesday, December 6, 2011

Table of Contents using XSL-FO

XSL-FO lets you convert XML into formatted text for use on the web of in PDFs.

A neat feature to have in you PDFs is a table of content. In your fo:root tag, after setting the 'layout-master-set' and before handling the sections of your xml:
<fo:page-sequence master-reference="A4" force-page-count="no-force">
<xsl:call-template name="header"/>
<xsl:call-template name="footer"/>
<fo:flow flow-name="xsl-region-body" font-family="Arial" font-size="10pt">
<fo:block color="white" keep-with-next.within-page="always">&#160;</fo:block>
<fo:block background-color="white" text-align="center" border="2pt solid black" font-weight="bold" font-size="12pt" keep-with-next.within-page="always">
<fo:block color="white" keep-with-next.within-page="always">&#160;</fo:block>
<xsl:for-each select="section">
<fo:block text-align-last="justify">
<xsl:value-of select="header"/>
<fo:leader leader-pattern="dots" leader-length.maximum="100%"/>
<fo:page-number-citation ref-id="{@sectionid}"/>

Remember for XSL to find the place you are linking to, you need to create a block item with id attribute of the correct section id value:
<fo:block id="{@sectionid}" />
<xsl:template match="section">
<fo:page-sequence master-reference="A4" force-page-count="no-force">
<xsl:call-template name="header"/>
<xsl:call-template name="footer"/>
<fo:flow flow-name="xsl-region-body" font-family="Arial" font-size="10pt">
<fo:block id="{@sectionid}" />
<xsl:apply-templates select="header" />
<xsl:apply-templates select="content" />
<xsl:apply-templates select="lastpage" />

NOTE: ref-id may let you select the id with or without curly brackets "{@sectionid}" or "@sectionid".

Also if you want to have a clickable link to the pages listed wrap the line in a basic-link tag:
<fo:basic-link internal-destination="{@sectionid}"></fo:basic-link>
<fo:block text-align-last="justify">
<fo:basic-link internal-destination="{@sectionid}">
<xsl:value-of select="header"/>
<fo:leader leader-pattern="dots" leader-length.maximum="100%"/>
<fo:page-number-citation ref-id="{@sectionid}"/>


Tuesday, October 4, 2011

Jquery UI Sortable Helper option

Jquery UI's sortable and droppable is great for a modular page system.

When you move modules around you see the content of each and they retain the size they had before you 'picked them up'. Sometimes you want to have a replacement draggable object instead of the original.

For this, the Sortable plugin has a 'helper' option, the example uses the value 'clone' for it, but if you want to use a different item you need to give it a function that returns a jquery object from the DOM:

$("#columncontent1, #columncontent2").sortable({
helper: function() {
return $('#draganddrophelper');

alternatively you can create a new one inside the function:

$("#columncontent1, #columncontent2").sortable({
helper: function() {
return $('<div id="dragdrophelper" style="height: 90px;"></div>');

Friday, September 23, 2011

IE8 max-height bug

The CSS tag max-height can be useful to make your divs extend to the height of the page.
IE8 doesn't understand max-height. A workaround is this hack:
div {
max-height: 1000px;
<!--[if IE 8]>
max-height: none\9;

Sources: and

Tuesday, June 28, 2011

Logging in to HTTPS websites using PHP cURL

To log in to a HTTPS website using PHP cURL you need to do the following:

enable cURL by uncommenting the line extension=php_curl.dll in your php.ini file.

Set up cURL to either accept all certificates or add the needed certificate authority to cURLs CA list (check out

Then you need to load the page to get the session cookie:
// Create temp file to store cookies
$ckfile = tempnam ("/tmp", "CURLCOOKIE");

// URL to login page
$url = "";

// Get Login page and its cookies and save cookies in the temp file
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); // Stores cookies in the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);

Now you have the cookie, you can POST login values (check the source of the login page to check if you need any other fields too)
$fields = array(
'username' => 'yourusername',
'password' => 'yourpassword',
$fields_string = '';
foreach($fields as $key=>$value) {
$fields_string .= $key . '=' . $value . '&';
rtrim($fields_string, '&');

// Post login form and follow redirects
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Tells cURL to follow redirects
$output = curl_exec($ch);

Now you should be able to access any pages within the password-restricted area by just including the cookies for each call:

$url = "";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);

Found from,,, and
Also see

Tuesday, June 21, 2011

Mount TonidoPlug as Local Drive

So you want to access your TonidoPlug USB harddrive as a native drive in Windows? Here is how:


To get NetDrive, go to for a free for non-commercial home use version. otherwise they'll try to sell it to you. :)

Instead of using the URL or Shared Location from your shares list on the TonidoPlug in the Site IP or URL field in NetDrive, just enter the base url. E.g. http://<username> .

This should open your root directory of the TonidoPlug, navigate to the USB drive. You can find it under T:\Drive_Root\media (or whatever drive letter you chose). Then you can make a shortcut directly there if you want.

Now you should no longer get the
Mounting drive T: failed
Login failed. Please check the internet connection.


Also check out if you have trouble with the username.

Thursday, May 26, 2011

SQLyog hide Query Builder and Schema Designer

When you open a new connection in SQLyog, you by default automatically get 3 tabs, the Query tab (to enter queries), Query Builder, and Schema Designer.
To prevent the Query Builder and Schema Designer tabs from opening every time you can disable them in the sqlyog.ini file.

The file can be found under C:\Users\<your username>\AppData\Roaming\SQLyog or similar in other Windows OSes. Find the lines called DefaultQueryBuilder and DefaultSchemaDesigner and change their values from 1 to 0.

SQLyog should now only open the Query tab.

(The tabs can easily be added by pressing Ctrl + K or Ctrl + Alt + D respectively or from the Powertools menu).

Wednesday, May 18, 2011

Thunderbird Ctrl+F open Quick Filter not Find in message

In Thunderbird, if you have selected a message so that it's shown below your message list (not double click to open in separate tab), pressing Ctrl + F won't give you a find box for the message. Instead, it will open the Quick Filter bar which lets you search for messages.

To get a search bar where you can search within the message text press Ctrl + F twice(!) OR press Ctrl + G.

Note: shortcut to hide the bars is escape, once for each bar.

Solution source:

Sunday, May 1, 2011

Ruby on Rails missing sqlite3.dll

I was following the official guide at on how to set up Ruby on Rails. At step 3.4 Configuring a Database I got the following error message:
"The program can't start because sqlite3.dll is missing from your computer. Try reinstalling the program to fix this problem."

After quite a lot of googling I found that the problem was that the sqlite3 gem
(installed with the bundle install in step 3.3 I believe) didn't include windows DLL. This is probably because "most Ruby developers use Linux".

The solution is to download the DLL from the official SQLite website You want the "This ZIP archive contains a DLL for the SQLite library" file. At the time of writing it is the following file:
Put the files from the ZIP file into your ruby/bin directory. Close and open a new console window and continue with the Ruby on Rails guide.

Thursday, April 14, 2011

Eclipse opens .class instead of .java

One neat feature of Eclipse (and other IDEs) is that you can hold CTRL and click on a function or variable to go to its definition.

A problem which may occur in Eclipse is that it opens the .class file (the compiled file) instead of opening the .java file when you do this. This is probably caused by the order of the entries in the .classpath file.

Go to your project directory and open the .classpath file. Move all entires of type classpathentry with attribute kind="src" to the top of the file (or at least above any entries with kind "output").

Restart Eclipse and the problem should be fixed.

Sunday, March 13, 2011

Firefox mouse pad move back in history

In firefox holding down shift and then swiping left, with two fingers, on your mouse pad will move you back in browsing history. This can be very annoying, especially if you just finished filling in a form and the hold shift and reach to the left the captialize the first letter of you name for signing (e.g. the H in Herikstad).

To disable this back action in firefox do the following:
Enter about:config into the url line.
Accept the warning.
Enter mousewheel.withshiftkey.action into the filter at the top of the page. You should get one line with the same name and the value set to 2.
Right click the line and change the value to 0.

Other values you can set for this field is:
* 0 - Scroll document by a number of lines (given by the numlines property)
* 1 - Scroll document by one page
* 2 - Move back/forward in history
* 3 - Make text larger/smaller
* 4 - Scroll document by a number of pixels (given by the numlines property)
Thanks to and for those.

Thursday, February 10, 2011

Remove 'Personal Safe' Icon from Desktop

Do you have an icon on your desktop called 'Personal Safe' that you can't get rid of?

It is part of the Protector Suite software. To remove it you must either uninstall the Protector Suite by going to Start Menu -> Control Panel -> Uninstall a program (or Add/remove programs) and then find Protector Suite and select to uninstall it.
Solution found at


Remove the icon by setting an option in the Protector Suite software. This is useful if you for example is using the Protector Suite to manage your fingerprints for logging into your computer. Go to Start Menu -> All Programs -> Protector Suite -> Control Panel (or equivalent in your language). Open Applications on the left hand menu and click Personal Safe under Encrypted Archives.
Next you will have to enter a backup password to enable the Personal Safe options. After doing so you should be able to uncheck the option Show on Desktop. Press Apply and the icon should disappear.

I am using Protector Suite 2009 so location of menu items and such might be different for you.

Wednesday, January 19, 2011

Step-by-step developing Android Apps on Nexus One in Windows 7 64-Bit

Most of this is found at

1. Download the Java JDK from Select the Java button, you don't need the Java EE.
2. Install the Java JDK.

3. Download the SDK (not the installer exe, but the zip file) from the above link. Currently you want the file.
4. Unpack the zip file to the location you want to have the SDK installed (doesn't much matter where, just remember where you put it). For example C:\Users\ which will be used here.

5. Add the ANDROID_SWT user variables:
5.1. Open start menu, enter sysdm.cpl into the text field and press enter.
5.2. In the opened window, select Advanced System Settings on the left.
5.3. Select Environment variables in the lower right corner.
5.4. Press the New button under the User variables windows (the top one).
5.5. Enter ANDROID_SWT in the variable name field and the path to the swt 64-bit SWT file into the variable value field. For example C:\Users\<YOUR USERNAME HERE>\android-sdk-windows\tools\lib\x86_64.
5.6. Press OK in all the windows to close them.

6. Download Eclipse from, you want Eclipse IDE for Java Developers for Windows 64 Bit. Unpack the eclipse folder to wherever you want to have eclipse installed. Go into the folder and drag the eclipse.exe file to your desktop or start menu while holding the SHIFT key to make a shortcut to Eclipse.

7. Follow the instructions at to install the Eclipse ADT Plugin. Here is the list from that page:
7.1. In Eclipse go to Help > Install New Software.....
7.2. Press Add in the top right hand corner.
7.3. write ADT Plugin in the name field and in the Location URL. If you get any errors, try changing from https to http.
7.4. In the Available Software dialog, select the checkbox next to Developer Tools, press Next.
7.5. In the next window, you'll see a list of the tools to be downloaded. Click Next.
7.6. Read and accept the license agreements, then click Finish.
7.7. When the installation completes, restart Eclipse.
7.8. After restaing Eclipse, go to Window > Preferences....
7.9. Select Android from the list on the left.
7.10. For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.
7.11. Click Apply, then OK.

8. Add the SDK components needed to code for Android (not just the manager which is what you downloaded):
8.1. In Eclipse select Window > Android SDK and AVD Manager.
8.2. Select Available Packages on the left.
8.3. Check the checkbox next to Android Repository to install all versions of the SDK (so you can develop for all versions of Android 1.5 - 2.3).
8.4. Click Install Selected.
8.5. Accept the licenses, press Accept All and then Install.

9. Follow to set up device (Nexus One):
9.1. Connect you Nexus One to the PC using an USB cable.
9.2. When/If Windows says it has failed to install drivers for a device, tell it you have drivers. If windows doesn't ask you for drivers go to the start menu and type devmgmt.msc into the field and press Enter. You will get a list of all your devices, find the one with a red mark and right click it. Select Update Driver Software.
9.3. Select Browse my computer for driver software.
9.4. Select Browse and select the google-usb_driver folder in the SDK folder you unpacked in step 3.

10. Turn on "USB Debugging" on the Nexus One.
10.1. press MENU, select Applications > Development, then enable USB debugging.

11. Try to see if your Nexus One is connected by opening command line (go to start menu, enter cmd and press enter). navigate to the location of your SDK and the platform-tools directory. Run adb devices or just run it directly by using the full path: C:\Users\<YOUR USERNAME HERE>\android-sdk-windows\platform-tools\adb.exe devices. You should see something like:
List of devices attached
HT9DSP500000 device

12. If you already have a project written in Eclipse open the AndroidManifest.xml file, open the Application tab at the bottom and then select true in the Debuggable drop-down box on the left.
12.1. If you do not have a project, follow to set one up.

13. To run yourIn Eclipse select Run > Run Configurations...
13.1. Select Android Application on the left and press the New icon.
13.2. Enter whatever you want in the Name field and press browse and select the project you want to run.
13.3. In the target tab. Select Manual.
13.4. Press run. In the dialog select you device and press OK.

Monday, January 10, 2011

"Recent changes" in Android Market

Been frustrated over apps updating, but not telling you about what changes they have done?
Not so big a problem anymore.
A "recent changes" section has been added in the latest release of Android Market, here's how to find it:

- Open the page for an app in Android Market.
- Scroll down to Description
- Click on More and scroll to the end of the section
- Under the title "Recently changed in this version" you'll find the latest changes.

Tuesday, January 4, 2011

TCPDF multipage table page break in multiline cell problem

I had a problem when I was creating PDFs from HTML with TCPDF. Tables spanning multiple pages which contained cells with multiple lines ended up page breaking in the middle of the cells and causing havoc with the automatically generated table header on the next page.

You might have seen other people having this problem:
And created their own class to circumvent the problem.

The fix now is as nicolaasuni says in, get the latest version of TCPDF.

Alternatively, if you can't upgrade, you can use the nobr attribute which tells TCPDF not to break in the middle of a cell or other HTML tag. Usage:
<tr nobr="true">
<td>your content here</td>

Solution found (nicolaasuni again):