public void endDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.endDocument(); }
/** * End the scope of a prefix-URI mapping: * remove entry from mapping tables. */ public void endPrefixMapping(String prefix) throws SAXException { // remove mappings for xalan-bug-workaround. // Unfortunately, we're not passed the uri, but the prefix here, // so we need to maintain maps in both directions. if (this.prefixToUriMap.containsKey(prefix)) { this.uriToPrefixMap.remove(this.prefixToUriMap.get(prefix)); this.prefixToUriMap.remove(prefix); } if (hasMappings) { // most of the time, start/endPrefixMapping calls have an element event between them, // which will clear the hasMapping flag and so this code will only be executed in the // rather rare occasion when there are start/endPrefixMapping calls with no element // event in between. If we wouldn't remove the items from the prefixList and uriList here, // the namespace would be incorrectly declared on the next element following the // endPrefixMapping call. int pos = prefixList.lastIndexOf(prefix); if (pos != -1) { prefixList.remove(pos); uriList.remove(pos); } } super.endPrefixMapping(prefix); }
public void startDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.startDocument(); }
/** * 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()); } } }
/** * Track mappings to be able to add <code>xmlns:</code> attributes * in <code>startElement()</code>. */ public void startPrefixMapping(String prefix, String uri) throws SAXException { // Store the mappings to reconstitute xmlns:attributes // except prefixes starting with "xml": these are reserved // VG: (uri != null) fixes NPE in startElement if (uri != null && !prefix.startsWith("xml")) { this.hasMappings = true; this.prefixList.add(prefix); this.uriList.add(uri); // append the prefix colon now, in order to save concatenations later, but // only for non-empty prefixes. if (prefix.length() > 0) { this.uriToPrefixMap.put(uri, prefix + ":"); } else { this.uriToPrefixMap.put(uri, prefix); } this.prefixToUriMap.put(prefix, uri); } super.startPrefixMapping(prefix, uri); }
/** * 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); } }
super.startElement(eltUri, eltLocalName, eltQName, newAttrs == null ? attrs : newAttrs); } else { super.startElement(eltUri, eltLocalName, eltQName, attrs);
/** * 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()); } } }
/** * Track mappings to be able to add <code>xmlns:</code> attributes * in <code>startElement()</code>. */ public void startPrefixMapping(String prefix, String uri) throws SAXException { // Store the mappings to reconstitute xmlns:attributes // except prefixes starting with "xml": these are reserved // VG: (uri != null) fixes NPE in startElement if (uri != null && !prefix.startsWith("xml")) { this.hasMappings = true; this.prefixList.add(prefix); this.uriList.add(uri); // append the prefix colon now, in order to save concatenations later, but // only for non-empty prefixes. if (prefix.length() > 0) { this.uriToPrefixMap.put(uri, prefix + ":"); } else { this.uriToPrefixMap.put(uri, prefix); } this.prefixToUriMap.put(prefix, uri); } super.startPrefixMapping(prefix, uri); }
/** * 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); } }
super.startElement(eltUri, eltLocalName, eltQName, newAttrs == null ? attrs : newAttrs); } else { super.startElement(eltUri, eltLocalName, eltQName, attrs);
public void endDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.endDocument(); }
public void startDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.startDocument(); }
/** * 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()); } } }
/** * Track mappings to be able to add <code>xmlns:</code> attributes * in <code>startElement()</code>. */ public void startPrefixMapping(String prefix, String uri) throws SAXException { // Store the mappings to reconstitute xmlns:attributes // except prefixes starting with "xml": these are reserved // VG: (uri != null) fixes NPE in startElement if (uri != null && !prefix.startsWith("xml")) { this.hasMappings = true; this.prefixList.add(prefix); this.uriList.add(uri); // append the prefix colon now, in order to save concatenations later, but // only for non-empty prefixes. if (prefix.length() > 0) { this.uriToPrefixMap.put(uri, prefix + ":"); } else { this.uriToPrefixMap.put(uri, prefix); } this.prefixToUriMap.put(prefix, uri); } super.startPrefixMapping(prefix, uri); }
/** * End the scope of a prefix-URI mapping: * remove entry from mapping tables. */ public void endPrefixMapping(String prefix) throws SAXException { // remove mappings for xalan-bug-workaround. // Unfortunately, we're not passed the uri, but the prefix here, // so we need to maintain maps in both directions. if (this.prefixToUriMap.containsKey(prefix)) { this.uriToPrefixMap.remove(this.prefixToUriMap.get(prefix)); this.prefixToUriMap.remove(prefix); } if (hasMappings) { // most of the time, start/endPrefixMapping calls have an element event between them, // which will clear the hasMapping flag and so this code will only be executed in the // rather rare occasion when there are start/endPrefixMapping calls with no element // event in between. If we wouldn't remove the items from the prefixList and uriList here, // the namespace would be incorrectly declared on the next element following the // endPrefixMapping call. int pos = prefixList.lastIndexOf(prefix); if (pos != -1) { prefixList.remove(pos); uriList.remove(pos); } } super.endPrefixMapping(prefix); }
/** * 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); } }
super.startElement(eltUri, eltLocalName, eltQName, newAttrs == null ? attrs : newAttrs); } else { super.startElement(eltUri, eltLocalName, eltQName, attrs);
public void endDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.endDocument(); }
public void startDocument() throws SAXException { // Cleanup this.uriToPrefixMap.clear(); this.prefixToUriMap.clear(); clearMappings(); super.startDocument(); }