Search in sources :

Example 31 with Attributes

use of org.xml.sax.Attributes in project geode by apache.

the class LuceneIndexXmlGeneratorJUnitTest method generateWithFields.

/**
   * Test of generating and reading cache configuration back in.
   */
@Test
public void generateWithFields() throws Exception {
    LuceneIndex index = mock(LuceneIndex.class);
    when(index.getName()).thenReturn("index");
    String[] fields = new String[] { "field1", "field2" };
    when(index.getFieldNames()).thenReturn(fields);
    LuceneIndexXmlGenerator generator = new LuceneIndexXmlGenerator(index);
    CacheXmlGenerator cacheXmlGenerator = mock(CacheXmlGenerator.class);
    ContentHandler handler = mock(ContentHandler.class);
    when(cacheXmlGenerator.getContentHandler()).thenReturn(handler);
    generator.generate(cacheXmlGenerator);
    ArgumentCaptor<Attributes> captor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler).startElement(eq(""), eq("index"), eq("lucene:index"), captor.capture());
    Attributes value = captor.getValue();
    assertEquals("index", value.getValue(LuceneXmlConstants.NAME));
    captor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, times(2)).startElement(eq(""), eq("field"), eq("lucene:field"), captor.capture());
    Set<String> foundFields = new HashSet<String>();
    for (Attributes fieldAttr : captor.getAllValues()) {
        foundFields.add(fieldAttr.getValue(LuceneXmlConstants.NAME));
    }
    HashSet<String> expected = new HashSet<String>(Arrays.asList(fields));
    assertEquals(expected, foundFields);
    verify(handler, times(2)).endElement(eq(""), eq("field"), eq("lucene:field"));
    verify(handler).endElement(eq(""), eq("index"), eq("lucene:index"));
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) CacheXmlGenerator(org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator) Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler) HashSet(java.util.HashSet) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 32 with Attributes

use of org.xml.sax.Attributes in project sling by apache.

the class Parser method parseParam.

/**
     * Param ::= '<jsp:param' S Attributes S? EmptyBody S?
     */
private void parseParam(Node parent) throws JasperException {
    if (!reader.matches("<jsp:param")) {
        err.jspError(reader.mark(), "jsp.error.paramexpected");
    }
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    Node paramActionNode = new Node.ParamAction(attrs, start, parent);
    parseEmptyBody(paramActionNode, "jsp:param");
    reader.skipSpaces();
}
Also used : Attributes(org.xml.sax.Attributes)

Example 33 with Attributes

use of org.xml.sax.Attributes in project sling by apache.

the class Parser method parsePageDirective.

/*
     * Parses a page directive with the following syntax: PageDirective ::= ( S
     * Attribute)*
     */
private void parsePageDirective(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    Node.PageDirective n = new Node.PageDirective(attrs, start, parent);
    /*
         * A page directive may contain multiple 'import' attributes, each of
         * which consists of a comma-separated list of package names. Store each
         * list with the node, where it is parsed.
         */
    for (int i = 0; i < attrs.getLength(); i++) {
        if ("import".equals(attrs.getQName(i))) {
            n.addImport(attrs.getValue(i));
        }
    }
}
Also used : Attributes(org.xml.sax.Attributes)

Example 34 with Attributes

use of org.xml.sax.Attributes in project sling by apache.

the class Parser method parseElement.

private void parseElement(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    reader.skipSpaces();
    Node elementNode = new Node.JspElement(attrs, start, parent);
    parseOptionalBody(elementNode, "jsp:element", TagInfo.BODY_CONTENT_JSP);
}
Also used : Attributes(org.xml.sax.Attributes)

Example 35 with Attributes

use of org.xml.sax.Attributes in project sling by apache.

the class Parser method parseVariableDirective.

/*
     * Parses a variable directive with the following syntax: PageDirective ::= (
     * S Attribute)*
     */
private void parseVariableDirective(Node parent) throws JasperException {
    Attributes attrs = parseAttributes();
    Node.VariableDirective n = new Node.VariableDirective(attrs, start, parent);
}
Also used : Attributes(org.xml.sax.Attributes)

Aggregations

Attributes (org.xml.sax.Attributes)274 DefaultHandler (org.xml.sax.helpers.DefaultHandler)70 SAXException (org.xml.sax.SAXException)66 Test (org.junit.Test)59 AttributesImpl (org.xml.sax.helpers.AttributesImpl)50 SAXParser (javax.xml.parsers.SAXParser)48 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)37 InputSource (org.xml.sax.InputSource)31 SAXParserFactory (javax.xml.parsers.SAXParserFactory)30 IOException (java.io.IOException)29 File (java.io.File)22 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ArrayList (java.util.ArrayList)17 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 InputStream (java.io.InputStream)16 ContentHandler (org.xml.sax.ContentHandler)15 XMLReader (org.xml.sax.XMLReader)15 StringReader (java.io.StringReader)10 Transformer (org.apache.sling.rewriter.Transformer)10 MockBundle (org.apache.sling.commons.testing.osgi.MockBundle)9