Search in sources :

Example 6 with NamespaceSupport

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

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 7 with NamespaceSupport

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

the class NamespaceSupportTest method testProcessName_Attribute.

public void testProcessName_Attribute() {
    String[] parts = new String[3];
    assertNotNull("Test 1: Non-null value expected.", ns.processName("ak:hello", parts, true));
    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, true));
    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, true));
    assertEquals("Test 10: Incorrect namespace URI;", "", 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, true));
    assertNull("Test 14: Null expected for xmlns prefix.", ns.processName("xmlns:ipsum", parts, true));
    ns = new NamespaceSupport();
    ns.setNamespaceDeclUris(true);
    ns.pushContext();
    assertNotNull("Test 15: Non-null value expected.", ns.processName("xmlns", parts, true));
    assertEquals("Test 16: Incorrect namespace URI;", NamespaceSupport.NSDECL, parts[0]);
    assertEquals("Test 17: Incorrect local name;", "xmlns", parts[1]);
    assertEquals("Test 18: Incorrect raw name;", "xmlns", parts[2]);
}
Also used : NamespaceSupport(org.xml.sax.helpers.NamespaceSupport)

Example 8 with NamespaceSupport

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

the class NamespaceSupportTest method testReset.

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

Example 9 with NamespaceSupport

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

the class NamespaceSupportTest method testConstructor.

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

Example 10 with NamespaceSupport

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

the class NamespaceSupportTest method setUp.

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

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