Source Code Cross Referenced for Page.java in  » Web-Framework » jpublish » org » jpublish » 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 Framework » jpublish » org.jpublish 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         *
016:         */
017:
018:        package org.jpublish;
019:
020:        import org.apache.commons.logging.Log;
021:        import org.apache.commons.logging.LogFactory;
022:        import org.jpublish.page.PageInstance;
023:        import org.jpublish.page.PageProperty;
024:
025:        import java.util.HashMap;
026:        import java.util.List;
027:        import java.util.Locale;
028:        import java.util.Map;
029:
030:        /**
031:         * This class represents the current Page.  A new Page object is created
032:         * for each request.  Each Page object actually wraps a shared PageInstance
033:         * object.  Methods which modify the Page's state are only effective for the
034:         * current request.  To change the shared PageInstance state use the
035:         * <code>getPageInstance()</code> method to retrieve the PageInstance object
036:         * and make changes.
037:         *
038:         * @author Anthony Eden
039:         * @author <a href="mailto:florin.patrascu@gmail.com">Florin T.PATRASCU</a>
040:         */
041:
042:        public class Page {
043:
044:            private static final Log log = LogFactory.getLog(Page.class);
045:
046:            private PageInstance pageInstance;
047:
048:            private Map properties;
049:            private String templateName;
050:            private Locale locale = Locale.getDefault();
051:
052:            /**
053:             * Construct a new Page.
054:             *
055:             * @param pageInstance The wrapped PageInstance
056:             */
057:            public Page(PageInstance pageInstance) {
058:                this .pageInstance = pageInstance;
059:
060:                this .properties = new HashMap();
061:                this .locale = Locale.getDefault();
062:            }
063:
064:            /**
065:             * Get the request path.
066:             *
067:             * @return The request path
068:             */
069:            public String getPath() {
070:                return pageInstance.getPath();
071:            }
072:
073:            /**
074:             * Get the page name.
075:             *
076:             * @return The page name
077:             */
078:            public String getPageName() {
079:                return pageInstance.getPageName();
080:            }
081:
082:            /**
083:             * Get the page type.
084:             *
085:             * @return The page type
086:             */
087:            public String getPageType() {
088:                return pageInstance.getPageType();
089:            }
090:
091:            /**
092:             * Get the wrapped PageInstance.
093:             *
094:             * @return The PageInstance
095:             */
096:            public PageInstance getPageInstance() {
097:                return pageInstance;
098:            }
099:
100:            /**
101:             * Return the page title.  Initially the page title is extracted from
102:             * the page's definition document, however it can be set programtically
103:             * at runtime.
104:             * <p/>
105:             * <p>This method is deprecated.  Use getProperty("title") instead and
106:             * include a property named title in the page configuration file.  The
107:             * old &lt;title&gt; element and this method will be removed for the
108:             * 1.0 release.
109:             *
110:             * @return The page title
111:             * @deprecated Use getProperty("title") instead
112:             */
113:            public String getTitle() {
114:                return getProperty("title");
115:            }
116:
117:            /**
118:             * Set the title.  This will temporarily alter the page's title.
119:             * <p/>
120:             * <p>This method is deprecated.  The old &lt;title&gt; element
121:             * and this method will be removed for the 1.0 release.
122:             *
123:             * @param title The page title
124:             * @deprecated
125:             */
126:            public void setTitle(String title) {
127:                setProperty("title", title);
128:            }
129:
130:            /**
131:             * Get the full template file name, with the .suffix attached.
132:             *
133:             * @return The full template name
134:             */
135:            public String getFullTemplateName() {
136:                return getTemplateName() + "." + getPageType();
137:            }
138:
139:            /**
140:             * Get the template name.  If the template name is not specified in the
141:             * page configuration then the default template as specified in the
142:             * SiteContext will be used.
143:             *
144:             * @return The template name
145:             */
146:            public String getTemplateName() {
147:                if (templateName == null) {
148:                    templateName = pageInstance.getTemplateName();
149:                }
150:                return templateName;
151:            }
152:
153:            /**
154:             * Set the template name.  Invoking this method with a null value will
155:             * reset the template to the default template as specified in the
156:             * SiteContext.
157:             *
158:             * @param templateName The new template name or null to reset
159:             */
160:            public void setTemplateName(String templateName) {
161:                this .templateName = templateName;
162:            }
163:
164:            /**
165:             * Get a List of page actions.  To add an action to the page just add
166:             * the action to this List.  Page actions are triggered each time the
167:             * page is requested.
168:             *
169:             * @return A List of page actions
170:             */
171:            public List getPageActions() {
172:                return pageInstance.getPageActions();
173:            }
174:
175:            /**
176:             * Get the named page property using the default Locale.  If the
177:             * property is not found then return null.
178:             *
179:             * @param name The property name
180:             * @return The value or null
181:             */
182:            public String getProperty(String name) {
183:                return getProperty(name, getLocale());
184:            }
185:
186:            /**
187:             * Get the Locale-specific value for the given named property.  If
188:             * the property is not found then return null.  This method will try to find
189:             * the most suitable locale by searching the property values in the
190:             * following manner:
191:             * <p/>
192:             * <p/>
193:             * language + "_" + country + "_" + variant<br>
194:             * language + "_" + country<br>
195:             * langauge<br>
196:             * ""
197:             * </p>
198:             *
199:             * @param name   The property name
200:             * @param locale The locale
201:             * @return The value
202:             */
203:            public String getProperty(String name, Locale locale) {
204:                if (log.isDebugEnabled())
205:                    log.debug("getProperty(" + name + "," + locale + ")");
206:
207:                PageProperty pageProperty = (PageProperty) properties.get(name);
208:                if (pageProperty == null) {
209:                    log.debug("Looking for property in PageInstance");
210:                    String value = pageInstance.getProperty(name, locale);
211:                    if (value != null) {
212:                        log.debug("Found property in page instance");
213:                        setProperty(name, value, locale);
214:                        return value;
215:                    }
216:                }
217:
218:                if (pageProperty == null) {
219:                    return null;
220:                } else {
221:                    return pageProperty.getValue(locale);
222:                }
223:            }
224:
225:            /**
226:             * Get the named property.  This method is equivilent to the
227:             * <code>getProperty(name)</code> method.  This method is provided
228:             * as a convenience to view code.
229:             *
230:             * @param name The property name
231:             * @return The value
232:             */
233:            public String get(String name) {
234:                return getProperty(name);
235:            }
236:
237:            /**
238:             * Execute the page actions using the given context.
239:             *
240:             * @param context The current context
241:             * @return A redirection value or null if there is no redirection
242:             * @throws Exception Any Exception which occurs while executing the action
243:             */
244:            public String executeActions(JPublishContext context)
245:                    throws Exception {
246:                return pageInstance.executeActions(context);
247:            }
248:
249:            /**
250:             * Get the current page's locale.
251:             *
252:             * @return The Locale
253:             */
254:            public Locale getLocale() {
255:                return locale;
256:            }
257:
258:            /**
259:             * Set the current page's locale.  This locale is used when retrieving
260:             * page properties.
261:             *
262:             * @param locale
263:             */
264:            public void setLocale(Locale locale) {
265:                if (locale == null) {
266:                    locale = Locale.getDefault();
267:                }
268:                this .locale = locale;
269:            }
270:
271:            /**
272:             * Set the property value.
273:             *
274:             * @param name  The property name
275:             * @param value The property value
276:             */
277:            public void setProperty(String name, String value) {
278:                setProperty(name, value, getLocale());
279:            }
280:
281:            /**
282:             * Set the property value.
283:             *
284:             * @param name   The property name
285:             * @param value  The property value
286:             * @param locale The Locale
287:             */
288:
289:            public void setProperty(String name, String value, Locale locale) {
290:                //        if(log.isDebugEnabled())
291:                //            log.debug("setProperty(" + name + "," + value + "," + locale + ")");
292:                //
293:                PageProperty property = (PageProperty) properties.get(name);
294:                if (property == null) {
295:                    // named property not in property map
296:                    property = new PageProperty(name);
297:                    properties.put(name, property);
298:                }
299:                property.setValue(value, locale);
300:            }
301:
302:            /**
303:             * @return a read/write Map containing the page properties
304:             */
305:            public Map getProperties() {
306:                return this.properties;
307:            }
308:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.