Source Code Cross Referenced for PropsTemplate.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:         * PropsTemplate.java
003:         *
004:         * Brazil project web application Framework,
005:         * export version: 1.1 
006:         * Copyright (c) 1998-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.29
024:         * Created by suhler on 98/09/14
025:         * Last modified by suhler on 00/12/11 13:29:09
026:         */
027:
028:        package sunlabs.brazil.template;
029:
030:        import sunlabs.brazil.util.Format;
031:
032:        import java.util.Enumeration;
033:        import java.util.Hashtable;
034:        import java.util.Dictionary;
035:        import java.util.Properties;
036:        import java.io.Serializable;
037:
038:        /**
039:         * Template class for substituting request properties into an HTML page
040:         * This class is used by the TemplateHandler
041:         * The following request properties are used:
042:         * <dl class=props>
043:         * <dt>query	<dd> The query parameters are placed into the request object,
044:         *	        prefixed by the value assigned to "query".
045:         * <dt>headers	<dd> The mime headers are placed into the request object,
046:         *		prefixed by the value assigned to "headers".  The values:
047:         *		url, query, method, and version are copied from the request
048:         *		object into the properties. The clients IP address is
049:         *		saved in the "address" property.
050:         * </dl>
051:         * <p>
052:         * A new HTML tag,  
053:         * <code>&lt;property&gt;</code> is defined.  It takes the following 
054:         * tag attributes:
055:         * <dl>
056:         * <dt>name	<dd> The name of the property in
057:         *                   {@link sunlabs.brazil.server.Request#props props}
058:         *		     to replace the <code>property</code> tag with.
059:         * <dt>default	<dd> The value to use if the property is not defined.
060:         *		     If no <code>default</code> is specified, the empty
061:         *		     string is used instead.
062:         * </dl>
063:         *
064:         * @author		Stephen Uhler
065:         * @version		1.0, 09/04/98
066:         */
067:
068:        public class PropsTemplate extends Template implements  Serializable {
069:            private static final String DEBUG = "debug";
070:
071:            transient boolean debug;
072:
073:            /**
074:             * This gets called at every page, at the beginning.  See if we should add
075:             * the mime headers and query parameters into the request object
076:             */
077:
078:            public boolean init(RewriteContext hr) {
079:                Properties props = hr.request.props;
080:
081:                debug = (props.getProperty(hr.prefix + DEBUG) != null);
082:
083:                String query = props.getProperty(hr.prefix + "query");
084:                if (query != null) {
085:                    Dictionary h = hr.request.getQueryData(null);
086:                    Enumeration keys = h.keys();
087:                    while (keys.hasMoreElements()) {
088:                        String key = (String) keys.nextElement();
089:                        props.put(query + key, h.get(key));
090:                    }
091:                }
092:
093:                String headers = props.getProperty(hr.prefix + "headers");
094:                if (headers != null) {
095:                    Enumeration keys = hr.request.headers.keys();
096:                    while (keys.hasMoreElements()) {
097:                        String key = (String) keys.nextElement();
098:                        props.put(headers + key.toLowerCase(),
099:                                hr.request.headers.get(key));
100:                    }
101:                    props.put(headers + "method", hr.request.method);
102:                    props.put(headers + "url", hr.request.url);
103:                    props.put(headers + "query", hr.request.query);
104:                    props.put(headers + "protocol", hr.request.protocol);
105:                    props.put(headers + "address", ""
106:                            + hr.request.getSocket().getInetAddress()
107:                                    .getHostAddress());
108:                }
109:                return true;
110:            }
111:
112:            /**
113:             * Convert the html tag "property" in to the request's property
114:             * @param key	The name of the property to substitute.  Variable
115:             *			substitution using the style described in 
116:             *		 	{@link Format#getProperty} is permitted, e.g.:
117:             *			<code>employee.${id}.last</code>
118:             */
119:
120:            public void tag_property(RewriteContext hr) {
121:                String name = hr.getArgs();
122:                String value = null;
123:                if (name.indexOf('=') >= 0) {
124:                    name = hr.get("name");
125:                    value = hr.get("default");
126:                }
127:
128:                String result = null;
129:                if (name != null) {
130:                    result = Format.getProperty(hr.request.props, name, value);
131:                }
132:
133:                if (result != null) {
134:                    hr.append(result);
135:                } else if (debug) {
136:                    hr.append("<!-- property: no value for " + name + " -->");
137:                } else {
138:                    hr.killToken();
139:                }
140:            }
141:
142:            /**
143:             * Insert a liteteral "&lt;".
144:             * Using the current scheme, there is no easy way to substitute into
145:             * a tag parameter.  So we'll invent a "magic" tag (called tag)
146:             * that will allow us to create entities dynamically.  Thus values
147:             * can be substituted into entities by escaping the entity as in:
148:             * <pre>
149:             * &lt;tag&gt;a href=&lt;property href&gt;&lt;/tag&gt;
150:             * </pre>
151:             */
152:
153:            public void tag_tag(RewriteContext hr) {
154:                hr.append("<");
155:            }
156:
157:            /**
158:             * Insert a literal "&gt;"
159:             */
160:
161:            public void tag_slash_tag(RewriteContext hr) {
162:                hr.append(">");
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.