/** * @see <a href="https://issues.apache.org/jira/browse/TIKA-1937">TIKA-1937</a> */ @Test public void testEmbeddedScriptTag() throws Exception { LinkContentHandler linkContentHandler = new LinkContentHandler(); AttributesImpl atts = new AttributesImpl(); // no "src" attribute implies it's an embedded script linkContentHandler.startElement(XHTMLContentHandler.XHTML, "script", "", atts); linkContentHandler.endElement(XHTMLContentHandler.XHTML, "script", ""); assert(linkContentHandler.getLinks().isEmpty()); } }
@Override public void ignorableWhitespace(char[] ch, int start, int length) { characters(ch, start, length); }
public void rollback(File deployArea) throws IOException, SAXException, TikaException { LinkContentHandler handler = new LinkContentHandler(); Metadata met = new Metadata(); DeploymentAreaParser parser = new DeploymentAreaParser(); parser.parse(IOUtils.toInputStream(deployArea.getAbsolutePath(), UTF_8), handler, met); List<Link> links = handler.getLinks(); if (links.size() < 2) throw new IOException("Must have installed at least 2 versions!"); Collections.sort(links, new Comparator<Link>() { public int compare(Link o1, Link o2) { return o1.getText().compareTo(o2.getText()); } }); this.updateVersion(links.get(links.size() - 2).getText()); }
public static void testTeeContentHandler(String filename) throws Exception { InputStream stream = new ByteArrayInputStream(new byte[0]); Metadata metadata = new Metadata(); ParseContext context = new ParseContext(); Parser parser = new AutoDetectParser(); LinkContentHandler linkCollector = new LinkContentHandler(); try (OutputStream output = new FileOutputStream(new File(filename))) { ContentHandler handler = new TeeContentHandler( new BodyContentHandler(output), linkCollector); parser.parse(stream, handler, metadata, context); } }
try { LinkContentHandler linkHandler = new LinkContentHandler(); HtmlParser parser = new HtmlParser(); parser.parse(new ByteArrayInputStream(val.getBytes("utf-8")), linkHandler, new Metadata(), new ParseContext()); return linkHandler.getLinks().stream().map(Link::getUri); } catch (Exception e) { return Stream.empty();
/** * @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()); }
LinkContentHandler linkHandler = new LinkContentHandler(); ContentHandler textHandler = new BodyContentHandler(-1); TeeContentHandler teeHandler = new TeeContentHandler(linkHandler, List<Outlink> outlinks = toOutlinks(url, linkHandler.getLinks(), metadata);
if (alt != null) { char[] ch = alt.toCharArray(); characters(ch, 0, ch.length);
/** * @see <a href="https://issues.apache.org/jira/browse/TIKA-975">TIKA-975</a> */ @Test public void testWhitespaceCollapsing() throws Exception { LinkContentHandler linkContentHandler = new LinkContentHandler(true); linkContentHandler.startElement(XHTMLContentHandler.XHTML, "a", "", new AttributesImpl()); char[] anchorText = {'\n', 'N', 'o', ' ', 'w', 'h', 'i', 't', 'e', '\n', '\t', '\t', 's', 'p', 'a', 'c', 'e'}; linkContentHandler.characters(anchorText, 1, anchorText.length - 1); linkContentHandler.endElement(XHTMLContentHandler.XHTML, "a", ""); assertEquals("No white space", linkContentHandler.getLinks().get(0).getText()); }
@Override public void ignorableWhitespace(char[] ch, int start, int length) { characters(ch, start, length); }
/** * @see <a href="https://issues.apache.org/jira/browse/TIKA-1835">TIKA-1835</a> */ @Test public void testIframeTag() throws Exception { LinkContentHandler linkContentHandler = new LinkContentHandler(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "src", "src", "", "http://tika.apache.org/iframe.html"); linkContentHandler.startElement(XHTMLContentHandler.XHTML, "iframe", "", atts); linkContentHandler.endElement(XHTMLContentHandler.XHTML, "iframe", ""); assertEquals("http://tika.apache.org/iframe.html", linkContentHandler.getLinks().get(0).getUri()); }
@Override public void ignorableWhitespace(char[] ch, int start, int length) { characters(ch, start, length); }
/** * @see <a href="https://issues.apache.org/jira/browse/TIKA-1937">TIKA-1937</a> */ @Test public void testScriptTag() throws Exception { LinkContentHandler linkContentHandler = new LinkContentHandler(); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "src", "src", "", "http://tika.apache.org/script.js"); linkContentHandler.startElement(XHTMLContentHandler.XHTML, "script", "", atts); linkContentHandler.endElement(XHTMLContentHandler.XHTML, "script", ""); assertEquals("http://tika.apache.org/script.js", linkContentHandler.getLinks().get(0).getUri()); }
if (alt != null) { char[] ch = alt.toCharArray(); characters(ch, 0, ch.length);
/** * @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()); }
if (alt != null) { char[] ch = alt.toCharArray(); characters(ch, 0, ch.length);