Source Code Cross Referenced for DynamicBlogNavigator.java in  » J2EE » OpenCore » org » opensubsystems » blog » www » 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 » OpenCore » org.opensubsystems.blog.www 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
003:         * 
004:         * Project: OpenChronicle
005:         * 
006:         * $Id: DynamicBlogNavigator.java,v 1.1 2007/02/20 02:18:11 bastafidli Exp $
007:         * 
008:         * This program is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU General Public License as published by
010:         * the Free Software Foundation; version 2 of the License. 
011:         * 
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
020:         */
021:
022:        package org.opensubsystems.blog.www;
023:
024:        import java.util.logging.Level;
025:        import java.util.logging.Logger;
026:
027:        import javax.servlet.http.HttpServletRequest;
028:
029:        import org.opensubsystems.blog.data.Blog;
030:        import org.opensubsystems.blog.data.Entry;
031:        import org.opensubsystems.core.data.DataConstant;
032:        import org.opensubsystems.core.util.Log;
033:        import org.opensubsystems.core.www.WebCommonConstants;
034:        import org.opensubsystems.core.www.WebUtils;
035:        import org.opensubsystems.patterns.listdata.data.DataCondition;
036:        import org.opensubsystems.patterns.listdata.www.ListBrowserServlet;
037:
038:        /**
039:         * Class responsible for parsing and creating URLs for blogs and their entries.
040:         * The URLs are dynamic that is they use parameter names and values in the URL
041:         * in the format required by the ListBrowserServlet.
042:         *
043:         * @version $Id: DynamicBlogNavigator.java,v 1.1 2007/02/20 02:18:11 bastafidli Exp $
044:         * @author Miro Halas
045:         * @code.reviewer Miro Halas
046:         * @code.reviewed 1.3 2006/07/15 09:09:26 bastafidli
047:         */
048:        public class DynamicBlogNavigator extends BlogNavigator {
049:            // Constants ////////////////////////////////////////////////////////////////
050:
051:            /**
052:             * Page where user can login to the system when accessing the application
053:             * using dynamic URLs.
054:             */
055:            public static final String DYNAMIC_LOGIN_WEB_PAGE = "logindynamic.html";
056:
057:            /**
058:             * Page where user can logout to the system when accessing the application
059:             * using dynamic URLs.
060:             */
061:            public static final String DYNAMIC_LOGOUT_WEB_PAGE = "logoutdynamic.html";
062:
063:            /**
064:             * Static URL that will be used to handle posted data from the dynamic
065:             * pages. This URL will invoke the BlogEditServlet that can handle the
066:             * data posted from the dynamically generated URL and then redirect back
067:             * to the dynamically generated URL.
068:             */
069:            public static final String DYNAMIC_POST_WEB_PAGE = "dynamic.html";
070:
071:            // Cached values ////////////////////////////////////////////////////////////
072:
073:            /**
074:             * Logger for this class
075:             */
076:            private static Logger s_logger = Log
077:                    .getInstance(DynamicBlogNavigator.class);
078:
079:            // Constructors /////////////////////////////////////////////////////////////
080:
081:            /** 
082:             * Creates a new instance of DynamicBlogNavigator 
083:             *
084:             * @param hsrqRequest  - request that will be used by this navigator
085:             */
086:            public DynamicBlogNavigator(HttpServletRequest hsrqRequest) {
087:                super (hsrqRequest);
088:            }
089:
090:            // URL Accessors ////////////////////////////////////////////////////////////
091:
092:            /**
093:             * {@inheritDoc}
094:             */
095:            public boolean getIsDynamic() {
096:                return true;
097:            }
098:
099:            /**
100:             * {@inheritDoc}
101:             */
102:            public String getPostURL() {
103:                // For dynamic navigation the URL will be posted to the servlet which 
104:                // handles the static URLs using special page name to detect that 
105:                // once the processing is done, it should go back to the dynamic URL
106:                return DYNAMIC_POST_WEB_PAGE;
107:            }
108:
109:            /**
110:             * {@inheritDoc}
111:             */
112:            public String getRootURL() {
113:                StringBuffer sbURL;
114:
115:                sbURL = new StringBuffer(m_strBlogDirectoryURL);
116:                sbURL.append("blogs");
117:
118:                return sbURL.toString();
119:            }
120:
121:            /**
122:             * {@inheritDoc}
123:             */
124:            public String getURL(Blog blog) {
125:                return getBlogURL(blog.getIdAsObject());
126:            }
127:
128:            /**
129:             * {@inheritDoc}
130:             */
131:            public String getBlogURL(Object objBlogIdentification) {
132:                String strURL;
133:
134:                if (objBlogIdentification instanceof  Integer) {
135:                    // The object identification is blog id so we can construct the dynamic 
136:                    // URL
137:                    StringBuffer sbURL;
138:
139:                    /*
140:                    <a href="<%=contextpath
141:                       %>/entries?<%=ListBrowserServlet.LIST_PARAM_LIST_PARENT_DATA_TYPE
142:                       %>=<%=DataConstant.BLOG_DATA_TYPE
143:                       %>&<%=ListBrowserServlet.LIST_PARAM_LIST_PARENT_IDENTIFIER
144:                       %>=<bean:write name="blog" property="id" format="#"/>">
145:                     */
146:
147:                    sbURL = new StringBuffer(m_strBlogDirectoryURL);
148:                    sbURL.append("entries");
149:                    sbURL
150:                            .append(WebCommonConstants.URL_PARAMETER_SEPARATOR_CHAR); // ?
151:                    sbURL
152:                            .append(ListBrowserServlet.LIST_PARAM_LIST_PARENT_DATA_TYPE);
153:                    sbURL
154:                            .append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); // =
155:                    sbURL.append(DataConstant.BLOG_DATA_TYPE);
156:                    sbURL
157:                            .append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); // &
158:                    sbURL
159:                            .append(ListBrowserServlet.LIST_PARAM_LIST_PARENT_IDENTIFIER);
160:                    sbURL
161:                            .append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); // =
162:                    sbURL.append(((Integer) objBlogIdentification).intValue());
163:
164:                    strURL = sbURL.toString();
165:                } else {
166:                    strURL = super .getBlogURL(objBlogIdentification);
167:                }
168:
169:                return strURL;
170:            }
171:
172:            /**
173:             * {@inheritDoc}
174:             */
175:            public String getURL(Blog blog, Entry entry) {
176:                return getURL(entry);
177:            }
178:
179:            /**
180:             * {@inheritDoc}
181:             */
182:            public String getURL(Entry entry) {
183:                BlogEntryIdentification entryIdentification = new BlogEntryIdentification();
184:
185:                entryIdentification.m_objBlogIdentification = new Integer(entry
186:                        .getParentId());
187:                entryIdentification.m_iBlogEntryIdentification = entry.getId();
188:
189:                return getURL(entryIdentification);
190:            }
191:
192:            /**
193:             * {@inheritDoc}
194:             */
195:            public String getURL(BlogEntryIdentification entryIdentification) {
196:                StringBuffer sbURL;
197:
198:                /*
199:                <a href="<%=contextpath
200:                   %>/entries?<%=ListBrowserServlet.LIST_PARAM_LIST_PARENT_DATA_TYPE
201:                   %>=<%=DataConstant.BLOG_DATA_TYPE
202:                   %>&<%=ListBrowserServlet.LIST_PARAM_LIST_PARENT_IDENTIFIER
203:                   %>=<bean:write name="blogentry" 
204:                                  property="parentId" 
205:                                  format="#"/>&EXTRA_CONDITION_ATTRIBUTE=<%=Entry.COL_BLOGENTRY_ID
206:                   %>&<%=ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_ATTRIBUTE
207:                   %>=<%=Entry.COL_BLOGENTRY_ID
208:                   %>&<%=ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_OPERAND
209:                   %>=<%=DataCondition.OPERAND_EQUALS
210:                   %>&<%=ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_VALUE_TYPE
211:                   %>=<%=DataCondition.VALUE_TYPE_ID
212:                   %>&<%=ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_VALUE
213:                   %>=<bean:write name="blogentry" 
214:                                  property="id" 
215:                                  format="#"/>">
216:                 */
217:
218:                sbURL = new StringBuffer(m_strBlogDirectoryURL);
219:                sbURL.append("entries");
220:                sbURL.append(WebCommonConstants.URL_PARAMETER_SEPARATOR_CHAR); // ?
221:                sbURL
222:                        .append(ListBrowserServlet.LIST_PARAM_LIST_PARENT_DATA_TYPE);
223:                sbURL
224:                        .append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); // =
225:                sbURL.append(DataConstant.BLOG_DATA_TYPE);
226:                sbURL
227:                        .append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); // &
228:                sbURL
229:                        .append(ListBrowserServlet.LIST_PARAM_LIST_PARENT_IDENTIFIER);
230:                sbURL
231:                        .append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); // =
232:                sbURL
233:                        .append(((Integer) entryIdentification.m_objBlogIdentification)
234:                                .intValue());
235:                sbURL
236:                        .append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); // &
237:                sbURL
238:                        .append(ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_ATTRIBUTE);
239:                sbURL
240:                        .append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); // =
241:                sbURL.append(Entry.COL_BLOGENTRY_ID);
242:                sbURL
243:                        .append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); // &
244:                sbURL
245:                        .append(ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_OPERAND);
246:                sbURL
247:                        .append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); // =
248:                sbURL.append(DataCondition.OPERAND_EQUALS);
249:                sbURL
250:                        .append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); // &
251:                sbURL
252:                        .append(ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_VALUE_TYPE);
253:                sbURL
254:                        .append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); // =
255:                sbURL.append(DataCondition.VALUE_TYPE_ID);
256:                sbURL
257:                        .append(WebCommonConstants.URL_PARAMETER_PARAMETER_SEPARATOR_CHAR); // &
258:                sbURL
259:                        .append(ListBrowserServlet.LIST_PARAM_EXTRA_CONDITION_VALUE);
260:                sbURL
261:                        .append(WebCommonConstants.URL_PARAMETER_VALUE_SEPARATOR_CHAR); // =
262:                sbURL.append(entryIdentification.m_iBlogEntryIdentification);
263:
264:                return sbURL.toString();
265:            }
266:
267:            /**
268:             * {@inheritDoc}
269:             */
270:            public Object getBlogIdentification(HttpServletRequest hsrqRequest) {
271:                Object objReturn;
272:                Integer iBlogId;
273:
274:                iBlogId = getBlogId(hsrqRequest);
275:                if (iBlogId == null) {
276:                    objReturn = super .getBlogIdentification(hsrqRequest);
277:                } else {
278:                    objReturn = iBlogId;
279:                }
280:
281:                return objReturn;
282:            }
283:
284:            /**
285:             * {@inheritDoc}
286:             */
287:            public BlogEntryIdentification getBlogEntryIdentification(
288:                    HttpServletRequest hsrqRequest) {
289:                BlogEntryIdentification entryIdentification = null;
290:                Object objBlogId;
291:                Integer iEntryId;
292:
293:                objBlogId = getBlogId(hsrqRequest);
294:                iEntryId = getBlogEntryId(hsrqRequest);
295:
296:                if ((objBlogId != null) && (iEntryId != null)) {
297:                    entryIdentification = new BlogEntryIdentification();
298:                    entryIdentification.m_objBlogIdentification = objBlogId;
299:                    entryIdentification.m_iBlogEntryIdentification = iEntryId
300:                            .intValue();
301:                } else {
302:                    s_logger.log(Level.FINEST,
303:                            "The request doesn't identify valid Blog entry.");
304:                    // Just return null and let the caller handle it
305:                }
306:
307:                return entryIdentification;
308:            }
309:
310:            /**
311:             * {@inheritDoc}
312:             */
313:            public int isIndexPage() {
314:                // When we are using dynamic navigation using ListBrowserServlet this 
315:                // method should never be called
316:                throw new UnsupportedOperationException(
317:                        "Application should never call this method for dynamic navigation");
318:            }
319:
320:            /**
321:             * {@inheritDoc}
322:             */
323:            public boolean isBlogIndexPage() {
324:                // When we are using dynamic navigation using ListBrowserServlet this 
325:                // method should never be called
326:                throw new UnsupportedOperationException(
327:                        "Application should never call this method for dynamic navigation");
328:            }
329:
330:            /**
331:             * Test if the requested path is path to the page where user can login to 
332:             * the system. 
333:             *
334:             * @return boolean - true if the page is login page 
335:             */
336:            public boolean isLoginPage() {
337:                String strPath;
338:
339:                strPath = WebUtils.getFullRequestPath(m_hsrqRequest);
340:
341:                return strPath.endsWith(DYNAMIC_LOGIN_WEB_PAGE);
342:            }
343:
344:            /**
345:             * Test if the requested path is path to the page where user can login to 
346:             * the system. 
347:             *
348:             * @return boolean - true if the page is login page 
349:             */
350:            public boolean isLogoutPage() {
351:                String strPath;
352:
353:                strPath = WebUtils.getFullRequestPath(m_hsrqRequest);
354:
355:                return strPath.endsWith(DYNAMIC_LOGOUT_WEB_PAGE);
356:            }
357:
358:            /**
359:             * {@inheritDoc}
360:             */
361:            public String getFirstPageURL() {
362:                // When we are using dynamic navigation using ListBrowserServlet we use
363:                // the listdata custom JSP tags and therefore this method is not necessary
364:                throw new UnsupportedOperationException(
365:                        "Application should never call this method for dynamic navigation");
366:            }
367:
368:            /**
369:             * {@inheritDoc}
370:             */
371:            public String getLastPageURL() {
372:                // When we are using dynamic navigation using ListBrowserServlet we use
373:                // the listdata custom JSP tags and therefore this method is not necessary
374:                throw new UnsupportedOperationException(
375:                        "Application should never call this method for dynamic navigation");
376:            }
377:
378:            // Helper methods ///////////////////////////////////////////////////////////
379:
380:            /**
381:             * Get blog id from the request by looking at all possible request parameters
382:             * that can be used in the page or in the URL
383:             * 
384:             * @param  hsrqRequest  - the servlet request.
385:             * @return Integer - id of the blog or null if no is present 
386:             */
387:            protected Integer getBlogId(HttpServletRequest hsrqRequest) {
388:                Integer iBlogId = null;
389:                String strTemp;
390:
391:                // Parse all potential request parameters that can contain blog id 
392:                strTemp = hsrqRequest.getParameter("BLOG_ID");
393:                if (strTemp != null) {
394:                    try {
395:                        iBlogId = new Integer(strTemp);
396:                    } catch (NumberFormatException nfeExc) {
397:                        // Ignore this
398:                    }
399:                }
400:
401:                if (iBlogId == null) {
402:                    strTemp = hsrqRequest.getParameter("BLOGENTRY_BLOG_ID");
403:                    if (strTemp != null) {
404:                        try {
405:                            iBlogId = new Integer(strTemp);
406:                        } catch (NumberFormatException nfeExc) {
407:                            // Ignore this
408:                        }
409:                    }
410:                }
411:
412:                if (iBlogId == null) {
413:                    int iParentDataType = DataConstant.NO_DATA_TYPE;
414:
415:                    strTemp = hsrqRequest
416:                            .getParameter(ListBrowserServlet.LIST_PARAM_LIST_PARENT_DATA_TYPE);
417:                    if (strTemp != null) {
418:                        try {
419:                            iParentDataType = Integer.parseInt(strTemp);
420:                            if (iParentDataType == DataConstant.BLOG_DATA_TYPE) {
421:                                strTemp = hsrqRequest
422:                                        .getParameter(ListBrowserServlet.LIST_PARAM_LIST_PARENT_IDENTIFIER);
423:                                if (strTemp != null) {
424:                                    iBlogId = new Integer(strTemp);
425:                                }
426:                            }
427:                        } catch (NumberFormatException nfeExc) {
428:                            // Ignore this
429:                        }
430:                    }
431:                }
432:
433:                return iBlogId;
434:            }
435:
436:            /**
437:             * Get blog entry id from the request by looking at all possible request 
438:             * parameters that can be used in the page or in the URL
439:             * 
440:             * @param  hsrqRequest  - the servlet request.
441:             * @return Integer - id of the blog entry or null if no is present 
442:             */
443:            protected Integer getBlogEntryId(HttpServletRequest hsrqRequest) {
444:                Integer iBlogEntryId = null;
445:                String strTemp;
446:
447:                // Parse all potential request parameters that can contain blog id 
448:                strTemp = hsrqRequest.getParameter("BLOGENTRY_ID");
449:                if (strTemp != null) {
450:                    try {
451:                        iBlogEntryId = new Integer(strTemp);
452:                    } catch (NumberFormatException nfeExc) {
453:                        // Ignore this
454:                    }
455:                }
456:
457:                return iBlogEntryId;
458:            }
459:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.