Search in sources :

Example 1 with NamespaceSupport

use of org.xml.sax.helpers.NamespaceSupport in project robovm by robovm.

the class NamespaceSupportTest method testProcessName_Element.

public void testProcessName_Element() {
    String[] parts = new String[3];
    assertNotNull("Test 1: Non-null value expected.", ns.processName("ak:hello", parts, false));
    assertEquals("Test 2: Incorrect namespace URI;", marketUri, parts[0]);
    assertEquals("Test 3: Incorrect local name;", "hello", parts[1]);
    assertEquals("Test 4: Incorrect raw name;", "ak:hello", parts[2]);
    assertNotNull("Test 5: Non-null value expected.", ns.processName("bk:", parts, false));
    assertEquals("Test 6: Incorrect namespace URI;", marketUri, parts[0]);
    assertEquals("Test 7: Incorrect local name;", "", parts[1]);
    assertEquals("Test 8: Incorrect raw name;", "bk:", parts[2]);
    assertNotNull("Test 9: Non-null value expected.", ns.processName("world", parts, false));
    assertEquals("Test 10: Incorrect namespace URI;", defaultUri, parts[0]);
    assertEquals("Test 11: Incorrect local name;", "world", parts[1]);
    assertEquals("Test 12: Incorrect raw name;", "world", parts[2]);
    assertNull("Test 13: Null expected for undeclared prefix.", ns.processName("ck:lorem", parts, false));
    assertNull("Test 14: Null expected for xmlns prefix.", ns.processName("xmlns:ipsum", parts, false));
    ns = new NamespaceSupport();
    ns.pushContext();
    assertNotNull("Test 15: Non-null value expected.", ns.processName("world", parts, false));
    assertEquals("Test 16: Incorrect namespace URI;", "", parts[0]);
    assertEquals("Test 17: Incorrect local name;", "world", parts[1]);
    assertEquals("Test 18: Incorrect raw name;", "world", parts[2]);
}
Also used : NamespaceSupport(org.xml.sax.helpers.NamespaceSupport)

Example 2 with NamespaceSupport

use of org.xml.sax.helpers.NamespaceSupport in project robovm by robovm.

the class NamespaceSupportTest method testNamespaceDeclUris.

public void testNamespaceDeclUris() {
    assertFalse("Test 1: Incorrect default value returned by isNamespaceDeclUris().", ns.isNamespaceDeclUris());
    try {
        ns.setNamespaceDeclUris(true);
        fail("Test 2: IllegalStateException expected since a context has already been pushed in setUp().");
    } catch (IllegalStateException e) {
    // Expected.
    }
    ns = new NamespaceSupport();
    ns.setNamespaceDeclUris(true);
    assertTrue("Test 3: Incorrect value returned by isNamespaceDeclUris().", ns.isNamespaceDeclUris());
    ns.setNamespaceDeclUris(false);
    assertFalse("Test 4: Incorrect value returned by isNamespaceDeclUris().", ns.isNamespaceDeclUris());
}
Also used : NamespaceSupport(org.xml.sax.helpers.NamespaceSupport)

Example 3 with NamespaceSupport

use of org.xml.sax.helpers.NamespaceSupport in project robovm by robovm.

the class NamespaceSupportTest method testPush_PopContext.

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.
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) NamespaceSupport(org.xml.sax.helpers.NamespaceSupport)

Example 4 with NamespaceSupport

use of org.xml.sax.helpers.NamespaceSupport in project j2objc by google.

the class StylesheetHandler method startElement.

/**
   * Receive notification of the start of an element.
   *
   * @param uri The Namespace URI, or an empty string.
   * @param localName The local name (without prefix), or empty string if not namespace processing.
   * @param rawName The qualified name (with prefix).
   * @param attributes The specified or defaulted attributes.
   *
   * @throws org.xml.sax.SAXException
   */
public void startElement(String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
    NamespaceSupport nssupport = this.getNamespaceSupport();
    nssupport.pushContext();
    int n = m_prefixMappings.size();
    for (int i = 0; i < n; i++) {
        String prefix = (String) m_prefixMappings.elementAt(i++);
        String nsURI = (String) m_prefixMappings.elementAt(i);
        nssupport.declarePrefix(prefix, nsURI);
    }
    //m_prefixMappings.clear(); // JDK 1.2+ only -sc
    // JDK 1.1.x compat -sc
    m_prefixMappings.removeAllElements();
    m_elementID++;
    // This check is currently done for all elements.  We should possibly consider
    // limiting this check to xsl:stylesheet elements only since that is all it really
    // applies to.  Also, it could be bypassed if m_shouldProcess is already true.
    // In other words, the next two statements could instead look something like this:
    // if (!m_shouldProcess)
    // {
    //   if (localName.equals(Constants.ELEMNAME_STYLESHEET_STRING) &&
    //       url.equals(Constants.S_XSLNAMESPACEURL))
    //   {
    //     checkForFragmentID(attributes);
    //     if (!m_shouldProcess)
    //       return;
    //   }
    //   else
    //     return;
    // } 
    // I didn't include this code statement at this time because in practice 
    // it is a small performance hit and I was waiting to see if its absence
    // caused a problem. - GLP
    checkForFragmentID(attributes);
    if (!m_shouldProcess)
        return;
    flushCharacters();
    pushSpaceHandling(attributes);
    XSLTElementProcessor elemProcessor = getProcessorFor(uri, localName, rawName);
    if (// defensive, for better multiple error reporting. -sb
    null != elemProcessor) {
        this.pushProcessor(elemProcessor);
        elemProcessor.startElement(this, uri, localName, rawName, attributes);
    } else {
        m_shouldProcess = false;
        popSpaceHandling();
    }
}
Also used : NamespaceSupport(org.xml.sax.helpers.NamespaceSupport)

Example 5 with NamespaceSupport

use of org.xml.sax.helpers.NamespaceSupport in project XobotOS by xamarin.

the class XMLWriter method init.

/**
     * Internal initialization method.
     *
     * <p>All of the public constructors invoke this method.
     *
     * @param writer The output destination, or null to use
     *        standard output.
     */
private void init(Writer writer) {
    setOutput(writer);
    nsSupport = new NamespaceSupport();
    prefixTable = new Hashtable();
    forcedDeclTable = new Hashtable();
    doneDeclTable = new Hashtable();
    outputProperties = new Properties();
}
Also used : Hashtable(java.util.Hashtable) NamespaceSupport(org.xml.sax.helpers.NamespaceSupport) Properties(java.util.Properties)

Aggregations

NamespaceSupport (org.xml.sax.helpers.NamespaceSupport)11 EmptyStackException (java.util.EmptyStackException)3 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 Hashtable (java.util.Hashtable)1 Properties (java.util.Properties)1