本文整理汇总了Java中org.xml.sax.helpers.NamespaceSupport.pushContext方法的典型用法代码示例。如果您正苦于以下问题:Java NamespaceSupport.pushContext方法的具体用法?Java NamespaceSupport.pushContext怎么用?Java NamespaceSupport.pushContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.helpers.NamespaceSupport
的用法示例。
在下文中一共展示了NamespaceSupport.pushContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: buildNamespaceSupport
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
if (node==null || node.getNodeType()!=Node.ELEMENT_NODE) {
return;
}
buildNamespaceSupport( nss, node.getParentNode() );
nss.pushContext();
NamedNodeMap atts = node.getAttributes();
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
if( "xmlns".equals(a.getPrefix()) ) {
nss.declarePrefix( a.getLocalName(), a.getValue() );
continue;
}
if( "xmlns".equals(a.getName()) ) {
nss.declarePrefix( "", a.getValue() );
//continue;
}
}
}
示例3: buildNamespaceSupport
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
* Recursively visit ancestors and build up {@link NamespaceSupport} oject.
*/
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
return;
buildNamespaceSupport( nss, node.getParentNode() );
nss.pushContext();
NamedNodeMap atts = node.getAttributes();
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
if( "xmlns".equals(a.getPrefix()) ) {
nss.declarePrefix( a.getLocalName(), a.getValue() );
continue;
}
if( "xmlns".equals(a.getName()) ) {
nss.declarePrefix( "", a.getValue() );
continue;
}
}
}
示例4: testProcessName
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@Test
public void testProcessName() {
NamespaceSupport nssupport = new NamespaceSupport();
nssupport.pushContext();
nssupport.declarePrefix("", "http://www.java.com");
nssupport.declarePrefix("dc", "http://www.purl.org/dc");
String[] parts = new String[3];
nssupport.processName("dc:name1", parts, false);
Assert.assertTrue(parts[0].equals("http://www.purl.org/dc"));
Assert.assertTrue(parts[1].equals("name1"));
Assert.assertTrue(parts[2].equals("dc:name1"));
nssupport.processName("name2", parts, false);
Assert.assertTrue(parts[0].equals("http://www.java.com"));
Assert.assertTrue(parts[1].equals("name2"));
Assert.assertTrue(parts[2].equals("name2"));
}
示例5: testPopContext
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@Test
public void testPopContext() {
String[] parts = new String[3];
NamespaceSupport nssupport = new NamespaceSupport();
nssupport.pushContext();
nssupport.declarePrefix("dc", "http://www.purl.org/dc");
Assert.assertEquals(nssupport.getPrefix("http://www.purl.org/dc"), "dc");
nssupport.popContext();
Assert.assertNull(nssupport.getPrefix("http://www.purl.org/dc"));
nssupport.processName("dc:name1", parts, false);
Assert.assertNull(parts[0]);
Assert.assertNull(parts[1]);
Assert.assertNull(parts[2]);
}
示例6: testPrefixAndUri4
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@Test
public void testPrefixAndUri4() {
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");
AssertJUnit.assertTrue(nssupport.getURI("dc").equals("http://www.purl.org/dc"));
AssertJUnit.assertTrue(nssupport.getURI("dc1").equals("http://www.purl.org/dc"));
AssertJUnit.assertTrue(nssupport.getURI("dc2").equals("http://www.purl.org/dc2"));
AssertJUnit.assertTrue(nssupport.getURI("dcnew").equals("http://www.purl.org/dcnew"));
// Negative test
Assert.assertNull(nssupport.getURI("wrong_prefix"));
Assert.assertNull(nssupport.getURI(""));
}
示例7: testcase01
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
* Test for NamespaceSupport.getDeclaredPrefixes().
*/
@Test
public void testcase01() {
String[] prefixes = new String[2];
NamespaceSupport support = new NamespaceSupport();
support.pushContext();
support.declarePrefix(EMPTY_PREFIX, W3_URI);
support.declarePrefix(DC_PREFIX, PURL_URI);
Enumeration e = support.getDeclaredPrefixes();
int i = 0;
while(e.hasMoreElements()) {
prefixes[i++] = e.nextElement().toString();
}
support.popContext();
assertEquals(prefixes, new String[]{EMPTY_PREFIX, DC_PREFIX});
}
示例8: buildNamespaceSupport
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
* Recursively visit ancestors and build up {@link NamespaceSupport} oject.
*/
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
return;
buildNamespaceSupport( nss, node.getParentNode() );
nss.pushContext();
NamedNodeMap atts = node.getAttributes();
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
if( "xmlns".equals(a.getPrefix()) ) {
nss.declarePrefix( a.getLocalName(), a.getValue() );
continue;
}
if( "xmlns".equals(a.getName()) ) {
nss.declarePrefix( "", a.getValue() );
continue;
}
}
}
示例9: buildNamespaceSupport
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
private void buildNamespaceSupport(NamespaceSupport nss, Node node) {
if(node==null || node.getNodeType()!=Node.ELEMENT_NODE)
return;
buildNamespaceSupport( nss, node.getParentNode() );
nss.pushContext();
NamedNodeMap atts = node.getAttributes();
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
if( "xmlns".equals(a.getPrefix()) ) {
nss.declarePrefix( a.getLocalName(), a.getValue() );
continue;
}
if( "xmlns".equals(a.getName()) ) {
nss.declarePrefix( "", a.getValue() );
//continue;
}
}
}
示例10: testNamespaceDeclUris
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@Test
public void testNamespaceDeclUris() {
String[] parts = new String[3];
NamespaceSupport nssupport = new NamespaceSupport();
nssupport.pushContext();
Assert.assertFalse(nssupport.isNamespaceDeclUris());
nssupport.declarePrefix("xmlns", "");
nssupport.processName("xmlns:name", parts, true);
Assert.assertNull(parts[0]);
Assert.assertNull(parts[1]);
Assert.assertNull(parts[2]);
nssupport.reset();
nssupport.setNamespaceDeclUris(true);
nssupport.declarePrefix("xmlns", "");
nssupport.processName("xmlns:name", parts, true);
Assert.assertTrue(parts[0].equals(NamespaceSupport.NSDECL));
Assert.assertTrue(parts[1].equals("name"));
Assert.assertTrue(parts[2].equals("xmlns:name"));
nssupport.reset();
nssupport.setNamespaceDeclUris(true);
nssupport.declarePrefix("xml", "");
nssupport.processName("xml:name", parts, true);
Assert.assertTrue(parts[0].equals(NamespaceSupport.XMLNS));
Assert.assertTrue(parts[1].equals("name"));
Assert.assertTrue(parts[2].equals("xml:name"));
}
示例11: testPrefixAndUri1
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
@Test
public void testPrefixAndUri1() {
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.getDeclaredPrefixes();
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);
AssertJUnit.assertFalse(hasdc);
}
示例12: 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);
}
示例13: 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);
}
示例14: testcase02
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
* Test for NamespaceSupport.getDeclaredPrefixes() and support.processName().
*/
@Test
public void testcase02() {
String[] parts = new String[3];
NamespaceSupport support = new NamespaceSupport();
support.pushContext();
support.declarePrefix(DC_PREFIX, PURL_URI);
parts = support.processName("dc:title", parts, false);
support.popContext();
assertEquals(parts, new String[]{PURL_URI, "title", "dc:title"});
}
示例15: testcase03
import org.xml.sax.helpers.NamespaceSupport; //导入方法依赖的package包/类
/**
* Test for NamespaceSupport.getDeclaredPrefixes() and support.processName().
*/
@Test
public void testcase03() {
String[] parts = new String[3];
NamespaceSupport support = new NamespaceSupport();
support.pushContext();
support.declarePrefix(EMPTY_PREFIX, W3_URI);
parts = support.processName("a", parts, false);
support.popContext();
assertEquals(parts, new String[]{W3_URI, "a", "a"});
}