Source Code Cross Referenced for AbstractDocrootResourceImpl.java in  » J2EE » Pustefix » de » schlund » pfixxml » 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 » J2EE » Pustefix » de.schlund.pfixxml.resources 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of PFIXCORE.
003:         *
004:         * PFIXCORE is free software; you can redistribute it and/or modify
005:         * it under the terms of the GNU Lesser General Public License as published by
006:         * the Free Software Foundation; either version 2 of the License, or
007:         * (at your option) any later version.
008:         *
009:         * PFIXCORE is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public License
015:         * along with PFIXCORE; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package de.schlund.pfixxml.resources;
020:
021:        import java.io.FileNotFoundException;
022:        import java.io.IOException;
023:        import java.io.InputStream;
024:        import java.io.OutputStream;
025:        import java.net.MalformedURLException;
026:        import java.net.URI;
027:        import java.net.URISyntaxException;
028:        import java.net.URL;
029:        import java.util.ArrayList;
030:
031:        /**
032:         * Base class for classes implementing the {@link DocrootResource} interface.  
033:         * 
034:         * @author Sebastian Marsching <sebastian.marsching@1und1.de>
035:         */
036:        public abstract class AbstractDocrootResourceImpl implements 
037:                DocrootResource {
038:            /**
039:             * Stores the path relative to the docroot
040:             */
041:            protected String path;
042:
043:            /**
044:             * Stores the complete URI of the resource
045:             */
046:            protected URI uri;
047:
048:            /**
049:             * Is set to true, if the URI used to create the resource had a trailing
050:             * slash ("/").
051:             */
052:            protected boolean trailingSlash;
053:
054:            protected AbstractDocrootResourceImpl(URI uri) {
055:                // Sanity checks
056:                if (uri.getScheme() == null
057:                        || !uri.getScheme().equals("pfixroot")) {
058:                    throw new IllegalArgumentException("Cannot handle scheme "
059:                            + uri.getScheme());
060:                }
061:                if (uri.getAuthority() != null
062:                        && uri.getAuthority().length() != 0) {
063:                    throw new IllegalArgumentException(
064:                            "pfixroot:// URI may not specify authority");
065:                }
066:                if (uri.getHost() != null && uri.getHost().length() != 0) {
067:                    throw new IllegalArgumentException(
068:                            "pfixroot:// URI may not specify host");
069:                }
070:                if (uri.getPort() != -1) {
071:                    throw new IllegalArgumentException(
072:                            "pfixroot:// URI may not specify port");
073:                }
074:                if (uri.getQuery() != null && uri.getQuery().length() != 0) {
075:                    throw new IllegalArgumentException(
076:                            "pfixroot:// URI may not specify query");
077:                }
078:                if (uri.getFragment() != null
079:                        && uri.getFragment().length() != 0) {
080:                    throw new IllegalArgumentException(
081:                            "pfixroot:// URI may not specify fragment");
082:                }
083:
084:                String path = uri.getPath();
085:                if (!path.startsWith("/")) {
086:                    throw new IllegalArgumentException("Path \"" + path
087:                            + "\" does not start with a /");
088:                }
089:                if (path.contains("//")) {
090:                    throw new IllegalArgumentException("Path \"" + path
091:                            + "\" is not well-formed");
092:                }
093:
094:                if (path.endsWith("/")) {
095:                    this .trailingSlash = true;
096:                    path = path.substring(0, path.length() - 1);
097:                }
098:
099:                try {
100:                    this .uri = new URI("pfixroot", null, path, null, null)
101:                            .normalize();
102:                } catch (URISyntaxException e) {
103:                    throw new RuntimeException(e);
104:                }
105:                this .path = this .uri.getPath();
106:            }
107:
108:            public abstract boolean canRead();
109:
110:            public abstract boolean canWrite();
111:
112:            public abstract boolean createNewFile() throws IOException;
113:
114:            public abstract boolean delete();
115:
116:            public abstract boolean exists();
117:
118:            public String getName() {
119:                if (path == "/") {
120:                    return "/";
121:                } else {
122:                    return path.substring(path.lastIndexOf('/') + 1);
123:                }
124:            }
125:
126:            public FileResource getParentAsFileResource() {
127:                if (path.equals("/")) {
128:                    return null;
129:                } else {
130:                    String parentPath = path
131:                            .substring(0, path.lastIndexOf('/'));
132:                    try {
133:                        return ResourceUtil.getFileResource(new URI("pfixroot",
134:                                null, parentPath, null, null));
135:                    } catch (URISyntaxException e) {
136:                        throw new RuntimeException(e);
137:                    }
138:                }
139:            }
140:
141:            public abstract boolean isDirectory();
142:
143:            public abstract boolean isFile();
144:
145:            public abstract boolean isHidden();
146:
147:            public abstract long lastModified();
148:
149:            public abstract String[] list();
150:
151:            public FileResource[] listFileResources() {
152:                String[] names = list();
153:                ArrayList<FileResource> list = new ArrayList<FileResource>();
154:                for (String name : names) {
155:                    list.add(ResourceUtil.getFileResource(this , name));
156:                }
157:                return list.toArray(new FileResource[list.size()]);
158:            }
159:
160:            public abstract boolean mkdir();
161:
162:            public abstract boolean mkdirs();
163:
164:            public URI toURI() {
165:                return uri;
166:            }
167:
168:            public abstract URL toURL() throws MalformedURLException;
169:
170:            public abstract InputStream getInputStream()
171:                    throws FileNotFoundException;
172:
173:            public abstract OutputStream getOutputStream()
174:                    throws FileNotFoundException;
175:
176:            public abstract OutputStream getOutputStream(boolean append)
177:                    throws FileNotFoundException;
178:
179:            public int compareTo(FileResource o) {
180:                return uri.compareTo(o.toURI());
181:            }
182:
183:            public String toString() {
184:                return uri.toString();
185:            }
186:
187:            public boolean equals(Object o) {
188:                AbstractDocrootResourceImpl res;
189:                try {
190:                    res = (AbstractDocrootResourceImpl) o;
191:                } catch (ClassCastException e) {
192:                    return false;
193:                }
194:                return uri.equals(res.uri);
195:            }
196:
197:            public int hashCode() {
198:                return uri.hashCode();
199:            }
200:
201:            public String getRelativePath() {
202:                String path = toURI().getPath();
203:                if (path.length() > 0) {
204:                    path = path.substring(1);
205:                }
206:                return path;
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.