org.xml.sax.helpers.NamespaceSupport#pushContext ( )源码实例Demo

下面列出了org.xml.sax.helpers.NamespaceSupport#pushContext ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: StreamMessage.java
/**
 * 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 项目: jdk8u60   文件: StreamMessage.java
/**
 * 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()]);
}
 
源代码3 项目: j2objc   文件: NamespaceSupportTest.java
public void testPush_PopContext() {
    int count;

    ns = new NamespaceSupport();
    count = countPrefixes();

    ns.pushContext();
    ns.declarePrefix("dc", "http://www.purl.org/dc#");
    assertEquals("Test 1: Incorrect prefix count;",
            count + 1, countPrefixes());

    ns.popContext();
    assertEquals("Test 2: Incorrect prefix count;",
            count, countPrefixes());

    // Check that only one context has been created by pushContext().
    try {
        ns.popContext();
        fail("Test 3: EmptyStackException expected.");
    } catch (EmptyStackException e) {
        // Expected.
    }
}
 
源代码4 项目: openjdk-jdk8u   文件: StreamMessage.java
/**
 * 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()]);
}
 
源代码5 项目: hottub   文件: StreamMessage.java
/**
 * 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()]);
}
 
源代码6 项目: openjdk-jdk8u   文件: DOMScanner.java
/**
 * 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;
        }
    }
}
 
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;
        }
    }
}
 
源代码8 项目: j2objc   文件: NamespaceSupportTest.java
public void testReset() {
    int count;

    ns = new NamespaceSupport();
    count = countPrefixes();

    ns.pushContext();
    ns.declarePrefix("dc", "http://www.purl.org/dc#");

    assertEquals("Test 1: Incorrect prefix count;",
            count + 1, countPrefixes());

    ns.reset();
    assertEquals("Test 2: Incorrect prefix count;",
            count, countPrefixes());

    // Check that only one context has been created by reset().
    try {
        ns.popContext();
        fail("Test 3: EmptyStackException expected.");
    } catch (EmptyStackException e) {
        // Expected.
    }
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: DOMScanner.java
/**
 * 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;
        }
    }
}
 
源代码10 项目: openjdk-jdk9   文件: StreamMessage.java
/**
 * 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()]);
}
 
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;
        }
    }
}
 
源代码12 项目: openjdk-jdk9   文件: DOMScanner.java
/**
 * 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;
        }
    }
}
 
源代码13 项目: openjdk-jdk9   文件: NSSupportTest.java
@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"));
}
 
源代码14 项目: openjdk-8-source   文件: DOMScanner.java
/**
 * 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;
        }
    }
}
 
源代码15 项目: openjdk-jdk9   文件: NSSupportTest.java
@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]);
}
 
源代码16 项目: hottub   文件: AbstractSchemaValidationTube.java
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;
        }
    }
}
 
源代码17 项目: openjdk-8   文件: AbstractSchemaValidationTube.java
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;
        }
    }
}
 
源代码18 项目: openjdk-jdk9   文件: NSSupportTest.java
/**
 * 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"});
}
 
源代码19 项目: openjdk-jdk9   文件: NSSupportTest.java
/**
 * 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"});
}
 
源代码20 项目: j2objc   文件: NamespaceSupportTest.java
@Override
public void setUp() {
    expected = new ArrayList<String>();
    expected.add("ak");
    expected.add("bk");

    ns = new NamespaceSupport();
    ns.pushContext();

    ns.declarePrefix("ak", marketUri);
    ns.declarePrefix("bk", marketUri);
    ns.declarePrefix("", defaultUri);
}