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

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

源代码1 项目: 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]);
}
 
源代码2 项目: openjdk-jdk9   文件: NSSupportTest.java
/**
 * 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});
}
 
源代码3 项目: j2objc   文件: NamespaceSupportTest.java
@SuppressWarnings("unchecked")
public void testConstructor() {
    String prefix;
    boolean xmlPrefixExists = false;

    ns = new NamespaceSupport();
    Enumeration<String> prefixes = ns.getDeclaredPrefixes();

    while (prefixes.hasMoreElements()) {
        prefix = prefixes.nextElement();
        if (prefix.equals("xml")) xmlPrefixExists = true;
    }

    assertTrue("Test 1: xml prefix does not exist.", xmlPrefixExists);

    // Check that only one context has been created by the constructor.
    try {
        ns.popContext();
        fail("Test 2: EmptyStackException expected.");
    } catch (EmptyStackException e) {
        // Expected.
    }
}
 
源代码4 项目: 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.
    }
}
 
源代码5 项目: 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.
    }
}
 
源代码6 项目: 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"});
}
 
源代码7 项目: 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"});
}
 
源代码8 项目: openjdk-jdk9   文件: NSSupportTest.java
/**
 * Test for NamespaceSupport.popContext().
 */
@Test
public void testcase04() {
    NamespaceSupport support = new NamespaceSupport();

    support.pushContext();
    support.declarePrefix(EMPTY_PREFIX, W3_URI);
    support.declarePrefix(DC_PREFIX, PURL_URI);

    assertEquals(support.getURI(EMPTY_PREFIX), W3_URI);
    assertEquals(support.getURI(DC_PREFIX), PURL_URI);
    support.popContext();
    assertNull(support.getURI(EMPTY_PREFIX));
    assertNull(support.getURI(DC_PREFIX));
}