From 93d34d781a656468a68c4b0d3cab965b0831ab13 Mon Sep 17 00:00:00 2001 From: Chris Parker Date: Mon, 24 Feb 2020 23:51:41 -0600 Subject: [PATCH] Replaced some deprecated methods --- .../refine/extension/database/DBExtensionTestUtils.java | 4 ++-- main/pom.xml | 5 +++++ main/src/com/google/refine/ProjectManager.java | 2 +- .../google/refine/commands/lang/LoadLanguageCommand.java | 6 +++--- main/src/com/google/refine/exporters/HtmlTableExporter.java | 4 ++-- .../src/com/google/refine/expr/functions/strings/Chomp.java | 2 +- .../com/google/refine/expr/functions/strings/Escape.java | 2 +- main/src/com/google/refine/expr/functions/strings/SHA1.java | 2 +- .../google/refine/expr/functions/strings/ToTitlecase.java | 2 +- .../com/google/refine/expr/functions/strings/Unescape.java | 2 +- main/src/com/google/refine/importers/ExcelImporter.java | 6 +++--- main/src/com/google/refine/importers/JsonImporter.java | 4 ++-- .../com/google/refine/importers/SeparatorBasedImporter.java | 2 +- main/src/com/google/refine/importers/XmlImporter.java | 2 +- main/src/com/google/refine/util/JSONUtilities.java | 2 +- 15 files changed, 26 insertions(+), 21 deletions(-) diff --git a/extensions/database/tests/src/com/google/refine/extension/database/DBExtensionTestUtils.java b/extensions/database/tests/src/com/google/refine/extension/database/DBExtensionTestUtils.java index c098458b6..524dad560 100644 --- a/extensions/database/tests/src/com/google/refine/extension/database/DBExtensionTestUtils.java +++ b/extensions/database/tests/src/com/google/refine/extension/database/DBExtensionTestUtils.java @@ -13,7 +13,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Random; -import org.apache.commons.lang3.text.StrSubstitutor; +import org.apache.commons.text.StringSubstitutor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -438,7 +438,7 @@ public class DBExtensionTestUtils { substitutes.put("dbName", dbConfig.getDatabaseName()); substitutes.put("useSSL", dbConfig.isUseSSL()); String urlTemplate = "jdbc:${dbType}://${host}:${port}/${dbName}?useSSL=${useSSL}"; - StrSubstitutor strSub = new StrSubstitutor(substitutes); + StringSubstitutor strSub = new StringSubstitutor(substitutes); return strSub.replace(urlTemplate); } diff --git a/main/pom.xml b/main/pom.xml index cc3a0c8d8..49bc1840c 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -318,6 +318,11 @@ commons-collections 3.2.2 + + org.apache.commons + commons-text + 1.8 + commons-validator commons-validator diff --git a/main/src/com/google/refine/ProjectManager.java b/main/src/com/google/refine/ProjectManager.java index 2447ecd5e..48055276b 100644 --- a/main/src/com/google/refine/ProjectManager.java +++ b/main/src/com/google/refine/ProjectManager.java @@ -450,7 +450,7 @@ public abstract class ProjectManager { ObjectNode node = (ObjectNode)jsonObj; if (node.get("name").asText("").equals(placeHolderJsonObj.get("name").asText(""))) { found = true; - node.put("display", placeHolderJsonObj.get("display")); + node.set("display", placeHolderJsonObj.get("display")); break; } } diff --git a/main/src/com/google/refine/commands/lang/LoadLanguageCommand.java b/main/src/com/google/refine/commands/lang/LoadLanguageCommand.java index 0535e5cc1..002b90891 100644 --- a/main/src/com/google/refine/commands/lang/LoadLanguageCommand.java +++ b/main/src/com/google/refine/commands/lang/LoadLanguageCommand.java @@ -112,8 +112,8 @@ public class LoadLanguageCommand extends Command { if (translations != null) { try { ObjectNode node = ParsingUtilities.mapper.createObjectNode(); - node.put("dictionary", translations); - node.put("lang", new TextNode(bestLang)); + node.set("dictionary", translations); + node.set("lang", new TextNode(bestLang)); respondJSON(response, node); } catch (IOException e) { logger.error("Error writing language labels to response stream"); @@ -158,7 +158,7 @@ public class LoadLanguageCommand extends Command { if (value == null) {; value = entry.getValue(); } - results.put(code, value); + results.set(code, value); } return results; } diff --git a/main/src/com/google/refine/exporters/HtmlTableExporter.java b/main/src/com/google/refine/exporters/HtmlTableExporter.java index 0f3f3ff0c..9efde58f5 100644 --- a/main/src/com/google/refine/exporters/HtmlTableExporter.java +++ b/main/src/com/google/refine/exporters/HtmlTableExporter.java @@ -38,7 +38,7 @@ import java.io.Writer; import java.util.List; import java.util.Properties; -import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.text.StringEscapeUtils; import com.fasterxml.jackson.databind.JsonNode; import com.google.refine.ProjectManager; @@ -106,7 +106,7 @@ public class HtmlTableExporter implements WriterExporter { writer.write(StringEscapeUtils.escapeHtml4(cellData.link)); writer.write("\">"); } - writer.write(StringEscapeUtils.escapeXml(cellData.text)); + writer.write(StringEscapeUtils.escapeXml10(cellData.text)); if (cellData.link != null) { writer.write(""); } diff --git a/main/src/com/google/refine/expr/functions/strings/Chomp.java b/main/src/com/google/refine/expr/functions/strings/Chomp.java index 5a0de0ae1..cb9858267 100644 --- a/main/src/com/google/refine/expr/functions/strings/Chomp.java +++ b/main/src/com/google/refine/expr/functions/strings/Chomp.java @@ -47,7 +47,7 @@ public class Chomp implements Function { Object o1 = args[0]; Object o2 = args[1]; if (o1 != null && o2 != null && o1 instanceof String && o2 instanceof String) { - return StringUtils.chomp((String) o1, (String) o2); + return StringUtils.removeEnd((String) o1, (String) o2); } } return null; diff --git a/main/src/com/google/refine/expr/functions/strings/Escape.java b/main/src/com/google/refine/expr/functions/strings/Escape.java index 9f0e5d0e9..c36a8c260 100644 --- a/main/src/com/google/refine/expr/functions/strings/Escape.java +++ b/main/src/com/google/refine/expr/functions/strings/Escape.java @@ -37,7 +37,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Properties; -import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.text.StringEscapeUtils; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; diff --git a/main/src/com/google/refine/expr/functions/strings/SHA1.java b/main/src/com/google/refine/expr/functions/strings/SHA1.java index 97eee6946..abb9f00a1 100644 --- a/main/src/com/google/refine/expr/functions/strings/SHA1.java +++ b/main/src/com/google/refine/expr/functions/strings/SHA1.java @@ -48,7 +48,7 @@ public class SHA1 implements Function { if (args.length == 1 && args[0] != null) { Object o = args[0]; String s = (o instanceof String) ? (String) o : o.toString(); - return DigestUtils.shaHex(s); + return DigestUtils.sha1Hex(s); } return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects a string"); } diff --git a/main/src/com/google/refine/expr/functions/strings/ToTitlecase.java b/main/src/com/google/refine/expr/functions/strings/ToTitlecase.java index 17a1a3e7e..fe376493b 100644 --- a/main/src/com/google/refine/expr/functions/strings/ToTitlecase.java +++ b/main/src/com/google/refine/expr/functions/strings/ToTitlecase.java @@ -35,7 +35,7 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.text.WordUtils; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; diff --git a/main/src/com/google/refine/expr/functions/strings/Unescape.java b/main/src/com/google/refine/expr/functions/strings/Unescape.java index 95a7742ae..08f9461a0 100644 --- a/main/src/com/google/refine/expr/functions/strings/Unescape.java +++ b/main/src/com/google/refine/expr/functions/strings/Unescape.java @@ -37,7 +37,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.Properties; -import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.text.StringEscapeUtils; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; diff --git a/main/src/com/google/refine/importers/ExcelImporter.java b/main/src/com/google/refine/importers/ExcelImporter.java index 421ccc66a..2563817c2 100644 --- a/main/src/com/google/refine/importers/ExcelImporter.java +++ b/main/src/com/google/refine/importers/ExcelImporter.java @@ -47,7 +47,7 @@ import java.util.Map; import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.common.usermodel.Hyperlink; -import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.CellType; @@ -258,8 +258,8 @@ public class ExcelImporter extends TabularImportingParserBase { } else if (cellType.equals(CellType.NUMERIC)) { double d = cell.getNumericCellValue(); - if (HSSFDateUtil.isCellDateFormatted(cell)) { - value = HSSFDateUtil.getJavaDate(d); + if (DateUtil.isCellDateFormatted(cell)) { + value = DateUtil.getJavaDate(d); // TODO: If we had a time datatype, we could use something like the following // to distinguish times from dates (although Excel doesn't really make the distinction) // Another alternative would be to look for values < 0.60 diff --git a/main/src/com/google/refine/importers/JsonImporter.java b/main/src/com/google/refine/importers/JsonImporter.java index 318b60b6e..2b2528a0a 100644 --- a/main/src/com/google/refine/importers/JsonImporter.java +++ b/main/src/com/google/refine/importers/JsonImporter.java @@ -89,7 +89,7 @@ public class JsonImporter extends TreeImportingParserBase { ObjectNode firstFileRecord = fileRecords.get(0); File file = ImportingUtilities.getFile(job, firstFileRecord); JsonFactory factory = new JsonFactory(); - JsonParser parser = factory.createJsonParser(file); + JsonParser parser = factory.createParser(file); PreviewParsingState state = new PreviewParsingState(); JsonNode rootValue = parseForPreview(parser, state); @@ -223,7 +223,7 @@ public class JsonImporter extends TreeImportingParserBase { public JSONTreeReader(InputStream is) { try { - parser = factory.createJsonParser(is); + parser = factory.createParser(is); current = null; next = parser.nextToken(); } catch (IOException e) { diff --git a/main/src/com/google/refine/importers/SeparatorBasedImporter.java b/main/src/com/google/refine/importers/SeparatorBasedImporter.java index 243fc69b2..0ba84153d 100644 --- a/main/src/com/google/refine/importers/SeparatorBasedImporter.java +++ b/main/src/com/google/refine/importers/SeparatorBasedImporter.java @@ -49,7 +49,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.text.StringEscapeUtils; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.refine.ProjectMetadata; diff --git a/main/src/com/google/refine/importers/XmlImporter.java b/main/src/com/google/refine/importers/XmlImporter.java index 6b31cb856..00d6f3ac8 100644 --- a/main/src/com/google/refine/importers/XmlImporter.java +++ b/main/src/com/google/refine/importers/XmlImporter.java @@ -186,7 +186,7 @@ public class XmlImporter extends TreeImportingParserBase { } if (children.size() > 0) { - result.put("c", children); + result.set("c", children); } return result; } diff --git a/main/src/com/google/refine/util/JSONUtilities.java b/main/src/com/google/refine/util/JSONUtilities.java index 2258099e1..5ee23d17c 100644 --- a/main/src/com/google/refine/util/JSONUtilities.java +++ b/main/src/com/google/refine/util/JSONUtilities.java @@ -149,7 +149,7 @@ public class JSONUtilities { } static public void safePut(ObjectNode options, String key, JsonNode rootElement) { - options.put(key, rootElement); + options.set(key, rootElement); } static public void safeInc(ObjectNode obj, String key) {