Source Code Cross Referenced for PageModel.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » ui » rendering » model » 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 » Blogger System » apache roller 3.1 » org.apache.roller.ui.rendering.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  The ASF licenses this file to You
004:         * under the Apache License, Version 2.0 (the "License"); you may not
005:         * 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.  For additional information regarding
015:         * copyright in this work, please see the NOTICE file in the top level
016:         * directory of this distribution.
017:         */
018:
019:        package org.apache.roller.ui.rendering.model;
020:
021:        import java.util.ArrayList;
022:        import java.util.List;
023:        import java.util.Map;
024:        import org.apache.commons.lang.StringUtils;
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:        import org.apache.roller.RollerException;
028:        import org.apache.roller.business.Roller;
029:        import org.apache.roller.business.RollerFactory;
030:        import org.apache.roller.business.WeblogManager;
031:        import org.apache.roller.pojos.WebsiteData;
032:        import org.apache.roller.pojos.wrapper.TemplateWrapper;
033:        import org.apache.roller.pojos.wrapper.WeblogCategoryDataWrapper;
034:        import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
035:        import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
036:        import org.apache.roller.ui.rendering.pagers.WeblogEntriesDayPager;
037:        import org.apache.roller.ui.rendering.pagers.WeblogEntriesLatestPager;
038:        import org.apache.roller.ui.rendering.pagers.WeblogEntriesMonthPager;
039:        import org.apache.roller.ui.rendering.pagers.WeblogEntriesPager;
040:        import org.apache.roller.ui.rendering.pagers.WeblogEntriesPermalinkPager;
041:        import org.apache.roller.ui.rendering.util.WeblogEntryCommentForm;
042:        import org.apache.roller.ui.rendering.util.WeblogPageRequest;
043:        import org.apache.roller.ui.rendering.util.WeblogRequest;
044:
045:        /**
046:         * Model which provides information needed to render a weblog page.
047:         */
048:        public class PageModel implements  Model {
049:
050:            private static Log log = LogFactory.getLog(PageModel.class);
051:
052:            private WeblogPageRequest pageRequest = null;
053:            private WeblogEntryCommentForm commentForm = null;
054:            private Map requestParameters = null;
055:            private WebsiteData weblog = null;
056:
057:            /** 
058:             * Creates an un-initialized new instance, Roller calls init() to complete
059:             * construction. 
060:             */
061:            public PageModel() {
062:            }
063:
064:            /** 
065:             * Template context name to be used for model.
066:             */
067:            public String getModelName() {
068:                return "model";
069:            }
070:
071:            /** 
072:             * Init page model based on request. 
073:             */
074:            public void init(Map initData) throws RollerException {
075:
076:                // we expect the init data to contain a weblogRequest object
077:                WeblogRequest weblogRequest = (WeblogRequest) initData
078:                        .get("weblogRequest");
079:                if (weblogRequest == null) {
080:                    throw new RollerException(
081:                            "expected weblogRequest from init data");
082:                }
083:
084:                // PageModel only works on page requests, so cast weblogRequest
085:                // into a WeblogPageRequest and if it fails then throw exception
086:                if (weblogRequest instanceof  WeblogPageRequest) {
087:                    this .pageRequest = (WeblogPageRequest) weblogRequest;
088:                } else {
089:                    throw new RollerException(
090:                            "weblogRequest is not a WeblogPageRequest."
091:                                    + "  PageModel only supports page requests.");
092:                }
093:
094:                // see if there is a comment form
095:                this .commentForm = (WeblogEntryCommentForm) initData
096:                        .get("commentForm");
097:
098:                // custom request parameters
099:                this .requestParameters = (Map) initData
100:                        .get("requestParameters");
101:
102:                // extract weblog object
103:                weblog = pageRequest.getWeblog();
104:            }
105:
106:            /**
107:             * Get the weblog locale used to render this page, null if no locale.
108:             */
109:            public String getLocale() {
110:                return pageRequest.getLocale();
111:            }
112:
113:            /**
114:             * Get weblog being displayed.
115:             */
116:            public WebsiteDataWrapper getWeblog() {
117:                return WebsiteDataWrapper.wrap(weblog);
118:            }
119:
120:            /**
121:             * Is this page considered a permalink?
122:             */
123:            public boolean isPermalink() {
124:                return (pageRequest.getWeblogAnchor() != null);
125:            }
126:
127:            /**
128:             * Is this page showing search results?
129:             */
130:            public boolean isSearchResults() {
131:                // the search results model will extend this class and override this
132:                return false;
133:            }
134:
135:            /**
136:             * Get weblog entry being displayed or null if none specified by request.
137:             */
138:            public WeblogEntryDataWrapper getWeblogEntry() {
139:                if (pageRequest.getWeblogEntry() != null) {
140:                    return WeblogEntryDataWrapper.wrap(pageRequest
141:                            .getWeblogEntry());
142:                }
143:                return null;
144:            }
145:
146:            /**
147:             * Get weblog entry being displayed or null if none specified by request.
148:             */
149:            public TemplateWrapper getWeblogPage() {
150:                if (pageRequest.getWeblogPageName() != null) {
151:                    return TemplateWrapper.wrap(pageRequest.getWeblogPage());
152:                } else {
153:                    try {
154:                        return TemplateWrapper.wrap(weblog.getDefaultPage());
155:                    } catch (RollerException ex) {
156:                        log.error("Error getting default page", ex);
157:                    }
158:                }
159:                return null;
160:            }
161:
162:            /**
163:             * Get weblog category specified by request, or null if the category path
164:             * found in the request does not exist in the current weblog.
165:             */
166:            public WeblogCategoryDataWrapper getWeblogCategory() {
167:                if (pageRequest.getWeblogCategory() != null) {
168:                    return WeblogCategoryDataWrapper.wrap(pageRequest
169:                            .getWeblogCategory());
170:                }
171:                return null;
172:            }
173:
174:            /**
175:             * A map of entries representing this page. The collection is grouped by 
176:             * days of entries.  Each value is a list of entry objects keyed by the 
177:             * date they were published.
178:             * @param catArgument Category restriction (null or "nil" for no restriction)
179:             */
180:            public WeblogEntriesPager getWeblogEntriesPager(String catArgument) {
181:
182:                // category specified by argument wins over request parameter
183:                String cat = pageRequest.getWeblogCategoryName();
184:                if (catArgument != null && !StringUtils.isEmpty(catArgument)
185:                        && !"nil".equals(catArgument)) {
186:                    cat = catArgument;
187:                }
188:
189:                String dateString = pageRequest.getWeblogDate();
190:
191:                // determine which mode to use
192:                if (pageRequest.getWeblogAnchor() != null) {
193:                    return new WeblogEntriesPermalinkPager(weblog, pageRequest
194:                            .getLocale(), pageRequest.getWeblogPageName(),
195:                            pageRequest.getWeblogAnchor(), pageRequest
196:                                    .getWeblogDate(), cat, pageRequest
197:                                    .getTags(), pageRequest.getPageNum());
198:                } else if (dateString != null && dateString.length() == 8) {
199:                    return new WeblogEntriesDayPager(weblog, pageRequest
200:                            .getLocale(), pageRequest.getWeblogPageName(),
201:                            pageRequest.getWeblogAnchor(), pageRequest
202:                                    .getWeblogDate(), cat, pageRequest
203:                                    .getTags(), pageRequest.getPageNum());
204:                } else if (dateString != null && dateString.length() == 6) {
205:                    return new WeblogEntriesMonthPager(weblog, pageRequest
206:                            .getLocale(), pageRequest.getWeblogPageName(),
207:                            pageRequest.getWeblogAnchor(), pageRequest
208:                                    .getWeblogDate(), cat, pageRequest
209:                                    .getTags(), pageRequest.getPageNum());
210:
211:                } else {
212:                    return new WeblogEntriesLatestPager(weblog, pageRequest
213:                            .getLocale(), pageRequest.getWeblogPageName(),
214:                            pageRequest.getWeblogAnchor(), pageRequest
215:                                    .getWeblogDate(), cat, pageRequest
216:                                    .getTags(), pageRequest.getPageNum());
217:                }
218:            }
219:
220:            /**
221:             * A map of entries representing this page. The collection is grouped by 
222:             * days of entries.  Each value is a list of entry objects keyed by the 
223:             * date they were published.
224:             */
225:            public WeblogEntriesPager getWeblogEntriesPager() {
226:                return getWeblogEntriesPager(null);
227:            }
228:
229:            /**
230:             * Get comment form to be displayed, may contain preview data.
231:             *
232:             * @return Comment form object
233:             */
234:            public WeblogEntryCommentForm getCommentForm() {
235:
236:                if (commentForm == null) {
237:                    commentForm = new WeblogEntryCommentForm();
238:                }
239:                return commentForm;
240:            }
241:
242:            /**
243:             * Get request parameter by name.
244:             */
245:            public String getRequestParameter(String paramName) {
246:                String[] values = (String[]) requestParameters.get(paramName);
247:                if (values != null && values.length > 0) {
248:                    return values[0];
249:                }
250:                return null;
251:            }
252:
253:            /**
254:             * Returns the list of tags specified in the request /tags/foo+bar
255:             * @return
256:             */
257:            public List getTags() {
258:                return pageRequest.getTags();
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.