Source Code Cross Referenced for URLFactoryImpl.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » url » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.components.url 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.components.url;
018:
019:        import org.apache.avalon.framework.activity.Disposable;
020:        import org.apache.avalon.framework.component.ComponentException;
021:        import org.apache.avalon.framework.component.ComponentManager;
022:        import org.apache.avalon.framework.component.Composable;
023:        import org.apache.avalon.framework.configuration.Configurable;
024:        import org.apache.avalon.framework.configuration.Configuration;
025:        import org.apache.avalon.framework.configuration.ConfigurationException;
026:        import org.apache.avalon.framework.context.Context;
027:        import org.apache.avalon.framework.context.ContextException;
028:        import org.apache.avalon.framework.context.Contextualizable;
029:        import org.apache.avalon.framework.logger.AbstractLogEnabled;
030:        import org.apache.avalon.framework.logger.LogEnabled;
031:        import org.apache.avalon.framework.parameters.ParameterException;
032:        import org.apache.avalon.framework.parameters.Parameterizable;
033:        import org.apache.avalon.framework.parameters.Parameters;
034:        import org.apache.avalon.framework.thread.ThreadSafe;
035:        import org.apache.cocoon.Constants;
036:        import org.apache.cocoon.util.ClassUtils;
037:
038:        import java.io.File;
039:        import java.net.MalformedURLException;
040:        import java.net.URL;
041:        import java.util.HashMap;
042:        import java.util.Iterator;
043:        import java.util.Map;
044:
045:        /**
046:         * @deprecated by the new source resolving of avalon excalibur
047:         *
048:         * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
049:         * @version CVS $Id: URLFactoryImpl.java 433543 2006-08-22 06:22:54Z crossley $
050:         */
051:        public class URLFactoryImpl extends AbstractLogEnabled implements 
052:                ThreadSafe, Configurable, Disposable, Composable,
053:                Contextualizable, URLFactory {
054:
055:            /**
056:             * The context
057:             */
058:            protected Context context;
059:
060:            /**
061:             * The special URL factories
062:             */
063:            protected Map factories;
064:
065:            /** The component manager */
066:            private ComponentManager manager;
067:
068:            /**
069:             * Create a URL from a location. This method supports specific
070:             * pseudo-protocol as defined in its configuration
071:             *
072:             * @param location The location
073:             * @return The URL pointed to by the location
074:             * @exception MalformedURLException If the location is malformed
075:             */
076:            public URL getURL(String location) throws MalformedURLException {
077:                Iterator iter = factories.keySet().iterator();
078:                String protocol = null;
079:                while (iter.hasNext()) {
080:                    protocol = (String) iter.next();
081:                    if (location.startsWith(protocol + "://")) {
082:                        return ((URLFactory) factories.get(protocol))
083:                                .getURL(location
084:                                        .substring(protocol.length() + 3));
085:                    }
086:                }
087:                try {
088:                    if (getLogger().isDebugEnabled()) {
089:                        getLogger().debug("Making URL from " + location);
090:                    }
091:                    return new URL(location);
092:                } catch (MalformedURLException mue) {
093:                    if (getLogger().isDebugEnabled()) {
094:                        getLogger()
095:                                .debug(
096:                                        "Making URL - MalformedURLException in getURL:",
097:                                        mue);
098:                    }
099:
100:                    org.apache.cocoon.environment.Context envContext = null;
101:                    try {
102:                        envContext = (org.apache.cocoon.environment.Context) context
103:                                .get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
104:                    } catch (ContextException e) {
105:                        getLogger().error(
106:                                "Making URL - ContextException in getURL", e);
107:                    }
108:
109:                    final String path = envContext.getRealPath(location);
110:                    if (path != null)
111:                        return (new File(path)).toURL();
112:
113:                    if (getLogger().isDebugEnabled()) {
114:                        getLogger().debug("Making URL a Resource:" + location);
115:                    }
116:                    URL url = envContext.getResource(location);
117:                    if (url != null)
118:                        return url;
119:
120:                    if (getLogger().isDebugEnabled()) {
121:                        getLogger().debug(
122:                                "Making URL a File (assuming that it is full path):"
123:                                        + location);
124:                    }
125:                    return (new File(location)).toURL();
126:                }
127:            }
128:
129:            public URL getURL(URL base, String location)
130:                    throws MalformedURLException {
131:                if (base != null) {
132:                    if (base.getProtocol().equals("file")) {
133:                        File temp = new File(base.toExternalForm().substring(
134:                                "file:".length()), location);
135:                        String path = temp.getAbsolutePath();
136:                        // VG: M$ paths starts with drive letter
137:                        if (path.charAt(0) != File.separator.charAt(0)) {
138:                            return getURL("file:/" + path);
139:                        } else {
140:                            return getURL("file:" + path);
141:                        }
142:                    }
143:
144:                    return getURL(new URL(base, location).toExternalForm());
145:                } else {
146:                    return getURL(location);
147:                }
148:            }
149:
150:            /**
151:             * Get the context
152:             */
153:            public void contextualize(Context context) throws ContextException {
154:                if (this .context == null) {
155:                    this .context = context;
156:                }
157:            }
158:
159:            /**
160:             * Configure the URLFactories
161:             */
162:            public void configure(final Configuration conf)
163:                    throws ConfigurationException {
164:                try {
165:                    getLogger().debug("Getting the URLFactories");
166:                    factories = new HashMap();
167:                    Configuration[] configs = conf.getChildren("protocol");
168:                    URLFactory urlFactory = null;
169:                    String protocol = null;
170:                    for (int i = 0; i < configs.length; i++) {
171:                        protocol = configs[i].getAttribute("name");
172:                        if (factories.containsKey(protocol)) {
173:                            throw new ConfigurationException(
174:                                    "URLFactory defined twice for protocol: "
175:                                            + protocol);
176:                        }
177:                        if (getLogger().isDebugEnabled()) {
178:                            getLogger().debug(
179:                                    "\tfor protocol: " + protocol + " "
180:                                            + configs[i].getAttribute("class"));
181:                        }
182:                        urlFactory = (URLFactory) ClassUtils
183:                                .newInstance(configs[i].getAttribute("class"));
184:                        this .init(urlFactory, configs[i]);
185:                        factories.put(protocol, urlFactory);
186:                    }
187:                } catch (Exception e) {
188:                    getLogger().error("Could not get URLFactories", e);
189:                    throw new ConfigurationException(
190:                            "Could not get parameters because: "
191:                                    + e.getMessage());
192:                }
193:            }
194:
195:            /**
196:             * Set the current <code>ComponentManager</code> instance used by this
197:             * <code>Composable</code>.
198:             */
199:            public void compose(ComponentManager manager)
200:                    throws ComponentException {
201:                this .manager = manager;
202:            }
203:
204:            /**
205:             * Dispose
206:             */
207:            public void dispose() {
208:                Iterator iter = this .factories.values().iterator();
209:                URLFactory current;
210:                while (iter.hasNext()) {
211:                    current = (URLFactory) iter.next();
212:                    this .deinit(current);
213:                }
214:                this .factories = null;
215:            }
216:
217:            /**
218:             * Init a url factory
219:             */
220:            private void init(URLFactory factory, Configuration config)
221:                    throws ContextException, ComponentException,
222:                    ConfigurationException, ParameterException {
223:                if (factory instanceof  LogEnabled) {
224:                    ((LogEnabled) factory).enableLogging(getLogger());
225:                }
226:                if (factory instanceof  Contextualizable) {
227:                    ((Contextualizable) factory).contextualize(this .context);
228:                }
229:                if (factory instanceof  Composable) {
230:                    ((Composable) factory).compose(this .manager);
231:                }
232:                if (config != null && factory instanceof  Configurable) {
233:                    ((Configurable) factory).configure(config);
234:                }
235:                if (config != null && factory instanceof  Parameterizable) {
236:                    ((Parameterizable) factory).parameterize(Parameters
237:                            .fromConfiguration(config));
238:                }
239:            }
240:
241:            /**
242:             * Deinit a url factory
243:             */
244:            private void deinit(URLFactory factory) {
245:                if (factory instanceof  Disposable) {
246:                    ((Disposable) factory).dispose();
247:                }
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.