public Link getLink(boolean collapseWhitespace) { String anchor = text.toString(); if (collapseWhitespace) { anchor = anchor.replaceAll("\\s+", " ").trim(); } return new Link(type, uri, title, anchor, rel); } }
public String toString() { StringBuilder builder = new StringBuilder(); if (isImage()) { builder.append("<img src=\""); builder.append(uri);
/** * @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()); }
/** * @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()); }
/** * @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()); }
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 Link getLink(boolean collapseWhitespace) { String anchor = text.toString(); if (collapseWhitespace) { anchor = anchor.replaceAll("\\s+", " ").trim(); } return new Link(type, uri, title, anchor, rel); } }
public String toString() { StringBuilder builder = new StringBuilder(); if (isImage()) { builder.append("<img src=\""); builder.append(uri);
/** * @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()); }
public Link getLink(boolean collapseWhitespace) { String anchor = text.toString(); if (collapseWhitespace) { anchor = anchor.replaceAll("\\s+", " ").trim(); } return new Link(type, uri, title, anchor, rel); } }
public String toString() { StringBuilder builder = new StringBuilder(); if (isImage()) { builder.append("<img src=\""); builder.append(uri);
/** * @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()); }