Search in sources :

Example 86 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project tika by apache.

the class LinkContentHandlerTest method testDefaultBehavior.

/**
     * @see <a href="https://issues.apache.org/jira/browse/TIKA-975">TIKA-975</a>
     */
@Test
public void testDefaultBehavior() throws Exception {
    LinkContentHandler linkContentHandler = new LinkContentHandler();
    linkContentHandler.startElement(XHTMLContentHandler.XHTML, "a", "", new AttributesImpl());
    char[] anchorText = { ' ', 'a', 'n', 'c', 'h', 'o', 'r', ' ' };
    linkContentHandler.characters(anchorText, 0, anchorText.length);
    linkContentHandler.endElement(XHTMLContentHandler.XHTML, "a", "");
    assertEquals(" anchor ", linkContentHandler.getLinks().get(0).getText());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Test(org.junit.Test)

Example 87 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project tika by apache.

the class LinkContentHandlerTest method testLinkTag.

/**
     * @see <a href="https://issues.apache.org/jira/browse/TIKA-1835">TIKA-1835</a>
     */
@Test
public void testLinkTag() throws Exception {
    LinkContentHandler linkContentHandler = new LinkContentHandler();
    AttributesImpl atts = new AttributesImpl();
    atts.addAttribute("", "href", "href", "", "http://tika.apache.org/stylesheet.css");
    atts.addAttribute("", "rel", "rel", "", "stylesheet");
    linkContentHandler.startElement(XHTMLContentHandler.XHTML, "link", "", atts);
    linkContentHandler.endElement(XHTMLContentHandler.XHTML, "link", "");
    assertEquals("http://tika.apache.org/stylesheet.css", linkContentHandler.getLinks().get(0).getUri());
    assertEquals("stylesheet", linkContentHandler.getLinks().get(0).getRel());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Test(org.junit.Test)

Example 88 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project tika by apache.

the class OOXMLTikaBodyPartHandler method embeddedPicRef.

@Override
public void embeddedPicRef(String picFileName, String picDescription) {
    try {
        AttributesImpl attr = new AttributesImpl();
        if (picFileName != null) {
            attr.addAttribute("", "src", "src", "CDATA", "embedded:" + picFileName);
        }
        if (picDescription != null) {
            attr.addAttribute("", "alt", "alt", "CDATA", picDescription);
        }
        xhtml.startElement("img", attr);
        xhtml.endElement("img");
    } catch (SAXException e) {
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) SAXException(org.xml.sax.SAXException)

Example 89 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project tika by apache.

the class OOXMLTikaBodyPartHandler method embeddedOLERef.

@Override
public void embeddedOLERef(String relId) {
    if (relId == null) {
        return;
    }
    try {
        AttributesImpl attributes = new AttributesImpl();
        attributes.addAttribute("", "class", "class", "CDATA", "embedded");
        attributes.addAttribute("", "id", "id", "CDATA", relId);
        xhtml.startElement("div", attributes);
        xhtml.endElement("div");
    } catch (SAXException e) {
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) SAXException(org.xml.sax.SAXException)

Example 90 with AttributesImpl

use of org.xml.sax.helpers.AttributesImpl in project tika by apache.

the class SXSLFPowerPointExtractorDecorator method handleBasicRelatedParts.

/**
     * This should handle the comments, master, notes, etc
     *
     * @param contentType
     * @param xhtmlClassLabel
     * @param parentPart
     * @param contentHandler
     */
private void handleBasicRelatedParts(String contentType, String xhtmlClassLabel, PackagePart parentPart, ContentHandler contentHandler) throws SAXException {
    PackageRelationshipCollection relatedPartPRC = null;
    try {
        relatedPartPRC = parentPart.getRelationshipsByType(contentType);
    } catch (InvalidFormatException e) {
        metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e));
    }
    if (relatedPartPRC != null && relatedPartPRC.size() > 0) {
        AttributesImpl attributes = new AttributesImpl();
        attributes.addAttribute("", "class", "class", "CDATA", xhtmlClassLabel);
        contentHandler.startElement("", "div", "div", attributes);
        for (int i = 0; i < relatedPartPRC.size(); i++) {
            PackageRelationship relatedPartPackageRelationship = relatedPartPRC.getRelationship(i);
            try {
                PackagePart relatedPartPart = parentPart.getRelatedPart(relatedPartPackageRelationship);
                try (InputStream stream = relatedPartPart.getInputStream()) {
                    context.getSAXParser().parse(stream, new OfflineContentHandler(new EmbeddedContentHandler(contentHandler)));
                } catch (IOException | TikaException e) {
                    metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e));
                }
            } catch (InvalidFormatException e) {
                metadata.add(TikaCoreProperties.TIKA_META_EXCEPTION_WARNING, ExceptionUtils.getStackTrace(e));
            }
        }
        contentHandler.endElement("", "div", "div");
    }
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) AttributesImpl(org.xml.sax.helpers.AttributesImpl) OfflineContentHandler(org.apache.tika.sax.OfflineContentHandler) TikaException(org.apache.tika.exception.TikaException) PackageRelationshipCollection(org.apache.poi.openxml4j.opc.PackageRelationshipCollection) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream) InputStream(java.io.InputStream) EmbeddedContentHandler(org.apache.tika.sax.EmbeddedContentHandler) IOException(java.io.IOException) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException)

Aggregations

AttributesImpl (org.xml.sax.helpers.AttributesImpl)310 SAXException (org.xml.sax.SAXException)53 Test (org.junit.Test)34 DiskWriteAttributesImpl (org.apache.geode.internal.cache.DiskWriteAttributesImpl)23 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)23 ContentHandler (org.xml.sax.ContentHandler)21 Attributes (org.xml.sax.Attributes)17 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 Map (java.util.Map)16 PackOut (org.adempiere.pipo.PackOut)16 IOException (java.io.IOException)15 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)12 Iterator (java.util.Iterator)11 TransformerHandler (javax.xml.transform.sax.TransformerHandler)11 StreamResult (javax.xml.transform.stream.StreamResult)11 Metadata (org.apache.tika.metadata.Metadata)11 File (java.io.File)9 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)9 DatabaseAccessException (org.adempiere.pipo.exception.DatabaseAccessException)9