Mercurial > dive4elements > framework
changeset 301:b0a949d3fe09
Moved StringUtils to common package. Added some Override annotations.
artifacts/trunk@2394 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jul 2011 09:36:04 +0000 |
parents | 0035e2511342 |
children | c066343c63b0 |
files | ChangeLog artifact-database/pom.xml artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java artifact-database/src/main/java/de/intevation/artifactdatabase/StringUtils.java artifacts-common/pom.xml artifacts-common/src/main/java/de/intevation/artifacts/common/utils/StringUtils.java artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java |
diffstat | 10 files changed, 137 insertions(+), 112 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Jul 21 15:05:49 2011 +0000 +++ b/ChangeLog Fri Jul 22 09:36:04 2011 +0000 @@ -1,3 +1,21 @@ +2011-07-22 Sascha L. Teichmann <teichmann@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/StringUtils.java, + artifacts-common/src/main/java/de/intevation/artifacts/common/utils/StringUtils.java: + Moved StringUtils to common package. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java: + Adjusted imports. + + * artifacts-common/pom.xml, artifact-database/pom.xml: Moved dependency to Apache codec + to other package. + + * artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java: + Added Override annotations (forgot to commit last time). + 2011-07-21 Ingo Weinzierl <ingo@intevation.de> * artifacts-common/src/main/java/de/intevation/artifacts/common/utils/ClientProtocolUtils.java:
--- a/artifact-database/pom.xml Thu Jul 21 15:05:49 2011 +0000 +++ b/artifact-database/pom.xml Fri Jul 22 09:36:04 2011 +0000 @@ -80,11 +80,6 @@ <version>8.3-603.jdbc4</version> </dependency> <dependency> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - <version>1.4</version> - </dependency> - <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.2.2</version>
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Thu Jul 21 15:05:49 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Fri Jul 22 09:36:04 2011 +0000 @@ -9,6 +9,7 @@ package de.intevation.artifactdatabase; import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.artifacts.common.utils.StringUtils; import de.intevation.artifactdatabase.Backend.PersistentArtifact;
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Thu Jul 21 15:05:49 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Fri Jul 22 09:36:04 2011 +0000 @@ -16,6 +16,7 @@ import de.intevation.artifacts.User; import de.intevation.artifacts.UserFactory; +import de.intevation.artifacts.common.utils.StringUtils; import de.intevation.artifacts.common.utils.XMLUtils; import java.sql.SQLException;
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java Thu Jul 21 15:05:49 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java Fri Jul 22 09:36:04 2011 +0000 @@ -9,6 +9,7 @@ package de.intevation.artifactdatabase; import de.intevation.artifacts.common.utils.Config; +import de.intevation.artifacts.common.utils.StringUtils; import de.intevation.artifacts.Artifact;
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java Thu Jul 21 15:05:49 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java Fri Jul 22 09:36:04 2011 +0000 @@ -19,6 +19,7 @@ import de.intevation.artifacts.ServiceFactory; import de.intevation.artifacts.UserFactory; +import de.intevation.artifacts.common.utils.StringUtils; import de.intevation.artifactdatabase.rest.HTTPServer;
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/StringUtils.java Thu Jul 21 15:05:49 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2010 by Intevation GmbH - * - * This program is free software under the LGPL (>=v2.1) - * Read the file LGPL.txt coming with the software for details - * or visit http://www.gnu.org/licenses/ if it does not exist. - */ - -package de.intevation.artifactdatabase; - -import java.io.UnsupportedEncodingException; - -import java.util.UUID; - -import org.apache.commons.codec.DecoderException; - -import org.apache.commons.codec.binary.Hex; - -import org.apache.log4j.Logger; - -/** - * Commonly used string functions. - * - * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> - */ -public final class StringUtils -{ - private static Logger logger = Logger.getLogger(StringUtils.class); - - /** - * Generated a random UUIDv4 in form of a string. - * @return the UUID - */ - public static final String newUUID() { - return UUID.randomUUID().toString(); - } - - /** - * Checks if a given string is a valid UUID. - * @param uuid The string to test. - * @return true if the string is a valid UUID else false. - */ - public static final boolean checkUUID(String uuid) { - try { - UUID.fromString(uuid); - } - catch (IllegalArgumentException iae) { - logger.warn(iae.getLocalizedMessage()); - return false; - } - return true; - } - - /** - * Returns the UTF-8 byte array representation of a given string. - * @param s The string to be transformed. - * @return The byte array representation. - */ - public static final byte [] getUTF8Bytes(String s) { - try { - return s.getBytes("UTF-8"); - } - catch (UnsupportedEncodingException usee) { - logger.error(usee.getLocalizedMessage(), usee); - return s.getBytes(); - } - } - - /** - * Tries to convert a Base64 encoded string into the - * corresponing byte array. - * @param s The Base64 encoded string - * @return The byte array representation or null if - * an decoding error occurs. - */ - public static final byte [] decodeHex(String s) { - try { - return Hex.decodeHex(s.toCharArray()); - } - catch (DecoderException de) { - return null; - } - } - - public static final String repeat(String s, int count, String sep) { - if (count <= 0) { - return ""; - } - StringBuilder sb = new StringBuilder(s); - for (--count; count > 0; --count) { - sb.append(sep).append(s); - } - return sb.toString(); - } - - public static final String repeat(char c, int count, char sep) { - if (count <= 0) { - return ""; - } - StringBuilder sb = new StringBuilder(2*count-1).append(c); - for (--count; count > 0; --count) { - sb.append(sep).append(c); - } - return sb.toString(); - } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts-common/pom.xml Thu Jul 21 15:05:49 2011 +0000 +++ b/artifacts-common/pom.xml Fri Jul 22 09:36:04 2011 +0000 @@ -26,6 +26,11 @@ <artifactId>log4j</artifactId> <version>1.2.14</version> </dependency> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.4</version> + </dependency> </dependencies> <build>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts-common/src/main/java/de/intevation/artifacts/common/utils/StringUtils.java Fri Jul 22 09:36:04 2011 +0000 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2010 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ + +package de.intevation.artifacts.common.utils; + +import java.io.UnsupportedEncodingException; + +import java.util.UUID; + +import org.apache.commons.codec.DecoderException; + +import org.apache.commons.codec.binary.Hex; + +import org.apache.log4j.Logger; + +/** + * Commonly used string functions. + * + * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> + */ +public final class StringUtils +{ + private static Logger logger = Logger.getLogger(StringUtils.class); + + /** + * Generated a random UUIDv4 in form of a string. + * @return the UUID + */ + public static final String newUUID() { + return UUID.randomUUID().toString(); + } + + /** + * Checks if a given string is a valid UUID. + * @param uuid The string to test. + * @return true if the string is a valid UUID else false. + */ + public static final boolean checkUUID(String uuid) { + try { + UUID.fromString(uuid); + } + catch (IllegalArgumentException iae) { + logger.warn(iae.getLocalizedMessage()); + return false; + } + return true; + } + + /** + * Returns the UTF-8 byte array representation of a given string. + * @param s The string to be transformed. + * @return The byte array representation. + */ + public static final byte [] getUTF8Bytes(String s) { + try { + return s.getBytes("UTF-8"); + } + catch (UnsupportedEncodingException usee) { + logger.error(usee.getLocalizedMessage(), usee); + return s.getBytes(); + } + } + + /** + * Tries to convert a Base64 encoded string into the + * corresponing byte array. + * @param s The Base64 encoded string + * @return The byte array representation or null if + * an decoding error occurs. + */ + public static final byte [] decodeHex(String s) { + try { + return Hex.decodeHex(s.toCharArray()); + } + catch (DecoderException de) { + return null; + } + } + + public static final String repeat(String s, int count, String sep) { + if (count <= 0) { + return ""; + } + StringBuilder sb = new StringBuilder(s); + for (--count; count > 0; --count) { + sb.append(sep).append(s); + } + return sb.toString(); + } + + public static final String repeat(char c, int count, char sep) { + if (count <= 0) { + return ""; + } + StringBuilder sb = new StringBuilder(2*count-1).append(c); + for (--count; count > 0; --count) { + sb.append(sep).append(c); + } + return sb.toString(); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java Thu Jul 21 15:05:49 2011 +0000 +++ b/artifacts/src/main/java/de/intevation/artifacts/ArtifactNamespaceContext.java Fri Jul 22 09:36:04 2011 +0000 @@ -68,6 +68,7 @@ * @param prefix The prefix * @return The corresponing URI */ + @Override public String getNamespaceURI(String prefix) { if (prefix == null) { @@ -83,6 +84,7 @@ * @see javax.xml.namespace.NamespaceContext#getPrefix(String) * @param uri The URI */ + @Override public String getPrefix(String uri) { if (uri == null) { @@ -102,6 +104,7 @@ * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String) * @param uri The URI */ + @Override public Iterator getPrefixes(String uri) { ArrayList<String> results = new ArrayList<String>(); for (Map.Entry<String, String> entry: map.entrySet()) {