View Javadoc
1   /**
2    * This file Copyright (c) 2003-2017 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 info.magnolia.cms.util.DeprecationUtil;
37  import info.magnolia.init.AbstractMagnoliaConfigurationProperties;
38  import info.magnolia.init.MagnoliaConfigurationProperties;
39  import info.magnolia.init.PropertySource;
40  
41  import java.util.ArrayList;
42  import java.util.Properties;
43  
44  import org.apache.commons.lang3.StringUtils;
45  
46  
47  /**
48   * A global holder for system-wide configuration properties.
49   *
50   * @see info.magnolia.cms.beans.config.PropertiesInitializer
51   * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
52   */
53  @Deprecated
54  public final class SystemProperty {
55  
56      public static final String MAGNOLIA_REPOSITORIES_HOME = MagnoliaConfigurationProperties.MAGNOLIA_REPOSITORIES_HOME;
57  
58      public static final String MAGNOLIA_REPOSITORIES_CONFIG = MagnoliaConfigurationProperties.MAGNOLIA_REPOSITORIES_CONFIG;
59  
60      public static final String MAGNOLIA_REPOSITORIES_CLUSTER_CONFIG = MagnoliaConfigurationProperties.MAGNOLIA_REPOSITORIES_CLUSTER_CONFIG;
61  
62      public static final String MAGNOLIA_REPOSITORIES_CLUSTER_MASTER = MagnoliaConfigurationProperties.MAGNOLIA_REPOSITORIES_CLUSTER_MASTER;
63  
64      public static final String MAGNOLIA_EXCHANGE_HISTORY = MagnoliaConfigurationProperties.MAGNOLIA_EXCHANGE_HISTORY;
65  
66      public static final String MAGNOLIA_UPLOAD_TMPDIR = MagnoliaConfigurationProperties.MAGNOLIA_UPLOAD_TMPDIR;
67  
68      public static final String MAGNOLIA_CACHE_STARTDIR = MagnoliaConfigurationProperties.MAGNOLIA_CACHE_STARTDIR;
69  
70      public static final String MAGNOLIA_APP_ROOTDIR = MagnoliaConfigurationProperties.MAGNOLIA_APP_ROOTDIR;
71  
72      public static final String MAGNOLIA_BOOTSTRAP_ROOTDIR = MagnoliaConfigurationProperties.MAGNOLIA_BOOTSTRAP_ROOTDIR;
73  
74      public static final String MAGNOLIA_BOOTSTRAP_SAMPLES = MagnoliaConfigurationProperties.MAGNOLIA_BOOTSTRAP_SAMPLES;
75  
76      public static final String MAGNOLIA_UTF8_ENABLED = MagnoliaConfigurationProperties.MAGNOLIA_UTF8_ENABLED;
77  
78      public static final String MAGNOLIA_WEBAPP = MagnoliaConfigurationProperties.MAGNOLIA_WEBAPP;
79  
80      public static final String MAGNOLIA_SERVERNAME = MagnoliaConfigurationProperties.MAGNOLIA_SERVERNAME;
81  
82      public static final String MAGNOLIA_CONTEXTPATH = MagnoliaConfigurationProperties.MAGNOLIA_CONTEXTPATH;
83  
84      private static Properties properties = new Properties();
85      private static MagnoliaConfigurationProperties magnoliaConfigurationProperties = newMagnoliaConfigurationProperties();
86  
87      /**
88       * Utility class, don't instantiate.
89       */
90      private SystemProperty() {
91          // unused
92      }
93  
94      /**
95       * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
96       */
97      public static void setProperty(String name, String value) {
98          // DeprecationUtil.isDeprecated();
99          properties.put(name, value);
100     }
101 
102     /**
103      * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
104      */
105     public static String getProperty(String name) {
106         final String legacy = (String) properties.get(name);
107         if (legacy != null) {
108             // DeprecationUtil.isDeprecated("Property [" + name + "] was found with value ["+legacy+"] in the legacy Properties field of SystemProperty. Please consider using MagnoliaConfigurationProperties instead.");
109             return legacy;
110         }
111         return getMagnoliaConfigurationProperties().getProperty(name);
112     }
113 
114     /**
115      * Returns a boolean property, returning <code>false</code> if the property is not set.
116      *
117      * @param name property name
118      * @return true only if the request property has a value of <code>true</code>
119      * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
120      */
121     public static boolean getBooleanProperty(String name) {
122         return "true".equals(getProperty(name));
123     }
124 
125     /**
126      * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
127      */
128     public static String getProperty(String name, String defaultValue) {
129         String value = getProperty(name);
130         if (StringUtils.isEmpty(value)) {
131             return defaultValue;
132         }
133         return value;
134     }
135 
136     /**
137      * @deprecated since 4.5, use {@link info.magnolia.init.MagnoliaConfigurationProperties}
138      */
139     public static boolean hasProperty(String name) {
140         final boolean legacy = properties.containsKey(name);
141         if (legacy) {
142             DeprecationUtil.isDeprecated("Property [" + name + "] was found in the legacy Properties field of SystemProperty. Please consider using MagnoliaConfigurationProperties instead.");
143             return legacy;
144         }
145         return getMagnoliaConfigurationProperties().hasProperty(name);
146     }
147 
148     /**
149      * @deprecated since 4.5 - while this still "works" and returns an aggregate of the local properties and those provided by
150      *             MagnoliaConfigurationProperties, writing to this Property object will not be reflected anywhere.
151      */
152     public static Properties getProperties() {
153         // DeprecationUtil.isDeprecated();
154         // providing a MagnoliaConfigurationProperties-compliant replacement...
155         final Properties p = new Properties();
156         p.putAll(properties);
157         for (String k : magnoliaConfigurationProperties.getKeys()) {
158             p.put(k, magnoliaConfigurationProperties.getProperty(k));
159         }
160         return p;
161     }
162 
163     private static MagnoliaConfigurationProperties getMagnoliaConfigurationProperties() {
164         // can't do Components.getComponent(MagnoliaConfigurationProperties.class) because this currently gets used before Components is ready.
165         return magnoliaConfigurationProperties;
166     }
167 
168     /**
169      * @deprecated since 4.5 - this is only here to allow tests to work until their tested classes are all converted.
170      */
171     public static void setMagnoliaConfigurationProperties(MagnoliaConfigurationProperties magnoliaConfigurationProperties) {
172         SystemProperty.magnoliaConfigurationProperties = magnoliaConfigurationProperties;
173     }
174 
175     /**
176      * @since 4.5 needed to clear up the hacks above, in tests.
177      */
178     public static void clear() {
179         properties.clear();
180         magnoliaConfigurationProperties = newMagnoliaConfigurationProperties();
181     }
182 
183     private static AbstractMagnoliaConfigurationProperties newMagnoliaConfigurationProperties() {
184         return new AbstractMagnoliaConfigurationProperties(new ArrayList<PropertySource>()) {
185         };
186     }
187 
188 }