Source Code Cross Referenced for ReplaceFilter.java in  » Web-Server » Brazil » sunlabs » brazil » filter » 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 Server » Brazil » sunlabs.brazil.filter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ReplaceFilter.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1999-2000 Sun Microsystems, Inc.
007:         *
008:         * Sun Public License Notice
009:         *
010:         * The contents of this file are subject to the Sun Public License Version 
011:         * 1.0 (the "License"). You may not use this file except in compliance with 
012:         * the License. A copy of the License is included as the file "license.terms",
013:         * and also available at http://www.sun.com/
014:         * 
015:         * The Original Code is from:
016:         *    Brazil project web application Framework release 1.1.
017:         * The Initial Developer of the Original Code is: suhler.
018:         * Portions created by suhler are Copyright (C) Sun Microsystems, Inc.
019:         * All Rights Reserved.
020:         * 
021:         * Contributor(s): suhler.
022:         *
023:         * Version:  1.5
024:         * Created by suhler on 99/09/01
025:         * Last modified by suhler on 00/12/11 13:26:06
026:         */
027:
028:        package sunlabs.brazil.filter;
029:
030:        import sunlabs.brazil.server.Request;
031:        import sunlabs.brazil.server.Server;
032:        import java.io.File;
033:        import java.io.FileInputStream;
034:        import java.io.IOException;
035:        import sunlabs.brazil.util.http.MimeHeaders;
036:
037:        /**
038:         * Filter to replace current content with a static form, or template.
039:         * This should be called
040:         * the TemplateFiler, but that name's already taken.  The content is
041:         * replaced by the template lock-stock-and-barrel.  Typically, an upstream 
042:         * filter has extracted the relevent parts of the content, and a down-stream
043:         * filter will combine it with the template.
044:         * The filename to use for the template
045:         * is computed at each request, so it may be modified dynamically.
046:         *
047:         * The following server properties are used:
048:         * <dl class=props>
049:         * <dt>type	<dd>    Text subtype of content to filter.  Defaults to "html"
050:         * <dt>debug	<dd>    If set, the template is re-read each time.  Otherwise
051:         *			a cached copy is used.
052:         * <dt>fileName	<dd>    Name of the file to use as the form or template.
053:         * <dt>root	<dd>	he document root used to find the template file.
054:         * </dl>
055:         *
056:         * @author		Stephen Uhler
057:         * @version		%V% ReplaceFilter.java
058:         */
059:
060:        public class ReplaceFilter implements  Filter {
061:            static final String FILE = "fileName";
062:            String type; // the text sub-type to replace (defaults to html)
063:            String prefix; // the properties prefix
064:            byte[] data; // cache of the last template
065:            String path; // cache of last file name;
066:            boolean debug; // don't cache file
067:
068:            public boolean init(Server server, String prefix) {
069:                type = server.props.getProperty(prefix + "type", "html");
070:                debug = server.props.getProperty(prefix + "debug") != null;
071:                this .prefix = prefix;
072:                path = null;
073:                return true;
074:            }
075:
076:            /**
077:             * This is the request object before the content was fetched
078:             */
079:
080:            public boolean respond(Request request) {
081:                return false;
082:            }
083:
084:            /**
085:             * Only replace text documents
086:             */
087:
088:            public boolean shouldFilter(Request request, MimeHeaders headers) {
089:                String type = headers.get("content-type");
090:                return (type != null && type.startsWith("text/"));
091:            }
092:
093:            /**
094:             * Grab the template file name, Read in the file, and
095:             * deliver it as content.
096:             */
097:
098:            public byte[] filter(Request request, MimeHeaders headers,
099:                    byte[] content) {
100:                if (!(headers.get("content-type")).startsWith("text/" + type)) {
101:                    return content;
102:                }
103:                String name = request.props.getProperty(prefix + "fileName");
104:                if (name == null) {
105:                    request.log(Server.LOG_WARNING,
106:                            "No fileName property found for " + prefix);
107:                    return content;
108:                }
109:
110:                if (!debug && path != null && name.equals(path)) {
111:                    request.log(Server.LOG_DIAGNOSTIC,
112:                            "using cached content for: " + name);
113:                    return data;
114:                }
115:
116:                File file;
117:                if (name.startsWith("/")) {
118:                    file = new File(name);
119:                } else {
120:                    String root = request.props.getProperty("root", ".");
121:                    file = new File(root, name);
122:                }
123:                try {
124:                    FileInputStream in = new FileInputStream(file);
125:                    data = new byte[(int) file.length()];
126:                    in.read(data);
127:                    in.close();
128:                    path = name; // cache for next use
129:                    return data;
130:                } catch (IOException e) {
131:                    request.log(Server.LOG_WARNING, prefix + " can't get "
132:                            + file + ": " + e);
133:                    return content;
134:                }
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.