From: Ole B. Rosentreter Date: Fri, 27 Sep 2024 15:16:04 +0000 (+0200) Subject: Initial project version X-Git-Url: https://git.laktatnebel.de/?a=commitdiff_plain;ds=inline;p=propertylib.git Initial project version --- e98672fb79221ddd367d9032f79995eb0c4bfb8f diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9aac7d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.classpath +.project +.settings +bin +target diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..713d6b2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + de.laktatnebel.libs + propertylib + 2.1.1-SNAPSHOT + + PropertyLib + + + de.laktatnebel.maven + laktatnebellib + 2.1.7 + + + + 2.6 + + + + + + commons-lang + commons-lang + ${commons-lang.version} + + + + + + + commons-lang + commons-lang + + + diff --git a/src/main/java/de/laktatnebel/libs/propertylib/Property.java b/src/main/java/de/laktatnebel/libs/propertylib/Property.java new file mode 100644 index 0000000..b3cb019 --- /dev/null +++ b/src/main/java/de/laktatnebel/libs/propertylib/Property.java @@ -0,0 +1,12 @@ +package de.laktatnebel.libs.propertylib; + +import java.util.Properties; + +public class Property extends Properties { + + /** + * + */ + private static final long serialVersionUID = -8856554447398616480L; + +} diff --git a/src/main/java/de/laktatnebel/libs/propertylib/PropertyReader.java b/src/main/java/de/laktatnebel/libs/propertylib/PropertyReader.java new file mode 100644 index 0000000..6cd2e4e --- /dev/null +++ b/src/main/java/de/laktatnebel/libs/propertylib/PropertyReader.java @@ -0,0 +1,166 @@ +/* + * Projekt: + * Dateiname: PropertyReader.java + * Erzeugt: 07.01.2010 + * + * Beschreibung: + * + * + ************************************************************************ + * Modification History: + * + ************************************************************************ + * + */ +package de.laktatnebel.libs.propertylib; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringReader; +import java.nio.file.Files; +import java.util.Iterator; +import java.util.Properties; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; + +import de.laktatnebel.libs.propertylib.execption.PropertyReaderException; + +/** + * @author olgehrma + */ +public class PropertyReader { + + public static final char CHAR_BACKSLASH = '\\'; + public static final String CHAR_DOUBLEBACKSLASH = "\\\\"; + + public PropertyReader() { + super(); + } + + /** + * @param path + * Path to Property-File + * @return properties + * @throws IOException + * IOException + * @throws PropertyReaderException + */ + @Deprecated + public static Properties readProperties(final String path) throws IOException, PropertyReaderException { + + final Properties properties = new Properties(); + + final File propertyFile = new File(path + "gallery.properties"); + + BufferedReader br = null; + + try { + final FileReader fr = new FileReader(propertyFile); + br = new BufferedReader(fr); + + properties.load(br); + + br.close(); + } catch (final IOException ioe) { + throw new PropertyReaderException(ioe.getMessage(), ioe); + } finally { + if (br != null) { + br.close(); + } + } + + return properties; + } + + /** + * + * @param args + * @return + * @throws PropertyReaderException + * @throws IOException + */ + public static Properties readPropertiesWithFileSeparatorReplacement(final String pathToPropertyFile) throws PropertyReaderException { + + // Properties einlesen + final Properties props = new Properties(); + + try { + final String propertiesString = new String(Files.readAllBytes(new File(pathToPropertyFile).toPath())); + props.load(new StringReader(propertiesString.replace(Character.toString(PropertyReader.CHAR_BACKSLASH), PropertyReader.CHAR_DOUBLEBACKSLASH))); + } catch (final IOException ioe) { + throw new PropertyReaderException(ioe.getMessage(), ioe); + } + + return props; + } + + /** + * @param properties + * Properties + * @return + */ + public static StringBuffer examineProperties(final Properties properties) { + final StringBuffer sb = new StringBuffer("Properties-Size:\t" + properties.size()); + + final Set allPropertyKeys = properties.keySet(); + + final Iterator itAllPropertyKeys = allPropertyKeys.iterator(); + + while (itAllPropertyKeys.hasNext()) { + final Object obj = itAllPropertyKeys.next(); + final String key = obj.toString(); + + sb.append(key + " = " + properties.getProperty(key)); + } + + return sb; + } + + /** + * @return + * @throws IOException + * + */ + public static String[] getPropertyValueArray(final Properties properties, final String propertyKey, final Character delim) { + return PropertyReader.getPropertyValueArray(properties, propertyKey, null, Character.toString(delim)); + } + + /** + * @return + * @throws IOException + * + */ + public static String[] getPropertyValueArray(final Properties properties, final String propertyKey, final String propertyDefaultValue, final Character delim) { + return PropertyReader.getPropertyValueArray(properties, propertyKey, propertyDefaultValue, Character.toString(delim)); + } + + /** + * @return + * @throws IOException + * + */ + public static String[] getPropertyValueArray(final Properties properties, final String propertyKey, final String delim) { + return PropertyReader.getPropertyValueArray(properties, propertyKey, null, delim); + } + + /** + * @return + * @throws IOException + * + */ + public static String[] getPropertyValueArray(final Properties properties, final String propertyKey, final String propertyDefaultValue, final String delim) { + String valueString = ""; + + if (propertyDefaultValue == null) { + valueString = properties.getProperty(propertyKey); + } else { + valueString = properties.getProperty(propertyKey, propertyDefaultValue); + } + + return StringUtils.split(valueString.replaceAll("\\s+", ""), delim); + } + +} diff --git a/src/main/java/de/laktatnebel/libs/propertylib/execption/PropertyReaderException.java b/src/main/java/de/laktatnebel/libs/propertylib/execption/PropertyReaderException.java new file mode 100644 index 0000000..865716e --- /dev/null +++ b/src/main/java/de/laktatnebel/libs/propertylib/execption/PropertyReaderException.java @@ -0,0 +1,15 @@ +package de.laktatnebel.libs.propertylib.execption; + +public class PropertyReaderException extends Exception { + + /** long serialVersionUID field */ + private static final long serialVersionUID = 3161542354710291399L; + + public PropertyReaderException(final Throwable t) { + super(t); + } + + public PropertyReaderException(final String message, final Throwable t) { + super(message, t); + } +}