Repository: openmeetings Updated Branches: refs/heads/3.3.x 4aee66760 -> b3070ba0b
[OPENMEETINGS-1612] compilation warnings are fixed Project: http://git-wip-us.apache.org/repos/asf/openmeetings/repo Commit: http://git-wip-us.apache.org/repos/asf/openmeetings/commit/b3070ba0 Tree: http://git-wip-us.apache.org/repos/asf/openmeetings/tree/b3070ba0 Diff: http://git-wip-us.apache.org/repos/asf/openmeetings/diff/b3070ba0 Branch: refs/heads/3.3.x Commit: b3070ba0b99584100d94ead40bd8f335d631a9a5 Parents: 4aee667 Author: Maxim Solodovnik <[email protected]> Authored: Thu Jun 22 20:40:35 2017 +0700 Committer: Maxim Solodovnik <[email protected]> Committed: Thu Jun 22 20:40:35 2017 +0700 ---------------------------------------------------------------------- .../openmeetings/db/util/FormatHelper.java | 4 +-- .../cli/ConnectionPropertiesPatcher.java | 37 ++++++++++---------- openmeetings-util/pom.xml | 4 +++ .../apache/openmeetings/util/StoredFile.java | 3 +- .../util/crypt/AbstractCryptTest.java | 17 ++++++--- .../web/common/tree/FileTreePanel.java | 2 +- pom.xml | 5 +++ 7 files changed, 45 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/openmeetings/blob/b3070ba0/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/FormatHelper.java ---------------------------------------------------------------------- diff --git a/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/FormatHelper.java b/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/FormatHelper.java index 64409b7..ea9a80f 100644 --- a/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/FormatHelper.java +++ b/openmeetings-db/src/main/java/org/apache/openmeetings/db/util/FormatHelper.java @@ -18,7 +18,7 @@ */ package org.apache.openmeetings.db.util; -import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; +import static org.apache.commons.text.StringEscapeUtils.escapeHtml4; import java.util.regex.Pattern; @@ -27,7 +27,7 @@ import org.apache.openmeetings.db.entity.user.User; public class FormatHelper { /** * taken from BidiUtils - * + * * A regular expression for matching right-to-left language codes. See * {@link #isRtlLanguage} for the design. */ http://git-wip-us.apache.org/repos/asf/openmeetings/blob/b3070ba0/openmeetings-install/src/main/java/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java ---------------------------------------------------------------------- diff --git a/openmeetings-install/src/main/java/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java b/openmeetings-install/src/main/java/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java index a5b562c..9a4cf8b 100644 --- a/openmeetings-install/src/main/java/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java +++ b/openmeetings-install/src/main/java/org/apache/openmeetings/cli/ConnectionPropertiesPatcher.java @@ -18,6 +18,8 @@ */ package org.apache.openmeetings.cli; +import static org.apache.commons.text.StringEscapeUtils.escapeXml10; + import java.io.File; import javax.xml.parsers.DocumentBuilder; @@ -31,10 +33,9 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; -import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.openmeetings.util.ConnectionProperties.DbType; import org.apache.openmeetings.util.ConnectionProperties; +import org.apache.openmeetings.util.ConnectionProperties.DbType; import org.apache.openmeetings.util.OmFileHelper; import org.w3c.dom.Attr; import org.w3c.dom.Document; @@ -46,7 +47,7 @@ public abstract class ConnectionPropertiesPatcher { protected static final String USER_PREFIX = "Username"; protected static final String PASS_PREFIX = "Password"; protected ConnectionProperties props; - + public static ConnectionPropertiesPatcher getPatcher(ConnectionProperties props) { ConnectionPropertiesPatcher patcher = null; switch (props.getDbType()) { @@ -73,24 +74,24 @@ public abstract class ConnectionPropertiesPatcher { patcher.props = props; return patcher; } - + public static ConnectionProperties getConnectionProperties(File conf) throws Exception { ConnectionProperties props = new ConnectionProperties(); Document doc = getDocument(conf); Attr attr = getConnectionProperties(doc); String[] tokens = attr.getValue().split(","); loadProperties(tokens, props); - + return props; } - + private static Document getDocument(File xml) throws Exception { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); //dbFactory.setNamespaceAware(true); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); return dBuilder.parse(xml); } - + private static Attr getConnectionProperties(Document doc) throws Exception { XPath xPath = XPathFactory.newInstance().newXPath(); XPathExpression expr = xPath.compile("/persistence/persistence-unit/properties/property[@name='openjpa.ConnectionProperties']"); @@ -98,7 +99,7 @@ public abstract class ConnectionPropertiesPatcher { Element element = (Element)expr.evaluate(doc, XPathConstants.NODE); return element.getAttributeNode("value"); } - + public static void patch(ConnectionProperties props) throws Exception { ConnectionPropertiesPatcher patcher = getPatcher(props); Document doc = getDocument(OmFileHelper.getPersistence(props.getDbType())); @@ -106,13 +107,13 @@ public abstract class ConnectionPropertiesPatcher { String[] tokens = attr.getValue().split(","); patcher.patchAttribute(tokens); attr.setValue(StringUtils.join(tokens, ",")); - + TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); transformer.transform(source, new StreamResult(OmFileHelper.getPersistence().getCanonicalPath())); //this constructor is used to avoid transforming path to URI } - + public static ConnectionProperties patch(String dbType, String host, String port, String db, String user, String pass) throws Exception { ConnectionProperties props = getConnectionProperties(OmFileHelper.getPersistence(dbType)); props.setLogin(user); @@ -122,12 +123,12 @@ public abstract class ConnectionPropertiesPatcher { patch(props); return props; } - + public static void updateUrl(ConnectionProperties props, String host, String port, String db) { ConnectionPropertiesPatcher patcher = getPatcher(props); props.setURL(patcher.getUrl(props.getURL(), host, port, db)); } - + protected void patchAttribute(String[] tokens) { for (int i = 0; i < tokens.length; ++i) { patchProp(tokens, i, USER_PREFIX, props.getLogin()); @@ -139,11 +140,11 @@ public abstract class ConnectionPropertiesPatcher { protected static void patchProp(String[] tokens, int idx, String name, String value) { String prop = tokens[idx].trim(); if (prop.startsWith(name)) { - prop = name + "=" + StringEscapeUtils.escapeXml10(value); + prop = name + "=" + escapeXml10(value); tokens[idx] = prop; } } - + private static void loadProperties(String[] tokens, ConnectionProperties connectionProperties) { String prop; for (int i = 0; i < tokens.length; ++i) { @@ -151,12 +152,12 @@ public abstract class ConnectionPropertiesPatcher { if (prop != null) { connectionProperties.setDriver(prop); } - + prop = getPropFromPersistence(tokens, i, USER_PREFIX); if (prop != null) { connectionProperties.setLogin(prop); } - + prop = getPropFromPersistence(tokens, i, PASS_PREFIX); if (prop != null) { connectionProperties.setPassword(prop); @@ -175,7 +176,7 @@ public abstract class ConnectionPropertiesPatcher { } } } - + protected static String getPropFromPersistence(String[] tokens, int idx, String name){ String prop = tokens[idx].trim(); if (prop.startsWith(name)) { @@ -184,6 +185,6 @@ public abstract class ConnectionPropertiesPatcher { } return null; } - + protected abstract String getUrl(String url, String host, String port, String db); } http://git-wip-us.apache.org/repos/asf/openmeetings/blob/b3070ba0/openmeetings-util/pom.xml ---------------------------------------------------------------------- diff --git a/openmeetings-util/pom.xml b/openmeetings-util/pom.xml index fabf192..bf49afd 100644 --- a/openmeetings-util/pom.xml +++ b/openmeetings-util/pom.xml @@ -78,6 +78,10 @@ <artifactId>commons-lang3</artifactId> </dependency> <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-text</artifactId> + </dependency> + <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>${commons-codec.version}</version> http://git-wip-us.apache.org/repos/asf/openmeetings/blob/b3070ba0/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java b/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java index 5431fa4..919336a 100644 --- a/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java +++ b/openmeetings-util/src/main/java/org/apache/openmeetings/util/StoredFile.java @@ -21,6 +21,7 @@ package org.apache.openmeetings.util; import static org.apache.openmeetings.util.OmFileHelper.EXTENSION_JPG; import static org.apache.openmeetings.util.OmFileHelper.getFileExt; import static org.apache.openmeetings.util.OpenmeetingsVariables.webAppRootKey; +import static org.apache.tika.metadata.TikaMetadataKeys.RESOURCE_NAME_KEY; import static org.apache.tika.mime.MediaType.application; import static org.apache.tika.mime.MediaType.image; @@ -106,7 +107,7 @@ public class StoredFile { } Tika tika = new Tika(); Metadata md = new Metadata(); - md.add(Metadata.RESOURCE_NAME_KEY, String.format("%s.%s", name, ext)); + md.add(RESOURCE_NAME_KEY, String.format("%s.%s", name, ext)); try { mime = MediaType.parse(tika.detect(is, md)); } catch (Exception e) { http://git-wip-us.apache.org/repos/asf/openmeetings/blob/b3070ba0/openmeetings-util/src/test/java/org/apache/openmeetings/util/crypt/AbstractCryptTest.java ---------------------------------------------------------------------- diff --git a/openmeetings-util/src/test/java/org/apache/openmeetings/util/crypt/AbstractCryptTest.java b/openmeetings-util/src/test/java/org/apache/openmeetings/util/crypt/AbstractCryptTest.java index 4878de1..c641db4 100644 --- a/openmeetings-util/src/test/java/org/apache/openmeetings/util/crypt/AbstractCryptTest.java +++ b/openmeetings-util/src/test/java/org/apache/openmeetings/util/crypt/AbstractCryptTest.java @@ -18,13 +18,16 @@ */ package org.apache.openmeetings.util.crypt; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; import java.util.Random; -import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.text.RandomStringGenerator; import org.junit.Test; public abstract class AbstractCryptTest { @@ -37,17 +40,21 @@ public abstract class AbstractCryptTest { assertTrue("Hash for null should be null", crypt.verify(null, null)); } - + private static List<String> get(int count) { Random rnd = new Random(); List<String> l = new ArrayList<>(count + 1); l.add(""); + RandomStringGenerator generator = new RandomStringGenerator.Builder() + .withinRange('!', '}') + .usingRandom(rnd::nextInt) + .build(); for (int i = 0; i < count; ++i) { - l.add(RandomStringUtils.random(rnd.nextInt(256))); + l.add(generator.generate(rnd.nextInt(256))); } return l; } - + @Test public void test() { for (String str : get(64)) { http://git-wip-us.apache.org/repos/asf/openmeetings/blob/b3070ba0/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/tree/FileTreePanel.java ---------------------------------------------------------------------- diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/tree/FileTreePanel.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/tree/FileTreePanel.java index 37552d2..a540295 100644 --- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/tree/FileTreePanel.java +++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/tree/FileTreePanel.java @@ -18,7 +18,7 @@ */ package org.apache.openmeetings.web.common.tree; -import static org.apache.commons.lang3.StringEscapeUtils.escapeEcmaScript; +import static org.apache.commons.text.StringEscapeUtils.escapeEcmaScript; import static org.apache.openmeetings.util.OmFileHelper.EXTENSION_JPG; import static org.apache.openmeetings.util.OmFileHelper.EXTENSION_PDF; import static org.apache.openmeetings.web.app.Application.getBean; http://git-wip-us.apache.org/repos/asf/openmeetings/blob/b3070ba0/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 93eb597..d8a7c8e 100644 --- a/pom.xml +++ b/pom.xml @@ -677,6 +677,11 @@ <artifactId>commons-lang3</artifactId> <version>3.6</version> </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-text</artifactId> + <version>1.1</version> + </dependency> </dependencies> </dependencyManagement> <dependencies>
