private void initSerializer(XMLSerializer ser) { ser.fNSBinder = new NamespaceSupport(); ser.fLocalNSBinder = new NamespaceSupport(); ser.fSymbolTable = new SymbolTable(); }
public boolean reset() { super.reset(); if (fNSBinder != null){ fNSBinder.reset(); // during serialization always have a mapping to empty string // so we assume there is a declaration. fNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); } return true; }
public String getPrefix(String uri) { return fNamespaceContext.getPrefix(uri); }
public String getURI(String prefix) { String uri = fNamespaceContext.getURI(prefix); if (uri == null) { if (!fDOMContextBuilt) { fillNamespaceContext(); fDOMContextBuilt = true; } if (fNamespaceSize > 0 && !fNamespaceContext.containsPrefix(prefix)) { uri = getURI0(prefix); } } return uri; }
/** * Constructs a namespace context object and initializes it with * the prefixes declared in the specified context. */ public NamespaceSupport(NamespaceContext context) { pushContext(); // copy declaration in the context Enumeration prefixes = context.getAllPrefixes(); while (prefixes.hasMoreElements()){ String prefix = (String)prefixes.nextElement(); String uri = context.getURI(prefix); declarePrefix(prefix, uri); } } // <init>(NamespaceContext)
fLocalNSBinder.reset(); fNSBinder.pushContext(); fNSBinder.declarePrefix(localpart, value); } else { fNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, value); continue; prefix = (prefix == null || prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); if (fNSBinder.getURI(prefix) == uri) { fLocalNSBinder.declarePrefix(prefix, uri); fNSBinder.declarePrefix(prefix, uri); uri = fNSBinder.getURI(XMLSymbols.EMPTY_STRING); fLocalNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); fNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); localpart = fSymbolTable.addSymbol( attr.getLocalName()); if (prefix == XMLSymbols.PREFIX_XMLNS) { //xmlns:prefix localUri = fLocalNSBinder.getURI(localpart); // local prefix mapping value = fSymbolTable.addSymbol(value); if (value.length() != 0 ) { fLocalNSBinder.declarePrefix(localpart, value);
/** * @see org.apache.xerces.xni.NamespaceContext#getPrefix(String) */ public String getPrefix(String uri) { // find uri in current context for (int i = fNamespaceSize; i > 0; i -= 2) { if (fNamespace[i - 1] == uri) { if (getURI(fNamespace[i - 2]) == uri) return fNamespace[i - 2]; } } // uri not found return null; } // getPrefix(String):String
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { if (fNeedPushNSContext) { fNamespaceContext.pushContext(); } fNeedPushNSContext = true; // Fill element QName and XMLAttributes fillQName(fElementQName, uri, localName, qName); fillXMLAttributes(atts); // Add namespace declarations if necessary if (!fNamespacePrefixes) { final int prefixCount = fNamespaceContext.getDeclaredPrefixCount(); if (prefixCount > 0) { addNamespaceDeclarations(prefixCount); } } try { fSchemaDOMParser.startElement(fElementQName, fAttributes, null); } catch (XMLParseException e) { convertToSAXParseException(e); } catch (XNIException e) { convertToSAXException(e); } }
private void addNamespaceDeclarations(final int prefixCount) { String prefix = null; String localpart = null; String rawname = null; String nsPrefix = null; String nsURI = null; for (int i = 0; i < prefixCount; ++i) { nsPrefix = fNamespaceContext.getDeclaredPrefixAt(i); nsURI = fNamespaceContext.getURI(nsPrefix); if (nsPrefix.length() > 0) { prefix = XMLSymbols.PREFIX_XMLNS; localpart = nsPrefix; fStringBuffer.clear(); fStringBuffer.append(prefix); fStringBuffer.append(':'); fStringBuffer.append(localpart); rawname = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length); } else { prefix = XMLSymbols.EMPTY_STRING; localpart = XMLSymbols.PREFIX_XMLNS; rawname = XMLSymbols.PREFIX_XMLNS; } fAttributeQName.setValues(prefix, localpart, rawname, NamespaceContext.XMLNS_URI); fAttributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol, (nsURI != null) ? nsURI : XMLSymbols.EMPTY_STRING); } }
public void popContext() { fNamespaceContext.popContext(); }
if (isCtaEvaluator != null && isCtaEvaluator.booleanValue()) { String[] namespaceBindingInfo = xpath2NamespaceContext.getNamespaceBindingInfo(); List prefixes = getPrefixesXS11CTA(namespaceBindingInfo); for (int prfxIdx = 0; prfxIdx < prefixes.size(); prfxIdx++) { Enumeration currPrefixes = xpath2NamespaceContext.getAllPrefixes(); while (currPrefixes.hasMoreElements()) { String prefix = (String)currPrefixes.nextElement(); addNamespaceBindingToXPath2DynamicContext(prefix, xpath2NamespaceContext.getURI(prefix));
public boolean declarePrefix(String prefix, String uri) { return fNamespaceContext.declarePrefix(prefix, uri); }
public void pushContext() { fNamespaceContext.pushContext(); }
final Enumeration prefixes1 = nsContext1.getAllPrefixes(); final Enumeration prefixes2 = nsContext2.getAllPrefixes(); final String prefix2 = (String) prefixes2.nextElement(); if (nsContext1.getURI(prefix1) != nsContext2.getURI(prefix1) || nsContext1.getURI(prefix2) != nsContext2.getURI(prefix2)) { return false;
public void startDocument() throws SAXException { fNeedPushNSContext = true; fNamespaceContext.reset(); try { fSchemaDOMParser.startDocument(fSAXLocatorWrapper, null, fNamespaceContext, null); } catch (XMLParseException e) { convertToSAXParseException(e); } catch (XNIException e) { convertToSAXException(e); } }
fLocalNSBinder.reset(); fNSBinder.pushContext(); fNSBinder.declarePrefix(localpart, value); fNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, value); continue; prefix = (prefix == null || prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); if (fNSBinder.getURI(prefix) == uri) { fLocalNSBinder.declarePrefix(prefix, uri); fNSBinder.declarePrefix(prefix, uri); uri = fNSBinder.getURI(XMLSymbols.EMPTY_STRING); fLocalNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); fNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); localpart = fSymbolTable.addSymbol( attr.getLocalName()); if (prefix == XMLSymbols.PREFIX_XMLNS) { //xmlns:prefix localUri = fLocalNSBinder.getURI(localpart); // local prefix mapping value = fSymbolTable.addSymbol(value); if (value.length() != 0 ) { fLocalNSBinder.declarePrefix(localpart, value);
public void startPrefixMapping(String prefix, String uri) throws SAXException { if (fNeedPushNSContext) { fNeedPushNSContext = false; fNamespaceContext.pushContext(); } if (!fStringsInternalized) { prefix = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING; uri = (uri != null && uri.length() > 0) ? fSymbolTable.addSymbol(uri) : null; } else { if (prefix == null) { prefix = XMLSymbols.EMPTY_STRING; } if (uri != null && uri.length() == 0) { uri = null; } } fNamespaceContext.declarePrefix(prefix, uri); }
/** Do processing for the end of a node. */ private void finishNode(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { fCurrentElement = node; // end element fillQName(fElementQName, node); fSchemaValidator.endElement(fElementQName, null); // pop namespace context fNamespaceContext.popContext(); } }
private void processAttributes(NamedNodeMap attrMap) { final int attrCount = attrMap.getLength(); fAttributes.removeAllAttributes(); for (int i = 0; i < attrCount; ++i) { Attr attr = (Attr) attrMap.item(i); String value = attr.getValue(); if (value == null) { value = XMLSymbols.EMPTY_STRING; } fillQName(fAttributeQName, attr); // REVISIT: Assuming all attributes are of type CDATA. The actual type may not matter. -- mrglavas fAttributes.addAttributeNS(fAttributeQName, XMLSymbols.fCDATASymbol, value); fAttributes.setSpecified(i, attr.getSpecified()); // REVISIT: Should we be looking at non-namespace attributes // for additional mappings? Should we detect illegal namespace // declarations and exclude them from the context? -- mrglavas if (fAttributeQName.uri == NamespaceContext.XMLNS_URI) { // process namespace attribute if (fAttributeQName.prefix == XMLSymbols.PREFIX_XMLNS) { fNamespaceContext.declarePrefix(fAttributeQName.localpart, value.length() != 0 ? fSymbolTable.addSymbol(value) : null); } else { fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, value.length() != 0 ? fSymbolTable.addSymbol(value) : null); } } } }