diff --git a/main/src/com/google/refine/exporters/CustomizableTabularExporterUtilities.java b/main/src/com/google/refine/exporters/CustomizableTabularExporterUtilities.java index d7e6d334d..eb19a68e7 100644 --- a/main/src/com/google/refine/exporters/CustomizableTabularExporterUtilities.java +++ b/main/src/com/google/refine/exporters/CustomizableTabularExporterUtilities.java @@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.exporters; +import java.net.MalformedURLException; +import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.OffsetDateTime; @@ -45,6 +47,7 @@ import java.util.Properties; import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.validator.routines.UrlValidator; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -226,6 +229,8 @@ abstract public class CustomizableTabularExporterUtilities { boolean date_omitTime = false; DateFormat dateFormatter; + String[] urlSchemes = {"http","https", "ftp"}; + UrlValidator urlValidator = new UrlValidator(urlSchemes); Map identifierSpaceToUrl = null; @@ -348,6 +353,12 @@ abstract public class CustomizableTabularExporterUtilities { if (text == null) { if (value instanceof String) { text = (String) value; + + if(text.contains(":")) { + if(urlValidator.isValid(text)) { + link = text; + } + } } else if (value instanceof OffsetDateTime) { text = ((OffsetDateTime) value).format(DateTimeFormatter.ISO_INSTANT); } else { diff --git a/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java b/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java index 131a47ea2..252808a93 100644 --- a/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java +++ b/main/tests/server/src/com/google/refine/tests/exporters/HtmlExporterTests.java @@ -184,6 +184,33 @@ public class HtmlExporterTests extends RefineTest { "\n" + "\n"); } + + @Test + public void exportHtmlTableWithURLs(){ + CreateGrid(3,3); + + project.rows.get(1).cells.set(1, new Cell("ftp://ftp.ripe.net/ripe/", null)); + project.rows.get(2).cells.set(0, new Cell("https://gnu.org/", null)); + try { + SUT.export(project, options, engine, writer); + } catch (IOException e) { + Assert.fail(); + } + + Assert.assertEquals(writer.toString(), "\n" + + "\n" + "" + TEST_PROJECT_NAME + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "
column0column1column2
row0cell0row0cell1row0cell2
row1cell0ftp://ftp.ripe.net/ripe/row1cell2
https://gnu.org/row2cell1row2cell2
\n" + + "\n" + + "\n"); + } //helper methods