Source Code Cross Referenced for ResourceFactory.java in  » Content-Management-System » harmonise » com » ibm » webdav » 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 » harmonise » com.ibm.webdav 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ibm.webdav;
002:
003:        /*
004:         * (C) Copyright IBM Corp. 2000  All rights reserved.
005:         *
006:         * The program is provided "AS IS" without any warranty express or
007:         * implied, including the warranty of non-infringement and the implied
008:         * warranties of merchantibility and fitness for a particular purpose.
009:         * IBM will not be liable for any damages suffered by you as a result
010:         * of using the Program. In no event will IBM be liable for any
011:         * special, indirect or consequential damages or lost profits even if
012:         * IBM has been advised of the possibility of their occurrence. IBM
013:         * will not be liable for any third party claims against you.
014:         * 
015:         * Portions Copyright (C) Simulacra Media Ltd, 2004.
016:         */
017:        import java.io.*;
018:        import java.net.*;
019:        import java.rmi.*;
020:        import java.rmi.UnknownHostException;
021:        import java.util.*;
022:        import java.util.logging.*;
023:        import java.util.logging.Logger;
024:
025:        import com.ibm.webdav.impl.*;
026:        import com.ibm.webdav.protocol.http.*;
027:
028:        /** A ResourceFactory is used to construct Resources or their subclasses
029:         * based on the desired communication protocol, http:, rmi:, or iiop: as
030:         * specified in the resource URL.
031:         * @author Jim Amsden <jamsden@us.ibm.com>
032:         * @see com.ibm.webdav.impl.ResourceHTTPStub
033:         * @see com.ibm.webdav.impl.ResourceImpl
034:         */
035:        public class ResourceFactory {
036:            public static String defaultDocRoot = "c:\\www\\html\\dav";
037:
038:            /** All WebDAV properties from the dav4j.properties file located somewhere
039:             * in the classpath. See the dav4j.properties file for details.
040:             */
041:            public static Properties properties = null;
042:
043:            /**
044:             * Logger for this class
045:             */
046:            private static Logger m_logger = Logger
047:                    .getLogger(ResourceFactory.class.getName());
048:
049:            // load the webdav properties
050:            static {
051:                properties = new Properties();
052:                String resource = "dav4j.properties";
053:
054:                try {
055:                    // in the current build environment, dav4j.properties will most likely be in the 
056:                    // jar file for harmonise-dav-server, so look in here first
057:                    ClassLoader loader = Thread.currentThread()
058:                            .getContextClassLoader();
059:                    InputStream istream = loader.getResourceAsStream(resource); // will return null if not found
060:                    if (istream != null) {
061:                        properties.load(loader.getResourceAsStream(resource));
062:                    } else {
063:                        // If that fails, find the dav4j.properties file in the classpath
064:                        String classpath = System
065:                                .getProperty("java.class.path");
066:                        StringTokenizer paths = new StringTokenizer(classpath,
067:                                File.pathSeparator);
068:                        File propertiesFile = null;
069:                        boolean found = false;
070:                        while (!found && paths.hasMoreTokens()) {
071:                            String path = paths.nextToken();
072:                            propertiesFile = new File(path, resource);
073:                            found = propertiesFile.exists();
074:                        }
075:                        if (found) {
076:                            try {
077:                                properties.load(new FileInputStream(
078:                                        propertiesFile));
079:                            } catch (Exception exc) {
080:                                exc.printStackTrace();
081:                            }
082:                        }
083:                    }
084:                } catch (RuntimeException e) {
085:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
086:                } catch (IOException e) {
087:                    m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
088:                }
089:            }
090:
091:            /** Create a Resource identified by the given URL. The URL
092:             * specifies the protocol to use for remote communication, and
093:             * the host name. If the host name is "localhost", the communication
094:             * is local (typical fat client).
095:             * <p>
096:             * This method does attempt to determine
097:             * if the url is for a collection or a normal resource.  At the
098:             * moment it does this by asking the server.  If it can not
099:             * determine what type the resource is by asking the server
100:             * (often because the resource doesn't yet exist at the server),
101:             * then an exception is thrown.
102:             * <p>
103:             * The caller should be aware that just because we've
104:             * asked the server if this URL is a collection/resouce, that doesn't
105:             * insure that it wasn't deleted a moment or replaced a moment later
106:             * by something different.  Locking is required to do that and this
107:             * method doesn't lock.
108:             *
109:             * @param url the identifier of the resource
110:             * @return a Resource, ResourceCollection, or one of its subclasses.
111:             * @exception java.io.IOException
112:             */
113:            public static Resource create(String url)
114:                    throws java.io.IOException {
115:                return create(url, null);
116:            }
117:
118:            /** Create a Resource identified by the given URL. The URL
119:             * specifies the protocol to use for remote communication, and
120:             * the host name. If the host name is "localhost", the communication
121:             * is local (typical fat client).
122:             * <p>
123:             * This method does attempt to determine
124:             * if the url is for a collection or a normal resource.  At the
125:             * moment it does this by asking the server.  If it can not
126:             * determine what type the resource is by asking the server
127:             * (often because the resource doesn't yet exist at the server),
128:             * then an exception is thrown.
129:             * <p>
130:             * The caller should be aware that just because we've
131:             * asked the server if this URL is a collection/resouce, that doesn't
132:             * insure that it wasn't deleted a moment or replaced a moment later
133:             * by something different.  Locking is required to do that and this
134:             * method doesn't lock.
135:             *
136:             * @param resourceURL the identifier of the resource
137:             * @return a Resource, ResourceCollection, or one of its subclasses.
138:             * @exception java.io.IOException
139:             */
140:            public static Resource create(String url,
141:                    TargetSelector targetSelector) throws java.io.IOException {
142:                Resource resource = null;
143:                try {
144:                    resource = new Resource(url, targetSelector);
145:                    if (resource.isCollection()) {
146:                        resource = null;
147:                        resource = new Collection(url, targetSelector);
148:                    }
149:                } catch (WebDAVException exc) {
150:                    throw exc;
151:                }
152:                return resource;
153:            }
154:
155:            /** Create a Collection identified by the given URL. The URL
156:             * specifies the protocol to use for remote communication, and
157:             * the host name. If the host name is "localhost", the communication
158:             * is local (typical fat client).
159:             *
160:             * @param resourceURL the identifier of the resource
161:             * @return a Collection
162:             * @exception com.ibm.WebDAVException
163:             */
164:            public static IRCollection createCollection(URL url,
165:                    TargetSelector targetSelector) throws WebDAVException {
166:                IRCollection resource = null;
167:                String protocol = null;
168:                try {
169:                    protocol = url.getProtocol();
170:
171:                    // if the URL host is local, and the port was not specified,
172:                    // do local access
173:                    if (isLocalHost(url)) {
174:                        resource = new CollectionImpl(url, getRealPath(url),
175:                                targetSelector);
176:                    } else if (protocol.equals("http")) {
177:                        resource = new CollectionHTTPStub(url, targetSelector);
178:                    } else if (protocol.equals("rmi")) {
179:                        String name = url.toString();
180:                        name = name.substring(name.indexOf(":") + 1);
181:                        try {
182:                            resource = (IRCollection) Naming.lookup(name);
183:                        } catch (java.rmi.NotBoundException exc) {
184:                            throw new WebDAVException(
185:                                    WebDAVStatus.SC_NOT_FOUND, "Not bound");
186:                        }
187:                    } else {
188:                        throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
189:                                "WebDAV: Invalid communication protocol: "
190:                                        + protocol);
191:                    }
192:                } catch (WebDAVException exc) {
193:                    throw exc;
194:                } catch (java.io.IOException exc) {
195:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
196:                            "WebDAV: Invalid communication protocol: "
197:                                    + protocol);
198:                }
199:                return resource;
200:            }
201:
202:            /** Create a Resource identified by the given URL. The URL
203:             * specifies the protocol to use for remote communication, and
204:             * the host name. If the host name is "localhost", the communication
205:             * is local (typical fat client).
206:             *
207:             * @param resourceURL the identifier of the resource
208:             * @return a Resource
209:             * @exception com.ibm.webdav.WebDAVException
210:             */
211:            public static IRResource createResource(URL url,
212:                    TargetSelector targetSelector) throws WebDAVException {
213:                IRResource resource = null;
214:                String protocol = null;
215:                try {
216:                    protocol = url.getProtocol();
217:
218:                    // if the URL host is local, and the port was not specified,
219:                    // do local access
220:                    if (isLocalHost(url)) {
221:                        resource = new ResourceImpl(url, getRealPath(url),
222:                                targetSelector);
223:                    } else if (protocol.equals("http")) {
224:                        //@todo this ResourceHTTPStub won't work with Tomcat - needs work
225:                        resource = new ResourceHTTPStub(url, targetSelector);
226:                    } else if (protocol.equals("rmi")) {
227:                        String name = url.toString();
228:                        name = name.substring(name.indexOf(":") + 1);
229:                        try {
230:                            resource = (IRResource) Naming.lookup(name);
231:                        } catch (java.rmi.NotBoundException exc) {
232:                            throw new WebDAVException(
233:                                    WebDAVStatus.SC_NOT_FOUND, "Not bound");
234:                        }
235:                    } else {
236:                        throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
237:                                "WebDAV: Invalid communication protocol: "
238:                                        + protocol);
239:                    }
240:                } catch (WebDAVException exc) {
241:                    throw exc;
242:                } catch (java.io.IOException exc) {
243:                    throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST,
244:                            "WebDAV: Invalid communication protocol: "
245:                                    + protocol);
246:                }
247:                return resource;
248:            }
249:
250:            /** Translate a URL into a local path name using the doc.root property
251:             * from the webdav properties. The doc.root property in the dav4j.properties
252:             * file is used for local access without a server.
253:             *
254:             * @param url the URL of the resource
255:             * @return the translated pathname
256:             */
257:
258:            public static String getRealPath(URL url) {
259:                String docRoot = properties.getProperty("doc.root",
260:                        defaultDocRoot);
261:                String pathName = docRoot
262:                        + url.getFile().replace('/', File.separatorChar);
263:                return pathName;
264:            }
265:
266:            /** Does the given URL refer to the local host? Used to determine if there doesn't
267:             * need to be any RPC at all.
268:             * @return true if the host in the URL is the local host, and a port was not specified
269:             * @exception UnknownHostException
270:             */
271:            public static boolean isLocalHost(URL url) throws WebDAVException {
272:                /*String thisHost = null;
273:
274:                    System.out.println("RESOURCE FACTORY: isLocalHost check for url " + url.getProtocol() + url.getHost() + url.getPort() + url.getPort() + url.getQuery());
275:
276:                try {
277:                	thisHost = InetAddress.getLocalHost().getHostName();
278:
279:                } catch (java.net.UnknownHostException exc) {
280:                	throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Unknown Host");
281:                }
282:                return (url.getHost().equals("localhost") ||
283:                	    url.getHost().equals(thisHost))*//*&& url.getPort() == -1*///;
284:                return true;
285:            }
286:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.