Freitag, 22. Oktober 2010

Fop and Fonts for FO2PDF

During XSL-FO Transformation we faced some problems in getting all the Unicode characters displayed within the generated XML file. Instead of the Lambda and Delta characters a "#" character was displayed.

To solve this problem you need to provide a Configuration for your FopFactory. Usually you can use the fop.xconf file for that. By providing the tag <auto-detect/>, which automatically tries to resolve the fonts specified within the FO file (works for FOP 0.95, in previous versions you had to manually create the font file in order to embed it into the PDF).

fopFactory.setUserConfig(createAutoDetect());

    /**
     * Creates the <auto-detect/> swtich to enable auto creation
     * of specific fonts like Arial for particular Unicode characters
     * like lambda, delta.
     *
     * Part of fop.xconf which is generated here:
     * <?xml version="1.0"?>
     *    <fop version="1.0">
     *      <renderers>
     *        <renderer mime="application/pdf">
     *          <fonts>
     *            <auto-detect/>
     *          </fonts>
     *        </renderer>
     *      </renderers>
     *    </fop>
     *
     *
     * @return auto-detection enabled
     */
    private Configuration createAutoDetect() {
        DefaultConfiguration fop = new DefaultConfiguration("fop");
       
        DefaultConfiguration renderers = new DefaultConfiguration("renderers");
        fop.addChild(renderers);
       
        DefaultConfiguration renderer = new DefaultConfiguration("renderer");
        renderer.addAttribute("mime", "application/pdf");
        renderers.addChild(renderer);
       
        DefaultConfiguration fonts = new DefaultConfiguration("fonts");
        renderer.addChild(fonts);
       
        DefaultConfiguration autoDetect = new DefaultConfiguration("auto-detect");
        fonts.addChild(autoDetect);
       
        return fop;
    }

JaxB and Unicode

If you want to marshal Unicode code characters into XML with JaxB you should use the property JAXB_ENCODING with ISO-8859-1. Otherwise the output will result in some unreadable characters.
Applying this property will convert all Unicode characters in their escaped XML representation and it will also escape all control characters like greater.

Unicode characters and their escape sequence: http://www.fileformat.info/info/unicode/char/a.htm

Some Short, Self Contained, Correct (Compilable), Example:
public class TestJaxb {
    public static void main(String[] args) throws JAXBException, IOException {
        JAXBContext jc = JAXBContext.newInstance(MyElement.class);
        Marshaller marshaller = jc.createMarshaller();
       
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
       
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "ISO-8859-1");
       
        marshaller.marshal( new MyElement("ü UMLAUT > GREATER","\u03bb LAMBDA"), System.out );
       
        marshaller.marshal( new MyElement("ü UMLAUT","\u03bb LAMBDA"), new FileOutputStream("jaxb.xml"));
    }
   
    @XmlRootElement static class MyElement {
      @XmlElement public String x;
      @XmlAttribute public String y;
      MyElement() {}
      MyElement(String x, String y) { this.x=x; this.y=y;}
    }
}

Freitag, 17. September 2010

SWT Development Tools

Some really nice and helpful tools for SWT development and debugging you can find under: http://www.eclipse.org/swt/tools.php

Sleak helps you in finding memory leaks in your SWT software. E.g.: if you forgot to free your memory. This is necessary in SWT for all classes which implement the interface Resource, like Image, Font, Color, etc.
Sleak can take a snapshot at a given time and compare it after some time with another snapshot taken.
For Sleak you need to turn on some trace options under your Run Configuration choose Tracing->org.eclipse.ui and check debug and trace/graphics.

Spy helps you by displaying all the information about certain UI components by hovering with your mouse.

By the way, you can get also the source code of these tools, we integrated this tools into a debug view with our software.

Donnerstag, 16. September 2010

Installing Instantiations Software into STS

During this week Google made its recently acquired Ajax and Java development tools as Open Source Software for all developers available. Now I want to try to install all this development tools into an installation of Spring Tools Suite (e3.6). In order to get an awesome development environment for web, desktop, UI testing and code analyzes.


WindowBuilder Pro - http://dl.google.com/eclipse/inst/d2wbpro/latest/3.6

WindowTester Pro - http://dl.google.com/eclipse/inst/windowtester/latest/3.6
CodePro AnalytiX - http://dl.google.com/eclipse/inst/codepro/latest/3.6

The installation didn't cause any problems and afterwards I tried the SwingBuilder and I was surprised that MigLayout was also available. Tomorrow I will also test CodePro and WindowTester.

Unfortunately the WindowTesterPro didn't work with STS, even in Helios I had problems testing an RCP application.

Mittwoch, 15. September 2010

Dealing with the installation of Spring IDE

After developing my first Spring DM project completely without tool support, I tried to install STS (Spring Tool Suite) into eclipse 3.6 over the update site - but couldn't succeed due to some dependencies to org.eclipse.mylyn.jira.core.

After that I tried another approach, by reading the STS Installation Instruction. I discovered, that there is a STS installer available for download: http://www.springsource.com/downloads/sts?sid=726823

I took the installer for version 2.5.0 M3 with eclipse 3.6.

The installation went through smoothly.

After that I had to install git,svn, etc. over the update site: http://download.eclipse.org/releases/helios