]> git.laktatnebel.de Git - propertylib.git/commitdiff
Initial project version master
authorOle B. Rosentreter <ole@laktatnebel.de>
Fri, 27 Sep 2024 15:16:04 +0000 (17:16 +0200)
committerOle B. Rosentreter <ole@laktatnebel.de>
Fri, 27 Sep 2024 15:16:04 +0000 (17:16 +0200)
.gitignore [new file with mode: 0644]
pom.xml [new file with mode: 0644]
src/main/java/de/laktatnebel/libs/propertylib/Property.java [new file with mode: 0644]
src/main/java/de/laktatnebel/libs/propertylib/PropertyReader.java [new file with mode: 0644]
src/main/java/de/laktatnebel/libs/propertylib/execption/PropertyReaderException.java [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..9aac7d9
--- /dev/null
@@ -0,0 +1,5 @@
+.classpath
+.project
+.settings
+bin
+target
diff --git a/pom.xml b/pom.xml
new file mode 100644 (file)
index 0000000..713d6b2
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,35 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>de.laktatnebel.libs</groupId>
+       <artifactId>propertylib</artifactId>
+       <version>2.1.1-SNAPSHOT</version>
+
+       <name>PropertyLib</name>
+
+       <parent>
+               <groupId>de.laktatnebel.maven</groupId>
+               <artifactId>laktatnebellib</artifactId>
+               <version>2.1.7</version>
+       </parent>
+
+       <properties>
+               <commons-lang.version>2.6</commons-lang.version>
+       </properties>
+
+       <dependencyManagement>
+               <dependencies>
+                       <dependency>
+                               <groupId>commons-lang</groupId>
+                               <artifactId>commons-lang</artifactId>
+                               <version>${commons-lang.version}</version>
+                       </dependency>
+               </dependencies>
+       </dependencyManagement>
+
+       <dependencies>
+               <dependency>
+                       <groupId>commons-lang</groupId>
+                       <artifactId>commons-lang</artifactId>
+               </dependency>
+       </dependencies>
+</project>
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 (file)
index 0000000..b3cb019
--- /dev/null
@@ -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 (file)
index 0000000..6cd2e4e
--- /dev/null
@@ -0,0 +1,166 @@
+/*\r
+ * Projekt:\r
+ * Dateiname:   PropertyReader.java\r
+ * Erzeugt:     07.01.2010\r
+ *\r
+ * Beschreibung:\r
+ *\r
+ *\r
+ ************************************************************************\r
+ * Modification History:\r
+ *\r
+ ************************************************************************\r
+ *\r
+ */\r
+package de.laktatnebel.libs.propertylib;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+import java.io.StringReader;\r
+import java.nio.file.Files;\r
+import java.util.Iterator;\r
+import java.util.Properties;\r
+import java.util.Set;\r
+\r
+import org.apache.commons.lang.StringUtils;\r
+\r
+import de.laktatnebel.libs.propertylib.execption.PropertyReaderException;\r
+\r
+/**\r
+ * @author olgehrma\r
+ */\r
+public class PropertyReader {\r
+\r
+       public static final char        CHAR_BACKSLASH                  = '\\';\r
+       public static final String      CHAR_DOUBLEBACKSLASH    = "\\\\";\r
+\r
+       public PropertyReader() {\r
+               super();\r
+       }\r
+\r
+       /**\r
+        * @param path\r
+        *            Path to Property-File\r
+        * @return properties\r
+        * @throws IOException\r
+        *             IOException\r
+        * @throws PropertyReaderException\r
+        */\r
+       @Deprecated\r
+       public static Properties readProperties(final String path) throws IOException, PropertyReaderException {\r
+\r
+               final Properties properties = new Properties();\r
+\r
+               final File propertyFile = new File(path + "gallery.properties");\r
+\r
+               BufferedReader br = null;\r
+\r
+               try {\r
+                       final FileReader fr = new FileReader(propertyFile);\r
+                       br = new BufferedReader(fr);\r
+\r
+                       properties.load(br);\r
+\r
+                       br.close();\r
+               } catch (final IOException ioe) {\r
+                       throw new PropertyReaderException(ioe.getMessage(), ioe);\r
+               } finally {\r
+                       if (br != null) {\r
+                               br.close();\r
+                       }\r
+               }\r
+\r
+               return properties;\r
+       }\r
+\r
+       /**\r
+        * \r
+        * @param args\r
+        * @return\r
+        * @throws PropertyReaderException\r
+        * @throws IOException\r
+        */\r
+       public static Properties readPropertiesWithFileSeparatorReplacement(final String pathToPropertyFile) throws PropertyReaderException {\r
+\r
+               // Properties einlesen\r
+               final Properties props = new Properties();\r
+\r
+               try {\r
+                       final String propertiesString = new String(Files.readAllBytes(new File(pathToPropertyFile).toPath()));\r
+                       props.load(new StringReader(propertiesString.replace(Character.toString(PropertyReader.CHAR_BACKSLASH), PropertyReader.CHAR_DOUBLEBACKSLASH)));\r
+               } catch (final IOException ioe) {\r
+                       throw new PropertyReaderException(ioe.getMessage(), ioe);\r
+               }\r
+\r
+               return props;\r
+       }\r
+\r
+       /**\r
+        * @param properties\r
+        *            Properties\r
+        * @return\r
+        */\r
+       public static StringBuffer examineProperties(final Properties properties) {\r
+               final StringBuffer sb = new StringBuffer("Properties-Size:\t" + properties.size());\r
+\r
+               final Set<Object> allPropertyKeys = properties.keySet();\r
+\r
+               final Iterator<Object> itAllPropertyKeys = allPropertyKeys.iterator();\r
+\r
+               while (itAllPropertyKeys.hasNext()) {\r
+                       final Object obj = itAllPropertyKeys.next();\r
+                       final String key = obj.toString();\r
+\r
+                       sb.append(key + " = " + properties.getProperty(key));\r
+               }\r
+\r
+               return sb;\r
+       }\r
+\r
+       /**\r
+        * @return\r
+        * @throws IOException\r
+        * \r
+        */\r
+       public static String[] getPropertyValueArray(final Properties properties, final String propertyKey, final Character delim) {\r
+               return PropertyReader.getPropertyValueArray(properties, propertyKey, null, Character.toString(delim));\r
+       }\r
+\r
+       /**\r
+        * @return\r
+        * @throws IOException\r
+        * \r
+        */\r
+       public static String[] getPropertyValueArray(final Properties properties, final String propertyKey, final String propertyDefaultValue, final Character delim) {\r
+               return PropertyReader.getPropertyValueArray(properties, propertyKey, propertyDefaultValue, Character.toString(delim));\r
+       }\r
+\r
+       /**\r
+        * @return\r
+        * @throws IOException\r
+        * \r
+        */\r
+       public static String[] getPropertyValueArray(final Properties properties, final String propertyKey, final String delim) {\r
+               return PropertyReader.getPropertyValueArray(properties, propertyKey, null, delim);\r
+       }\r
+\r
+       /**\r
+        * @return\r
+        * @throws IOException\r
+        * \r
+        */\r
+       public static String[] getPropertyValueArray(final Properties properties, final String propertyKey, final String propertyDefaultValue, final String delim) {\r
+               String valueString = "";\r
+\r
+               if (propertyDefaultValue == null) {\r
+                       valueString = properties.getProperty(propertyKey);\r
+               } else {\r
+                       valueString = properties.getProperty(propertyKey, propertyDefaultValue);\r
+               }\r
+\r
+               return StringUtils.split(valueString.replaceAll("\\s+", ""), delim);\r
+       }\r
+\r
+}\r
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 (file)
index 0000000..865716e
--- /dev/null
@@ -0,0 +1,15 @@
+package de.laktatnebel.libs.propertylib.execption;\r
+\r
+public class PropertyReaderException extends Exception {\r
+\r
+       /** long serialVersionUID field */\r
+       private static final long       serialVersionUID        = 3161542354710291399L;\r
+\r
+       public PropertyReaderException(final Throwable t) {\r
+               super(t);\r
+       }\r
+\r
+       public PropertyReaderException(final String message, final Throwable t) {\r
+               super(message, t);\r
+       }\r
+}\r