Source Code Cross Referenced for ChainResources.java in  » Library » Apache-commons-chain-1.1-src » org » apache » commons » chain » web » 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 » Library » Apache commons chain 1.1 src » org.apache.commons.chain.web 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 1999-2004 The Apache Software Foundation
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:        package org.apache.commons.chain.web;
017:
018:        import java.net.URL;
019:        import java.util.ArrayList;
020:        import java.util.List;
021:        import javax.servlet.ServletContext;
022:        import org.apache.commons.chain.Catalog;
023:        import org.apache.commons.chain.config.ConfigParser;
024:        import org.apache.commons.logging.Log;
025:        import org.apache.commons.logging.LogFactory;
026:
027:        /**
028:         * <p>Utility methods for loading class loader and web application resources
029:         * to configure a {@link Catalog}.  These methods are shared between
030:         * <code>ChainListener</code> and <code>ChainServlet</code>.</p>
031:         *
032:         * @author Craig R. McClanahan
033:         * @author Ted Husted
034:         */
035:
036:        final class ChainResources {
037:
038:            // ---------------------------------------------------------- Static Methods
039:
040:            /**
041:             * <p>Parse the specified class loader resources.</p>
042:             *
043:             * @param resources Comma-delimited list of resources (or <code>null</code>)
044:             * @param parser {@link ConfigParser} to use for parsing
045:             */
046:            static void parseClassResources(String resources,
047:                    ConfigParser parser) {
048:
049:                if (resources == null) {
050:                    return;
051:                }
052:                Log log = LogFactory.getLog(ChainResources.class);
053:                ClassLoader loader = Thread.currentThread()
054:                        .getContextClassLoader();
055:                if (loader == null) {
056:                    loader = ChainResources.class.getClassLoader();
057:                }
058:                String[] paths = getResourcePaths(resources);
059:                String path = null;
060:                try {
061:                    for (int i = 0; i < paths.length; i++) {
062:                        path = paths[i];
063:                        URL url = loader.getResource(path);
064:                        if (url == null) {
065:                            throw new IllegalStateException(
066:                                    "Missing chain config resource '" + path
067:                                            + "'");
068:                        }
069:                        if (log.isDebugEnabled()) {
070:                            log.debug("Loading chain config resource '" + path
071:                                    + "'");
072:                        }
073:                        parser.parse(url);
074:                    }
075:                } catch (Exception e) {
076:                    throw new RuntimeException(
077:                            "Exception parsing chain config resource '" + path
078:                                    + "': " + e.getMessage());
079:                }
080:
081:            }
082:
083:            /**
084:             * <p>Parse the specified class loader resources.</p>
085:             *
086:             * @param catalog {@link Catalog} we are populating
087:             * @param resources Comma-delimited list of resources (or <code>null</code>)
088:             * @param parser {@link ConfigParser} to use for parsing
089:             *
090:             * @deprecated Use the variant that does not take a catalog, on a
091:             *  configuration resource containing "catalog" element(s)
092:             */
093:            static void parseClassResources(Catalog catalog, String resources,
094:                    ConfigParser parser) {
095:
096:                if (resources == null) {
097:                    return;
098:                }
099:                Log log = LogFactory.getLog(ChainResources.class);
100:                ClassLoader loader = Thread.currentThread()
101:                        .getContextClassLoader();
102:                if (loader == null) {
103:                    loader = ChainResources.class.getClassLoader();
104:                }
105:                String[] paths = getResourcePaths(resources);
106:                String path = null;
107:                try {
108:                    for (int i = 0; i < paths.length; i++) {
109:                        path = paths[i];
110:                        URL url = loader.getResource(path);
111:                        if (url == null) {
112:                            throw new IllegalStateException(
113:                                    "Missing chain config resource '" + path
114:                                            + "'");
115:                        }
116:                        if (log.isDebugEnabled()) {
117:                            log.debug("Loading chain config resource '" + path
118:                                    + "'");
119:                        }
120:                        parser.parse(catalog, url);
121:                    }
122:                } catch (Exception e) {
123:                    throw new RuntimeException(
124:                            "Exception parsing chain config resource '" + path
125:                                    + "': " + e.getMessage());
126:                }
127:
128:            }
129:
130:            /**
131:             * <p>Parse the specified web application resources.</p>
132:             *
133:             * @param context <code>ServletContext</code> for this web application
134:             * @param resources Comma-delimited list of resources (or <code>null</code>)
135:             * @param parser {@link ConfigParser} to use for parsing
136:             */
137:            static void parseWebResources(ServletContext context,
138:                    String resources, ConfigParser parser) {
139:
140:                if (resources == null) {
141:                    return;
142:                }
143:                Log log = LogFactory.getLog(ChainResources.class);
144:                String[] paths = getResourcePaths(resources);
145:                String path = null;
146:                try {
147:                    for (int i = 0; i < paths.length; i++) {
148:                        path = paths[i];
149:                        URL url = context.getResource(path);
150:                        if (url == null) {
151:                            throw new IllegalStateException(
152:                                    "Missing chain config resource '" + path
153:                                            + "'");
154:                        }
155:                        if (log.isDebugEnabled()) {
156:                            log.debug("Loading chain config resource '" + path
157:                                    + "'");
158:                        }
159:                        parser.parse(url);
160:                    }
161:                } catch (Exception e) {
162:                    throw new RuntimeException(
163:                            "Exception parsing chain config resource '" + path
164:                                    + "': " + e.getMessage());
165:                }
166:
167:            }
168:
169:            /**
170:             * <p>Parse the specified web application resources.</p>
171:             *
172:             * @param catalog {@link Catalog} we are populating
173:             * @param context <code>ServletContext</code> for this web application
174:             * @param resources Comma-delimited list of resources (or <code>null</code>)
175:             * @param parser {@link ConfigParser} to use for parsing
176:             *
177:             * @deprecated Use the variant that does not take a catalog, on a
178:             *  configuration resource containing "catalog" element(s)
179:             */
180:            static void parseWebResources(Catalog catalog,
181:                    ServletContext context, String resources,
182:                    ConfigParser parser) {
183:
184:                if (resources == null) {
185:                    return;
186:                }
187:                Log log = LogFactory.getLog(ChainResources.class);
188:                String[] paths = getResourcePaths(resources);
189:                String path = null;
190:                try {
191:                    for (int i = 0; i < paths.length; i++) {
192:                        path = paths[i];
193:                        URL url = context.getResource(path);
194:                        if (url == null) {
195:                            throw new IllegalStateException(
196:                                    "Missing chain config resource '" + path
197:                                            + "'");
198:                        }
199:                        if (log.isDebugEnabled()) {
200:                            log.debug("Loading chain config resource '" + path
201:                                    + "'");
202:                        }
203:                        parser.parse(catalog, url);
204:                    }
205:                } catch (Exception e) {
206:                    throw new RuntimeException(
207:                            "Exception parsing chain config resource '" + path
208:                                    + "': " + e.getMessage());
209:                }
210:
211:            }
212:
213:            /**
214:             * <p> Parse the resource string into an array of paths. Empty entries will
215:             * be skipped. (That is, all entries in the array are non-empty paths.)</p>
216:             *
217:             * @param resources A comma-delimited list of resource paths (or
218:             *                  <code>null</code>).
219:             *
220:             * @return An array of non-empty paths. The array itself may be empty.
221:             *
222:             * @since Chain 1.1
223:             */
224:            static String[] getResourcePaths(String resources) {
225:                List paths = new ArrayList();
226:
227:                if (resources != null) {
228:                    String path;
229:                    int comma;
230:
231:                    while ((comma = resources.indexOf(',')) >= 0) {
232:                        path = resources.substring(0, comma).trim();
233:                        if (path.length() > 0) {
234:                            paths.add(path);
235:                        }
236:                        resources = resources.substring(comma + 1);
237:                    }
238:                    resources = resources.trim();
239:                    if (resources.length() > 0) {
240:                        paths.add(resources);
241:                    }
242:                }
243:
244:                return (String[]) paths.toArray(new String[0]);
245:            }
246:
247:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.