Source Code Cross Referenced for RollerRuntimeConfig.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » config » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Blogger System » apache roller 3.1 » org.apache.roller.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  The ASF licenses this file to You
004:         * under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.  For additional information regarding
015:         * copyright in this work, please see the NOTICE file in the top level
016:         * directory of this distribution.
017:         */
018:
019:        package org.apache.roller.config;
020:
021:        import java.io.InputStream;
022:        import java.io.InputStreamReader;
023:        import java.io.StringWriter;
024:        import java.util.Properties;
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.apache.roller.config.runtime.RuntimeConfigDefs;
028:        import org.apache.roller.config.runtime.RuntimeConfigDefsParser;
029:        import org.apache.roller.business.PropertiesManager;
030:        import org.apache.roller.business.RollerFactory;
031:
032:        /**
033:         * This class acts as a convenience gateway for getting property values
034:         * via the PropertiesManager.  We do this because most calls to the
035:         * PropertiesManager are just to get the value of a specific property and
036:         * thus the caller doesn't need the full RollerPropertyData object.
037:         *
038:         * We also provide some methods for converting to different data types.
039:         */
040:        public class RollerRuntimeConfig {
041:
042:            private static Log log = LogFactory
043:                    .getLog(RollerRuntimeConfig.class);
044:
045:            private static String runtime_config = "/rollerRuntimeConfigDefs.xml";
046:            private static RuntimeConfigDefs configDefs = null;
047:
048:            // special case for our context urls
049:            private static String relativeContextURL = null;
050:            private static String absoluteContextURL = null;
051:
052:            // prevent instantiations
053:            private RollerRuntimeConfig() {
054:            }
055:
056:            /**
057:             * Retrieve a single property from the PropertiesManager ... returns null
058:             * if there is an error
059:             **/
060:            public static String getProperty(String name) {
061:
062:                String value = null;
063:
064:                try {
065:                    PropertiesManager pmgr = RollerFactory.getRoller()
066:                            .getPropertiesManager();
067:                    value = pmgr.getProperty(name).getValue();
068:                } catch (Exception e) {
069:                    log.warn("Trouble accessing property: " + name, e);
070:                }
071:
072:                log.debug("fetched property [" + name + "=" + value + "]");
073:
074:                return value;
075:            }
076:
077:            /**
078:             * Retrieve a property as a boolean ... defaults to false if there is an error
079:             **/
080:            public static boolean getBooleanProperty(String name) {
081:
082:                // get the value first, then convert
083:                String value = RollerRuntimeConfig.getProperty(name);
084:
085:                if (value == null)
086:                    return false;
087:
088:                return (new Boolean(value)).booleanValue();
089:            }
090:
091:            /**
092:             * Retrieve a property as an int ... defaults to -1 if there is an error
093:             **/
094:            public static int getIntProperty(String name) {
095:
096:                // get the value first, then convert
097:                String value = RollerRuntimeConfig.getProperty(name);
098:
099:                if (value == null)
100:                    return -1;
101:
102:                int intval = -1;
103:                try {
104:                    intval = Integer.parseInt(value);
105:                } catch (Exception e) {
106:                    log.warn("Trouble converting to int: " + name, e);
107:                }
108:
109:                return intval;
110:            }
111:
112:            public static RuntimeConfigDefs getRuntimeConfigDefs() {
113:
114:                if (configDefs == null) {
115:
116:                    // unmarshall the config defs file
117:                    try {
118:                        InputStream is = RollerRuntimeConfig.class
119:                                .getResourceAsStream(runtime_config);
120:
121:                        RuntimeConfigDefsParser parser = new RuntimeConfigDefsParser();
122:                        configDefs = parser.unmarshall(is);
123:
124:                    } catch (Exception e) {
125:                        // error while parsing :(
126:                        log.error("Error parsing runtime config defs", e);
127:                    }
128:
129:                }
130:
131:                return configDefs;
132:            }
133:
134:            /**
135:             * Get the runtime configuration definitions XML file as a string.
136:             *
137:             * This is basically a convenience method for accessing this file.
138:             * The file itself contains meta-data about what configuration
139:             * properties we change at runtime via the UI and how to setup
140:             * the display for editing those properties.
141:             */
142:            public static String getRuntimeConfigDefsAsString() {
143:
144:                log.debug("Trying to load runtime config defs file");
145:
146:                try {
147:                    InputStreamReader reader = new InputStreamReader(
148:                            RollerConfig.class
149:                                    .getResourceAsStream(runtime_config));
150:                    StringWriter configString = new StringWriter();
151:
152:                    char[] buf = new char[8196];
153:                    int length = 0;
154:                    while ((length = reader.read(buf)) > 0)
155:                        configString.write(buf, 0, length);
156:
157:                    reader.close();
158:
159:                    return configString.toString();
160:                } catch (Exception e) {
161:                    log.error("Error loading runtime config defs file", e);
162:                }
163:
164:                return "";
165:            }
166:
167:            /**
168:             * Special method which sets the non-persisted absolute url to this site.
169:             *
170:             * This property is *not* persisted in any way.
171:             */
172:            public static void setAbsoluteContextURL(String url) {
173:                absoluteContextURL = url;
174:            }
175:
176:            /**
177:             * Get the absolute url to this site.
178:             *
179:             * This method will just return the value of the "site.absoluteurl"
180:             * property if it is set, otherwise it will return the non-persisted
181:             * value which is set by the InitFilter.
182:             */
183:            public static String getAbsoluteContextURL() {
184:
185:                // db prop takes priority if it exists
186:                String absURL = getProperty("site.absoluteurl");
187:                if (absURL != null && absURL.trim().length() > 0) {
188:                    return absURL;
189:                }
190:
191:                return absoluteContextURL;
192:            }
193:
194:            /**
195:             * Special method which sets the non-persisted relative url to this site.
196:             *
197:             * This property is *not* persisted in any way.
198:             */
199:            public static void setRelativeContextURL(String url) {
200:                relativeContextURL = url;
201:            }
202:
203:            public static String getRelativeContextURL() {
204:                return relativeContextURL;
205:            }
206:
207:            /**
208:             * Convenience method for Roller classes trying to determine if a given
209:             * weblog handle represents the front page blog.
210:             */
211:            public static boolean isFrontPageWeblog(String weblogHandle) {
212:
213:                String frontPageHandle = getProperty("site.frontpage.weblog.handle");
214:
215:                return (frontPageHandle.equals(weblogHandle));
216:            }
217:
218:            /**
219:             * Convenience method for Roller classes trying to determine if a given
220:             * weblog handle represents the front page blog configured to render
221:             * site-wide data.
222:             */
223:            public static boolean isSiteWideWeblog(String weblogHandle) {
224:
225:                boolean siteWide = getBooleanProperty("site.frontpage.weblog.aggregated");
226:
227:                return (isFrontPageWeblog(weblogHandle) && siteWide);
228:            }
229:
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.