Source Code Cross Referenced for PropertyReader.java in  » J2EE » jag » com » finalist » util » 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 » jag » com.finalist.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2003 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:
018:        package com.finalist.util;
019:
020:        import java.io.*;
021:        import java.net.URL;
022:        import java.util.*;
023:
024:        /**
025:         * Util class that will read properties from the WEB-INF/classes/directory
026:         * or by specifying a URL on the filesystem.
027:         * Also has a helper method for creating a platform independent URL.
028:         *
029:         * @author Rudie Ekkelenkamp en Erik-Jan de Wit
030:         * @created 07 aug 2002
031:         * @version $Revision: 1.1 $, $Date: 2004/11/12 14:06:44 $
032:         */
033:        public class PropertyReader {
034:
035:            /**
036:             * Retrieve the properties specified by the fileName
037:             * The property file should be in the WEB-INF/classess directory
038:             * Suppose you need to get the properties in the
039:             * web-inf/classes/config/application.properties ,
040:             * you need to pass the propertyFile: config/application.properties
041:             *
042:             * @param propertyFile relative path to a properties file in the WEB-INF/classes directory
043:             * @return a <code>Properties<code> object based on the input file
044:             **/
045:            public static Properties getProperties(String propertyFile) {
046:                try {
047:                    URL url = getPropertiesURL(propertyFile);
048:                    return getProperties(url);
049:                } catch (Exception e) {
050:                    System.out
051:                            .println("Error ocurred during properties retrieval");
052:                    System.out.println(e.getMessage());
053:                    return null;
054:                }
055:            }
056:
057:            /**
058:             * This method will return a platform independent URL to a file
059:             * in the web-inf/classes direcotry.
060:             *
061:             * @param fileName relative path to a properties file in the WEB-INF/classes directory
062:             * @return a platform independent URL to the xml file.
063:             */
064:            public static URL getPropertiesURL(String fileName) {
065:                try {
066:                    System.out.println("Getting the properties URL");
067:                    URL url = null;
068:                    url = PropertyReader.class.getResource("/" + fileName);
069:                    String s = url.toString();
070:                    System.out.println("Filename of the  properties file is: "
071:                            + s);
072:                    if (s.indexOf("file://") != -1) {
073:                        int indexOf = s.indexOf("file://") + 6;
074:                        String temp = s.substring(0, indexOf);
075:                        System.out.println("temp = " + temp
076:                                + " moet zijn file:/");
077:                        url = new URL(temp + "//" + s.substring(indexOf));
078:                        System.out.println("The url is now: " + url);
079:                    }
080:                    return url;
081:                } catch (Exception e) {
082:                    System.out
083:                            .println("Error ocurred during properties retrieval");
084:                    System.out.println(e.getMessage());
085:                    return null;
086:                }
087:            }
088:
089:            /**
090:             * Retrieve the properties accesible through the specified URL
091:             *
092:             * @param url a reference to a properties file
093:             * @return a properties file
094:             **/
095:            public static Properties getProperties(URL url) {
096:                try {
097:                    Properties props = new Properties();
098:                    // Check for Solaris compatibility.
099:                    // A // in the file protocol won't be found in Solaris.
100:                    props.load(url.openStream());
101:                    System.out.println("Properties have been loaded: " + props);
102:                    return props;
103:                } catch (Exception e) {
104:                    System.out
105:                            .println("Error ocurred during properties retrieval");
106:                    System.out.println(e.getMessage());
107:                    return null;
108:                }
109:            }
110:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.