private void createXMLReader(XMLReader filterChain) { if (filterChain == null) { this.xmlReader = new SaxWriter(); } else { if (filterChain instanceof XMLFilter) { // Connect the filter chain to a document reader. XMLFilter filter = (XMLFilter)filterChain; while (filter.getParent() instanceof XMLFilter) { filter = (XMLFilter)(filter.getParent()); } if (!(filter.getParent() instanceof SaxWriter)) { filter.setParent(new SaxWriter()); } // Read XML data from filter chain. this.xmlReader = filterChain; } else { throw new UnsupportedOperationException(); } } this.configureXMLReader(); }
/** * Parses an XML document from a system identifier (URI). * <p> * This method is a shortcut for the common case of reading a * document from a system identifier. It is the exact * equivalent of the following:</p> * <blockquote> * <pre> * parse(new InputSource(systemId)); * </pre> * </blockquote> * <p> * If the system identifier is a URL, it must be fully resolved * by the application before it is passed to the parser.</p> * <p> * <strong>Note</strong>: As a custom SAX parser, this class * ignores the <code>systemId</code> argument of this method * and relies on the proprietary SAX property * {@link #SOURCE_OBJECT_LIST_PROPERTY}) to define the list of * objects to serialize.</p> * * @param systemId the system identifier (URI). * @throws SAXException Any SAX exception, possibly wrapping * another exception. * @see #parse(org.xml.sax.InputSource) */ public void parse(String systemId) throws SAXException { this.parse(); }
@Override protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, @Nullable LexicalHandler lexicalHandler) throws XmlMappingException { SaxWriter saxWriter = new SaxWriter(this.nameCoder); saxWriter.setContentHandler(contentHandler); doMarshal(graph, saxWriter, null); }
public void startNode(String name) { try { if (this.depth != 0) { this.flushStartTag(); } else if (includeEnclosingDocument) { this.startDocument(false); } this.elementStack.add(0, escapeXmlName(name)); this.startTagInProgress = true; this.depth++; } catch (SAXException e) { throw new StreamException(e); } }
public void endNode() { try { this.flushStartTag(); String tagName = (String) (this.elementStack.remove(0)); this.contentHandler.endElement("", tagName, tagName); this.depth--; if (this.depth == 0 && includeEnclosingDocument) { this.endDocument(false); } } catch (SAXException e) { throw new StreamException(e); } }
this.startDocument(true); for (Iterator i = source.iterator(); i.hasNext();) { xstream.marshal(i.next(), this); this.endDocument(true); } catch (StreamException e) { if (e.getCause() instanceof SAXException) {
public void addAttribute(String name, String value) { if (this.startTagInProgress) { String escapedName = escapeXmlName(name); this.attributeList.addAttribute("", escapedName, escapedName, "CDATA", value); } else { throw new StreamException(new IllegalStateException("No startElement being processed")); } }
public void setValue(String text) { try { this.flushStartTag(); int lg = text.length(); if (lg > buffer.length) { buffer = new char[lg]; } text.getChars(0, lg, buffer, 0); this.contentHandler.characters(buffer, 0, lg); } catch (SAXException e) { throw new StreamException(e); } }
public void setContentHandler(ContentHandler handler) { xstreamReader.setContentHandler(handler); }
public void startNode(String name) { try { if (this.depth != 0) { this.flushStartTag(); } else if (includeEnclosingDocument) { this.startDocument(false); } this.elementStack.add(0, escapeXmlName(name)); this.startTagInProgress = true; this.depth++; } catch (SAXException e) { throw new StreamException(e); } }
public void endNode() { try { this.flushStartTag(); String tagName = (String) (this.elementStack.remove(0)); this.contentHandler.endElement("", tagName, tagName); this.depth--; if (this.depth == 0 && includeEnclosingDocument) { this.endDocument(false); } } catch (SAXException e) { throw new StreamException(e); } }
/** * Serializes the Java objects of the configured list into a flow of SAX events. * * @throws SAXException if the configured object list is invalid or object serialization failed. */ private void parse() throws SAXException { XStream xstream = (XStream)properties.get(CONFIGURED_XSTREAM_PROPERTY); if (xstream == null) { xstream = new XStream(); } final List<?> source = (List<?>)properties.get(SOURCE_OBJECT_LIST_PROPERTY); if (source == null || source.isEmpty()) { throw new SAXException("Missing or empty source object list. Setting property \"" + SOURCE_OBJECT_LIST_PROPERTY + "\" is mandatory"); } try { startDocument(true); for (final Object name : source) { xstream.marshal(name, this); } endDocument(true); } catch (final StreamException e) { if (e.getCause() instanceof SAXException) { throw (SAXException)e.getCause(); } else { throw new SAXException(e); } } }
@Override public void addAttribute(final String name, final String value) { if (startTagInProgress) { final String escapedName = escapeXmlName(name); attributeList.addAttribute("", escapedName, escapedName, "CDATA", value); } else { throw new StreamException(new IllegalStateException("No startElement being processed")); } }
@Override public void setValue(final String text) { try { flushStartTag(); final int lg = text.length(); if (lg > buffer.length) { buffer = new char[lg]; } text.getChars(0, lg, buffer, 0); contentHandler.characters(buffer, 0, lg); } catch (final SAXException e) { throw new StreamException(e); } }
public void setContentHandler(ContentHandler handler) { xstreamReader.setContentHandler(handler); }
public void startNode(String name) { try { if (this.depth != 0) { this.flushStartTag(); } else if (includeEnclosingDocument) { this.startDocument(false); } this.elementStack.add(0, escapeXmlName(name)); this.startTagInProgress = true; this.depth++; } catch (SAXException e) { throw new StreamException(e); } }
@Initialize public void intialize() { xstreamReader = new SaxWriter(includeEnclosingDocument); }
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler) throws XmlMappingException { SaxWriter saxWriter = new SaxWriter(); saxWriter.setContentHandler(contentHandler); marshal(graph, saxWriter); }
public void endNode() { try { this.flushStartTag(); String tagName = (String) (this.elementStack.remove(0)); this.contentHandler.endElement("", tagName, tagName); this.depth--; if (this.depth == 0 && includeEnclosingDocument) { this.endDocument(false); } } catch (SAXException e) { throw new StreamException(e); } }