Source Code Cross Referenced for PropertiesLoader.java in  » RSS-RDF » Rome » com » sun » syndication » io » impl » 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 » RSS RDF » Rome » com.sun.syndication.io.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.syndication.io.impl;
002:
003:        import java.io.IOException;
004:        import java.io.InputStream;
005:        import java.net.URL;
006:        import java.util.*;
007:
008:        /**
009:         * Properties loader that aggregates a master properties file and several extra properties files,
010:         * all from the current classpath.
011:         * <P>
012:         * The master properties file has to be in a distinct location than the extra properties files.
013:         * First the master properties file is loaded, then all the extra properties files in their order
014:         * of appearance in the classpath.
015:         * <P>
016:         * Current use cases (plugin manager for parsers/converters/generators for feeds and modules
017:         * and date formats) assume properties are list of tokens, that why the only method to get
018:         * property values is the getTokenizedProperty().
019:         * <p>
020:         *
021:         * @author Alejandro Abdelnur
022:         *
023:         */
024:        public class PropertiesLoader {
025:
026:            private static final String MASTER_PLUGIN_FILE = "com/sun/syndication/rome.properties";
027:            private static final String EXTRA_PLUGIN_FILE = "rome.properties";
028:
029:            private static PropertiesLoader PROPERTIES_LOADER;
030:
031:            static {
032:                try {
033:                    PROPERTIES_LOADER = new PropertiesLoader(
034:                            MASTER_PLUGIN_FILE, EXTRA_PLUGIN_FILE);
035:                } catch (IOException ioex) {
036:                    throw new RuntimeException(ioex.getMessage(), ioex);
037:                }
038:            }
039:
040:            /**
041:             * Returns the PropertiesLoader singleton used by ROME to load plugin components.
042:             *
043:             * @return PropertiesLoader singleton.
044:             *
045:             */
046:            public static PropertiesLoader getPropertiesLoader() {
047:                return PROPERTIES_LOADER;
048:            }
049:
050:            private Properties[] _properties;
051:
052:            /**
053:             * Creates a PropertiesLoader.
054:             * <p>
055:             * @param masterFileLocation master file location, there must be only one.
056:             * @param extraFileLocation extra file location, there may be many.
057:             * @throws IOException thrown if one of the properties file could not be read.
058:             *
059:             */
060:            private PropertiesLoader(String masterFileLocation,
061:                    String extraFileLocation) throws IOException {
062:                List propertiesList = new ArrayList();
063:                ClassLoader classLoader = PluginManager.class.getClassLoader();
064:
065:                try {
066:                    InputStream is = classLoader
067:                            .getResourceAsStream(masterFileLocation);
068:                    Properties p = new Properties();
069:                    p.load(is);
070:                    is.close();
071:                    propertiesList.add(p);
072:                } catch (IOException ioex) {
073:                    IOException ex = new IOException(
074:                            "could not load ROME master plugins file ["
075:                                    + masterFileLocation + "], "
076:                                    + ioex.getMessage());
077:                    ex.setStackTrace(ioex.getStackTrace());
078:                    throw ex;
079:                }
080:
081:                Enumeration urls = classLoader.getResources(extraFileLocation);
082:                while (urls.hasMoreElements()) {
083:                    URL url = (URL) urls.nextElement();
084:                    Properties p = new Properties();
085:                    try {
086:                        InputStream is = url.openStream();
087:                        p.load(is);
088:                        is.close();
089:                    } catch (IOException ioex) {
090:                        IOException ex = new IOException(
091:                                "could not load ROME extensions plugins file ["
092:                                        + url.toString() + "], "
093:                                        + ioex.getMessage());
094:                        ex.setStackTrace(ioex.getStackTrace());
095:                        throw ex;
096:                    }
097:                    propertiesList.add(p);
098:                }
099:
100:                _properties = new Properties[propertiesList.size()];
101:                propertiesList.toArray(_properties);
102:            }
103:
104:            /**
105:             * Returns an array of tokenized values stored under a property key in all properties files.
106:             * If the master file has this property its tokens will be the first ones in the array.
107:             * <p>
108:             * @param key property key to retrieve values
109:             * @param separator String with all separator characters to tokenize from the values in all
110:             * properties files.
111:             * @return all the tokens for the given property key from all the properties files.
112:             *
113:             */
114:            public String[] getTokenizedProperty(String key, String separator) {
115:                List entriesList = new ArrayList();
116:                for (int i = 0; i < _properties.length; i++) {
117:                    String values = _properties[i].getProperty(key);
118:                    if (values != null) {
119:                        StringTokenizer st = new StringTokenizer(values,
120:                                separator);
121:                        while (st.hasMoreTokens()) {
122:                            String token = st.nextToken();
123:                            entriesList.add(token);
124:                        }
125:                    }
126:                }
127:                String[] entries = new String[entriesList.size()];
128:                entriesList.toArray(entries);
129:                return entries;
130:            }
131:
132:            /**
133:             * Returns an array of values stored under a property key in all properties files.
134:             * If the master file has this property it will be the first ones in the array.
135:             * <p>
136:             * @param key property key to retrieve values
137:             * @return all the values for the given property key from all the properties files.
138:             *
139:             */
140:            public String[] getProperty(String key) {
141:                List entriesList = new ArrayList();
142:                for (int i = 0; i < _properties.length; i++) {
143:                    String values = _properties[i].getProperty(key);
144:                    if (values != null) {
145:                        entriesList.add(values);
146:                    }
147:                }
148:                String[] entries = new String[entriesList.size()];
149:                entriesList.toArray(entries);
150:                return entries;
151:            }
152:
153:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.