Example usage for org.xml.sax.helpers AttributesImpl AttributesImpl

List of usage examples for org.xml.sax.helpers AttributesImpl AttributesImpl

Introduction

In this page you can find the example usage for org.xml.sax.helpers AttributesImpl AttributesImpl.

Prototype

public AttributesImpl() 

Source Link

Document

Construct a new, empty AttributesImpl object.

Usage

From source file:com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactoryTest.java

@Test
public void testCssClientLibraryWithSameSchemePath() throws Exception {

    when(htmlLibraryManager.getLibrary(eq(LibraryType.CSS), eq(PATH))).thenReturn(htmlLibrary);

    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "href", "", "CDATA", "//example.com/same/scheme/styles.css");
    in.addAttribute("", "type", "", "CDATA", "text/css");
    in.addAttribute("", "rel", "", "CDATA", "stylesheet");

    transformer.startElement(null, "link", null, in);

    ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);

    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class),
            attributesCaptor.capture());

    assertEquals("//example.com/same/scheme/styles.css", attributesCaptor.getValue().getValue(0));
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java

@Test(expected = SAXParseException.class)
public void processFieldMapTargetExceptionTest() throws Exception {
    ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS);
    test.startDocument();/*from  ww  w  .j  a va2s.  c  o  m*/
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "", "name", "", "Stream attr name"); // NON-NLS
    attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS
    attrs.addAttribute("", "", "target", "", null); // NON-NLS
    attrs.addAttribute("", "", "value", "", ""); // NON-NLS
    attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "field-map", attrs); // NON-NLS
}

From source file:com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactoryTest.java

@Test
public void testJavaScriptClientLibraryWithDomainedPath() throws Exception {

    when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PATH))).thenReturn(htmlLibrary);

    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "src", "", "CDATA", "http://www.example.com/same/scheme/script.js");
    in.addAttribute("", "type", "", "CDATA", "text/javascript");

    transformer.startElement(null, "script", null, in);

    ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);

    verify(handler, only()).startElement(isNull(String.class), eq("script"), isNull(String.class),
            attributesCaptor.capture());

    assertEquals("http://www.example.com/same/scheme/script.js", attributesCaptor.getValue().getValue(0));
}

From source file:biz.taoconsulting.oxf.processor.converter.FromPdfConverter.java

/**
 * processBookmark gets called recursively for all nested bookmarks extracts
 * the bookmark and the text//from  w w  w . j a  v a  2 s .  com
        
 */
private void processBookmark(ContentHandler hd, PDDocument doc, PDOutlineItem curItem, String scope,
        int level) {
    // First we check on what page the bookmark is. If we can't retrieve the
    // page the bookmark can't be the outline we are looking for, however we
    // would process children (you never know)
    try {

        int curPageNo = getPageNumber(doc, curItem);

        if (curPageNo > -1) {

            AttributesImpl atts = new AttributesImpl();
            atts.addAttribute("", ATT_LEVEL, ATT_LEVEL, ATT_CDATA, Integer.toString(level));
            atts.addAttribute("", ATT_PAGE, ATT_PAGE, ATT_CDATA, Integer.toString(curPageNo));

            hd.startElement("", TAG_BOOKMARK, TAG_BOOKMARK, atts);

            // Write the properties of interest
            atts.clear();
            hd.startElement("", TAG_TITLE, TAG_TITLE, atts);
            String curTitle = curItem.getTitle();
            hd.characters(curTitle.toCharArray(), 0, curTitle.length());
            hd.endElement("", TAG_TITLE, TAG_TITLE);

            //write out the text associated with this bookmark
            // if the scope allows for that

            if (!scope.toLowerCase().equals(SCOPE_BOOKMARKSONLY)) {

                PDFTextStripper stripper = new PDFTextStripper();
                stripper.setStartBookmark(curItem);
                stripper.setEndBookmark(curItem);
                String textBetweenBookmarks = stripper.getText(doc);
                hd.startElement("", TAG_TEXT, TAG_TEXT, atts);
                textBetweenBookmarks = MassageTextResult(textBetweenBookmarks);
                hd.characters(textBetweenBookmarks.toCharArray(), 0, textBetweenBookmarks.length());
                hd.endElement("", TAG_TEXT, TAG_TEXT);

            }

        }
        // Now check the children
        PDOutlineItem child = curItem.getFirstChild();
        while (child != null) {
            processBookmark(hd, doc, child, scope, level + 1);
            logger.info("Child:" + child.getTitle());
            child = child.getNextSibling();
        }
        // Close the mark
        hd.endElement("", TAG_BOOKMARK, TAG_BOOKMARK);
    } catch (SAXException e) {
        logger.error(e);
        addErrorTagToOutput(hd, e.toString());
    } catch (IOException e) {
        logger.error(e);
        addErrorTagToOutput(hd, e.toString());
    } finally {
        // Nothing concluding to do
    }
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java

@Test(expected = SAXException.class)
public void processStreamExceptionTest() throws Exception {
    ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS);
    test.startDocument();//  w w  w  . ja  v  a  2  s .c o m
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "", "name", "", "Stream attr name"); // NON-NLS
    attrs.addAttribute("", "", "source", "", null); // NON-NLS
    attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS
    attrs.addAttribute("", "", "value", "", ""); // NON-NLS
    attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "stream", attrs); // NON-NLS
}

From source file:com.adobe.acs.commons.rewriter.impl.VersionedClientlibsTransformerFactoryTest.java

@Test
public void testCssClientLibraryWithSameDomainedPath() throws Exception {

    when(htmlLibraryManager.getLibrary(eq(LibraryType.CSS), eq(PATH))).thenReturn(htmlLibrary);

    final AttributesImpl in = new AttributesImpl();
    in.addAttribute("", "href", "", "CDATA", "https://example.com/same/scheme/styles.css");
    in.addAttribute("", "type", "", "CDATA", "text/css");
    in.addAttribute("", "rel", "", "CDATA", "stylesheet");

    transformer.startElement(null, "link", null, in);

    ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);

    verify(handler, only()).startElement(isNull(String.class), eq("link"), isNull(String.class),
            attributesCaptor.capture());

    assertEquals("https://example.com/same/scheme/styles.css", attributesCaptor.getValue().getValue(0));
}

From source file:net.ontopia.topicmaps.db2tm.RelationMapping.java

protected void write(ContentHandler dh) throws SAXException {

    // initialize attributes
    AttributesImpl atts = new AttributesImpl();

    // <db2tm name="...">
    if (name != null)
        addAttribute(atts, "name", "CDATA", name);

    dh.startDocument();/*from  w  ww  .  j ava 2s. c o m*/
    dh.startElement("", "", "db2tm", atts);
    atts.clear();

    // prefixes
    for (Prefix prefix : iprefixes.values()) {
        addAttribute(atts, "prefix", "CDATA", prefix.getId());

        switch (prefix.getType()) {
        case Prefix.TYPE_SUBJECT_IDENTIFIER:
            addAttribute(atts, "subject-identifier", "CDATA", prefix.getLocator());
            break;
        case Prefix.TYPE_ITEM_IDENTIFIER:
            addAttribute(atts, "item-identifier", "CDATA", prefix.getLocator());
            break;
        case Prefix.TYPE_SUBJECT_LOCATOR:
            addAttribute(atts, "subject-locator", "CDATA", prefix.getLocator());
            break;
        }

        dh.startElement("", "", "using", atts);
        atts.clear();
        dh.endElement("", "", "using");
    }

    // relations
    for (Relation rel : getRelations()) {
        // <relation>
        addAttribute(atts, "name", "CDATA", rel.getName());
        addAttribute(atts, "columns", "CDATA", rel.getColumns());
        dh.startElement("", "", "relation", atts);
        atts.clear();

        outputEntities(rel, dh);

        // </relation>
        dh.endElement("", "", "relation");
    }

    // </db2tm>
    dh.endElement("", "", "db2tm");
    dh.endDocument();
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java

@Test(expected = SAXException.class)
public void processStreamNotNullStreamTest() throws Exception {
    ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS);
    TNTInputStream<?, ?> my = Mockito.mock(TNTInputStream.class, Mockito.CALLS_REAL_METHODS);
    test.startDocument();/*from   ww w.  java 2  s  .  co  m*/
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "", "name", "", "Stream attr name"); // NON-NLS
    attrs.addAttribute("", "", "source", "", null); // NON-NLS
    attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS
    attrs.addAttribute("", "", "value", "", ""); // NON-NLS
    attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS
    my.setName("Stream attr name"); // NON-NLS
    test.getStreamsConfigData().addStream(my);
    test.startElement("TEST_URL", "TEST_LOCALNAME", "stream", attrs); // NON-NLS
}

From source file:nl.architolk.ldt.processors.HttpClientProcessor.java

private void parseJSONObject(ContentHandler contentHandler, JSONObject json) throws SAXException {
    Object[] names = json.names().toArray();
    for (int i = 0; i < names.length; i++) {
        String name = (String) names[i];
        Object value = json.get(name);
        String safeName = name.replace('@', '_');
        contentHandler.startElement("", safeName, safeName, new AttributesImpl());

        if (value instanceof JSONObject) {
            parseJSONObject(contentHandler, (JSONObject) value);
        } else if (value instanceof JSONArray) {
            Iterator<?> jsonit = ((JSONArray) value).iterator();
            while (jsonit.hasNext()) {
                Object arrayValue = jsonit.next();
                if (arrayValue instanceof JSONObject) {
                    parseJSONObject(contentHandler, (JSONObject) arrayValue);
                } else {
                    String textValue = String.valueOf(arrayValue);
                    contentHandler.characters(textValue.toCharArray(), 0, textValue.length());
                }/*from   ww w  .  j a  va2  s . c  o m*/
                //Array means repeating the XML node, so end the current node, and start a new one
                if (jsonit.hasNext()) {
                    contentHandler.endElement("", safeName, safeName);
                    contentHandler.startElement("", safeName, safeName, new AttributesImpl());
                }
            }
        } else {
            String textValue = String.valueOf(value);
            contentHandler.characters(textValue.toCharArray(), 0, textValue.length());
        }

        contentHandler.endElement("", safeName, safeName);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.ConfigParserHandlerTest.java

@Test(expected = SAXParseException.class)
public void processStreamIsEmptyClassExceptionTest() throws Exception {
    ConfigParserHandler test = Mockito.mock(ConfigParserHandler.class, Mockito.CALLS_REAL_METHODS);
    test.startDocument();//from   w w w .j ava2 s .  c  om
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "", "name", "", "Stream name value"); // NON-NLS
    attrs.addAttribute("", "", "source", "", "Stream source value"); // NON-NLS
    attrs.addAttribute("", "", "target", "", "Stream target value"); // NON-NLS
    attrs.addAttribute("", "", "value", "", ""); // NON-NLS
    attrs.addAttribute("", "", "class", "", "com.jkoolcloud.tnt4j.streams.parsers.ActivityTokenParser"); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "parser", attrs); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "field", attrs); // NON-NLS
    attrs.addAttribute("", "", "class", "", ""); // NON-NLS
    test.startElement("TEST_URL", "TEST_LOCALNAME", "stream", attrs); // NON-NLS
}