Source Code Cross Referenced for MyFacesResourceLoader.java in  » Workflow-Engines » wfmopen-2.1.1 » de » danet » an » util » jsf » taglib » 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 » Workflow Engines » wfmopen 2.1.1 » de.danet.an.util.jsf.taglib 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the WfMOpen project.
003:         * Copyright (C) 2001-2006 Danet GmbH (www.danet.de), BU BTS.
004:         * All rights reserved.
005:         *
006:         * This program is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU General Public License as published by
008:         * the Free Software Foundation; either version 2 of the License, or
009:         * (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * $Id: MyFacesResourceLoader.java,v 1.3 2006/12/12 09:58:39 drmlipp Exp $
021:         *
022:         * $Log: MyFacesResourceLoader.java,v $
023:         * Revision 1.3  2006/12/12 09:58:39  drmlipp
024:         * Added resources and minor cleanup.
025:         *
026:         * Revision 1.2.4.1  2006/11/08 12:47:02  drmlipp
027:         * Started using stylesheet.
028:         *
029:         * Revision 1.2  2006/10/06 15:26:51  drmlipp
030:         * Improved.
031:         *
032:         * Revision 1.1  2006/10/05 13:27:39  drmlipp
033:         * New tag for XML display.
034:         *
035:         */
036:        package de.danet.an.util.jsf.taglib;
037:
038:        import java.io.IOException;
039:        import java.io.InputStream;
040:        import java.util.Calendar;
041:
042:        import javax.servlet.ServletContext;
043:        import javax.servlet.http.HttpServletRequest;
044:        import javax.servlet.http.HttpServletResponse;
045:
046:        /**
047:         * This class provides the resource loader for this taglib.
048:         *
049:         * @author Michael Lipp
050:         *
051:         */
052:        public class MyFacesResourceLoader extends
053:                org.apache.myfaces.renderkit.html.util.MyFacesResourceLoader {
054:
055:            static final String DE_DANET_AN_UTIL_JSF_TAGLIB = "de.danet.an.util.jsf";
056:            private static final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
057:                    .getLog(MyFacesResourceLoader.class);
058:
059:            /**
060:             * Given a URI of form "{partial.class.name}/{resourceName}", locate the
061:             * specified file within the current classpath and write it to the response
062:             * object.
063:             * <p>
064:             * The partial class name has "de.danet.an.util.jsf.taglib." prepended to it
065:             * to form the fully qualified classname. This class object is loaded, and
066:             * Class.getResourceAsStream is called on it, passing a uri of "resource/" +
067:             * {resourceName}.
068:             * <p>
069:             * The data written to the response stream includes http headers which
070:             * define the mime content-type; this is deduced from the filename suffix of
071:             * the resource.
072:             * <p>
073:             * 
074:             * @see org.apache.myfaces.shared.renderkit.html.util.ResourceLoader#serveResource
075:             *      javax.servlet.http.HttpServletRequest,
076:             *      javax.servlet.http.HttpServletResponse, java.lang.String)
077:             */
078:            public void serveResource(ServletContext context,
079:                    HttpServletRequest request, HttpServletResponse response,
080:                    String resourceUri) throws IOException {
081:                String[] uriParts = resourceUri.split("/", 2);
082:
083:                String component = uriParts[0];
084:                if (component == null || component.trim().length() == 0) {
085:                    response.sendError(HttpServletResponse.SC_BAD_REQUEST,
086:                            "Invalid request");
087:                    logger
088:                            .error("Could not find parameter for component to load a resource.");
089:                    return;
090:                }
091:                Class componentClass;
092:                String className = DE_DANET_AN_UTIL_JSF_TAGLIB + "."
093:                        + component;
094:                try {
095:                    componentClass = loadComponentClass(className);
096:                } catch (ClassNotFoundException e) {
097:                    response.sendError(HttpServletResponse.SC_BAD_REQUEST, e
098:                            .getMessage());
099:                    logger.error("Could not find the class for component "
100:                            + className + " to load a resource.");
101:                    return;
102:                }
103:                String resource = uriParts[1];
104:                if (resource == null || resource.trim().length() == 0) {
105:                    response.sendError(HttpServletResponse.SC_BAD_REQUEST,
106:                            "No resource defined");
107:                    logger.error("No resource defined component class "
108:                            + className);
109:                    return;
110:                }
111:                resource = "resource/" + resource;
112:
113:                InputStream is = componentClass.getResourceAsStream(resource);
114:                if (is == null) {
115:                    response.sendError(HttpServletResponse.SC_NOT_FOUND,
116:                            "Unable to find resource " + resource
117:                                    + " for component " + component
118:                                    + ". Check that this file is available "
119:                                    + "in the classpath in sub-directory "
120:                                    + "/resource of the package-directory.");
121:                    logger.error("Unable to find resource " + resource
122:                            + " for component " + component
123:                            + ". Check that this file is available "
124:                            + "in the classpath in sub-directory "
125:                            + "/resource of the package-directory.");
126:                } else {
127:                    defineContentHeaders(request, response, resource);
128:                    defineCaching(request, response, resource);
129:                    writeResource(request, response, is);
130:                }
131:            }
132:
133:            private static long loadTime = System.currentTimeMillis();
134:
135:            /**
136:             * Get the last-modified time of the resource.
137:             * <p>
138:             * Unfortunately this is not possible with files inside jars. We therefore
139:             * simply use the load time of the application.
140:             */
141:            private static long getLastModified() {
142:                return loadTime;
143:            }
144:
145:            /**
146:             * Output http headers telling the browser (and possibly intermediate
147:             * caches) how to cache this data.
148:             * <p>
149:             * The expiry time in this header info is set to 7 days. This is not a
150:             * problem as the overall URI contains a "cache key" that changes whenever
151:             * the webapp is redeployed (see AddResource.getCacheKey), meaning that all
152:             * browsers will effectively reload files on webapp redeploy.
153:             */
154:            protected void defineCaching(HttpServletRequest request,
155:                    HttpServletResponse response, String resource) {
156:                response.setDateHeader("Last-Modified", getLastModified());
157:
158:                Calendar expires = Calendar.getInstance();
159:                expires.add(Calendar.DAY_OF_YEAR, 7);
160:                response.setDateHeader("Expires", expires.getTimeInMillis());
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.