| Revision 1757,
1.0 KB
checked in by jharrop, 3 months ago
(diff) |
|
New method getProperty(String key, String defaultValue) ie specify defaultValue
|
| Line | |
|---|
| 1 | package org.docx4j; |
|---|
| 2 | |
|---|
| 3 | import java.io.IOException; |
|---|
| 4 | import java.util.Properties; |
|---|
| 5 | |
|---|
| 6 | import org.apache.log4j.Logger; |
|---|
| 7 | import org.docx4j.utils.ResourceUtils; |
|---|
| 8 | |
|---|
| 9 | public class Docx4jProperties { |
|---|
| 10 | |
|---|
| 11 | protected static Logger log = Logger.getLogger(Docx4jProperties.class); |
|---|
| 12 | |
|---|
| 13 | private static Properties properties; |
|---|
| 14 | |
|---|
| 15 | private static void init() { |
|---|
| 16 | |
|---|
| 17 | properties = new Properties(); |
|---|
| 18 | try { |
|---|
| 19 | properties.load( |
|---|
| 20 | ResourceUtils.getResource("docx4j.properties")); |
|---|
| 21 | } catch (Exception e) { |
|---|
| 22 | log.error("Error reading docx4j.properties", e); |
|---|
| 23 | } |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | public static String getProperty(String key) { |
|---|
| 27 | |
|---|
| 28 | if (properties==null) {init();} |
|---|
| 29 | |
|---|
| 30 | return properties.getProperty(key); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * @since 2.7.2 |
|---|
| 36 | */ |
|---|
| 37 | public static String getProperty(String key, String defaultValue) { |
|---|
| 38 | |
|---|
| 39 | if (properties==null) {init();} |
|---|
| 40 | |
|---|
| 41 | return properties.getProperty(key, defaultValue); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | public static Properties getProperties() { |
|---|
| 45 | |
|---|
| 46 | if (properties==null) {init();} |
|---|
| 47 | return properties; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.