John Cato

All | General | Java
XML
20080417 Thursday April 17, 2008
Data Visualization and Processing

I've been interested in data visualization for a long time now, probably because I have backgrounds in both programming and art. After a quick look at the kind of output that the language Processing can create, I think that it's got to go on my lengthening to do list.

Posted by jcato Apr 17 2008, 07:58:52 AM EDT
20080331 Monday March 31, 2008
Good article about character encodings.

I hate blogs that are just links to other blogs, but here's an article about character encodings that everyone should take a look at if you don't have a good understanding of how they work.

http://www.joelonsoftware.com/articles/Unicode.html

Posted by jcato Mar 31 2008, 08:39:47 AM EST
20080124 Thursday January 24, 2008
XIncludes using Java OK, this isn't a lot of code, but seriously, it took two days to write. The documentation on how to do an XSL style XInclude in Java is pretty much non existent. I've added a maven plugin that wraps this to our maven plugins project as well to replace Ant targets that use <xcluder> tags.

public class XIncluder implements EntityResolver
{
    private File inFile;
    private File outFile;

    public XIncluder(File in, File out)
    {
        this.inFile = in;
        this.outFile = out;
    }
	
    public void processFiles() throws
        IOException, 
        ParserConfigurationException, 
        TransformerException, 
        SAXException
    {
        if (outFile.exists())
        {
            outFile.delete();
        }
        outFile.createNewFile();

        SAXParserFactory saxFactory = SAXParserFactory.newInstance();
        saxFactory.setNamespaceAware(true);
        saxFactory.setXIncludeAware(true);

        XMLReader reader = saxFactory.newSAXParser().getXMLReader();
        reader.setEntityResolver(this);

        SAXSource source = new SAXSource(reader,new InputSource(
                new FileInputStream(inFile)));

        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.transform(source, new StreamResult(outFile));
    }

    public InputSource resolveEntity(String publicId, String systemId)
    {
        try
        {
            return new InputSource(new FileInputStream(new File(systemId)));
        }
        catch (FileNotFoundException e)
        {
            return null;
        }
    }
	
}
Posted by jcato Jan 24 2008, 01:18:07 PM EST