Source Code Cross Referenced for OldPageHelper.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » ui » rendering » velocity » deprecated » 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.velocity.deprecated 
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.velocity.deprecated;
020:
021:        import java.net.MalformedURLException;
022:        import java.util.Date;
023:        import java.util.Hashtable;
024:        import java.util.Iterator;
025:        import java.util.List;
026:        import java.util.Locale;
027:        import java.util.Map;
028:        import java.util.Vector;
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:        import javax.servlet.jsp.PageContext;
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.apache.struts.Globals;
035:        import org.apache.struts.util.RequestUtils;
036:        import org.apache.roller.RollerException;
037:        import org.apache.roller.business.WeblogEntryPlugin;
038:        import org.apache.roller.business.PluginManager;
039:        import org.apache.roller.business.Roller;
040:        import org.apache.roller.business.RollerFactory;
041:        import org.apache.roller.pojos.FolderData;
042:        import org.apache.roller.pojos.WebsiteData;
043:        import org.apache.roller.pojos.wrapper.RefererDataWrapper;
044:        import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper;
045:        import org.apache.roller.ui.core.RequestConstants;
046:        import org.apache.roller.ui.core.RollerContext;
047:        import org.apache.roller.ui.core.RollerSession;
048:        import org.apache.roller.ui.core.tags.calendar.CalendarModel;
049:        import org.apache.roller.ui.core.tags.calendar.CalendarTag;
050:        import org.apache.roller.ui.core.tags.menu.EditorNavigationBarTag;
051:        import org.apache.roller.ui.core.tags.menu.MenuTag;
052:        import org.apache.roller.ui.core.tags.calendar.BigWeblogCalendarModel;
053:        import org.apache.roller.ui.core.tags.calendar.WeblogCalendarModel;
054:        import org.apache.roller.ui.rendering.util.WeblogPageRequest;
055:
056:        /**
057:         * Provides assistance to VelociMacros, filling in where Velocity falls.
058:         */
059:        public class OldPageHelper {
060:
061:            private static Log mLogger = LogFactory.getLog(OldPageHelper.class);
062:
063:            private PageContext mPageContext = null;
064:            private HttpServletRequest mRequest = null;
065:            private HttpServletResponse mResponse = null;
066:
067:            private Map mPagePlugins = null; // Plugins keyed by name
068:            private WebsiteData mWebsite = null;
069:            private Date mDate = null;
070:            private FolderData mFolder = null;
071:            private String mPageName = null;
072:            private WeblogPageRequest mPageRequest = null;
073:
074:            /**
075:             * Initialize VelocityHelper, setting the variables it will be hiding from
076:             * the Velocimacros.
077:             */
078:            public OldPageHelper(HttpServletRequest request,
079:                    HttpServletResponse response, Map ctx, WebsiteData website,
080:                    Date date, FolderData folder, String pageName,
081:                    PageContext pageContext, WeblogPageRequest pageRequest)
082:                    throws RollerException {
083:
084:                // general request objects
085:                mRequest = request;
086:                mResponse = response;
087:                mPageContext = pageContext;
088:                mPageRequest = pageRequest;
089:
090:                // data that we'll be reusing
091:                mWebsite = website;
092:                mDate = date;
093:                mFolder = folder;
094:
095:                // init plugins
096:                Roller roller = RollerFactory.getRoller();
097:                PluginManager ppmgr = roller.getPagePluginManager();
098:                mPagePlugins = ppmgr.getWeblogEntryPlugins(mWebsite);
099:            }
100:
101:            /**
102:             * Another stupid helper method to make up for the shortcomings of Velocity.
103:             * @return HashMap
104:             */
105:            public Hashtable addParam(String key, String value, Hashtable map) {
106:                if (map == null)
107:                    map = new Hashtable();
108:                if (key != null && value != null)
109:                    map.put(key, value);
110:                return map;
111:            }
112:
113:            /**
114:             * Evaluates the String as a Velocimacro, returning the results.
115:             *
116:             * @deprecated shouldn't be used anymore because it's dangerous
117:             *
118:             * @param str String
119:             * @return String
120:             */
121:            public String evaluateString(String str) {
122:                // we no longer allow users to do this because it is dangerous
123:                return str;
124:            }
125:
126:            /** Build the URL for editing an WeblogEntry **/
127:            public String getEntryEditUrl(WeblogEntryDataWrapper entry) {
128:                Hashtable params = new Hashtable();
129:                params.put(RequestConstants.WEBLOGENTRY_ID, entry.getId());
130:                params.put(RequestConstants.ANCHOR, entry.getAnchor());
131:                if (mWebsite != null) {
132:                    params.put(RequestConstants.USERNAME, mWebsite.getHandle());
133:                }
134:                try {
135:                    return RequestUtils.computeURL(mPageContext, "weblogEdit",
136:                            null, null, null, params, null, false);
137:                } catch (MalformedURLException mue) {
138:                    mLogger.warn("RollerRequest.editEntryUrl exception: ", mue);
139:                }
140:                return mRequest.getContextPath()
141:                        + "edtior/weblog.do?method=edit";
142:            }
143:
144:            public String getToggleLinkbackDisplayHTML(
145:                    RefererDataWrapper referer) {
146:                String ret = "";
147:                String link = null;
148:                try {
149:                    RollerSession rollerSession = RollerSession
150:                            .getRollerSession(mRequest);
151:                    if (mWebsite != null
152:                            && rollerSession.isUserAuthorizedToAdmin(mWebsite)) {
153:                        Hashtable params = new Hashtable();
154:                        params.put(RequestConstants.REFERRER_ID, referer
155:                                .getId());
156:                        params.put(RequestConstants.WEBLOG, mWebsite
157:                                .getHandle());
158:                        link = RequestUtils.computeURL(mPageContext,
159:                                "toggleLinkback", null, null, null, params,
160:                                null, false);
161:
162:                        StringBuffer sb = new StringBuffer();
163:                        sb.append("[<a href=\"");
164:                        sb.append(link);
165:                        if (referer.getVisible().booleanValue()) {
166:                            sb.append("\">Visible</a>] ");
167:                        } else {
168:                            sb.append("\">Hidden</a>] ");
169:                        }
170:                        ret = sb.toString();
171:                    }
172:                } catch (Exception e) {
173:                    // should never happen, but if it does:
174:                    mLogger.error("ERROR creating toggle-linkback URL", e);
175:                }
176:
177:                return ret;
178:            }
179:
180:            public boolean isUserAuthorizedToEdit() {
181:                try {
182:                    RollerSession rses = RollerSession
183:                            .getRollerSession(mRequest);
184:                    if (rses.getAuthenticatedUser() != null && mWebsite != null) {
185:                        return rses.isUserAuthorizedToAdmin(mWebsite);
186:                    }
187:                } catch (Exception e) {
188:                    mLogger.warn("PageHelper.isUserAuthorizedToEdit)", e);
189:                }
190:                return false;
191:            }
192:
193:            public void setContentType(String type) {
194:                mResponse.setContentType(type);
195:            }
196:
197:            /**
198:             * Display big weblog calendar, well suited for an archive page.
199:             * @return HTML for calendar.
200:             */
201:            public String showBigWeblogCalendar() {
202:                return showWeblogCalendar(true, null);
203:            }
204:
205:            /**
206:             * Call hybrid EditorNavBarTag to render editor navbar.
207:             * @param vertical True for vertical navbar.
208:             * @return String HTML for navbar.
209:             */
210:            public String showEditorNavBar(boolean vertical) {
211:                EditorNavigationBarTag editorTag = new EditorNavigationBarTag();
212:                editorTag.setPageContext(mPageContext);
213:                if (vertical) {
214:                    editorTag.setView("templates/navbar/navbar-vertical.vm");
215:                } else {
216:                    editorTag.setView("templates/navbar/navbar-horizontal.vm");
217:                }
218:                editorTag.setModel("editor-menu.xml");
219:                return editorTag.emit();
220:            }
221:
222:            /**
223:             * Call hybrid EditorNavBarTag to render editor navbar.
224:             * @param model Name of XML file in WEB-INF that contains XML for menu.
225:             * @param template Name of Velocity template in classpath to display menu.
226:             * @return String HTML for menu.
227:             */
228:            public String showMenu(String model, String template) {
229:                MenuTag menuTag = new MenuTag();
230:                menuTag.setPageContext(mPageContext);
231:                menuTag.setModel(model);
232:                menuTag.setView(template);
233:                return menuTag.emit();
234:            }
235:
236:            //------------------------------------------------- WeblogCalendar methods
237:
238:            /**
239:             * Display weblog calendar.
240:             * @return HTML for calendar.
241:             */
242:            public String showWeblogCalendar() {
243:                return showWeblogCalendar(false, null);
244:            }
245:
246:            /**
247:             * Weblog calendar display implementation.
248:             * @param big Show big archive style calendar.
249:             * @return HTML for calendar.
250:             */
251:            public String showWeblogCalendar(boolean big, String cat) {
252:                if (OldWeblogPageModel.VELOCITY_NULL.equals(cat))
253:                    cat = null;
254:                String ret = null;
255:                try {
256:                    // setup weblog calendar model
257:                    CalendarModel model = null;
258:                    if (big) {
259:                        model = new BigWeblogCalendarModel(mPageRequest, cat);
260:                    } else {
261:                        model = new WeblogCalendarModel(mPageRequest, cat);
262:                    }
263:
264:                    // save model in JSP page context so CalendarTag can find it
265:                    mPageContext.setAttribute("calendarModel", model);
266:
267:                    // Create and setup calendar tag
268:                    CalendarTag calTag = new CalendarTag();
269:                    calTag.setPageContext(mPageContext);
270:                    calTag.setName("calendar");
271:                    calTag.setModel("calendarModel");
272:                    calTag.setLocale(mPageRequest.getLocaleInstance());
273:                    if (big) {
274:                        calTag.setClassSuffix("Big");
275:                    }
276:                    ret = calTag.emit();
277:                } catch (Exception e) {
278:                    mLogger.error("Unexpected exception", e);
279:                }
280:                return ret;
281:            }
282:
283:            /**
284:             * Convenience method, contrived helper for Velocity.
285:             * @param useIds
286:             * @param isAction
287:             * @param path
288:             * @param val1
289:             * @param val2
290:             * @return String
291:             */
292:            public String strutsUrlHelper(boolean useIds, boolean isAction,
293:                    String path, String val1, String val2) {
294:                Hashtable params = new Hashtable();
295:                return strutsUrlHelper1(useIds, isAction, path, val1, val2,
296:                        params);
297:            }
298:
299:            /**
300:             * Very contrived helper method for Velocimacros generating Struts links.
301:             * This is really only of use to the showNavBar macro.
302:             * @param useIds
303:             * @param isAction
304:             * @param path
305:             * @param val1
306:             * @param val2
307:             * @return String
308:             */
309:            public String strutsUrlHelper1(boolean useIds, boolean isAction,
310:                    String path, String val1, String val2, Hashtable params) {
311:                if (useIds) {
312:                    if (mFolder != null) {
313:                        params.put(RequestConstants.FOLDER_ID, mFolder.getId());
314:                    }
315:                    if (mWebsite != null) {
316:                        params.put(RequestConstants.WEBLOG, mWebsite
317:                                .getHandle());
318:                    }
319:                }
320:
321:                if (OldStringUtils.isNotEmpty(val1) && !val1.equals("null")) {
322:                    params.clear();
323:                    params.put("weblog", val1);
324:                }
325:
326:                String returnUrl = "";
327:                try {
328:                    if (isAction) {
329:                        returnUrl = RequestUtils.computeURL(mPageContext, path,
330:                                null, null, null, params, null, false);
331:                    } else {
332:                        returnUrl = RequestUtils.computeURL(mPageContext, null,
333:                                path, null, null, params, null, false);
334:                    }
335:                } catch (MalformedURLException mue) {
336:                    mLogger.warn("RollerRequest.strutsUrlHelper exception: ",
337:                            mue);
338:                    returnUrl = "<span class=\"error\">ERROR generating link</span>";
339:                }
340:                return returnUrl;
341:            }
342:
343:            /**
344:             * Pass the String through any PagePlugins that have been
345:             * assigned to the PageHelper, as selected by the Entry.
346:             *
347:             * @param entry Entry being rendered.
348:             * @param str   String to which plugins are to be applied.
349:             * @return      Result of applying plugins to str.
350:             */
351:            public String renderPlugins(WeblogEntryDataWrapper entry, String str) {
352:                String ret = str;
353:                mLogger.debug("Applying page plugins to string");
354:
355:                if (mPagePlugins != null) {
356:                    List entryPlugins = entry.getPluginsList();
357:                    // if no Entry plugins, don't bother looping.
358:                    if (entryPlugins != null && !entryPlugins.isEmpty()) {
359:
360:                        // now loop over mPagePlugins, matching
361:                        // against Entry plugins (by name):
362:                        // where a match is found render Plugin.
363:                        Iterator iter = mPagePlugins.keySet().iterator();
364:                        while (iter.hasNext()) {
365:                            String key = (String) iter.next();
366:                            if (entryPlugins.contains(key)) {
367:                                WeblogEntryPlugin pagePlugin = (WeblogEntryPlugin) mPagePlugins
368:                                        .get(key);
369:                                try {
370:                                    ret = pagePlugin.render(entry.getPojo(),
371:                                            ret);
372:                                } catch (Throwable t) {
373:                                    mLogger.error("ERROR from plugin: "
374:                                            + pagePlugin.getName(), t);
375:                                }
376:                            }
377:                        }
378:                    }
379:                }
380:
381:                return ret;
382:            }
383:
384:            /**
385:             * This method used to return an array of supported locales based on some
386:             * of the old i18n work done in Roller, however, as of Roller 3.0 there is
387:             * no longer a list of supported languages.  The languages available to a
388:             * weblog are unbounded and are purely determined by the weblog author.
389:             *
390:             * This method always returns null.
391:             */
392:            public Locale[] getSupportedLanguages() {
393:                return null;
394:            }
395:
396:            /**
397:             * @return relative URL to page, starting with /username
398:             */
399:            public String getPathInfo() {
400:                String pathInfo = mRequest.getPathInfo();
401:                if (pathInfo == null) {
402:                    pathInfo = "";
403:                }
404:
405:                return pathInfo;
406:            }
407:
408:            public String getCommentAuthenticatorHtml() {
409:                // deprecated, does nothing now
410:                return "";
411:            }
412:
413:        }
ww___w_.__j___a__v___a__2s_.c___o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.