Source Code Cross Referenced for ResourceFinderClasspath.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » resources » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.resources 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: ResourceFinderClasspath.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.resources;
009:
010:        import com.uwyn.rife.resources.exceptions.CantOpenResourceStreamException;
011:        import com.uwyn.rife.resources.exceptions.CantRetrieveResourceContentException;
012:        import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
013:        import com.uwyn.rife.tools.FileUtils;
014:        import com.uwyn.rife.tools.InnerClassException;
015:        import com.uwyn.rife.tools.InputStreamUser;
016:        import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
017:        import java.io.IOException;
018:        import java.io.InputStream;
019:        import java.net.URL;
020:        import java.net.URLConnection;
021:
022:        /**
023:         * This class offers <code>ResourceFinder</code> capabilities for resources that
024:         * are available through the classloader. This is done for directories as well
025:         * as for jar files. Basically, this corresponds to the resources that are
026:         * available through the classpath.
027:         * <p>
028:         * Since the application's classloader isn't supposed to change in a global way,
029:         * the <code>ResourceFinderClasspath</code> class can only be instantiated
030:         * through the static <code>getInstance()</code> method that always returns
031:         * the same instance as a singleton.
032:         *
033:         * @author Geert Bevin (gbevin[remove] at uwyn dot com)
034:         * @version $Revision: 3634 $
035:         * @see com.uwyn.rife.resources.ResourceFinder
036:         * @since 1.0
037:         */
038:        public class ResourceFinderClasspath extends AbstractResourceFinder {
039:            protected ResourceFinderClasspath() {
040:            }
041:
042:            /**
043:             * Returns the shared singleton instance of the
044:             * <code>ResourceFinderClasspath</code> class.
045:             *
046:             * @return the singleton <code>ResourceFinderClasspath</code> instance
047:             *
048:             * @since 1.0
049:             */
050:            public static ResourceFinderClasspath getInstance() {
051:                return ResourceFinderClasspathSingleton.INSTANCE;
052:            }
053:
054:            public URL getResource(String name) {
055:                URL resource = null;
056:
057:                if (this .getClass().getClassLoader() != null) {
058:                    // Try the class loader that loaded this class.
059:                    resource = this .getClass().getClassLoader().getResource(
060:                            name);
061:                } else {
062:                    // Try the system class loader.
063:                    resource = ClassLoader.getSystemClassLoader().getResource(
064:                            name);
065:                }
066:
067:                if (null == resource) {
068:                    // if not found in classpath fall back to default
069:                    resource = this .getClass().getResource(name);
070:                }
071:
072:                return resource;
073:            }
074:
075:            public <ResultType> ResultType useStream(URL resource,
076:                    InputStreamUser user) throws ResourceFinderErrorException,
077:                    InnerClassException {
078:                if (null == resource || null == user) {
079:                    return null;
080:                }
081:
082:                InputStream stream = null;
083:                try {
084:                    URLConnection connection = resource.openConnection();
085:                    connection.setUseCaches(false);
086:                    stream = connection.getInputStream();
087:                    return (ResultType) user.useInputStream(stream);
088:                } catch (IOException e) {
089:                    throw new CantOpenResourceStreamException(resource, e);
090:                } finally {
091:                    if (stream != null) {
092:                        try {
093:                            stream.close();
094:                        } catch (IOException e) {
095:                            // couldn't close stream since it probably already has been
096:                            // closed after an exception
097:                            // proceed without reporting an error message.
098:                        }
099:                    }
100:                }
101:            }
102:
103:            public String getContent(URL resource, String encoding)
104:                    throws ResourceFinderErrorException {
105:                if (null == resource) {
106:                    return null;
107:                }
108:
109:                try {
110:                    return FileUtils.readString(resource, encoding);
111:                } catch (FileUtilsErrorException e) {
112:                    throw new CantRetrieveResourceContentException(resource,
113:                            encoding, e);
114:                }
115:            }
116:
117:            public long getModificationTime(URL resource)
118:                    throws ResourceFinderErrorException {
119:                return ModificationTimeClasspath.getModificationTime(resource);
120:            }
121:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.