Source Code Cross Referenced for TextTemplateHeaderContributor.java in  » J2EE » wicket » wicket » extensions » util » resource » 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 » J2EE » wicket » wicket.extensions.util.resource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: StringBufferResourceStream.java 3307 2005-11-30 15:57:34 -0800 (Wed, 30
003:         * Nov 2005) ivaynberg $ $Revision: 3307 $ $Date: 2005-11-30 15:57:34 -0800
004:         * (Wed, 30 Nov 2005) $
005:         * 
006:         * ==============================================================================
007:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
008:         * use this file except in compliance with the License. You may obtain a copy of
009:         * the License at
010:         * 
011:         * http://www.apache.org/licenses/LICENSE-2.0
012:         * 
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
015:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
016:         * License for the specific language governing permissions and limitations under
017:         * the License.
018:         */
019:        package wicket.extensions.util.resource;
020:
021:        import java.util.Map;
022:
023:        import wicket.Component;
024:        import wicket.behavior.StringHeaderContributor;
025:        import wicket.model.AbstractReadOnlyDetachableModel;
026:        import wicket.model.IModel;
027:
028:        /**
029:         * A header contributor that will contribute the contents of the given template
030:         * interpolated with the provided map of variables.
031:         * 
032:         * @author Eelco Hillenius
033:         */
034:        public class TextTemplateHeaderContributor extends
035:                StringHeaderContributor {
036:            private static final long serialVersionUID = 1L;
037:
038:            /**
039:             * This model holds the template and returns the interpolation of the
040:             * template with of any of the
041:             */
042:            private static final class TemplateModel extends
043:                    AbstractReadOnlyDetachableModel {
044:                private static final long serialVersionUID = 1L;
045:
046:                /**
047:                 * The template to operate on and which makes the contribution.
048:                 */
049:                private final TextTemplate template;
050:
051:                /**
052:                 * The model that holds any variables for interpolation. It should
053:                 * return a {@link Map} or null.
054:                 */
055:                private final IModel variablesModel;
056:
057:                /**
058:                 * Construct.
059:                 * 
060:                 * @param template
061:                 *            the template to work on
062:                 * @param variablesModel
063:                 *            The model that holds any variables for interpolation. It
064:                 *            should return a {@link Map} or null.
065:                 */
066:                protected TemplateModel(TextTemplate template,
067:                        IModel variablesModel) {
068:                    if (template == null) {
069:                        throw new IllegalArgumentException(
070:                                "argument template must be not null");
071:                    }
072:
073:                    this .template = template;
074:                    this .variablesModel = variablesModel;
075:                }
076:
077:                /**
078:                 * @see wicket.model.AbstractDetachableModel#getNestedModel()
079:                 */
080:                public IModel getNestedModel() {
081:                    return null;
082:                }
083:
084:                /**
085:                 * @see wicket.model.AbstractDetachableModel#onAttach()
086:                 */
087:                protected void onAttach() {
088:                }
089:
090:                /**
091:                 * @see wicket.model.AbstractDetachableModel#onDetach()
092:                 */
093:                protected void onDetach() {
094:                    if (variablesModel != null) {
095:                        variablesModel.detach();
096:                    }
097:                }
098:
099:                /**
100:                 * @see wicket.model.AbstractDetachableModel#onGetObject(wicket.Component)
101:                 */
102:                protected Object onGetObject(Component component) {
103:                    if (variablesModel != null) {
104:                        Map variables = (Map) variablesModel
105:                                .getObject(component);
106:                        if (variables != null) {
107:                            return template.asString(variables);
108:                        }
109:                    }
110:                    return template.asString();
111:                }
112:            }
113:
114:            /**
115:             * Gets a css header contributor based on the given text template. The
116:             * template will be interpolated with the given variables. The content will
117:             * be written as the body of a script tag pair.
118:             * 
119:             * @param template
120:             *            The text template that is the base for the contribution
121:             * @param variablesModel
122:             *            The variables to interpolate
123:             * @return The header contributor instance
124:             */
125:            public static TextTemplateHeaderContributor forCss(
126:                    TextTemplate template, IModel variablesModel) {
127:                return new TextTemplateHeaderContributor(new CssTemplate(
128:                        template), variablesModel);
129:            }
130:
131:            /**
132:             * Gets a css header contributor that will load the template from the given
133:             * file name relative to (/in the same package as) the provided clazz
134:             * argument. The template will be interpolated with the given variables. The
135:             * content will be written as the body of a script tag pair.
136:             * 
137:             * @param clazz
138:             *            The class to be used for retrieving the classloader for
139:             *            loading the packaged template.
140:             * @param fileName
141:             *            The name of the file, relative to the clazz position
142:             * @param variablesModel
143:             *            The variables to interpolate
144:             * @return The header contributor instance
145:             */
146:            public static TextTemplateHeaderContributor forCss(
147:                    final Class clazz, final String fileName,
148:                    IModel variablesModel) {
149:                return forCss(new PackagedTextTemplate(clazz, fileName),
150:                        variablesModel);
151:            }
152:
153:            /**
154:             * Gets a javascript header contributor based on the given text template.
155:             * The template will be interpolated with the given variables. The content
156:             * will be written as the body of a script tag pair.
157:             * 
158:             * @param template
159:             *            The text template that is the base for the contribution
160:             * @param variablesModel
161:             *            The variables to interpolate
162:             * @return The header contributor instance
163:             */
164:            public static TextTemplateHeaderContributor forJavaScript(
165:                    TextTemplate template, IModel variablesModel) {
166:                return new TextTemplateHeaderContributor(
167:                        new JavaScriptTemplate(template), variablesModel);
168:            }
169:
170:            /**
171:             * Gets a javascript header contributor that will load the template from the
172:             * given file name relative to (/in the same package as) the provided clazz
173:             * argument. The template will be interpolated with the given variables. The
174:             * content will be written as the body of a script tag pair.
175:             * 
176:             * @param clazz
177:             *            The class to be used for retrieving the classloader for
178:             *            loading the packaged template.
179:             * @param fileName
180:             *            The name of the file, relative to the clazz position
181:             * @param variablesModel
182:             *            The variables to interpolate
183:             * @return The header contributor instance
184:             */
185:            public static TextTemplateHeaderContributor forJavaScript(
186:                    final Class clazz, final String fileName,
187:                    IModel variablesModel) {
188:                return forJavaScript(new PackagedTextTemplate(clazz, fileName),
189:                        variablesModel);
190:            }
191:
192:            /**
193:             * Construct.
194:             * 
195:             * @param template
196:             *            The template with the contribution
197:             * @param variablesModel
198:             *            Optional model for variable substitution
199:             */
200:            protected TextTemplateHeaderContributor(TextTemplate template,
201:                    IModel variablesModel) {
202:                super (new TemplateModel(template, variablesModel));
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.