Merge pull request #1697 from OpenRefine/issue1696
Clickable URLs in HTML exporter
This commit is contained in:
commit
07ab7da872
@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
package com.google.refine.exporters;
|
package com.google.refine.exporters;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
@ -45,6 +47,7 @@ import java.util.Properties;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.validator.routines.UrlValidator;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -226,6 +229,8 @@ abstract public class CustomizableTabularExporterUtilities {
|
|||||||
boolean date_omitTime = false;
|
boolean date_omitTime = false;
|
||||||
|
|
||||||
DateFormat dateFormatter;
|
DateFormat dateFormatter;
|
||||||
|
String[] urlSchemes = {"http","https", "ftp"};
|
||||||
|
UrlValidator urlValidator = new UrlValidator(urlSchemes);
|
||||||
|
|
||||||
Map<String, String> identifierSpaceToUrl = null;
|
Map<String, String> identifierSpaceToUrl = null;
|
||||||
|
|
||||||
@ -348,6 +353,12 @@ abstract public class CustomizableTabularExporterUtilities {
|
|||||||
if (text == null) {
|
if (text == null) {
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
text = (String) value;
|
text = (String) value;
|
||||||
|
|
||||||
|
if(text.contains(":")) {
|
||||||
|
if(urlValidator.isValid(text)) {
|
||||||
|
link = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (value instanceof OffsetDateTime) {
|
} else if (value instanceof OffsetDateTime) {
|
||||||
text = ((OffsetDateTime) value).format(DateTimeFormatter.ISO_INSTANT);
|
text = ((OffsetDateTime) value).format(DateTimeFormatter.ISO_INSTANT);
|
||||||
} else {
|
} else {
|
||||||
|
@ -184,6 +184,33 @@ public class HtmlExporterTests extends RefineTest {
|
|||||||
"</body>\n" +
|
"</body>\n" +
|
||||||
"</html>\n");
|
"</html>\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(), "<html>\n" +
|
||||||
|
"<head>\n" + "<title>" + TEST_PROJECT_NAME + "</title>\n" +
|
||||||
|
"<meta charset=\"utf-8\" />\n" +
|
||||||
|
"</head>\n" +
|
||||||
|
"<body>\n" +
|
||||||
|
"<table>\n" +
|
||||||
|
"<tr><th>column0</th><th>column1</th><th>column2</th></tr>\n" +
|
||||||
|
"<tr><td>row0cell0</td><td>row0cell1</td><td>row0cell2</td></tr>\n" +
|
||||||
|
"<tr><td>row1cell0</td><td><a href=\"ftp://ftp.ripe.net/ripe/\">ftp://ftp.ripe.net/ripe/</a></td><td>row1cell2</td></tr>\n" +
|
||||||
|
"<tr><td><a href=\"https://gnu.org/\">https://gnu.org/</a></td><td>row2cell1</td><td>row2cell2</td></tr>\n" +
|
||||||
|
"</table>\n" +
|
||||||
|
"</body>\n" +
|
||||||
|
"</html>\n");
|
||||||
|
}
|
||||||
|
|
||||||
//helper methods
|
//helper methods
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user