本文整理汇总了Java中org.xml.sax.helpers.NamespaceSupport.getPrefixes方法的典型用法代码示例。如果您正苦于以下问题:Java NamespaceSupport.getPrefixes方法的具体用法?Java NamespaceSupport.getPrefixes怎么用?Java NamespaceSupport.getPrefixes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.helpers.NamespaceSupport
的用法示例。
在下文中一共展示了NamespaceSupport.getPrefixes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInscopeNamespaces
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
* There is no way to enumerate inscope namespaces for XMLStreamReader. That means
* namespaces declared in envelope, and body tags need to be computed using their
* {@link TagInfoset}s.
*
* @return array of the even length of the form { prefix0, uri0, prefix1, uri1, ... }
*/
private String[] getInscopeNamespaces() {
NamespaceSupport nss = new NamespaceSupport();
nss.pushContext();
for(int i=0; i < envelopeTag.ns.length; i+=2) {
nss.declarePrefix(envelopeTag.ns[i], envelopeTag.ns[i+1]);
}
nss.pushContext();
for(int i=0; i < bodyTag.ns.length; i+=2) {
nss.declarePrefix(bodyTag.ns[i], bodyTag.ns[i+1]);
}
List<String> inscope = new ArrayList<String>();
for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) {
String prefix = (String)en.nextElement();
inscope.add(prefix);
inscope.add(nss.getURI(prefix));
}
return inscope.toArray(new String[inscope.size()]);
}
示例2: patchDOMFragment
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
* Adds inscope namespaces as attributes to <xsd:schema> fragment nodes.
*
* @param nss namespace context info
* @param elem that is patched with inscope namespaces
*/
private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) {
NamedNodeMap atts = elem.getAttributes();
for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) {
String prefix = (String)en.nextElement();
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Patching with xmlns:{0}={1}", new Object[]{prefix, nss.getURI(prefix)});
}
elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix));
}
}
}
}
示例3: testPrefixAndUri2
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@Test
public void testPrefixAndUri2() {
boolean hasdc = false;
boolean hasdc1 = false;
boolean hasdc2 = false;
boolean hasdcnew = false;
NamespaceSupport nssupport = new NamespaceSupport();
nssupport.pushContext();
nssupport.declarePrefix("dc", "http://www.purl.org/dc");
nssupport.pushContext();
nssupport.declarePrefix("dc1", "http://www.purl.org/dc");
nssupport.declarePrefix("dc2", "http://www.purl.org/dc2");
nssupport.declarePrefix("dcnew", "http://www.purl.org/dcnew");
Enumeration enu1 = nssupport.getPrefixes();
while (enu1.hasMoreElements()) {
String str = (String) enu1.nextElement();
if (str.equals("dc")) {
hasdc = true;
} else if (str.equals("dc1")) {
hasdc1 = true;
} else if (str.equals("dc2")) {
hasdc2 = true;
} else if (str.equals("dcnew")) {
hasdcnew = true;
}
}
AssertJUnit.assertTrue(hasdcnew && hasdc1 && hasdc2 && hasdc);
}
示例4: testPrefixAndUri3
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@Test
public void testPrefixAndUri3() {
boolean hasdc = false;
boolean hasdc1 = false;
boolean hasdc2 = false;
boolean hasdcnew = false;
NamespaceSupport nssupport = new NamespaceSupport();
nssupport.pushContext();
nssupport.declarePrefix("dc", "http://www.purl.org/dc");
nssupport.pushContext();
nssupport.declarePrefix("dc1", "http://www.purl.org/dc");
nssupport.declarePrefix("dc2", "http://www.purl.org/dc2");
nssupport.declarePrefix("dcnew", "http://www.purl.org/dcnew");
Enumeration enu1 = nssupport.getPrefixes("http://www.purl.org/dc");
while (enu1.hasMoreElements()) {
String str = (String) enu1.nextElement();
if (str.equals("dc")) {
hasdc = true;
} else if (str.equals("dc1")) {
hasdc1 = true;
} else if (str.equals("dc2")) {
hasdc2 = true;
} else if (str.equals("dcnew")) {
hasdcnew = true;
}
}
AssertJUnit.assertTrue(hasdc1 && hasdc);
AssertJUnit.assertFalse(hasdc2);
AssertJUnit.assertFalse(hasdcnew);
}
示例5: patchDOMFragment
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
* Adds inscope namespaces as attributes to <xsd:schema> fragment nodes.
*
* @param nss namespace context info
* @param elem that is patched with inscope namespaces
*/
private @Nullable void patchDOMFragment(NamespaceSupport nss, Element elem) {
NamedNodeMap atts = elem.getAttributes();
for( Enumeration en = nss.getPrefixes(); en.hasMoreElements(); ) {
String prefix = (String)en.nextElement();
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
if (!"xmlns".equals(a.getPrefix()) || !a.getLocalName().equals(prefix)) {
LOGGER.fine("Patching with xmlns:"+prefix+"="+nss.getURI(prefix));
elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:"+prefix, nss.getURI(prefix));
}
}
}
}