View Javadoc

1   /**
2    * This file Copyright (c) 2003-2011 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.cms.core;
35  
36  import java.util.ArrayList;
37  import java.util.Map;
38  import java.util.Properties;
39  
40  import info.magnolia.cms.util.DeprecationUtil;
41  import info.magnolia.init.AbstractMagnoliaConfigurationProperties;
42  import info.magnolia.init.MagnoliaConfigurationProperties;
43  import info.magnolia.init.PropertySource;
44  
45  import org.apache.commons.lang.StringUtils;
46  
47  
48  /**
49   * A global holder for system-wide configuration properties.
50   *
51   * @see info.magnolia.cms.beans.config.PropertiesInitializer
52   *
53   * @author Sameer charles
54   * @version 2.0 $Id$
55   *
56   * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
57   */
58  public final class SystemProperty {
59  
60      public static final String MAGNOLIA_REPOSITORIES_HOME = "magnolia.repositories.home";
61  
62      public static final String MAGNOLIA_REPOSITORIES_CONFIG = "magnolia.repositories.config";
63  
64      public static final String MAGNOLIA_EXCHANGE_HISTORY = "magnolia.exchange.history";
65  
66      public static final String MAGNOLIA_UPLOAD_TMPDIR = "magnolia.upload.tmpdir";
67  
68      public static final String MAGNOLIA_CACHE_STARTDIR = "magnolia.cache.startdir";
69  
70      public static final String MAGNOLIA_APP_ROOTDIR = "magnolia.app.rootdir";
71  
72      public static final String MAGNOLIA_BOOTSTRAP_ROOTDIR = "magnolia.bootstrap.dir";
73  
74      public static final String MAGNOLIA_BOOTSTRAP_SAMPLES = "magnolia.bootstrap.samples";
75  
76      public static final String MAGNOLIA_UTF8_ENABLED = "magnolia.utf8.enabled";
77  
78      public static final String MAGNOLIA_WEBAPP = "magnolia.webapp";
79  
80      public static final String MAGNOLIA_SERVERNAME = "magnolia.servername";
81  
82      public static final String MAGNOLIA_CONTEXTPATH = "magnolia.contextpath";
83  
84      private static Properties properties = new Properties();
85  
86      /**
87       * Utility class, don't instantiate.
88       */
89      private SystemProperty() {
90          // unused
91      }
92  
93      /**
94       * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
95       */
96      public static void setProperty(String name, String value) {
97          // DeprecationUtil.isDeprecated();
98          properties.put(name, value);
99      }
100 
101     /**
102      * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
103      */
104     public static String getProperty(String name) {
105         final String legacy = (String) properties.get(name);
106         if (legacy != null) {
107             // DeprecationUtil.isDeprecated("Property [" + name + "] was found with value ["+legacy+"] in the legacy Properties field of SystemProperty. Please consider using MagnoliaConfigurationProperties instead.");
108             return legacy;
109         }
110         return getMagnoliaConfigurationProperties().getProperty(name);
111     }
112 
113     /**
114      * Returns a boolean property, returning <code>false</code> if the property is not set.
115      * @param name property name
116      * @return true only if the request property has a value of <code>true</code>
117      * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
118      */
119     public static boolean getBooleanProperty(String name) {
120         return "true".equals(getProperty(name));
121     }
122 
123     /**
124      * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
125      */
126     public static String getProperty(String name, String defaultValue) {
127         String value = getProperty(name);
128         if (StringUtils.isEmpty(value)) {
129             return defaultValue;
130         }
131         return value;
132     }
133 
134     /**
135      * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
136      */
137     public static boolean hasProperty(String name) {
138         final boolean legacy = properties.containsKey(name);
139         if (legacy) {
140             DeprecationUtil.isDeprecated("Property [" + name + "] was found in the legacy Properties field of SystemProperty. Please consider using MagnoliaConfigurationProperties instead.");
141             return legacy;
142         }
143         return getMagnoliaConfigurationProperties().hasProperty(name);
144     }
145 
146     /**
147      * @deprecated since 3.0 - use getProperties() instead
148      */
149     public static Map getPropertyList() {
150         return properties;
151     }
152 
153     /**
154      * @deprecated since 4.5 - while this still "works" and returns an aggregate of the local properties and those provided by
155      * MagnoliaConfigurationProperties, writing to this Property object will not be reflected anywhere.
156      */
157     public static Properties getProperties() {
158         // DeprecationUtil.isDeprecated();
159         // providing a MagnoliaConfigurationProperties-compliant replacement...
160         final Properties p = new Properties();
161         p.putAll(properties);
162         for (String k : magnoliaConfigurationProperties.getKeys()) {
163             p.put(k, magnoliaConfigurationProperties.getProperty(k));
164         }
165         return p;
166     }
167 
168     static MagnoliaConfigurationProperties magnoliaConfigurationProperties = new AbstractMagnoliaConfigurationProperties(new ArrayList<PropertySource>()) {};
169     private static MagnoliaConfigurationProperties getMagnoliaConfigurationProperties() {
170         // can't do Components.getComponent(MagnoliaConfigurationProperties.class) because this currently gets used before Components is ready.
171         return magnoliaConfigurationProperties;
172     }
173 
174     /**
175      * @deprecated since 4.5 - this is only here to allow tests to work until their tested classes are all converted.
176      */
177     public static void setMagnoliaConfigurationProperties(MagnoliaConfigurationProperties magnoliaConfigurationProperties) {
178         SystemProperty.magnoliaConfigurationProperties = magnoliaConfigurationProperties;
179     }
180 
181     /**
182      * @since 4.5 needed to clear up the hacks above, in tests.
183      */
184     public static void clear() {
185         properties.clear();
186         // magnoliaConfigurationProperties = null;
187     }
188 }