/** * Creates a serializing content handler that writes to the given writer. * * @param writer serialization target * @return serializing content handler * @throws SAXException if the content handler could not be initialized */ public static DefaultHandler getSerializer(Writer writer) throws SAXException { return getSerializer(new StreamResult(writer)); }
public void startDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.startDocument(); }
checkPrefixMapping(eltUri, eltQName); for (int i = 0; i < attrs.getLength(); i++) { checkPrefixMapping(attrs.getURI(i), attrs.getQName(i)); clearMappings();
/** * Receive notification of the end of an element. * Try to restore the element qName. */ public void endElement(String eltUri, String eltLocalName, String eltQName) throws SAXException { // try to restore the qName. The map already contains the colon if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) { eltQName = this.uriToPrefixMap.get(eltUri) + eltLocalName; } super.endElement(eltUri, eltLocalName, eltQName); // JCR-1767: Generate extra prefix un-mapping calls where needed int last = addedPrefixMappings.size() - 1; List prefixes = (List) addedPrefixMappings.remove(last); if (prefixes != null) { Iterator iterator = prefixes.iterator(); while (iterator.hasNext()) { endPrefixMapping((String) iterator.next()); } } }
/** * Creates a serializing content handler that writes to the given result. * * @param result serialization target * @return serializing content handler * @throws SAXException if the content handler could not be initialized */ public static DefaultHandler getSerializer(Result result) throws SAXException { try { TransformerHandler handler = FACTORY.newTransformerHandler(); handler.setResult(result); // Specify the output properties to avoid surprises especially in // character encoding or the output method (might be html for some // documents!) Transformer transformer = handler.getTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, ENCODING); transformer.setOutputProperty(OutputKeys.INDENT, "no"); if (NEEDS_XMLNS_ATTRIBUTES) { // The serializer does not output xmlns declarations, // so we need to do it explicitly with this wrapper return new SerializingContentHandler(handler); } else { return new DefaultContentHandler(handler); } } catch (TransformerConfigurationException e) { throw new SAXException("Failed to initialize XML serializer", e); } }
checkPrefixMapping(eltUri, eltQName); for (int i = 0; i < attrs.getLength(); i++) { checkPrefixMapping(attrs.getURI(i), attrs.getQName(i)); clearMappings();
/** * Receive notification of the end of an element. * Try to restore the element qName. */ public void endElement(String eltUri, String eltLocalName, String eltQName) throws SAXException { // try to restore the qName. The map already contains the colon if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) { eltQName = this.uriToPrefixMap.get(eltUri) + eltLocalName; } super.endElement(eltUri, eltLocalName, eltQName); // JCR-1767: Generate extra prefix un-mapping calls where needed int last = addedPrefixMappings.size() - 1; List prefixes = (List) addedPrefixMappings.remove(last); if (prefixes != null) { Iterator iterator = prefixes.iterator(); while (iterator.hasNext()) { endPrefixMapping((String) iterator.next()); } } }
/** * Creates a serializing content handler that writes to the given result. * * @param result serialization target * @return serializing content handler * @throws SAXException if the content handler could not be initialized */ public static DefaultHandler getSerializer(Result result) throws SAXException { try { TransformerHandler handler = FACTORY.newTransformerHandler(); handler.setResult(result); // Specify the output properties to avoid surprises especially in // character encoding or the output method (might be html for some // documents!) Transformer transformer = handler.getTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, ENCODING); transformer.setOutputProperty(OutputKeys.INDENT, "no"); if (NEEDS_XMLNS_ATTRIBUTES) { // The serializer does not output xmlns declarations, // so we need to do it explicitly with this wrapper return new SerializingContentHandler(handler); } else { return new DefaultContentHandler(handler); } } catch (TransformerConfigurationException e) { throw new SAXException("Failed to initialize XML serializer", e); } }
startPrefixMapping(prefix, uri);
/** * Creates a serializing content handler that writes to the given writer. * * @param writer serialization target * @return serializing content handler * @throws SAXException if the content handler could not be initialized */ public static DefaultHandler getSerializer(Writer writer) throws SAXException { return getSerializer(new StreamResult(writer)); }
checkPrefixMapping(eltUri, eltQName); for (int i = 0; i < attrs.getLength(); i++) { checkPrefixMapping(attrs.getURI(i), attrs.getQName(i)); clearMappings();
public void endDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.endDocument(); }
/** * Receive notification of the end of an element. * Try to restore the element qName. */ public void endElement(String eltUri, String eltLocalName, String eltQName) throws SAXException { // try to restore the qName. The map already contains the colon if (null != eltUri && eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri)) { eltQName = this.uriToPrefixMap.get(eltUri) + eltLocalName; } super.endElement(eltUri, eltLocalName, eltQName); // JCR-1767: Generate extra prefix un-mapping calls where needed int last = addedPrefixMappings.size() - 1; List prefixes = (List) addedPrefixMappings.remove(last); if (prefixes != null) { Iterator iterator = prefixes.iterator(); while (iterator.hasNext()) { endPrefixMapping((String) iterator.next()); } } }
/** * Creates a serializing content handler that writes to the given result. * * @param result serialization target * @return serializing content handler * @throws SAXException if the content handler could not be initialized */ public static DefaultHandler getSerializer(Result result) throws SAXException { try { TransformerHandler handler = FACTORY.newTransformerHandler(); handler.setResult(result); // Specify the output properties to avoid surprises especially in // character encoding or the output method (might be html for some // documents!) Transformer transformer = handler.getTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, ENCODING); transformer.setOutputProperty(OutputKeys.INDENT, "no"); if (NEEDS_XMLNS_ATTRIBUTES) { // The serializer does not output xmlns declarations, // so we need to do it explicitly with this wrapper return new SerializingContentHandler(handler); } else { return new DefaultContentHandler(handler); } } catch (TransformerConfigurationException e) { throw new SAXException("Failed to initialize XML serializer", e); } }
/** * Creates a serializing content handler that writes to the given writer. * * @param writer serialization target * @return serializing content handler * @throws SAXException if the content handler could not be initialized */ public static DefaultHandler getSerializer(Writer writer) throws SAXException { return getSerializer(new StreamResult(writer)); }
public void endDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.endDocument(); }
/** * Creates a serializing content handler that writes to the given stream. * * @param output serialization target * @return serializing content handler * @throws SAXException if the content handler could not be initialized */ public static DefaultHandler getSerializer(OutputStream output) throws SAXException { return getSerializer(new StreamResult(output)); }
public void startDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.startDocument(); }