本文整理汇总了Java中javax.xml.XMLConstants.XMLNS_ATTRIBUTE属性的典型用法代码示例。如果您正苦于以下问题:Java XMLConstants.XMLNS_ATTRIBUTE属性的具体用法?Java XMLConstants.XMLNS_ATTRIBUTE怎么用?Java XMLConstants.XMLNS_ATTRIBUTE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.xml.XMLConstants
的用法示例。
在下文中一共展示了XMLConstants.XMLNS_ATTRIBUTE属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrefixes
/**
* @return mapping from prefix to namespace.
*/
public Map<String, String> getPrefixes() {
Map<String,String> prefixes = new HashMap<String,String>();
NamedNodeMap nodes = getPeer().getAttributes();
for (int i = 0; i < nodes.getLength(); i++) {
Node n = nodes.item(i);
String name = n.getLocalName();
String prefix = n.getPrefix();
final String xmlns = XMLConstants.XMLNS_ATTRIBUTE; //NOI18N
if (xmlns.equals(name) || // default namespace
xmlns.equals(prefix)) { // namespace prefix
String ns = n.getNodeValue();
prefixes.put(name, ns);
}
}
String defaultNamespace = prefixes.remove(XMLConstants.XMLNS_ATTRIBUTE);
if (defaultNamespace != null) {
prefixes.put(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespace);
}
return prefixes;
}
示例2: cloneNode
public Element cloneNode(boolean deep, boolean cloneNamespacePrefix) {
Document root = isInTree() ? (Document) getOwnerDocument() : null;
Map<Integer,String> allNamespaces = null;
if (root != null && cloneNamespacePrefix) {
allNamespaces = root.getNamespaceMap();
}
Map<String,String> clonePrefixes = new HashMap<String,String>();
Element clone = (Element) super.cloneNode(deep, allNamespaces, clonePrefixes);
for (Map.Entry e : clonePrefixes.entrySet()) {
String prefix = (String) e.getKey();
String attr = prefix.length() > 0 ?
XMLConstants.XMLNS_ATTRIBUTE+":"+prefix :
XMLConstants.XMLNS_ATTRIBUTE;
Attribute attrNode = new Attribute(attr, (String) e.getValue());
clone.setAttributeNode(attrNode);
}
return clone;
}
示例3: getPrefix
@Override
public String getPrefix(String uri) {
if( uri==null )
throw new IllegalArgumentException();
if( uri.equals(XMLConstants.XML_NS_URI) )
return XMLConstants.XML_NS_PREFIX;
if( uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI) )
return XMLConstants.XMLNS_ATTRIBUTE;
for( int i=nsLen-2; i>=0; i-=2 )
if(uri.equals(nsBind[i+1]))
if( getNamespaceURI(nsBind[i]).equals(nsBind[i+1]) )
// make sure that this prefix is still effective.
return nsBind[i];
if(environmentNamespaceContext!=null)
return environmentNamespaceContext.getPrefix(uri);
return null;
}
示例4: writeNamespace
/**
* creates a namespace attribute and will associate it with the current element in
* the DOM tree.
* @param prefix {@inheritDoc}
* @param namespaceURI {@inheritDoc}
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
*/
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
if (prefix == null) {
throw new XMLStreamException("prefix cannot be null");
}
if (namespaceURI == null) {
throw new XMLStreamException("NamespaceURI cannot be null");
}
String qname = null;
if (prefix.equals("")) {
qname = XMLConstants.XMLNS_ATTRIBUTE;
} else {
qname = getQName(XMLConstants.XMLNS_ATTRIBUTE,prefix);
}
((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
}
示例5: addNamespace
/**
* Processes an attribute for namespace-related stuff. Detects and sets
* {@link #schemaLocation}, {@link #noNamespaceSchemaLocation}, {@link #defaultNamespace} URIs.
* Should be called for elements starting from root down to the context element for
* proper overriding
*/
private void addNamespace(String attrName, String value, String nodePrefix) {
String defNS = XMLConstants.XMLNS_ATTRIBUTE;
if(CompletionUtil.getLocalNameFromTag(attrName).
equals(XSI_SCHEMALOCATION)) {
schemaLocation = value.trim();
return;
}
if(CompletionUtil.getLocalNameFromTag(attrName).
equals(XSI_NONS_SCHEMALOCATION)) {
noNamespaceSchemaLocation = value.trim();
return;
}
if (CompletionUtil.getLocalNameFromTag(attrName).
equals(XSD_TARGET_NAMESPACE)) {
targetNamespace = value.trim();
return;
}
if(! attrName.startsWith(XMLConstants.XMLNS_ATTRIBUTE))
return;
if(attrName.equals(defNS)) {
this.defaultNamespace = value;
}
declaredNamespaces.put(attrName, value);
}
示例6: getPrefix
@Override
public String getPrefix(String uri) {
if (defaultNamespaceURI != null && defaultNamespaceURI.equals(uri)) {
return XMLConstants.DEFAULT_NS_PREFIX;
} else if (uri == null) {
throw new IllegalArgumentException("Null not allowed as prefix");
} else if (uri.equals(XMLConstants.XML_NS_URI)) {
return XMLConstants.XML_NS_PREFIX;
} else if (uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
return XMLConstants.XMLNS_ATTRIBUTE;
} else {
return namespaceIdsMap.get(uri);
}
}
示例7: main
public static void main (final String [] args)
{
final File aSchFile = new File ("../../../schematron/EN16931-EDIFACT-validation.sch");
final File aXsltFile = new File ("../../../stylesheet/EN16931-EDIFACT-validation-compiled.xsl");
logger.info ("Reading Schematron");
final SchematronResourceSCH aSch = SchematronResourceSCH.fromFile (aSchFile);
final ISchematronXSLTBasedProvider aXsltProvider = aSch.getXSLTProvider ();
// Write the resulting XSLT file to disk
final MapBasedNamespaceContext aNSContext = new MapBasedNamespaceContext ().addMapping ("svrl",
CSVRL.SVRL_NAMESPACE_URI);
// Add all namespaces from XSLT document root
final String sNSPrefix = XMLConstants.XMLNS_ATTRIBUTE + ":";
XMLHelper.getAllAttributesAsMap (aXsltProvider.getXSLTDocument ().getDocumentElement ())
.forEach ( (sAttrName, sAttrValue) -> {
if (sAttrName.startsWith (sNSPrefix))
aNSContext.addMapping (sAttrName.substring (sNSPrefix.length ()), sAttrValue);
});
final XMLWriterSettings aXWS = new XMLWriterSettings ();
aXWS.setNamespaceContext (aNSContext).setPutNamespaceContextPrefixesInRoot (true);
logger.info ("Writing XSLT");
final OutputStream aOS = FileHelper.getOutputStream (aXsltFile);
XMLWriter.writeToStream (aXsltProvider.getXSLTDocument (), aOS, aXWS);
logger.info ("Done");
}
示例8: getPrefix
@Override
public String getPrefix(String namespaceUri) {
if (null == namespaceUri) {
throw new IllegalArgumentException("namespaceURI");
} else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceUri)) {
return XMLConstants.XMLNS_ATTRIBUTE;
} else if (XMLConstants.XML_NS_URI.equals(namespaceUri)) {
return XMLConstants.XML_NS_PREFIX;
} else if ("http://www.example.com/my".equals(namespaceUri)) {
return "my";
} else {
return XMLConstants.DEFAULT_NS_PREFIX;
}
}
示例9: writeDefaultNamespace
/**
* Creates a DOM attribute and adds it to the current element in the DOM tree.
* @param namespaceURI {@inheritDoc}
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
*/
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
if(currentNode.getNodeType() == Node.ELEMENT_NODE){
String qname = XMLConstants.XMLNS_ATTRIBUTE;
((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
}else{
//Convert node type to String
throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
"and does not allow attributes to be set ");
}
}
示例10: populateNamespaces
/**
* Keeps all namespaces along with their prefixes in a HashMap.
* This is obtained from the root element's attributes, with
* the attribute value(namespace) as the key and name with prefix
* as the value.
* For example the hashmap may look like this
* KEY VALUE
* http://www.camera.com xmlns:c
* http://www.nikon.com xmlns:n
*/
private void populateNamespaces() {
if(docRoot == null)
return;
//Check if the tag has any prefix. If yes, the defaultNamespace
//is the one with this prefix.
String tagName = docRoot.getName();
String defNS = XMLConstants.XMLNS_ATTRIBUTE;
String temp = CompletionUtil.getPrefixFromTag(tagName);
if(temp != null) defNS = defNS+":"+temp; //NOI18N
List<DocRootAttribute> attributes = docRoot.getAttributes();
String version = null;
boolean xsltDeclared = false;
for(int index=0; index<attributes.size(); index++) {
DocRootAttribute attr = attributes.get(index);
String attrName = attr.getName();
String value = attr.getValue();
addNamespace(attrName, value, temp);
//resolve xsl stylesheets w/o the schema location specification.
//In such case the root element only contains the xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"
//along with the version attribute.
//If such ns is declared and the version is 2.0 then use the
//http://www.w3.org/2007/schema-for-xslt20.xsd schema for the completion model
if(attr.getValue().trim().equals("http://www.w3.org/1999/XSL/Transform")) { //NOI18N
xsltDeclared = true;
}
if(CompletionUtil.getLocalNameFromTag(attrName).
equals("version")) { //NOI18N
version = attr.getValue().trim();
}
}
if(schemaLocation == null && xsltDeclared && "2.0".equals(version)) {
//only the second "token" from the schemaLocation is considered as the schema
schemaLocation = "schema http://www.w3.org/2007/schema-for-xslt20.xsd"; //NOI18N
}
}
示例11: NamespaceImpl
/** Creates a new instance of NamespaceImpl */
public NamespaceImpl(String namespaceURI) {
super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null);
init();
}