From c056e6aea8db29c63023427c5111ea4634b1fbbf Mon Sep 17 00:00:00 2001 From: georgecao Date: Mon, 15 Jun 2020 13:55:01 +0800 Subject: [PATCH 1/3] Fix tag url --- .../src/main/java/org/jbake/app/Crawler.java | 6 +- .../DefaultJBakeConfiguration.java | 45 ++++- .../app/configuration/JBakeConfiguration.java | 20 +- .../app/configuration/JBakeProperty.java | 6 +- .../main/java/org/jbake/util/HtmlUtil.java | 61 +++--- .../src/main/resources/default.properties | 10 +- .../java/org/jbake/util/HtmlUtilTest.java | 175 ++++++++++++++++-- 7 files changed, 275 insertions(+), 48 deletions(-) diff --git a/jbake-core/src/main/java/org/jbake/app/Crawler.java b/jbake-core/src/main/java/org/jbake/app/Crawler.java index 764a3e035..80137dc2f 100644 --- a/jbake-core/src/main/java/org/jbake/app/Crawler.java +++ b/jbake-core/src/main/java/org/jbake/app/Crawler.java @@ -213,9 +213,9 @@ private void crawlSourceFile(final File sourceFile, final String sha1, final Str fileContents.put(Attributes.NO_EXTENSION_URI, uri.replace("/index.html", "/")); } - if (config.getImgPathUpdate()) { - // Prevent image source url's from breaking - HtmlUtil.fixImageSourceUrls(fileContents, config); + if (config.getImgPathUpdate() || config.getRelativePathUpdate()) { + // Prevent image or other tag's source url's from breaking + HtmlUtil.fixUrls(fileContents, config); } ODocument doc = new ODocument(documentType); diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java index 7a772acb8..2c8425af9 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java @@ -7,10 +7,7 @@ import org.slf4j.LoggerFactory; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -532,6 +529,15 @@ public boolean getImgPathPrependHost() { return getAsBoolean(JBakeProperty.IMG_PATH_PREPEND_HOST); } + @Override + public boolean getRelativePathPrependHost() { + return getAsBoolean(JBakeProperty.RELATIVE_PATH_PREPEND_HOST); + } + + public void setRelativePathPrependHost(boolean relativePathPrependHost) { + setProperty(JBakeProperty.RELATIVE_PATH_PREPEND_HOST, relativePathPrependHost); + } + public void setImgPathPrependHost(boolean imgPathPrependHost) { setProperty(JBakeProperty.IMG_PATH_PREPEND_HOST, imgPathPrependHost); } @@ -541,7 +547,36 @@ public boolean getImgPathUpdate() { return getAsBoolean(JBakeProperty.IMG_PATH_UPDATE); } - public void setImgPathUPdate(boolean imgPathUpdate) { + @Override + public boolean getRelativePathUpdate() { + return getAsBoolean(JBakeProperty.RELATIVE_PATH_UPDATE); + } + + public void setRelativePathUpdate(String relativePathUpdate) { + setProperty(JBakeProperty.RELATIVE_PATH_UPDATE, relativePathUpdate); + } + + @Override + public Map getTagAttributes() { + List pairs = getAsList(JBakeProperty.RELATIVE_TAG_ATTRIBUTE); + Map tagAttribute = new HashMap<>(); + char eq = '='; + for (String pair : pairs) { + int idx = pair.indexOf(eq); + if (idx > 0) { + String tag = pair.substring(0, idx); + String attr = pair.substring(idx + 1); + tagAttribute.put(tag, attr); + } + } + return tagAttribute; + } + + public void setTagAttributes(String... tagAttributes) { + setProperty(JBakeProperty.RELATIVE_TAG_ATTRIBUTE, StringUtils.join(tagAttributes, ",")); + } + + public void setImgPathUpdate(boolean imgPathUpdate) { setProperty(JBakeProperty.IMG_PATH_UPDATE, imgPathUpdate); } } diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java index 5e5435382..1ac1a9736 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfiguration.java @@ -3,10 +3,11 @@ import java.io.File; import java.util.Iterator; import java.util.List; +import java.util.Map; /** * JBakeConfiguration gives you access to the project configuration. Typically located in a file called jbake.properties. - * + *

* Use one of {@link JBakeConfigurationFactory} methods to create an instance. */ public interface JBakeConfiguration { @@ -288,12 +289,29 @@ public interface JBakeConfiguration { */ boolean getImgPathPrependHost(); + /** + * @return Flag indicating if a relative paths should be prepended with {@link #getSiteHost()} value - only has an effect if + * {@link #getRelativePathUpdate()} is set to true + */ + boolean getRelativePathPrependHost(); + /** * @return Flag indicating if image paths in content should be updated with absolute path (using URI value of content file), * see {@link #getImgPathUpdate()} which allows you to control the absolute path used */ boolean getImgPathUpdate(); + /** + * @return Flag indicating if relative paths in content should be updated with absolute path (using URI value of content file), + * see {@link #getRelativePathUpdate()} which allows you to control the absolute path used + */ + boolean getRelativePathUpdate(); + + /** + * @return Tag and it's attribute name which contains a path that maybe relative. + */ + Map getTagAttributes(); + /** * @return Version of JBake */ diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java index 375d8f903..3e15e1528 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java @@ -45,8 +45,12 @@ public class JBakeProperty { public static final String URI_NO_EXTENSION_PREFIX = "uri.noExtension.prefix"; public static final String IMG_PATH_UPDATE = "img.path.update"; public static final String IMG_PATH_PREPEND_HOST = "img.path.prepend.host"; + public static final String RELATIVE_PATH_UPDATE = "relative.path.update"; + public static final String RELATIVE_PATH_PREPEND_HOST = "relative.path.prepend.host"; + public static final String RELATIVE_TAG_ATTRIBUTE = "relative.tag.attribute"; public static final String VERSION = "version"; - private JBakeProperty() {} + private JBakeProperty() { + } } diff --git a/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java b/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java index cbafe6674..1bf680170 100644 --- a/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java +++ b/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java @@ -14,31 +14,41 @@ */ public class HtmlUtil { + private static final char SLASH = '/'; + private static final String SLASH_TEXT = String.valueOf(SLASH); + private static final String HTTP = "http://"; + private static final String HTTPS = "https://"; + private static final String WORKING_DIR = "\\./"; + private static final String EMPTY = ""; + private HtmlUtil() { } /** - * Image paths are specified as w.r.t. assets folder. This function prefix site host to all img src except + * Images or file paths are specified as w.r.t. assets folder. This function prefix site host to all path except * the ones that starts with http://, https://. *

- * If image path starts with "./", i.e. relative to the source file, then it first replace that with output file directory and the add site host. + * If path starts with "./", i.e. relative to the source file, then it first replace that with output file directory and the add site host. * * @param fileContents Map representing file contents * @param configuration Configuration object */ - public static void fixImageSourceUrls(Map fileContents, JBakeConfiguration configuration) { + public static void fixUrls(Map fileContents, JBakeConfiguration configuration) { String htmlContent = fileContents.get(Attributes.BODY).toString(); - boolean prependSiteHost = configuration.getImgPathPrependHost(); + boolean prependSiteHost = configuration.getImgPathPrependHost() && configuration.getRelativePathPrependHost(); String siteHost = configuration.getSiteHost(); String uri = getDocumentUri(fileContents); Document document = Jsoup.parseBodyFragment(htmlContent); - Elements allImgs = document.getElementsByTag("img"); - - for (Element img : allImgs) { - transformImageSource(img, uri, siteHost, prependSiteHost); + Map pairs = configuration.getTagAttributes(); + for (Map.Entry entry : pairs.entrySet()) { + String tagName = entry.getKey(); + String attKey = entry.getValue(); + Elements allTags = document.getElementsByTag(tagName); + for (Element tag : allTags) { + transformPath(tag, attKey, uri, siteHost, prependSiteHost); + } } - //Use body().html() to prevent adding from parsed fragment. fileContents.put(Attributes.BODY, document.body().html()); } @@ -51,46 +61,47 @@ private static String getDocumentUri(Map fileContents) { uri = removeTrailingSlash(uri); } - if (uri.contains("/")) { + if (uri.contains(SLASH_TEXT)) { uri = removeFilename(uri); } return uri; } - private static void transformImageSource(Element img, String uri, String siteHost, boolean prependSiteHost) { - String source = img.attr("src"); + private static void transformPath(Element tag, String attrKey, String uri, String siteHost, boolean prependSiteHost) { + String path = tag.attr(attrKey); // Now add the root path - if (!source.startsWith("http://") && !source.startsWith("https://")) { - - if (isRelative(source)) { - source = uri + source.replaceFirst("\\./", ""); + if (!isUrl(path)) { + if (isRelative(path)) { + path = uri + path.replaceFirst(WORKING_DIR, EMPTY); } - if (prependSiteHost) { - if (!siteHost.endsWith("/") && isRelative(source)) { - siteHost = siteHost.concat("/"); + if (!siteHost.endsWith(SLASH_TEXT) && isRelative(path)) { + siteHost = siteHost.concat(SLASH_TEXT); } - source = siteHost + source; + path = siteHost + path; } - - img.attr("src", source); + tag.attr(attrKey, path); } } private static String removeFilename(String uri) { - uri = uri.substring(0, uri.lastIndexOf('/') + 1); + uri = uri.substring(0, uri.lastIndexOf(SLASH) + 1); return uri; } private static String removeTrailingSlash(String uri) { - if (uri.endsWith("/")) { + if (uri.endsWith(SLASH_TEXT)) { uri = uri.substring(0, uri.length() - 1); } return uri; } + private static boolean isUrl(String path) { + return path.startsWith(HTTP) || path.startsWith(HTTPS); + } + private static boolean isRelative(String source) { - return !source.startsWith("/"); + return !source.startsWith(SLASH_TEXT); } } diff --git a/jbake-core/src/main/resources/default.properties b/jbake-core/src/main/resources/default.properties index 0ab5ff9a3..26286773d 100644 --- a/jbake-core/src/main/resources/default.properties +++ b/jbake-core/src/main/resources/default.properties @@ -1,7 +1,7 @@ # application version version=v${jbakeVersion} # build timestamp -build.timestamp=${timestamp} +build.timestamp=${timestamp} # path to destination folder by default destination.folder=output # folder that contains all template files @@ -58,7 +58,7 @@ render.tagsindex=false # folder name to use for tag files tag.path=tags # sanitize tag value before it is used as filename (i.e. replace spaces with hyphens) -tag.sanitize=false +tag.sanitize=false # file extension for output content files output.extension=.html @@ -124,3 +124,9 @@ header.separator=~~~~~~ img.path.update=false # Prepend site.host to image paths img.path.prepend.host=true +# update relative path +relative.path.update=false +# prepend site.host to tag paths +relative.path.prepend.host=true +# relative tag and attribute, for img's src and a's href. +relative.tag.attribute=img=src,a=href diff --git a/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java b/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java index b4f43e5f3..060e84b74 100644 --- a/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java +++ b/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java @@ -7,7 +7,6 @@ import org.junit.Before; import org.junit.Test; -import java.io.File; import java.util.HashMap; import java.util.Map; @@ -30,7 +29,23 @@ public void shouldNotAddBodyHTMLElement() { fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); fileContent.put(Attributes.BODY, "

Test
"); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).doesNotContain(""); + assertThat(body).doesNotContain(""); + + } + + @Test + public void shouldNotAddBodyHTMLElement0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.BODY, "
Test
"); + + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); @@ -47,7 +62,7 @@ public void shouldNotAddSiteHost() { fileContent.put(Attributes.BODY, "
Test
"); config.setImgPathPrependHost(false); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); @@ -55,6 +70,22 @@ public void shouldNotAddSiteHost() { } + @Test + public void shouldNotAddSiteHost0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.BODY, "
Test
"); + config.setRelativePathPrependHost(false); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"blog/2017/05/first.jpg\""); + + } + @Test public void shouldAddSiteHostWithRelativeImageToDocument() { Map fileContent = new HashMap<>(); @@ -63,13 +94,28 @@ public void shouldAddSiteHostWithRelativeImageToDocument() { fileContent.put(Attributes.BODY, "
Test
"); config.setImgPathPrependHost(true); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); assertThat(body).contains("src=\"http://www.jbake.org/blog/2017/05/img/deeper/underground.jpg\""); } + @Test + public void shouldAddSiteHostWithRelativeImageToDocument0() { + Map fileContent = new HashMap<>(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.BODY, "
Test
"); + config.setRelativePathPrependHost(true); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/img/deeper/underground.jpg\""); + } + @Test public void shouldAddContentPath() { Map fileContent = new HashMap(); @@ -77,7 +123,7 @@ public void shouldAddContentPath() { fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); fileContent.put(Attributes.BODY, "
Test
"); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); @@ -85,6 +131,21 @@ public void shouldAddContentPath() { } + @Test + public void shouldAddContentPath0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.BODY, "
Test
"); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); + + } + @Test public void shouldAddContentPathForCurrentDirectory() { Map fileContent = new HashMap(); @@ -92,7 +153,7 @@ public void shouldAddContentPathForCurrentDirectory() { fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); fileContent.put(Attributes.BODY, "
Test
"); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); @@ -100,6 +161,21 @@ public void shouldAddContentPathForCurrentDirectory() { } + @Test + public void shouldAddContentPathForCurrentDirectory0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.BODY, "
Test
"); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); + + } + @Test public void shouldNotAddRootPath() { Map fileContent = new HashMap(); @@ -107,7 +183,7 @@ public void shouldNotAddRootPath() { fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); fileContent.put(Attributes.BODY, "
Test
"); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); @@ -115,6 +191,21 @@ public void shouldNotAddRootPath() { } + @Test + public void shouldNotAddRootPath0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.BODY, "
Test
"); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); + + } + @Test public void shouldNotAddRootPathForNoExtension() { Map fileContent = new HashMap(); @@ -123,7 +214,7 @@ public void shouldNotAddRootPathForNoExtension() { fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); fileContent.put(Attributes.BODY, "
Test
"); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); @@ -131,6 +222,22 @@ public void shouldNotAddRootPathForNoExtension() { } + @Test + public void shouldNotAddRootPathForNoExtension0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); + fileContent.put(Attributes.BODY, "
Test
"); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); + + } + @Test public void shouldAddContentPathForNoExtension() { Map fileContent = new HashMap(); @@ -139,13 +246,28 @@ public void shouldAddContentPathForNoExtension() { fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); fileContent.put(Attributes.BODY, "
Test
"); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); assertThat(body).contains("src=\"http://www.jbake.org/blog/2017/05/first.jpg\""); } + @Test + public void shouldAddContentPathForNoExtension0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); + fileContent.put(Attributes.BODY, "
Test
"); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); + } + @Test public void shouldNotChangeForHTTP() { Map fileContent = new HashMap(); @@ -154,7 +276,7 @@ public void shouldNotChangeForHTTP() { fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); fileContent.put(Attributes.BODY, "
Test
"); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); @@ -162,6 +284,22 @@ public void shouldNotChangeForHTTP() { } + @Test + public void shouldNotChangeForHTTP0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); + fileContent.put(Attributes.BODY, "
Test
"); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"http://example.com/first.jpg\""); + + } + @Test public void shouldNotChangeForHTTPS() { Map fileContent = new HashMap(); @@ -170,10 +308,25 @@ public void shouldNotChangeForHTTPS() { fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); fileContent.put(Attributes.BODY, "
Test
"); - HtmlUtil.fixImageSourceUrls(fileContent, config); + HtmlUtil.fixUrls(fileContent, config); String body = fileContent.get(Attributes.BODY).toString(); assertThat(body).contains("src=\"https://example.com/first.jpg\""); } + + @Test + public void shouldNotChangeForHTTPS0() { + Map fileContent = new HashMap(); + fileContent.put(Attributes.ROOTPATH, "../../../"); + fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); + fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); + fileContent.put(Attributes.BODY, "
Test
"); + + HtmlUtil.fixUrls(fileContent, config); + + String body = fileContent.get(Attributes.BODY).toString(); + + assertThat(body).contains("href=\"https://example.com/first.jpg\""); + } } From 1d934522869e9e31ca18e21d8c903d4c379b420f Mon Sep 17 00:00:00 2001 From: georgecao Date: Tue, 18 May 2021 10:38:11 +0800 Subject: [PATCH 2/3] Import Map and HashMap after merging from the remote reop --- .../jbake/app/configuration/DefaultJBakeConfiguration.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java index 3f4f0bd25..ddb000c8d 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java @@ -9,10 +9,7 @@ import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; From f7bc334d27f4cea51067d82e2dd58fb1d5aaacd9 Mon Sep 17 00:00:00 2001 From: georgecao Date: Mon, 24 May 2021 18:44:48 +0800 Subject: [PATCH 3/3] Merge and fix conflicts. --- .../src/main/java/org/jbake/app/Crawler.java | 8 +- .../DefaultJBakeConfiguration.java | 64 ++++++---- .../JBakeConfigurationFactory.java | 39 +++--- .../app/configuration/JBakeProperty.java | 0 .../jbake/app/configuration/PropertyList.java | 14 +++ .../main/java/org/jbake/util/HtmlUtil.java | 6 +- .../java/org/jbake/util/HtmlUtilTest.java | 111 +++++++++--------- 7 files changed, 137 insertions(+), 105 deletions(-) delete mode 100644 jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java diff --git a/jbake-core/src/main/java/org/jbake/app/Crawler.java b/jbake-core/src/main/java/org/jbake/app/Crawler.java index 1d10eeeef..d8747d846 100644 --- a/jbake-core/src/main/java/org/jbake/app/Crawler.java +++ b/jbake-core/src/main/java/org/jbake/app/Crawler.java @@ -1,6 +1,5 @@ package org.jbake.app; -import com.orientechnologies.orient.core.record.impl.ODocument; import org.apache.commons.configuration2.CompositeConfiguration; import org.apache.commons.io.FilenameUtils; import org.jbake.app.configuration.JBakeConfiguration; @@ -19,7 +18,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Date; -import java.util.Map; /** * Crawls a file system looking for content. @@ -271,7 +269,7 @@ private void processSourceFile(final File sourceFile, final String sha1, final S if (config.getImgPathUpdate() || config.getRelativePathUpdate()) { // Prevent image or other tag's source url's from breaking - HtmlUtil.fixUrls(fileContents, config); + HtmlUtil.fixUrls(document, config); } db.addDocument(document); @@ -293,8 +291,8 @@ private void addAdditionalDocumentAttributes(DocumentModel document, File source document.setCached(true); if (document.getStatus().equals(ModelAttributes.Status.PUBLISHED_DATE) - && (document.getDate() != null) - && new Date().after(document.getDate())) { + && (document.getDate() != null) + && new Date().after(document.getDate())) { document.setStatus(ModelAttributes.Status.PUBLISHED); } diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java index a7e37b9a0..9bc312c87 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/DefaultJBakeConfiguration.java @@ -11,6 +11,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static org.jbake.app.configuration.PropertyList.*; @@ -227,7 +228,6 @@ public void setDatabaseStore(String storeType) { } - @Override public String getDateFormat() { return getAsString(DATE_FORMAT.getKey()); @@ -585,7 +585,7 @@ private void setupDefaultDestination() { String destinationPath = getAsString(DESTINATION_FOLDER.getKey()); File destination = new File(destinationPath); - if ( destination.isAbsolute() ) { + if (destination.isAbsolute()) { setDestinationFolder(destination); } else { setDestinationFolder(new File(getSourceFolder(), destinationPath)); @@ -597,7 +597,7 @@ private void setupDefaultAssetFolder() { File asset = new File(assetFolder); - if(asset.isAbsolute()) { + if (asset.isAbsolute()) { setAssetFolder(asset); } else { setAssetFolder(new File(getSourceFolder(), assetFolder)); @@ -608,7 +608,7 @@ private void setupDefaultTemplateFolder() { String templateFolder = getAsString(TEMPLATE_FOLDER.getKey()); File template = new File(templateFolder); - if(template.isAbsolute()) { + if (template.isAbsolute()) { setTemplateFolder(template); } else { setTemplateFolder(new File(getSourceFolder(), templateFolder)); @@ -619,7 +619,7 @@ private void setupDefaultDataFolder() { String dataFolder = getAsString(DATA_FOLDER.getKey()); File data = new File(dataFolder); - if(data.isAbsolute()) { + if (data.isAbsolute()) { setDataFolder(data); } else { setDataFolder(new File(getSourceFolder(), dataFolder)); @@ -646,15 +646,20 @@ public boolean getImgPathPrependHost() { @Override public boolean getRelativePathPrependHost() { - return getAsBoolean(JBakeProperty.RELATIVE_PATH_PREPEND_HOST); + return getAsBoolean(RELATIVE_PATH_PREPEND_HOST.getKey()); } public void setRelativePathPrependHost(boolean relativePathPrependHost) { - setProperty(JBakeProperty.RELATIVE_PATH_PREPEND_HOST, relativePathPrependHost); + setBothPathPrependHost(relativePathPrependHost); } public void setImgPathPrependHost(boolean imgPathPrependHost) { - setProperty(IMG_PATH_PREPEND_HOST.getKey(), imgPathPrependHost); + setBothPathPrependHost(imgPathPrependHost); + } + + private void setBothPathPrependHost(boolean prependHost) { + setProperty(RELATIVE_PATH_PREPEND_HOST.getKey(), prependHost); + setProperty(IMG_PATH_PREPEND_HOST.getKey(), prependHost); } @Override @@ -662,8 +667,13 @@ public boolean getImgPathUpdate() { return getAsBoolean(IMG_PATH_UPDATE.getKey()); } - public void setImgPathUPdate(boolean imgPathUpdate) { - setProperty(IMG_PATH_UPDATE.getKey(), imgPathUpdate); + public void setImgPathUpdate(boolean imgPathUpdate) { + setBothPathUpdate(imgPathUpdate); + } + + public void setBothPathUpdate(boolean pathUpdate) { + setProperty(IMG_PATH_UPDATE.getKey(), pathUpdate); + setProperty(RELATIVE_PATH_UPDATE.getKey(), pathUpdate); } public List getJbakeProperties() { @@ -695,22 +705,26 @@ public String getAbbreviatedGitHash() { @Override public String getJvmLocale() { return getAsString(JVM_LOCALE.getKey()); + } + @Override public boolean getRelativePathUpdate() { - return getAsBoolean(JBakeProperty.RELATIVE_PATH_UPDATE); + return getAsBoolean(RELATIVE_PATH_UPDATE.getKey()); } - public void setRelativePathUpdate(String relativePathUpdate) { - setProperty(JBakeProperty.RELATIVE_PATH_UPDATE, relativePathUpdate); + public void setRelativePathUpdate(boolean relativePathUpdate) { + setBothPathUpdate(relativePathUpdate); } + private static final String EQ = "="; + private static final String COMMA = ","; + @Override public Map getTagAttributes() { - List pairs = getAsList(JBakeProperty.RELATIVE_TAG_ATTRIBUTE); + List pairs = getAsList(RELATIVE_TAG_ATTRIBUTE.getKey()); Map tagAttribute = new HashMap<>(); - char eq = '='; for (String pair : pairs) { - int idx = pair.indexOf(eq); + int idx = pair.indexOf(EQ); if (idx > 0) { String tag = pair.substring(0, idx); String attr = pair.substring(idx + 1); @@ -720,11 +734,21 @@ public Map getTagAttributes() { return tagAttribute; } - public void setTagAttributes(String... tagAttributes) { - setProperty(JBakeProperty.RELATIVE_TAG_ATTRIBUTE, StringUtils.join(tagAttributes, ",")); + public void addTagAttribute(String tag, String attr) { + Map all = new HashMap<>(); + Map map = getTagAttributes(); + if (null != map) { + all.putAll(map); + } + all.put(tag, attr); + String val = all.entrySet().stream() + .map(e -> String.join(EQ, e.getKey(), e.getValue())) + .collect(Collectors.joining(COMMA)); + + setProperty(RELATIVE_TAG_ATTRIBUTE.getKey(), val); } - public void setImgPathUpdate(boolean imgPathUpdate) { - setProperty(JBakeProperty.IMG_PATH_UPDATE, imgPathUpdate); + public void setTagAttributes(String... tagAttributes) { + setProperty(RELATIVE_TAG_ATTRIBUTE.getKey(), StringUtils.join(tagAttributes, COMMA)); } } diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfigurationFactory.java b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfigurationFactory.java index 990b5f45b..298e9ae32 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfigurationFactory.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeConfigurationFactory.java @@ -20,7 +20,7 @@ public JBakeConfigurationFactory() { /** * Creates a {@link DefaultJBakeConfiguration} * @param sourceFolder The source folder of the project - * @param destination The destination folder to render and copy files to + * @param destination The destination folder to render and copy files to * @param isClearCache Whether to clear database cache or not * @return A configuration by given parameters * @throws ConfigurationException if loading the configuration fails @@ -33,10 +33,10 @@ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFold /** * Creates a {@link DefaultJBakeConfiguration} - * @param sourceFolder The source folder of the project - * @param destination The destination folder to render and copy files to + * @param sourceFolder The source folder of the project + * @param destination The destination folder to render and copy files to * @param propertiesFile The properties file for the project - * @param isClearCache Whether to clear database cache or not + * @param isClearCache Whether to clear database cache or not * @return A configuration by given parameters * @throws ConfigurationException if loading the configuration fails */ @@ -49,13 +49,12 @@ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFold /** * Creates a {@link DefaultJBakeConfiguration} - * * This is a compatibility factory method * - * @param sourceFolder The source folder of the project - * @param destination The destination folder to render and copy files to + * @param sourceFolder The source folder of the project + * @param destination The destination folder to render and copy files to * @param compositeConfiguration A given {@link CompositeConfiguration} - * @param isClearCache Whether to clear database cache or not + * @param isClearCache Whether to clear database cache or not * @return A configuration by given parameters */ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFolder, File destination, CompositeConfiguration compositeConfiguration, boolean isClearCache) { @@ -67,11 +66,10 @@ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFold /** * Creates a {@link DefaultJBakeConfiguration} - * * This is a compatibility factory method * - * @param sourceFolder The source folder of the project - * @param destination The destination folder to render and copy files to + * @param sourceFolder The source folder of the project + * @param destination The destination folder to render and copy files to * @param compositeConfiguration A given {@link CompositeConfiguration} * @return A configuration by given parameters */ @@ -84,13 +82,12 @@ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFold /** * Creates a {@link DefaultJBakeConfiguration} * - * * @param sourceFolder The source folder of the project - * @param config A {@link CompositeConfiguration} + * @param config A {@link CompositeConfiguration} * @return A configuration by given parameters */ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFolder, CompositeConfiguration config) { - return new DefaultJBakeConfiguration(sourceFolder,config); + return new DefaultJBakeConfiguration(sourceFolder, config); } /** @@ -98,16 +95,16 @@ public DefaultJBakeConfiguration createDefaultJbakeConfiguration(File sourceFold * by http://localhost:[server.port]. * The server.port is read from the project properties file. * - * @param sourceFolder The source folder of the project + * @param sourceFolder The source folder of the project * @param destinationFolder The destination folder to render and copy files to - * @param isClearCache Whether to clear database cache or not + * @param isClearCache Whether to clear database cache or not * @return A configuration by given parameters * @throws ConfigurationException if loading the configuration fails * @deprecated use {@link #createJettyJbakeConfiguration(File, File, File, boolean)} instead */ @Deprecated public DefaultJBakeConfiguration createJettyJbakeConfiguration(File sourceFolder, File destinationFolder, boolean isClearCache) throws ConfigurationException { - return createJettyJbakeConfiguration(sourceFolder, destinationFolder, (File)null, isClearCache); + return createJettyJbakeConfiguration(sourceFolder, destinationFolder, (File) null, isClearCache); } /** @@ -115,10 +112,10 @@ public DefaultJBakeConfiguration createJettyJbakeConfiguration(File sourceFolder * by http://localhost:[server.port]. * The server.port is read from the project properties file. * - * @param sourceFolder The source folder of the project + * @param sourceFolder The source folder of the project * @param destinationFolder The destination folder to render and copy files to - * @param propertiesFile The properties file for the project - * @param isClearCache Whether to clear database cache or not + * @param propertiesFile The properties file for the project + * @param isClearCache Whether to clear database cache or not * @return A configuration by given parameters * @throws ConfigurationException if loading the configuration fails */ @@ -126,7 +123,7 @@ public DefaultJBakeConfiguration createJettyJbakeConfiguration(File sourceFolder DefaultJBakeConfiguration configuration = (DefaultJBakeConfiguration) getConfigUtil().loadConfig(sourceFolder, propertiesFile); configuration.setDestinationFolder(destinationFolder); configuration.setClearCache(isClearCache); - configuration.setSiteHost("http://" + configuration.getServerHostname() + ":" +configuration.getServerPort() + configuration.getServerContextPath()); + configuration.setSiteHost("http://" + configuration.getServerHostname() + ":" + configuration.getServerPort() + configuration.getServerContextPath()); return configuration; } diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java b/jbake-core/src/main/java/org/jbake/app/configuration/JBakeProperty.java deleted file mode 100644 index e69de29bb..000000000 diff --git a/jbake-core/src/main/java/org/jbake/app/configuration/PropertyList.java b/jbake-core/src/main/java/org/jbake/app/configuration/PropertyList.java index f212c9bec..7e41ce8f5 100644 --- a/jbake-core/src/main/java/org/jbake/app/configuration/PropertyList.java +++ b/jbake-core/src/main/java/org/jbake/app/configuration/PropertyList.java @@ -129,6 +129,20 @@ public abstract class PropertyList { "img.path.update", "update image path?" ); + public static final Property RELATIVE_PATH_UPDATE = new Property( + "relative.path.update", + "update relative path?" + ); + + public static final Property RELATIVE_PATH_PREPEND_HOST = new Property( + "relative.path.prepend.host", + "Prepend site.host to relative paths" + ); + + public static final Property RELATIVE_TAG_ATTRIBUTE = new Property( + "relative.tag.attribute", + "Define tag and it's attribute that may contains relative paths" + ); public static final Property IMG_PATH_PREPEND_HOST = new Property( "img.path.prepend.host", diff --git a/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java b/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java index d5c30886f..8e9dbdd7a 100644 --- a/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java +++ b/jbake-core/src/main/java/org/jbake/util/HtmlUtil.java @@ -7,6 +7,8 @@ import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import java.util.Map; + /** * @author Manik Magar */ @@ -31,9 +33,9 @@ private HtmlUtil() { * @param fileContents Map representing file contents * @param configuration Configuration object */ - public static void fixImageSourceUrls(DocumentModel fileContents, JBakeConfiguration configuration) { + public static void fixUrls(DocumentModel fileContents, JBakeConfiguration configuration) { String htmlContent = fileContents.getBody(); - boolean prependSiteHost = configuration.getImgPathPrependHost(); + boolean prependSiteHost = configuration.getImgPathPrependHost() || configuration.getRelativePathPrependHost(); String siteHost = configuration.getSiteHost(); String uri = getDocumentUri(fileContents); diff --git a/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java b/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java index af26fed0d..ba3696514 100644 --- a/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java +++ b/jbake-core/src/test/java/org/jbake/util/HtmlUtilTest.java @@ -7,9 +7,6 @@ import org.junit.Before; import org.junit.Test; -import java.util.HashMap; -import java.util.Map; - import static org.assertj.core.api.Assertions.assertThat; @@ -31,7 +28,7 @@ public void shouldNotAddBodyHTMLElement() { HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).doesNotContain(""); assertThat(body).doesNotContain(""); @@ -40,10 +37,10 @@ public void shouldNotAddBodyHTMLElement() { @Test public void shouldNotAddBodyHTMLElement0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setBody("
Test
"); HtmlUtil.fixUrls(fileContent, config); @@ -72,15 +69,15 @@ public void shouldNotAddSiteHost() { @Test public void shouldNotAddSiteHost0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setBody("
Test
"); config.setRelativePathPrependHost(false); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"blog/2017/05/first.jpg\""); @@ -103,15 +100,15 @@ public void shouldAddSiteHostWithRelativeImageToDocument() { @Test public void shouldAddSiteHostWithRelativeImageToDocument0() { - Map fileContent = new HashMap<>(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setBody("
Test
"); config.setRelativePathPrependHost(true); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/img/deeper/underground.jpg\""); } @@ -134,14 +131,14 @@ public void shouldAddContentPath() { @Test public void shouldAddContentPath0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setBody("
Test
"); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); @@ -165,14 +162,14 @@ public void shouldAddContentPathForCurrentDirectory() { @Test public void shouldAddContentPathForCurrentDirectory0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setBody("
Test
"); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); @@ -195,14 +192,14 @@ public void shouldNotAddRootPath() { @Test public void shouldNotAddRootPath0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setBody("
Test
"); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); @@ -226,15 +223,15 @@ public void shouldNotAddRootPathForNoExtension() { @Test public void shouldNotAddRootPathForNoExtension0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setNoExtensionUri("blog/2017/05/first_post/"); + fileContent.setBody("
Test
"); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); @@ -257,15 +254,15 @@ public void shouldAddContentPathForNoExtension() { @Test public void shouldAddContentPathForNoExtension0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setNoExtensionUri("blog/2017/05/first_post/"); + fileContent.setBody("
Test
"); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"http://www.jbake.org/blog/2017/05/first.jpg\""); } @@ -288,15 +285,15 @@ public void shouldNotChangeForHTTP() { @Test public void shouldNotChangeForHTTP0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setNoExtensionUri("blog/2017/05/first_post/"); + fileContent.setBody("
Test
"); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"http://example.com/first.jpg\""); @@ -319,15 +316,15 @@ public void shouldNotChangeForHTTPS() { @Test public void shouldNotChangeForHTTPS0() { - Map fileContent = new HashMap(); - fileContent.put(Attributes.ROOTPATH, "../../../"); - fileContent.put(Attributes.URI, "blog/2017/05/first_post.html"); - fileContent.put(Attributes.NO_EXTENSION_URI, "blog/2017/05/first_post/"); - fileContent.put(Attributes.BODY, "
Test
"); + DocumentModel fileContent = new DocumentModel(); + fileContent.setRootPath("../../../"); + fileContent.setUri("blog/2017/05/first_post.html"); + fileContent.setNoExtensionUri("blog/2017/05/first_post/"); + fileContent.setBody("
Test
"); HtmlUtil.fixUrls(fileContent, config); - String body = fileContent.get(Attributes.BODY).toString(); + String body = fileContent.getBody(); assertThat(body).contains("href=\"https://example.com/first.jpg\""); }