Source Code Cross Referenced for DocrootResourceByServletContextImpl.java in  » J2EE » Pustefix » de » schlund » pfixxml » resources » internal » 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.internal 
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.internal;
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.URL;
028:        import java.util.ArrayList;
029:        import java.util.Set;
030:
031:        import javax.servlet.ServletContext;
032:
033:        import de.schlund.pfixxml.resources.AbstractDocrootResourceImpl;
034:        import de.schlund.pfixxml.resources.DocrootResource;
035:
036:        /**
037:         * Implementation of the {@link DocrootResource} using a servlet context to fetch resources. 
038:         * This class should never be exposed to any other packages as only the interface should be 
039:         * used to access the class.  
040:         * 
041:         * @author Sebastian Marsching <sebastian.marsching@1und1.de>
042:         */
043:        class DocrootResourceByServletContextImpl extends
044:                AbstractDocrootResourceImpl {
045:            private final static String ROOT_PREFIX = "/WEB-INF/pfixroot";
046:
047:            private ServletContext servletContext;
048:
049:            DocrootResourceByServletContextImpl(URI uri,
050:                    ServletContext servletContext) {
051:                super (uri);
052:
053:                this .servletContext = servletContext;
054:
055:                if (this .trailingSlash && this .exists() && !this .isDirectory()) {
056:                    throw new IllegalArgumentException("URI \""
057:                            + uri.toString()
058:                            + "\" points to a non-existent directory");
059:                }
060:            }
061:
062:            public boolean canRead() {
063:                return exists();
064:            }
065:
066:            public boolean canWrite() {
067:                return false;
068:            }
069:
070:            public boolean createNewFile() throws IOException {
071:                throw new IOException("Cannot create file in WAR-archive");
072:            }
073:
074:            public boolean delete() {
075:                return false;
076:            }
077:
078:            public boolean exists() {
079:                return isFile() || isDirectory();
080:            }
081:
082:            public boolean isDirectory() {
083:                Set<?> temp = this .servletContext.getResourcePaths(ROOT_PREFIX
084:                        + path + "/");
085:                return (temp != null && temp.size() > 0);
086:            }
087:
088:            public boolean isFile() {
089:                try {
090:                    return (servletContext.getResource(ROOT_PREFIX + path) != null);
091:                } catch (MalformedURLException e) {
092:                    return false;
093:                }
094:            }
095:
096:            public boolean isHidden() {
097:                return getName().startsWith(".");
098:            }
099:
100:            public long lastModified() {
101:                return -1;
102:            }
103:
104:            public String[] list() {
105:                if (!isDirectory()) {
106:                    return null;
107:                }
108:                Set<?> paths = this .servletContext.getResourcePaths(ROOT_PREFIX
109:                        + path + "/");
110:                ArrayList<String> rpaths = new ArrayList<String>();
111:                for (Object item : paths) {
112:                    String sitem = (String) item;
113:                    if (sitem.endsWith("/")) {
114:                        sitem = sitem.substring(0, sitem.length() - 1);
115:                        rpaths.add(sitem);
116:                    }
117:                }
118:                return rpaths.toArray(new String[rpaths.size()]);
119:            }
120:
121:            public boolean mkdir() {
122:                return false;
123:            }
124:
125:            public boolean mkdirs() {
126:                return false;
127:            }
128:
129:            public URI toURI() {
130:                return uri;
131:            }
132:
133:            public URL toURL() throws MalformedURLException {
134:                return servletContext.getResource(ROOT_PREFIX + path);
135:            }
136:
137:            public InputStream getInputStream() throws FileNotFoundException {
138:                if (isFile()) {
139:                    return servletContext.getResourceAsStream(ROOT_PREFIX
140:                            + path);
141:                } else {
142:                    throw new FileNotFoundException("Cannot find file \""
143:                            + path + "\" in Pustefix docroot");
144:                }
145:            }
146:
147:            public OutputStream getOutputStream() throws FileNotFoundException {
148:                throw new FileNotFoundException(
149:                        "Cannot write to file in WAR archive");
150:            }
151:
152:            public OutputStream getOutputStream(boolean append)
153:                    throws FileNotFoundException {
154:                throw new FileNotFoundException(
155:                        "Cannot write to file in WAR archive");
156:            }
157:
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.