Source Code Cross Referenced for VfsURI.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » plugins » repository » vfs » 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 » Code Analyzer » apache ivy » org.apache.ivy.plugins.repository.vfs 
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:         */
018:        package org.apache.ivy.plugins.repository.vfs;
019:
020:        import org.apache.ivy.Ivy;
021:
022:        public class VfsURI {
023:            private String host;
024:
025:            private String passwd;
026:
027:            private String path;
028:
029:            private String scheme;
030:
031:            private String user;
032:
033:            // VFS Schemes
034:            public static final String SCHEME_CIFS = "smb";
035:
036:            public static final String SCHEME_FILE = "file";
037:
038:            public static final String SCHEME_FTP = "ftp";
039:
040:            public static final String SCHEME_HTTP = "http";
041:
042:            public static final String SCHEME_HTTPS = "https";
043:
044:            public static final String SCHEME_SFTP = "sftp";
045:
046:            public static final String SCHEME_WEBDAV = "webdav";
047:
048:            public static final String[] SUPPORTED_SCHEMES = new String[] {
049:            // add other schemes here if other can be tested on your machine
050:            SCHEME_FILE };
051:
052:            /**
053:             * Create a set of valid VFS URIs for the file access protocol
054:             * 
055:             * @param resourcePath
056:             *            relative path (from the base repo) to the resource to be accessed
057:             * @return
058:             */
059:            public static VfsURI vfsURIFactory(String scheme, String resource,
060:                    Ivy ivy) {
061:                VfsURI vfsURI = null;
062:                if (scheme.equals(SCHEME_CIFS)) {
063:                    vfsURI = new VfsURI(SCHEME_CIFS, ivy
064:                            .getVariable(VfsTestHelper.PROP_VFS_USER_ID), ivy
065:                            .getVariable(VfsTestHelper.PROP_VFS_USER_PASSWD),
066:                            ivy.getVariable(VfsTestHelper.PROP_VFS_HOST),
067:                            ivy.getVariable(VfsTestHelper.PROP_VFS_SAMBA_REPO)
068:                                    + "/" + resource);
069:                } else if (scheme.equals(SCHEME_FILE)) {
070:                    vfsURI = new VfsURI(SCHEME_FILE, null, null, null,
071:                            VfsTestHelper.CWD + "/"
072:                                    + VfsTestHelper.TEST_REPO_DIR + "/"
073:                                    + resource);
074:                } else if (scheme.equals(SCHEME_FTP)) {
075:                    vfsURI = new VfsURI(SCHEME_FTP, ivy
076:                            .getVariable(VfsTestHelper.PROP_VFS_USER_ID), ivy
077:                            .getVariable(VfsTestHelper.PROP_VFS_USER_PASSWD),
078:                            ivy.getVariable(VfsTestHelper.PROP_VFS_HOST),
079:                            VfsTestHelper.CWD + "/"
080:                                    + VfsTestHelper.TEST_REPO_DIR + "/"
081:                                    + resource);
082:                } else if (scheme.equals(SCHEME_SFTP)) {
083:                    vfsURI = new VfsURI(SCHEME_SFTP, ivy
084:                            .getVariable(VfsTestHelper.PROP_VFS_USER_ID), ivy
085:                            .getVariable(VfsTestHelper.PROP_VFS_USER_PASSWD),
086:                            ivy.getVariable(VfsTestHelper.PROP_VFS_HOST),
087:                            VfsTestHelper.CWD + "/"
088:                                    + VfsTestHelper.TEST_REPO_DIR + "/"
089:                                    + resource);
090:                }
091:                return vfsURI;
092:            }
093:
094:            /**
095:             * Create a wellformed VFS resource identifier
096:             * 
097:             * @param scheme
098:             *            the name of the scheme used to acces the resource
099:             * @param user
100:             *            a user name. May be <code>null</code>
101:             * @param passwd
102:             *            a passwd. May be <code>null</code>
103:             * @param host
104:             *            a host identifier. May be <code>null</code>
105:             * @param path
106:             *            a scheme spacific path to a resource
107:             */
108:            public VfsURI(String scheme, String user, String passwd,
109:                    String host, String path) {
110:                this .scheme = scheme.trim();
111:
112:                if (user != null) {
113:                    this .user = user.trim();
114:                } else {
115:                    this .user = null;
116:                }
117:
118:                if (passwd != null) {
119:                    this .passwd = passwd.trim();
120:                } else {
121:                    this .passwd = null;
122:                }
123:
124:                if (host != null) {
125:                    this .host = host.trim();
126:                } else {
127:                    this .host = null;
128:                }
129:
130:                this .path = normalizePath(path);
131:            }
132:
133:            /**
134:             * Return a well-formed VFS Resource identifier
135:             * 
136:             * @return <code>String<code> representing a well formed VFS resource identifier
137:             */
138:            public String getVfsURI() {
139:                StringBuffer uri = new StringBuffer();
140:                uri.append(this .scheme + "://");
141:
142:                // not all resource identifiers include user/passwd specifiers
143:                if (user != null && user.trim().length() > 0) {
144:                    uri.append(this .user + ":");
145:
146:                    if (passwd != null && passwd.trim().length() > 0) {
147:                        this .passwd = passwd.trim();
148:                    } else {
149:                        this .passwd = "";
150:                    }
151:                    uri.append(this .passwd + "@");
152:                }
153:
154:                // not all resource identifiers include a host specifier
155:                if (host != null && host.trim().length() > 0) {
156:                    this .host = host.trim();
157:                    uri.append(this .host);
158:                }
159:
160:                uri.append(this .path);
161:                return uri.toString();
162:            }
163:
164:            /**
165:             * Convert a resource path to the format required for a VFS resource identifier
166:             * 
167:             * @param path
168:             *            <code>String</code> path to the resource
169:             * @return <code>String</code> representing a normalized resource path
170:             */
171:            private String normalizePath(String path) {
172:                // all backslashes replaced with forward slashes
173:                String normalizedPath = path.replaceAll("\\\\", "/");
174:
175:                // collapse multiple instance of forward slashes to single slashes
176:                normalizedPath = normalizedPath.replaceAll("//+", "/");
177:
178:                // ensure that our path starts with a forward slash
179:                if (!normalizedPath.startsWith("/")) {
180:                    normalizedPath = "/" + normalizedPath;
181:                }
182:
183:                return normalizedPath.trim();
184:            }
185:
186:            public String toString() {
187:                return getVfsURI();
188:            }
189:
190:            public String getScheme() {
191:                return scheme;
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.