Java Code Examples for com.sun.org.apache.xerces.internal.util.XMLSymbols#EMPTY_STRING
The following examples show how to use
com.sun.org.apache.xerces.internal.util.XMLSymbols#EMPTY_STRING .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaContentHandler.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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; rawname = fSymbolTable.addSymbol(prefix + ":" + localpart); } 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); } }
Example 2
Source File: XML11NSDTDValidator.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** Handles end element. */ protected void endNamespaceScope(QName element, Augmentations augs, boolean isEmpty) throws XNIException { // bind element String eprefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; element.uri = fNamespaceContext.getURI(eprefix); if (element.uri != null) { element.prefix = eprefix; } // call handlers if (fDocumentHandler != null) { if (!isEmpty) { fDocumentHandler.endElement(element, augs); } } // pop context fNamespaceContext.popContext(); }
Example 3
Source File: XMLNSDTDValidator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** Handles end element. */ protected void endNamespaceScope(QName element, Augmentations augs, boolean isEmpty) throws XNIException { // bind element String eprefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; element.uri = fNamespaceContext.getURI(eprefix); if (element.uri != null) { element.prefix = eprefix; } // call handlers if (fDocumentHandler != null) { if (!isEmpty) { fDocumentHandler.endElement(element, augs); } } // pop context fNamespaceContext.popContext(); }
Example 4
Source File: DOMValidatorHelper.java From Bytecoder with Apache License 2.0 | 6 votes |
private void fillQName(QName toFill, Node node) { final String prefix = node.getPrefix(); final String localName = node.getLocalName(); final String rawName = node.getNodeName(); final String namespace = node.getNamespaceURI(); toFill.uri = (namespace != null && namespace.length() > 0) ? fSymbolTable.addSymbol(namespace) : null; toFill.rawname = (rawName != null) ? fSymbolTable.addSymbol(rawName) : XMLSymbols.EMPTY_STRING; // Is this a DOM level1 document? if (localName == null) { int k = rawName.indexOf(':'); if (k > 0) { toFill.prefix = fSymbolTable.addSymbol(rawName.substring(0, k)); toFill.localpart = fSymbolTable.addSymbol(rawName.substring(k + 1)); } else { toFill.prefix = XMLSymbols.EMPTY_STRING; toFill.localpart = toFill.rawname; } } else { toFill.prefix = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING; toFill.localpart = (localName != null) ? fSymbolTable.addSymbol(localName) : XMLSymbols.EMPTY_STRING; } }
Example 5
Source File: DOMNormalizer.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Adds a namespace attribute or replaces the value of existing namespace * attribute with the given prefix and value for URI. * In case prefix is empty will add/update default namespace declaration. * * @param prefix * @param uri * @exception IOException */ protected final void addNamespaceDecl(String prefix, String uri, ElementImpl element){ if (DEBUG) { System.out.println("[ns-fixup] addNamespaceDecl ["+prefix+"]"); } if (prefix == XMLSymbols.EMPTY_STRING) { if (DEBUG) { System.out.println("=>add xmlns=\""+uri+"\" declaration"); } element.setAttributeNS(NamespaceContext.XMLNS_URI, XMLSymbols.PREFIX_XMLNS, uri); } else { if (DEBUG) { System.out.println("=>add xmlns:"+prefix+"=\""+uri+"\" declaration"); } element.setAttributeNS(NamespaceContext.XMLNS_URI, "xmlns:"+prefix, uri); } }
Example 6
Source File: XMLSerializer.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Serializes a namespace attribute with the given prefix and value for URI. * In case prefix is empty will serialize default namespace declaration. * * @param prefix * @param uri * @exception IOException */ private void printNamespaceAttr(String prefix, String uri) throws IOException{ _printer.printSpace(); if (prefix == XMLSymbols.EMPTY_STRING) { if (DEBUG) { System.out.println("=>add xmlns=\""+uri+"\" declaration"); } _printer.printText( XMLSymbols.PREFIX_XMLNS ); } else { if (DEBUG) { System.out.println("=>add xmlns:"+prefix+"=\""+uri+"\" declaration"); } _printer.printText( "xmlns:"+prefix ); } _printer.printText( "=\"" ); printEscaped( uri ); _printer.printText( '"' ); }
Example 7
Source File: DOMValidatorHelper.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private void fillQName(QName toFill, Node node) { final String prefix = node.getPrefix(); final String localName = node.getLocalName(); final String rawName = node.getNodeName(); final String namespace = node.getNamespaceURI(); toFill.uri = (namespace != null && namespace.length() > 0) ? fSymbolTable.addSymbol(namespace) : null; toFill.rawname = (rawName != null) ? fSymbolTable.addSymbol(rawName) : XMLSymbols.EMPTY_STRING; // Is this a DOM level1 document? if (localName == null) { int k = rawName.indexOf(':'); if (k > 0) { toFill.prefix = fSymbolTable.addSymbol(rawName.substring(0, k)); toFill.localpart = fSymbolTable.addSymbol(rawName.substring(k + 1)); } else { toFill.prefix = XMLSymbols.EMPTY_STRING; toFill.localpart = toFill.rawname; } } else { toFill.prefix = (prefix != null) ? fSymbolTable.addSymbol(prefix) : XMLSymbols.EMPTY_STRING; toFill.localpart = (localName != null) ? fSymbolTable.addSymbol(localName) : XMLSymbols.EMPTY_STRING; } }
Example 8
Source File: XML11NSDTDValidator.java From Bytecoder with Apache License 2.0 | 6 votes |
/** Handles end element. */ protected void endNamespaceScope(QName element, Augmentations augs, boolean isEmpty) throws XNIException { // bind element String eprefix = element.prefix != null ? element.prefix : XMLSymbols.EMPTY_STRING; element.uri = fNamespaceContext.getURI(eprefix); if (element.uri != null) { element.prefix = eprefix; } // call handlers if (fDocumentHandler != null) { if (!isEmpty) { fDocumentHandler.endElement(element, augs); } } // pop context fNamespaceContext.popContext(); }
Example 9
Source File: DOMValidatorHelper.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void fillNamespaceContext() { if (fRoot != null) { Node currentNode = fRoot.getParentNode(); while (currentNode != null) { if (Node.ELEMENT_NODE == currentNode.getNodeType()) { NamedNodeMap attributes = currentNode.getAttributes(); final int attrCount = attributes.getLength(); for (int i = 0; i < attrCount; ++i) { Attr attr = (Attr) attributes.item(i); String value = attr.getValue(); if (value == null) { value = XMLSymbols.EMPTY_STRING; } fillQName(fAttributeQName, attr); // 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) { declarePrefix0(fAttributeQName.localpart, value.length() != 0 ? fSymbolTable.addSymbol(value) : null); } else { declarePrefix0(XMLSymbols.EMPTY_STRING, value.length() != 0 ? fSymbolTable.addSymbol(value) : null); } } } } currentNode = currentNode.getParentNode(); } } }
Example 10
Source File: XPath.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Used by {@link #parseExpression} to parse a node test * from the token list. */ private NodeTest parseNodeTest( int typeToken, Tokens xtokens, NamespaceContext context ) throws XPathException { switch(typeToken) { case XPath.Tokens.EXPRTOKEN_NAMETEST_ANY: return new NodeTest(NodeTest.WILDCARD); case XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE: case XPath.Tokens.EXPRTOKEN_NAMETEST_QNAME: // consume QName token String prefix = xtokens.nextTokenAsString(); String uri = null; if (context != null && prefix != XMLSymbols.EMPTY_STRING) { uri = context.getURI(prefix); } if (prefix != XMLSymbols.EMPTY_STRING && context != null && uri == null) { throw new XPathException("c-general-xpath-ns"); } if (typeToken==XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE) return new NodeTest(prefix,uri); String localpart = xtokens.nextTokenAsString(); String rawname = prefix != XMLSymbols.EMPTY_STRING ? fSymbolTable.addSymbol(prefix+':'+localpart) : localpart; return new NodeTest(new QName(prefix, localpart, rawname, uri)); default: // assertion error throw new XPathException("c-general-xpath"); } }
Example 11
Source File: DOMValidatorHelper.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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); } } } }
Example 12
Source File: XPath.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Used by {@link #parseExpression} to parse a node test * from the token list. */ private NodeTest parseNodeTest( int typeToken, Tokens xtokens, NamespaceContext context ) throws XPathException { switch(typeToken) { case XPath.Tokens.EXPRTOKEN_NAMETEST_ANY: return new NodeTest(NodeTest.WILDCARD); case XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE: case XPath.Tokens.EXPRTOKEN_NAMETEST_QNAME: // consume QName token String prefix = xtokens.nextTokenAsString(); String uri = null; if (context != null && prefix != XMLSymbols.EMPTY_STRING) { uri = context.getURI(prefix); } if (prefix != XMLSymbols.EMPTY_STRING && context != null && uri == null) { throw new XPathException("c-general-xpath-ns"); } if (typeToken==XPath.Tokens.EXPRTOKEN_NAMETEST_NAMESPACE) return new NodeTest(prefix,uri); String localpart = xtokens.nextTokenAsString(); String rawname = prefix != XMLSymbols.EMPTY_STRING ? fSymbolTable.addSymbol(prefix+':'+localpart) : localpart; return new NodeTest(new QName(prefix, localpart, rawname, uri)); default: // assertion error throw new XPathException("c-general-xpath"); } }
Example 13
Source File: XSDHandler.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private int changeRedefineGroup(String originalQName, String elementSought, String newName, Element curr, XSDocumentInfo schemaDoc) { int result = 0; for (Element child = DOMUtil.getFirstChildElement(curr); child != null; child = DOMUtil.getNextSiblingElement(child)) { String name = DOMUtil.getLocalName(child); if (!name.equals(elementSought)) result += changeRedefineGroup(originalQName, elementSought, newName, child, schemaDoc); else { String ref = child.getAttribute( SchemaSymbols.ATT_REF ); if (ref.length() != 0) { String processedRef = findQName(ref, schemaDoc); if (originalQName.equals(processedRef)) { String prefix = XMLSymbols.EMPTY_STRING; int colonptr = ref.indexOf(":"); if (colonptr > 0) { prefix = ref.substring(0,colonptr); child.setAttribute(SchemaSymbols.ATT_REF, prefix + ":" + newName); } else child.setAttribute(SchemaSymbols.ATT_REF, newName); result++; if (elementSought.equals(SchemaSymbols.ELT_GROUP)) { String minOccurs = child.getAttribute( SchemaSymbols.ATT_MINOCCURS ); String maxOccurs = child.getAttribute( SchemaSymbols.ATT_MAXOCCURS ); if (!((maxOccurs.length() == 0 || maxOccurs.equals("1")) && (minOccurs.length() == 0 || minOccurs.equals("1")))) { reportSchemaError("src-redefine.6.1.2", new Object [] {ref}, child); } } } } // if ref was null some other stage of processing will flag the error } } return result; }
Example 14
Source File: XSDHandler.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
Object getGrpOrAttrGrpRedefinedByRestriction(int type, QName name, XSDocumentInfo currSchema, Element elmNode) { String realName = name.uri != null?name.uri+","+name.localpart: ","+name.localpart; String nameToFind = null; switch (type) { case ATTRIBUTEGROUP_TYPE: nameToFind = (String)fRedefinedRestrictedAttributeGroupRegistry.get(realName); break; case GROUP_TYPE: nameToFind = (String)fRedefinedRestrictedGroupRegistry.get(realName); break; default: return null; } if (nameToFind == null) return null; int commaPos = nameToFind.indexOf(","); QName qNameToFind = new QName(XMLSymbols.EMPTY_STRING, nameToFind.substring(commaPos+1), nameToFind.substring(commaPos), (commaPos == 0)? null : nameToFind.substring(0, commaPos)); Object retObj = getGlobalDecl(currSchema, type, qNameToFind, elmNode); if(retObj == null) { switch (type) { case ATTRIBUTEGROUP_TYPE: reportSchemaError("src-redefine.7.2.1", new Object []{name.localpart}, elmNode); break; case GROUP_TYPE: reportSchemaError("src-redefine.6.2.1", new Object []{name.localpart}, elmNode); break; } return null; } return retObj; }
Example 15
Source File: XSDHandler.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
Object getGrpOrAttrGrpRedefinedByRestriction(int type, QName name, XSDocumentInfo currSchema, Element elmNode) { String realName = name.uri != null?name.uri+","+name.localpart: ","+name.localpart; String nameToFind = null; switch (type) { case ATTRIBUTEGROUP_TYPE: nameToFind = (String)fRedefinedRestrictedAttributeGroupRegistry.get(realName); break; case GROUP_TYPE: nameToFind = (String)fRedefinedRestrictedGroupRegistry.get(realName); break; default: return null; } if (nameToFind == null) return null; int commaPos = nameToFind.indexOf(","); QName qNameToFind = new QName(XMLSymbols.EMPTY_STRING, nameToFind.substring(commaPos+1), nameToFind.substring(commaPos), (commaPos == 0)? null : nameToFind.substring(0, commaPos)); Object retObj = getGlobalDecl(currSchema, type, qNameToFind, elmNode); if(retObj == null) { switch (type) { case ATTRIBUTEGROUP_TYPE: reportSchemaError("src-redefine.7.2.1", new Object []{name.localpart}, elmNode); break; case GROUP_TYPE: reportSchemaError("src-redefine.6.2.1", new Object []{name.localpart}, elmNode); break; } return null; } return retObj; }
Example 16
Source File: StAXSchemaParser.java From Bytecoder with Apache License 2.0 | 5 votes |
private void addNamespaceDeclarations() { String prefix = null; String localpart = null; String rawname = null; String nsPrefix = null; String nsURI = null; final Iterator<String> iter = fDeclaredPrefixes.iterator(); while (iter.hasNext()) { nsPrefix = iter.next(); 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); } }
Example 17
Source File: XSDHandler.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private String emptyString2Null(String ns) { return ns == XMLSymbols.EMPTY_STRING ? null : ns; }
Example 18
Source File: XMLSerializer.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * DOM Level 3: * Check a node to determine if it contains unbound namespace prefixes. * * @param node The node to check for unbound namespace prefices */ protected void checkUnboundNamespacePrefixedNode (Node node) throws IOException{ if (fNamespaces) { if (DEBUG) { System.out.println("==>serializeNode("+node.getNodeName()+") [Entity Reference - Namespaces on]"); System.out.println("==>Declared Prefix Count: " + fNSBinder.getDeclaredPrefixCount()); System.out.println("==>Node Name: " + node.getNodeName()); System.out.println("==>First Child Node Name: " + node.getFirstChild().getNodeName()); System.out.println("==>First Child Node Prefix: " + node.getFirstChild().getPrefix()); System.out.println("==>First Child Node NamespaceURI: " + node.getFirstChild().getNamespaceURI()); } Node child, next; for (child = node.getFirstChild(); child != null; child = next) { next = child.getNextSibling(); if (DEBUG) { System.out.println("==>serializeNode("+child.getNodeName()+") [Child Node]"); System.out.println("==>serializeNode("+child.getPrefix()+") [Child Node Prefix]"); } //If a NamespaceURI is not declared for the current //node's prefix, raise a fatal error. String prefix = child.getPrefix(); prefix = (prefix == null || prefix.length() == 0) ? XMLSymbols.EMPTY_STRING : fSymbolTable.addSymbol(prefix); if (fNSBinder.getURI(prefix) == null && prefix != null) { fatalError("The replacement text of the entity node '" + node.getNodeName() + "' contains an element node '" + child.getNodeName() + "' with an undeclared prefix '" + prefix + "'."); } if (child.getNodeType() == Node.ELEMENT_NODE) { NamedNodeMap attrs = child.getAttributes(); for (int i = 0; i< attrs.getLength(); i++ ) { String attrPrefix = attrs.item(i).getPrefix(); attrPrefix = (attrPrefix == null || attrPrefix.length() == 0) ? XMLSymbols.EMPTY_STRING : fSymbolTable.addSymbol(attrPrefix); if (fNSBinder.getURI(attrPrefix) == null && attrPrefix != null) { fatalError("The replacement text of the entity node '" + node.getNodeName() + "' contains an element node '" + child.getNodeName() + "' with an attribute '" + attrs.item(i).getNodeName() + "' an undeclared prefix '" + attrPrefix + "'."); } } } if (child.hasChildNodes()) { checkUnboundNamespacePrefixedNode(child); } } } }
Example 19
Source File: XMLNamespaceBinder.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
protected boolean prefixBoundToNullURI(String uri, String localpart) { return (uri == XMLSymbols.EMPTY_STRING && localpart != XMLSymbols.PREFIX_XMLNS); }
Example 20
Source File: SchemaDOM.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
void startAnnotation(String elemRawName, XMLAttributes attributes, NamespaceContext namespaceContext) { if(fAnnotationBuffer == null) fAnnotationBuffer = new StringBuffer(256); fAnnotationBuffer.append("<").append(elemRawName).append(" "); // attributes are a bit of a pain. To get this right, we have to keep track // of the namespaces we've seen declared, then examine the namespace context // for other namespaces so that we can also include them. // optimized for simplicity and the case that not many // namespaces are declared on this annotation... ArrayList namespaces = new ArrayList(); for (int i = 0; i < attributes.getLength(); ++i) { String aValue = attributes.getValue(i); String aPrefix = attributes.getPrefix(i); String aQName = attributes.getQName(i); // if it's xmlns:* or xmlns, must be a namespace decl if (aPrefix == XMLSymbols.PREFIX_XMLNS || aQName == XMLSymbols.PREFIX_XMLNS) { namespaces.add(aPrefix == XMLSymbols.PREFIX_XMLNS ? attributes.getLocalName(i) : XMLSymbols.EMPTY_STRING); } fAnnotationBuffer.append(aQName).append("=\"").append(processAttValue(aValue)).append("\" "); } // now we have to look through currently in-scope namespaces to see what // wasn't declared here Enumeration currPrefixes = namespaceContext.getAllPrefixes(); while(currPrefixes.hasMoreElements()) { String prefix = (String)currPrefixes.nextElement(); String uri = namespaceContext.getURI(prefix); if (uri == null) { uri = XMLSymbols.EMPTY_STRING; } if (!namespaces.contains(prefix)) { // have to declare this one if(prefix == XMLSymbols.EMPTY_STRING) { fAnnotationBuffer.append("xmlns").append("=\"").append(processAttValue(uri)).append("\" "); } else { fAnnotationBuffer.append("xmlns:").append(prefix).append("=\"").append(processAttValue(uri)).append("\" "); } } } fAnnotationBuffer.append(">\n"); }