Beispiel #1
0
 /** Convert an Object to a String and generate SAX characters events. */
 public static void objectToCharacters(Object o, ContentHandler contentHandler) {
   try {
     char[] charValue = (o == null) ? null : o.toString().toCharArray();
     if (charValue != null) contentHandler.characters(charValue, 0, charValue.length);
   } catch (Exception e) {
     throw new OXFException(e);
   }
 }
Beispiel #2
0
 /**
  * Read characters from a Reader and generate SAX characters events.
  *
  * <p>The caller has to close the Reader if needed.
  */
 public static void readerToCharacters(Reader reader, ContentHandler contentHandler) {
   try {
     // Work with buffered Reader
     reader = new BufferedReader(reader);
     // Read and write in chunks
     char[] buf = new char[1024];
     int count;
     while ((count = reader.read(buf)) != -1) contentHandler.characters(buf, 0, count);
   } catch (Exception e) {
     throw new OXFException(e);
   }
 }
Beispiel #3
0
 public static void streamNullDocument(ContentHandler contentHandler) throws SAXException {
   contentHandler.startDocument();
   contentHandler.startPrefixMapping(XMLConstants.XSI_PREFIX, XMLConstants.XSI_URI);
   final AttributesImpl attributes = new AttributesImpl();
   attributes.addAttribute(XMLConstants.XSI_URI, "nil", "xsi:nil", "CDATA", "true");
   contentHandler.startElement("", "null", "null", attributes);
   contentHandler.endElement("", "null", "null");
   contentHandler.endPrefixMapping(XMLConstants.XSI_PREFIX);
   contentHandler.endDocument();
 }