Source Code Cross Referenced for PropertiesLoaderUtils.java in  » J2EE » spring-framework-2.0.6 » org » springframework » core » io » support » 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 » J2EE » spring framework 2.0.6 » org.springframework.core.io.support 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not 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.
015:         */
016:
017:        package org.springframework.core.io.support;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.net.URL;
022:        import java.net.URLConnection;
023:        import java.util.Enumeration;
024:        import java.util.Properties;
025:
026:        import org.springframework.core.io.Resource;
027:        import org.springframework.util.Assert;
028:        import org.springframework.util.ClassUtils;
029:
030:        /**
031:         * Convenient utility methods for loading of <code>java.util.Properties</code>,
032:         * performing standard handling of input streams.
033:         *
034:         * <p>For more configurable properties loading, including the option of a
035:         * customized encoding, consider using the PropertiesLoaderSupport class.
036:         *
037:         * @author Juergen Hoeller
038:         * @author Rob Harrop
039:         * @since 2.0
040:         * @see PropertiesLoaderSupport
041:         */
042:        public abstract class PropertiesLoaderUtils {
043:
044:            /**
045:             * Load properties from the given resource.
046:             * @param resource the resource to load from
047:             * @return the populated Properties instance
048:             * @throws IOException if loading failed
049:             */
050:            public static Properties loadProperties(Resource resource)
051:                    throws IOException {
052:                Properties props = new Properties();
053:                fillProperties(props, resource);
054:                return props;
055:            }
056:
057:            /**
058:             * Fill the given properties from the given resource.
059:             * @param props the Properties instance to fill
060:             * @param resource the resource to load from
061:             * @throws IOException if loading failed
062:             */
063:            public static void fillProperties(Properties props,
064:                    Resource resource) throws IOException {
065:                InputStream is = resource.getInputStream();
066:                try {
067:                    props.load(is);
068:                } finally {
069:                    is.close();
070:                }
071:            }
072:
073:            /**
074:             * Load all properties from the given class path resource,
075:             * using the default class loader.
076:             * <p>Merges properties if more than one resource of the same name
077:             * found in the class path.
078:             * @param resourceName the name of the class path resource
079:             * @return the populated Properties instance
080:             * @throws IOException if loading failed
081:             */
082:            public static Properties loadAllProperties(String resourceName)
083:                    throws IOException {
084:                return loadAllProperties(resourceName, null);
085:            }
086:
087:            /**
088:             * Load all properties from the given class path resource,
089:             * using the given class loader.
090:             * <p>Merges properties if more than one resource of the same name
091:             * found in the class path.
092:             * @param resourceName the name of the class path resource
093:             * @param classLoader the ClassLoader to use for loading
094:             * (or <code>null</code> to use the default class loader)
095:             * @return the populated Properties instance
096:             * @throws IOException if loading failed
097:             */
098:            public static Properties loadAllProperties(String resourceName,
099:                    ClassLoader classLoader) throws IOException {
100:                Assert.notNull(resourceName, "Resource name must not be null");
101:                ClassLoader clToUse = classLoader;
102:                if (clToUse == null) {
103:                    clToUse = ClassUtils.getDefaultClassLoader();
104:                }
105:                Properties properties = new Properties();
106:                Enumeration urls = clToUse.getResources(resourceName);
107:                while (urls.hasMoreElements()) {
108:                    URL url = (URL) urls.nextElement();
109:                    InputStream is = null;
110:                    try {
111:                        URLConnection con = url.openConnection();
112:                        con.setUseCaches(false);
113:                        is = con.getInputStream();
114:                        properties.load(is);
115:                    } finally {
116:                        if (is != null) {
117:                            is.close();
118:                        }
119:                    }
120:                }
121:                return properties;
122:            }
123:
124:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.