@Test public void testReplacementLinks() throws Exception { Assert.assertEquals("test_test", dc.cleanLinkId(LINK_URL, "test*&^$#˜∂test", false)); Assert.assertEquals("test", dc.cleanLinkId(LINK_URL, "&(^test", false)); Assert.assertEquals("test", dc.cleanLinkId(LINK_URL, "test^%$", false)); }
String cleanLinkId(String url, String linkId, boolean image) { String ret = linkId.replace('\n', ' '); ret = LINK_MULTIPLE_SPACES.matcher(ret).replaceAll(" "); ret = LINK_SAFE_CHARS.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_MULTIPLE_REPLACE.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_EDGE_REPLACE.matcher(ret).replaceAll(""); ret = ret.trim(); if(ret.length() == 0 || ret.equals(LINK_REPLACEMENT)) { if(image) { if(url != null) { Matcher m = LINK_FILENAME.matcher(url); if(m.find()) { ret = cleanLinkId(null, m.group(1), true); } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericLinkUrlCounter++; ret = "Link " + genericLinkUrlCounter; } } return ret; }
DocumentConverter { String cleanLinkId(String url, String linkId, boolean image) { String ret = linkId.replace('\n', ' '); ret = LINK_MULTIPLE_SPACES.matcher(ret).replaceAll(" "); ret = LINK_SAFE_CHARS.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_MULTIPLE_REPLACE.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_EDGE_REPLACE.matcher(ret).replaceAll(""); ret = ret.trim(); if(ret.length() == 0 || ret.equals(LINK_REPLACEMENT)) { if(image) { if(url != null) { Matcher m = LINK_FILENAME.matcher(url); if(m.find()) { ret = cleanLinkId(null, m.group(1), true); } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericLinkUrlCounter++; ret = "Link " + genericLinkUrlCounter; } } return ret; } }
DocumentConverter { String cleanLinkId(String url, String linkId, boolean image) { String ret = linkId.replace('\n', ' '); ret = LINK_MULTIPLE_SPACES.matcher(ret).replaceAll(" "); ret = LINK_SAFE_CHARS.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_MULTIPLE_REPLACE.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_EDGE_REPLACE.matcher(ret).replaceAll(""); ret = ret.trim(); if(ret.length() == 0 || ret.equals(LINK_REPLACEMENT)) { if(image) { if(url != null) { Matcher m = LINK_FILENAME.matcher(url); if(m.find()) { ret = cleanLinkId(null, m.group(1), true); } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericLinkUrlCounter++; ret = "Link " + genericLinkUrlCounter; } } return ret; } DocumentConverter(Options options); }
DocumentConverter { String cleanLinkId(String url, String linkId, boolean image) { String ret = linkId.replace('\n', ' '); ret = LINK_MULTIPLE_SPACES.matcher(ret).replaceAll(" "); ret = LINK_SAFE_CHARS.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_MULTIPLE_REPLACE.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_EDGE_REPLACE.matcher(ret).replaceAll(""); ret = ret.trim(); if(ret.length() == 0 || ret.equals(LINK_REPLACEMENT)) { if(image) { if(url != null) { Matcher m = LINK_FILENAME.matcher(url); if(m.find()) { ret = cleanLinkId(null, m.group(1), true); } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericLinkUrlCounter++; ret = "Link " + genericLinkUrlCounter; } } return ret; } DocumentConverter(Options options); @SuppressWarnings({"UnusedDeclaration"}) Options getOptions(); @SuppressWarnings({"UnusedDeclaration"}) TextCleaner getCleaner(); @SuppressWarnings({"UnusedDeclaration"}) Map<String, NodeHandler> getBlockNodes(); @SuppressWarnings({"UnusedDeclaration"}) Map<String, NodeHandler> getInlineNodes(); @SuppressWarnings({"UnusedDeclaration"}) BlockWriter getOutput(); @SuppressWarnings({"UnusedDeclaration"}) void setOutput(BlockWriter output); @SuppressWarnings({"WeakerAccess"}) void addInlineNode(NodeHandler handler, String tagnames); @SuppressWarnings({"WeakerAccess"}) void addBlockNode(NodeHandler handler, String tagnames); void convert(Document doc, Writer out); void convert(Document doc, OutputStream out); String convert(Document doc); void walkNodes(NodeHandler currentNode, Element el); void walkNodes(NodeHandler currentNodeHandler, Element el, Map<String, NodeHandler> nodeList); String getInlineContent(NodeHandler currentNode, Element el); String getInlineContent(NodeHandler currentNode, Element el, boolean undoLeadingEscapes); String addLink(String url, String recommendedName, boolean image); }
DocumentConverter { String cleanLinkId(String url, String linkId, boolean image) { String ret = linkId.replace('\n', ' '); ret = LINK_MULTIPLE_SPACES.matcher(ret).replaceAll(" "); ret = LINK_SAFE_CHARS.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_MULTIPLE_REPLACE.matcher(ret).replaceAll(LINK_REPLACEMENT); ret = LINK_EDGE_REPLACE.matcher(ret).replaceAll(""); ret = ret.trim(); if(ret.length() == 0 || ret.equals(LINK_REPLACEMENT)) { if(image) { if(url != null) { Matcher m = LINK_FILENAME.matcher(url); if(m.find()) { ret = cleanLinkId(null, m.group(1), true); } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericImageUrlCounter++; ret = "Image " + genericImageUrlCounter; } } else { genericLinkUrlCounter++; ret = "Link " + genericLinkUrlCounter; } } return ret; } DocumentConverter(Options options); @SuppressWarnings({"UnusedDeclaration"}) Options getOptions(); @SuppressWarnings({"UnusedDeclaration"}) TextCleaner getCleaner(); @SuppressWarnings({"UnusedDeclaration"}) Map<String, NodeHandler> getBlockNodes(); @SuppressWarnings({"UnusedDeclaration"}) Map<String, NodeHandler> getInlineNodes(); @SuppressWarnings({"UnusedDeclaration"}) BlockWriter getOutput(); @SuppressWarnings({"UnusedDeclaration"}) void setOutput(BlockWriter output); @SuppressWarnings({"WeakerAccess"}) void addInlineNode(NodeHandler handler, String tagnames); @SuppressWarnings({"WeakerAccess"}) void addBlockNode(NodeHandler handler, String tagnames); void convert(Document doc, Writer out); void convert(Document doc, OutputStream out); String convert(Document doc); void walkNodes(NodeHandler currentNode, Element el); void walkNodes(NodeHandler currentNodeHandler, Element el, Map<String, NodeHandler> nodeList); String getInlineContent(NodeHandler currentNode, Element el); String getInlineContent(NodeHandler currentNode, Element el, boolean undoLeadingEscapes); String addLink(String url, String recommendedName, boolean image);  }