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());
}
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());
}
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) {
}
}
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) {
}
}
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");
}
}
Aggregations