org.apache.felix.scrplugin.xml
Class IOUtils

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

public class IOUtils
extends java.lang.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, java.lang.String name, java.lang.Object value)
          Helper method to add an attribute.
static org.xml.sax.ContentHandler getSerializer(java.io.File file)
           
protected static void indent(org.xml.sax.ContentHandler ch, int level)
          Helper method to indent the xml elements.
protected static boolean needsNamespacesAsAttributes(java.util.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(org.xml.sax.ContentHandler ch)
          Helper method to create a new line.
static void parse(java.io.File file, org.xml.sax.ContentHandler handler)
          Parse a file and send the sax events to the content handler.
protected static void text(org.xml.sax.ContentHandler ch, java.lang.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(java.io.File file,
                               org.xml.sax.ContentHandler handler)
                        throws java.io.IOException,
                               javax.xml.transform.TransformerException
Parse a file and send the sax events to the content handler.

Parameters:
file -
handler -
Throws:
java.io.IOException
javax.xml.transform.TransformerException

getSerializer

public static org.xml.sax.ContentHandler getSerializer(java.io.File file)
                                                throws java.io.IOException,
                                                       javax.xml.transform.TransformerException
Throws:
java.io.IOException
javax.xml.transform.TransformerException

needsNamespacesAsAttributes

protected static boolean needsNamespacesAsAttributes(java.util.Properties format)
                                              throws javax.xml.transform.TransformerException,
                                                     org.xml.sax.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:
javax.xml.transform.TransformerException
org.xml.sax.SAXException

addAttribute

protected static void addAttribute(org.xml.sax.helpers.AttributesImpl ai,
                                   java.lang.String name,
                                   java.lang.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(org.xml.sax.ContentHandler ch,
                           java.lang.String text)
                    throws org.xml.sax.SAXException
Helper method writing out a string.

Parameters:
ch - The content handler.
text -
Throws:
org.xml.sax.SAXException

indent

protected static void indent(org.xml.sax.ContentHandler ch,
                             int level)
                      throws org.xml.sax.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:
org.xml.sax.SAXException

newline

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

Parameters:
ch - The content handler.
Throws:
org.xml.sax.SAXException


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.