Skip to content

Commit

Permalink
#38 replace the scrubbed link with text (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeach47 authored Aug 6, 2020
1 parent ca9338d commit 6a550f0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ jspApiVersion=2.3.3
servletApiVersion=4.0.1
junitVersion=4.12
# All building blocks / web services are re-versioned when this changes.
artifactVersion=2.2.0
artifactVersion=2.2.1-Alpha
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public synchronized void submit(HttpServletRequest request) throws Exception {
Runnable runner = new Runnable() {
@Override
public void run() {
// At the start of any run, reset the stats
// `percent` is reset elsewhere, so ignore for this
lookedAt = 0;
equellaLookedAt = 0;
fixedItems = 0;
try {
if(dryrun) {
utils.log(0, dryrunStr + "No changes to the content will be performed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;

import java.net.MalformedURLException;
Expand Down Expand Up @@ -433,9 +434,17 @@ private String scrubDescription(String str, int level, String[] urls) {
// Remove all old integration links
Elements elems = d.select("a[href^=\"/webapps/dych-tle-\"]");
for(Element e : elems) {
e.remove();
log(level + 1, "Removing the element ([lt] == <): " + e.outerHtml().replaceAll("<", "[lt]"));
}
final String origElem = e.outerHtml();
if(e.hasText() && e.hasParent()) {
// Leave the visible text of the link intact to provide more context
TextNode textNode = new TextNode(e.text());
e.replaceWith(textNode);
log(level + 1, "Replacing the element ([lt] == <): " + origElem.replaceAll("<", "[lt]") + " with: " + e.outerHtml().replaceAll("<", "[lt]"));
} else {
e.remove();
log(level + 1, "Removing the element ([lt] == <): " + origElem.replaceAll("<", "[lt]"));
}
}

// Remove all old image spacers
elems = d.select("img");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class FixerUtilsTests {
"type=default&content_id=@X@content.pk_string@X@&course_id=@X@course.pk_string@X@&page=\" " +
"class=\"info\">Test name: is this real bb name?</a></td></table></td></tr></table></td></tr></table>";
public static final String TEST_BODY_1_CLEANED =
"<!--<item id=\"ee5ee6e4-2e2e-4444-4444-ee6c44543977\" itemdefid=\"ee5ee6e4-2e2e-4444-4444-ee6c44543979\" itemstatus=\"live\" key=\"11\" moderating=\"false\" version=\"1\"><name>Test name: is this real item name?</name><newitem>false</newitem><owner>apereouser</owner><datecreated>2011-10-14T11:11:11-0100</datecreated><datemodified>2011-12-14T15:03:53-0100</datemodified><dateforindex>2011-12-14T15:03:53-0100</dateforindex><rating average=\"-1.0\"/><attachments selectedTitle=\"Test name: is this real att name?\"/><badurls/><history><edit applies=\"false\" date=\"2011-12-14T15:03:53-0100\" state=\"draft\" user=\"cmdalzell\">apereouser</edit><resetworkflow applies=\"false\" date=\"2011-12-14T15:03:53-0100\" state=\"draft\" user=\"apereouser\">apereouser</resetworkflow><statechange applies=\"false\" date=\"2011-12-14T15:03:53-0100\" state=\"live\" user=\"apereouser\">apereouser</statechange></history><moderation><liveapprovaldate>2011-12-14T15:03:53-0100</liveapprovaldate></moderation></item>--><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"450px\"><tbody><tr><td colspan=\"2\"></td></tr><tr><td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"100%\"><tbody><tr><td></td></tr><tr><td colspan=\"2\"></td></tr><tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\"><tbody><tr><td><img src=\"https://apereo.org/attachment.gif\" alt=\"*\" style=\"border:none;\"></td><td>&nbsp;&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>";
"<!--<item id=\"ee5ee6e4-2e2e-4444-4444-ee6c44543977\" itemdefid=\"ee5ee6e4-2e2e-4444-4444-ee6c44543979\" itemstatus=\"live\" key=\"11\" moderating=\"false\" version=\"1\"><name>Test name: is this real item name?</name><newitem>false</newitem><owner>apereouser</owner><datecreated>2011-10-14T11:11:11-0100</datecreated><datemodified>2011-12-14T15:03:53-0100</datemodified><dateforindex>2011-12-14T15:03:53-0100</dateforindex><rating average=\"-1.0\"/><attachments selectedTitle=\"Test name: is this real att name?\"/><badurls/><history><edit applies=\"false\" date=\"2011-12-14T15:03:53-0100\" state=\"draft\" user=\"cmdalzell\">apereouser</edit><resetworkflow applies=\"false\" date=\"2011-12-14T15:03:53-0100\" state=\"draft\" user=\"apereouser\">apereouser</resetworkflow><statechange applies=\"false\" date=\"2011-12-14T15:03:53-0100\" state=\"live\" user=\"apereouser\">apereouser</statechange></history><moderation><liveapprovaldate>2011-12-14T15:03:53-0100</liveapprovaldate></moderation></item>--><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"450px\"><tbody><tr><td colspan=\"2\"></td></tr><tr><td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"100%\"><tbody><tr><td></td></tr><tr><td colspan=\"2\"></td></tr><tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\"><tbody><tr><td><img src=\"https://apereo.org/attachment.gif\" alt=\"*\" style=\"border:none;\"></td><td>&nbsp;&nbsp;Test name: is this real bb name?</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>";
public static final String TEST_BODY_2 = "<!--<item id=\"ee5ee6e4-2e2e-4444-4444-ee6c44543971\" " +
"itemdefid=\"ee5ee6e4-2e2e-4444-4444-ee6c12543977\" itemstatus=\"live\" key=\"2\" moderating=\"false\" " +
"version=\"0\"><name>Test name - 2 item</name><newitem>false</newitem><owner>apereouser2</owner>" +
Expand All @@ -69,7 +69,7 @@ public class FixerUtilsTests {
"</td><td>&nbsp;&nbsp;<a href=\"/webapps/dych-tle-BB432345/ViewContent?type=default&content_id=" +
"@X@content.pk_string@X@&course_id=@X@course.pk_string@X@&page=_zips/Test%20name%20-%202%20att.zip\" " +
"class=\"info\">Test name - 2 att.zip</a></td></table></td></tr></table></td></tr></table>";
public static final String TEST_BODY_2_CLEANED = "<!--<item id=\"ee5ee6e4-2e2e-4444-4444-ee6c44543971\" itemdefid=\"ee5ee6e4-2e2e-4444-4444-ee6c12543977\" itemstatus=\"live\" key=\"2\" moderating=\"false\" version=\"0\"><name>Test name - 2 item</name><newitem>false</newitem><owner>apereouser2</owner><datecreated>2012-08-14T14:30:05-0400</datecreated><datemodified>2012-08-19T14:50:05-0400</datemodified><dateforindex>2012-08-14T12:50:25-0400</dateforindex><rating average=\"-1.0\"/><attachments selected=\"ee5ee6e4-2e2e-4444-4444-ee6c12543911\" selectedTitle=\"Test name - 2 att.zip\"><attachment mapped=\"false\" type=\"zip\"><uuid>ee5ee6e4-2e2e-4444-4444-ee6c12543911</uuid><file>_zips/Test name - 2 att.zip</file><description>Test name - 2 att desc.zip</description></attachment></attachments><badurls/><history><edit applies=\"false\" date=\"2019-08-19T14:50:05-0400\" state=\"draft\" user=\"apereo2\">apereo2</edit><resetworkflow applies=\"false\" date=\"2002-08-10T14:43:05-0400\" state=\"draft\" user=\"apereo2\">apereo2</resetworkflow><statechange applies=\"false\" date=\"2002-08-14T04:50:05-0400\" state=\"live\" user=\"apereo2\">apereo2</statechange></history><moderation><liveapprovaldate>2010-04-13T14:52:05-0400</liveapprovaldate></moderation></item>--><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"450px\"><tbody><tr><td colspan=\"2\"></td></tr><tr><td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"100%\"><tbody><tr><td></td></tr><tr><td colspan=\"2\"></td></tr><tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\"><tbody><tr><td><img src=\"https://apereo.org/oeq/icons/attachment.gif\" alt=\"*\" style=\"border:none;\"></td><td>&nbsp;&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>";
public static final String TEST_BODY_2_CLEANED = "<!--<item id=\"ee5ee6e4-2e2e-4444-4444-ee6c44543971\" itemdefid=\"ee5ee6e4-2e2e-4444-4444-ee6c12543977\" itemstatus=\"live\" key=\"2\" moderating=\"false\" version=\"0\"><name>Test name - 2 item</name><newitem>false</newitem><owner>apereouser2</owner><datecreated>2012-08-14T14:30:05-0400</datecreated><datemodified>2012-08-19T14:50:05-0400</datemodified><dateforindex>2012-08-14T12:50:25-0400</dateforindex><rating average=\"-1.0\"/><attachments selected=\"ee5ee6e4-2e2e-4444-4444-ee6c12543911\" selectedTitle=\"Test name - 2 att.zip\"><attachment mapped=\"false\" type=\"zip\"><uuid>ee5ee6e4-2e2e-4444-4444-ee6c12543911</uuid><file>_zips/Test name - 2 att.zip</file><description>Test name - 2 att desc.zip</description></attachment></attachments><badurls/><history><edit applies=\"false\" date=\"2019-08-19T14:50:05-0400\" state=\"draft\" user=\"apereo2\">apereo2</edit><resetworkflow applies=\"false\" date=\"2002-08-10T14:43:05-0400\" state=\"draft\" user=\"apereo2\">apereo2</resetworkflow><statechange applies=\"false\" date=\"2002-08-14T04:50:05-0400\" state=\"live\" user=\"apereo2\">apereo2</statechange></history><moderation><liveapprovaldate>2010-04-13T14:52:05-0400</liveapprovaldate></moderation></item>--><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"450px\"><tbody><tr><td colspan=\"2\"></td></tr><tr><td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"100%\"><tbody><tr><td></td></tr><tr><td colspan=\"2\"></td></tr><tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\"><tbody><tr><td><img src=\"https://apereo.org/oeq/icons/attachment.gif\" alt=\"*\" style=\"border:none;\"></td><td>&nbsp;&nbsp;Test name - 2 att.zip</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>";
public static final String TEST_BODY_3 = "<!--<item id=\"ee5ee6e4-2e2e-4444-4444-ff6c44543971\" " +
"itemdefid=\"ee5ee6e4-2e2e-4444-4774-ee6c44543971\" itemstatus=\"live\" key=\"99\" moderating=\"false\" " +
"version=\"0\"><name>Test body 3 name</name><newitem>false</newitem><thumbnail>default</thumbnail>" +
Expand Down Expand Up @@ -149,7 +149,7 @@ public class FixerUtilsTests {
" <string>lastmodified</string>\n" +
" <date>2017-09-22 22:22:00.0 EDT</date>\n" +
" </entry>\n" +
"</attributes></attachment></attachments><badurls/><history><contributed applies=\"false\" date=\"2017-02-22T22:22:22-0400\" state=\"draft\" user=\"apereo1\">apereo1</contributed></history><moderation><liveapprovaldate>2017-02-22T22:22:22-0400</liveapprovaldate></moderation></item>--><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"450px\"><tbody><tr><td colspan=\"2\"><img src=\"https://.../prod/images/spacer.gif\" alt=\" \" style=\"border:none; width:0px; height:4px;\"></td></tr><tr><td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"100%\"><tbody><tr><td class=\"bbdesc\"></td></tr><tr><td colspan=\"2\"><img src=\"https://.../prod/images/spacer.gif\" alt=\" \" style=\"border:none; width:0px; height:4px;\"></td></tr><tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\"><tbody><tr><td><img src=\"https://apereo.org//icons/attachment.gif\" alt=\"*\" style=\"border:none;\"></td><td>&nbsp;&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>";
"</attributes></attachment></attachments><badurls/><history><contributed applies=\"false\" date=\"2017-02-22T22:22:22-0400\" state=\"draft\" user=\"apereo1\">apereo1</contributed></history><moderation><liveapprovaldate>2017-02-22T22:22:22-0400</liveapprovaldate></moderation></item>--><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"450px\"><tbody><tr><td colspan=\"2\"><img src=\"https://.../prod/images/spacer.gif\" alt=\" \" style=\"border:none; width:0px; height:4px;\"></td></tr><tr><td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"100%\"><tbody><tr><td class=\"bbdesc\"></td></tr><tr><td colspan=\"2\"><img src=\"https://.../prod/images/spacer.gif\" alt=\" \" style=\"border:none; width:0px; height:4px;\"></td></tr><tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\"><tbody><tr><td><img src=\"https://apereo.org//icons/attachment.gif\" alt=\"*\" style=\"border:none;\"></td><td>&nbsp;&nbsp;class info test 3.docx</td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table>";
public static String TEST_BODY_4 = "<!--<item id=\"ee5ee6e4-2f2e-4444-4444-ff6ee4543971\" " +
"itemdefid=\"ee5ee6e4-2e2e-4446-4444-ff6ee4543971\" link=\"false\" live=\"false\" " +
"modified=\"false\" notify=\"true\" version=\"0\"><name>test body 4 name metadata</name>" +
Expand All @@ -169,12 +169,12 @@ public class FixerUtilsTests {
"ViewContent?type=default&content_id=@X@content.pk_string@X@&course_id=@X@course.pk_string@X@&page=" +
"randomness%20forSearch.pptx\" class=\"info\">2. Module 2 Selected Att by anchor class.pptx</a></td></table>" +
"</td></tr></table></td><td ><img src=\"https://apereo.org//icons/attachment.gif\" alt=\"*\" style=\"border:none;\" /></td></tr></table>";
public static String TEST_BODY_4_CLEANED = "<!--<item id=\"ee5ee6e4-2f2e-4444-4444-ff6ee4543971\" itemdefid=\"ee5ee6e4-2e2e-4446-4444-ff6ee4543971\" link=\"false\" live=\"false\" modified=\"false\" notify=\"true\" version=\"0\"><name>test body 4 name metadata</name><description/><requestUuid/><attachments selected=\"2.%20Module%202%20SelectedAttByName%2021.pptx\" selectedDescription=\"\" selectedTitle=\"selected title.pptx\"><attachment scorm=\"\"><file>att name. in att file.pptx</file><description>att desc. in att desc.pptx</description></attachment></attachments></item>--><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"450px\"><tbody><tr><td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"100%\"><tbody><tr><td></td></tr><tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\"><tbody><tr><td></td><td>&nbsp;&nbsp;</td></tr></tbody></table></td></tr></tbody></table></td><td></td></tr></tbody></table>";
public static String TEST_BODY_4_CLEANED = "<!--<item id=\"ee5ee6e4-2f2e-4444-4444-ff6ee4543971\" itemdefid=\"ee5ee6e4-2e2e-4446-4444-ff6ee4543971\" link=\"false\" live=\"false\" modified=\"false\" notify=\"true\" version=\"0\"><name>test body 4 name metadata</name><description/><requestUuid/><attachments selected=\"2.%20Module%202%20SelectedAttByName%2021.pptx\" selectedDescription=\"\" selectedTitle=\"selected title.pptx\"><attachment scorm=\"\"><file>att name. in att file.pptx</file><description>att desc. in att desc.pptx</description></attachment></attachments></item>--><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"450px\"><tbody><tr><td valign=\"top\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\" width=\"100%\"><tbody><tr><td></td></tr><tr><td><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12pt\"><tbody><tr><td></td><td>&nbsp;&nbsp;2. Module 2 Selected Att by anchor class.pptx</td></tr></tbody></table></td></tr></tbody></table></td><td></td></tr></tbody></table>";
public static String TEST_BODY_5 = "<div class=\"equella-link contextItemDetailsHeaders\"><a target=\"_blank\" " +
"href=\"/webapps/dych-tle-BB59999/ViewContent?content_id=@X@content.pk_string@X@&course_id=" +
"@X@course.pk_string@X@\"><img alt=\"application.document\" src=\"https://apereo.org/icons/attachment.gif\" " +
"style=\"margin-right:10px\">div title.docx</a></div>";
public static String TEST_BODY_5_CLEANED = "<div class=\"equella-link contextItemDetailsHeaders\"></div>";
public static String TEST_BODY_5_CLEANED = "<div class=\"equella-link contextItemDetailsHeaders\">div title.docx</div>";

@Test
public void testGetDomainName() {
Expand Down

0 comments on commit 6a550f0

Please sign in to comment.