org.apache.felix.scrplugin.xml
Class IOUtils

java.lang.Object
  extended by org.apache.felix.scrplugin.xml.IOUtils

public class IOUtils
extends Object

Utility class for xml/sax handling. It provides support for "older" sax implementations (like the default one shipped with JDK 1.4.2) which have bugs in the namespace handling.


Nested Class Summary
static class IOUtils.NamespaceAsAttributes
          A pipe that ensures that all namespace prefixes are also present as 'xmlns:' attributes.
 
Constructor Summary
IOUtils()
           
 
Method Summary
protected static void addAttribute(org.xml.sax.helpers.AttributesImpl ai, String name, Object value)
          Helper method to add an attribute.
static ContentHandler getSerializer(File file)
           
protected static void indent(ContentHandler ch, int level)
          Helper method to indent the xml elements.
protected static boolean needsNamespacesAsAttributes(Properties format)
          Checks if the used Trax implementation correctly handles namespaces set using startPrefixMapping(), but wants them also as 'xmlns:' attributes.
protected static void newline(ContentHandler ch)
          Helper method to create a new line.
static void parse(InputStream file, ContentHandler handler)
          Parse a file and send the sax events to the content handler.
protected static void text(ContentHandler ch, String text)
          Helper method writing out a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOUtils

public IOUtils()
Method Detail

parse

public static final void parse(InputStream file,
                               ContentHandler handler)
                        throws TransformerException
Parse a file and send the sax events to the content handler.

Parameters:
file -
handler -
Throws:
TransformerException

getSerializer

public static ContentHandler getSerializer(File file)
                                    throws IOException,
                                           TransformerException
Throws:
IOException
TransformerException

needsNamespacesAsAttributes

protected static boolean needsNamespacesAsAttributes(Properties format)
                                              throws TransformerException,
                                                     SAXException
Checks if the used Trax implementation correctly handles namespaces set using startPrefixMapping(), but wants them also as 'xmlns:' attributes.

The check consists in sending SAX events representing a minimal namespaced document with namespaces defined only with calls to startPrefixMapping (no xmlns:xxx attributes) and check if they are present in the resulting text.

Throws:
TransformerException
SAXException

addAttribute

protected static void addAttribute(org.xml.sax.helpers.AttributesImpl ai,
                                   String name,
                                   Object value)
Helper method to add an attribute. This implementation adds a new attribute with the given name and value. Before adding the value is checked for non-null.

Parameters:
ai - The attributes impl receiving the additional attribute.
name - The name of the attribute.
value - The value of the attribute.

text

protected static void text(ContentHandler ch,
                           String text)
                    throws SAXException
Helper method writing out a string.

Parameters:
ch - The content handler.
text -
Throws:
SAXException

indent

protected static void indent(ContentHandler ch,
                             int level)
                      throws SAXException
Helper method to indent the xml elements. Each level is indented with four spaces.

Parameters:
ch - The content handler.
level - The level of indention.
Throws:
SAXException

newline

protected static void newline(ContentHandler ch)
                       throws SAXException
Helper method to create a new line.

Parameters:
ch - The content handler.
Throws:
SAXException


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.