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


001:        /*
002:         * ContentTemplate.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): cstevens, suhler.
022:         *
023:         * Version:  1.16
024:         * Created by suhler on 99/06/28
025:         * Last modified by suhler on 00/12/27 12:22:42
026:         */
027:
028:        package sunlabs.brazil.template;
029:
030:        import java.util.Dictionary;
031:
032:        /**
033:         * Template class for extracting content out of remote html page
034:         * This class is used by the TemplateHandler, for extracting
035:         * the "content" out of html documents for later integration with
036:         * a look-and-feel template using one or more of:
037:         * {@link PropsTemplate}, 
038:         * {@link BSLTemplate}, 
039:         * or
040:         * {@link sunlabs.brazil.filter.ReplaceFilter},
041:         *
042:         * The plan is to snag the title and the content, and put them into
043:         * request properties.  The resultant processed output will be
044:         * discarded.  The following properties are gathered:
045:         * <dl class=other>
046:         * <dt>title		<dd> The document title
047:         * <dt>bodyArgs		<dd> The attributes to the body tag, if any
048:         * <dt>content		<dd> The body, delimited by content.../content>.
049:         *			The text inside multiple content ... /content pairs
050:         *			are concatenated together.
051:         * <dt>script		<dd> All "script"..."/script" tags found in the document head
052:         * <dt>style		<dd> All "style"..."/style" tags found in the document head
053:         * <dt>meta-[name]	<dd> Every meta tag "name" and "content"
054:         * <dt>link-[rel]	<dd> Every link tag "rel" and "href"
055:         * <dt>user-agent	<dd> The origin user agent
056:         * <dt>referer		<dd> The user agent referrer (if any)
057:         * <dt>last-modified	<dd> The document last modified time (if any) in std format
058:         * <dt>content-length	<dd> The document content length, as fetched from the origin server
059:         * </dl>
060:         *
061:         * @author		Stephen Uhler
062:         * @version		%V% 1.16
063:         */
064:
065:        public class ContentTemplate extends Template {
066:            boolean inHead = true;
067:
068:            /**
069:             * Toss everything up to and including this entity.
070:             */
071:
072:            public void tag_title(RewriteContext hr) {
073:                hr.reset();
074:            }
075:
076:            /**
077:             * Gather up the title - no tags allowed between title .... /title.
078:             */
079:
080:            public void tag_slash_title(RewriteContext hr) {
081:                hr.request.props.put("title", hr.toString().trim());
082:                hr.reset();
083:            }
084:
085:            /**
086:             * Append all "script" code while in the head section.
087:             */
088:
089:            public void tag_script(RewriteContext hr) {
090:                if (inHead) {
091:                    boolean save = hr.accumulate(false);
092:                    hr.nextToken();
093:                    String script = hr.request.props.getProperty("script", "")
094:                            + hr.getBody();
095:                    hr.request.props.put("script", script);
096:                    hr.accumulate(save);
097:                    hr.reset();
098:                }
099:            }
100:
101:            /**
102:             * Append all "style" code while in the head section.
103:             */
104:
105:            public void tag_style(RewriteContext hr) {
106:                if (inHead) {
107:                    boolean save = hr.accumulate(false);
108:                    hr.nextToken();
109:                    String style = hr.request.props.getProperty("style", "")
110:                            + hr.getBody();
111:                    hr.request.props.put("style", style);
112:                    hr.accumulate(save);
113:                    hr.reset();
114:                }
115:            }
116:
117:            /**
118:             * Mark end of head section.  All "script" content in the "body"
119:             * is left alone.
120:             */
121:
122:            public void tag_slash_head(RewriteContext hr) {
123:                inHead = false;
124:            }
125:
126:            /**
127:             * toss everything up to and including here, but turn on
128:             * content accumulation.
129:             */
130:
131:            public void tag_content(RewriteContext hr) {
132:                hr.reset();
133:                hr.accumulate(true);
134:            }
135:
136:            /**
137:             * Grab the "body" attributes, and toss all output to this point.
138:             */
139:
140:            public void tag_body(RewriteContext hr) {
141:                inHead = false;
142:                String bodyArgs = hr.getArgs();
143:                if (bodyArgs != null) {
144:                    hr.request.props.put("bodyArgs", bodyArgs);
145:                }
146:                hr.reset();
147:            }
148:
149:            /**
150:             * Save the content gathered so far, and turn off content accumulation.
151:             */
152:
153:            public void tag_slash_content(RewriteContext hr) {
154:                String content = hr.request.props.getProperty("content", "")
155:                        + hr.toString();
156:                hr.request.props.put("content", content);
157:                hr.accumulate(false);
158:            }
159:
160:            /**
161:             * If no content tags are present, use the entire "body" instead.
162:             */
163:
164:            public void tag_slash_body(RewriteContext hr) {
165:                if (!hr.request.props.containsKey("content")) {
166:                    hr.request.props.put("content", hr.toString());
167:                    hr.accumulate(false);
168:                }
169:            }
170:
171:            /**
172:             * Extract data out of meta tags into the properties.
173:             * For "http-equiv" tags, set the corrosponding http respones header.
174:             */
175:
176:            public void tag_meta(RewriteContext hr) {
177:                String name = hr.get("name");
178:                String equiv = hr.get("http-equiv");
179:                String content = hr.get("content");
180:                if ((name != null) && (content != null)) {
181:                    hr.request.props.put("meta-" + name, content);
182:                } else if ((equiv != null) && (content != null)) {
183:                    hr.request.addHeader(equiv, content);
184:                }
185:            }
186:
187:            /**
188:             * Extract data out of link tags into the properties.
189:             * Prefix the "rel" attribute with "link-" to use as the 
190:             * property name.
191:             */
192:
193:            public void tag_link(RewriteContext hr) {
194:                String type = hr.get("rel");
195:                String href = hr.get("href");
196:                if ((type != null) && (href != null)) {
197:                    hr.request.props.put("link-" + type, href);
198:                }
199:            }
200:
201:            /**
202:             * Extract useful properties out of the http mime headers.
203:             */
204:
205:            public boolean done(RewriteContext hr) {
206:                tag_slash_body(hr);
207:
208:                transfer("user-agent", hr.request.headers, hr.request.props);
209:                transfer("referer", hr.request.headers, hr.request.props);
210:                transfer("last-modified", hr.request.responseHeaders,
211:                        hr.request.props);
212:                transfer("content-length", hr.request.responseHeaders,
213:                        hr.request.props);
214:                return true;
215:            }
216:
217:            /**
218:             * Transfer an item to another hash table, if it exists
219:             */
220:
221:            private boolean transfer(String key, Dictionary src, Dictionary dst) {
222:                Object obj = src.get(key);
223:                if (obj != null) {
224:                    dst.put(key, obj);
225:                    return true;
226:                } else {
227:                    return false;
228:                }
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.