Source Code Cross Referenced for ServletContextRepository.java in  » Web-Framework » jpublish » org » jpublish » repository » servletcontext » 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 » Web Framework » jpublish » org.jpublish.repository.servletcontext 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         *
016:         */
017:
018:        package org.jpublish.repository.servletcontext;
019:
020:        import java.io.InputStream;
021:        import java.io.StringWriter;
022:        import java.io.StringReader;
023:        import java.io.File;
024:        import java.util.Iterator;
025:
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:
029:        import com.anthonyeden.lib.util.IOUtilities;
030:        import com.anthonyeden.lib.config.Configuration;
031:
032:        import org.jpublish.JPublishContext;
033:        import org.jpublish.view.ViewRenderer;
034:        import org.jpublish.util.PathUtilities;
035:        import org.jpublish.util.BreadthFirstPathTreeIterator;
036:        import org.jpublish.util.vfs.VFSFile;
037:        import org.jpublish.repository.AbstractRepository;
038:
039:        /** Repository implementation which pulls content from the servlet
040:         context.
041:        
042:         @author Anthony Eden
043:         @since 2.0    
044:         */
045:
046:        public class ServletContextRepository extends AbstractRepository {
047:
048:            private static final Log log = LogFactory
049:                    .getLog(ServletContextRepository.class);
050:
051:            /** Get the content from the given path.  Implementations of this method
052:                should NOT merge the content using view renderer.
053:
054:                @param path The relative content path
055:                @return The content as a String
056:                @throws Exception Any Exception
057:             */
058:
059:            public String get(String path) throws Exception {
060:                InputStream in = null;
061:                StringWriter out = null;
062:                try {
063:                    String root = PathUtilities.toResourcePath(getRoot());
064:                    String relativePath = PathUtilities.toResourcePath(path);
065:
066:                    in = siteContext.getServletContext().getResourceAsStream(
067:                            root + relativePath);
068:                    out = new StringWriter();
069:
070:                    int c = -1;
071:                    while ((c = in.read()) != -1) {
072:                        out.write((char) c);
073:                    }
074:
075:                    return out.toString();
076:                } finally {
077:                    IOUtilities.close(in);
078:                    IOUtilities.close(out);
079:                }
080:            }
081:
082:            /** Get the content from the given path and merge it with
083:                the given context.
084:                
085:                @param path The content path
086:                @param context The current context
087:                @return The content as a String
088:                @throws Exception Any Exception
089:             */
090:
091:            public String get(String path, JPublishContext context)
092:                    throws Exception {
093:                if (log.isDebugEnabled())
094:                    log.debug("Getting dynamic content element for path "
095:                            + path);
096:
097:                StringWriter writer = null;
098:                StringReader reader = null;
099:
100:                try {
101:                    writer = new StringWriter();
102:                    reader = new StringReader(get(path));
103:
104:                    String name = PathUtilities.makeRepositoryURI(getName(),
105:                            path);
106:                    ViewRenderer renderer = siteContext.getViewRenderer();
107:                    renderer.render(context, name, reader, writer);
108:
109:                    return writer.toString();
110:                } finally {
111:                    IOUtilities.close(writer);
112:                    IOUtilities.close(reader);
113:                }
114:            }
115:
116:            /** Remove the content at the specified path.
117:            
118:                @param path The path
119:             */
120:
121:            public void remove(String path) throws Exception {
122:                throw new UnsupportedOperationException(
123:                        "Cannot remove web content");
124:            }
125:
126:            /** Make the directory for the specified path.  Parent directories
127:                will also be created if they do not exist.
128:                
129:                @param path The directory path
130:             */
131:
132:            public void makeDirectory(String path) {
133:                throw new UnsupportedOperationException(
134:                        "Make directory not supported");
135:            }
136:
137:            /** Remove the directory for the specified path.  The directory
138:                must be empty.
139:            
140:                @param path The path
141:                @throws Exception
142:             */
143:
144:            public void removeDirectory(String path) throws Exception {
145:                throw new UnsupportedOperationException(
146:                        "Remove directory not supported");
147:            }
148:
149:            /** Get the last modified time in milliseconds for the given path.
150:
151:                @param path The content path
152:                @return The last modified time in milliseconds
153:                @throws Exception Any exception
154:             */
155:
156:            public long getLastModified(String path) throws Exception {
157:                // unfortunately the servlet API offers no way to determine the
158:                // last modified time
159:                return -1;
160:            }
161:
162:            /** Get an Iterator of paths which are known to the repository.
163:                
164:                @return An iterator of paths
165:                @throws Exception
166:             */
167:
168:            public Iterator getPaths() throws Exception {
169:                return getPaths("");
170:            }
171:
172:            /** Get an Iterator of paths which are known to the repository, starting
173:                from the specified base path.
174:                
175:                @param base The base path
176:                @return An iterator of paths
177:                @throws Exception
178:             */
179:
180:            public Iterator getPaths(String path) throws Exception {
181:                String root = PathUtilities.toResourcePath(getRoot());
182:                String basePath = PathUtilities.toResourcePath(path);
183:                return new ServletContextPathIterator(this ,
184:                        new BreadthFirstPathTreeIterator(root + basePath,
185:                                siteContext.getServletContext()));
186:            }
187:
188:            /** Get the Virtual File System root file.  The Virtual File System
189:                provides a datasource-independent way of navigating through all
190:                items known to the Repository.
191:                
192:                @return The root VFSFile
193:                @throws Exception
194:             */
195:
196:            public VFSFile getVFSRoot() throws Exception {
197:                // NYI
198:                throw new UnsupportedOperationException();
199:            }
200:
201:            public File pathToFile(String path) {
202:                // NYI
203:                throw new UnsupportedOperationException();
204:            }
205:
206:            /** Load the repository's configuration from the given configuration 
207:                object.
208:
209:                @param element The configuration object
210:                @throws Exception
211:             */
212:
213:            public void loadConfiguration(Configuration configuration)
214:                    throws Exception {
215:                this .name = configuration.getAttribute("name");
216:                setRoot(configuration.getChildValue("root"));
217:            }
218:
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.