KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > RollerRequest


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18
19 package org.apache.roller.ui.core;
20
21 import java.text.ParsePosition JavaDoc;
22 import java.text.SimpleDateFormat JavaDoc;
23 import java.util.Calendar JavaDoc;
24 import java.util.Date JavaDoc;
25
26 import javax.servlet.ServletContext JavaDoc;
27 import javax.servlet.ServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.jsp.PageContext JavaDoc;
30
31 import org.apache.commons.lang.StringUtils;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.apache.roller.RollerException;
35 import org.apache.roller.config.RollerRuntimeConfig;
36 import org.apache.roller.model.Roller;
37 import org.apache.roller.model.RollerFactory;
38 import org.apache.roller.pojos.Template;
39 import org.apache.roller.model.UserManager;
40 import org.apache.roller.model.WeblogManager;
41 import org.apache.roller.pojos.BookmarkData;
42 import org.apache.roller.pojos.FolderData;
43 import org.apache.roller.pojos.UserData;
44 import org.apache.roller.pojos.WeblogCategoryData;
45 import org.apache.roller.pojos.WeblogEntryData;
46 import org.apache.roller.pojos.WebsiteData;
47 import org.apache.roller.util.DateUtil;
48 import org.apache.roller.util.Utilities;
49  
50 //////////////////////////////////////////////////////////////////////////////
51
/**
52  * Access to objects and values specified by request. Parses out arguments from
53  * request URL needed for various parts of Roller and makes them available via
54  * getter methods.
55  * <br/><br/>
56  *
57  * These forms of pathinfo get special support (where 'handle' indicates website):
58  * <br/><br/>
59  *
60  * <pre>
61  * [handle] - get default page for user for today's date
62  * [handle]/[date] - get default page for user for specified date
63  * [handle]/[pagelink] - get specified page for today's date
64  * [handle]/[pagelink]/[date] - get specified page for specified date
65  * [handle]/[pagelink]/[anchor] - get specified page & entry (by anchor)
66  * [handle]/[pagelink]/[date]/[anchor] - get specified page & entry (by anchor)
67  * </pre>
68  *
69  * @author David M Johnson
70  */

71 public class RollerRequest
72 {
73     //----------------------------------------------------------------- Fields
74

75     private static Log mLogger =
76         LogFactory.getFactory().getInstance(RollerRequest.class);
77
78     private BookmarkData mBookmark;
79     private ServletContext JavaDoc mContext = null;
80     private Date JavaDoc mDate = null;
81     private String JavaDoc mDateString = null;
82     private String JavaDoc mPathInfo = null;
83     private String JavaDoc mPageLink = null;
84     private Template mPage;
85     private PageContext JavaDoc mPageContext = null;
86     private HttpServletRequest JavaDoc mRequest = null;
87     private WebsiteData mWebsite;
88     private WeblogEntryData mWeblogEntry;
89     private WeblogCategoryData mWeblogCategory;
90     
91     private boolean mIsDaySpecified = false;
92     private boolean mIsMonthSpecified = false;
93         
94     private static ThreadLocal JavaDoc mRollerRequestTLS = new ThreadLocal JavaDoc();
95     
96     public static final String JavaDoc ROLLER_REQUEST = "roller_request";
97     
98     private SimpleDateFormat JavaDoc m8charDateFormat = DateUtil.get8charDateFormat();
99     private SimpleDateFormat JavaDoc m6charDateFormat = DateUtil.get6charDateFormat();
100
101     //----------------------------------------------------------- Constructors
102

103     /** Construct Roller request for a Servlet request */
104     public RollerRequest( HttpServletRequest JavaDoc req, ServletContext JavaDoc ctx )
105         throws RollerException
106     {
107         mRequest = req;
108         mContext = ctx;
109         init();
110     }
111     
112     /** Convenience */
113     public RollerRequest( ServletRequest JavaDoc req, ServletContext JavaDoc ctx )
114         throws RollerException
115     {
116         mRequest = (HttpServletRequest JavaDoc)req;
117         mContext = ctx;
118         init();
119     }
120     
121     public RollerRequest( PageContext JavaDoc pCtx) throws RollerException
122     {
123         mRequest = (HttpServletRequest JavaDoc) pCtx.getRequest();
124         mContext = pCtx.getServletContext();
125         mPageContext = pCtx;
126         init();
127     }
128
129     private void init() throws RollerException
130     {
131         mRollerRequestTLS.set(this);
132         if (mRequest.getContextPath().equals("/atom"))
133         {
134             return; // Atom servlet request needs no init
135
}
136         
137         // Bind persistence session to authenticated user, if we have one
138
RollerContext rctx = RollerContext.getRollerContext();
139         Authenticator auth = rctx.getAuthenticator();
140         String JavaDoc userName = auth.getAuthenticatedUserName(mRequest);
141         if (userName != null)
142         {
143             UserManager userMgr = RollerFactory.getRoller().getUserManager();
144             UserData currentUser = userMgr.getUserByUserName(userName);
145             // TODO: possible fix for backend refactoryings
146
//RollerFactory.getRoller().setUser(currentUser);
147
}
148         
149         // path info may be null, (e.g. on JSP error page)
150
mPathInfo = mRequest.getPathInfo();
151         mPathInfo = (mPathInfo!=null) ? mPathInfo : "";
152         
153         String JavaDoc[] pathInfo = StringUtils.split(mPathInfo,"/");
154         if ( pathInfo.length > 0 )
155         {
156             // Parse pathInfo and throw exception if it is invalid
157
if (!"j_security_check".equals(pathInfo[0]))
158             {
159                 parsePathInfo( pathInfo );
160                 return;
161             }
162         }
163
164         // Parse user, page, and entry from request params if possible
165
parseRequestParams();
166     }
167     
168     public String JavaDoc toString()
169     {
170         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
171         sb.append("[");
172         sb.append(getRequestURL());
173         sb.append(", ");
174         sb.append(getRefererURL());
175         sb.append("]");
176         return sb.toString();
177     }
178
179     //------------------------------------------------------------------------
180
/**
181      * Bind persistence session to specific user.
182      */

183     private void bindUser() throws RollerException
184     {
185     }
186     
187     //------------------------------------------------------------------------
188
/** Parse pathInfo and throw exception if it is invalid */
189     private void parsePathInfo( String JavaDoc[] pathInfo ) throws RollerException
190     {
191         try
192         {
193             // If there is any path info, it must be in one of the
194
// below formats or the request is considered to be invalid.
195
//
196
// /username
197
// /username/datestring
198
// /username/pagelink
199
// /username/pagelink/datestring
200
// /username/pagelink/anchor (specific entry)
201
// /username/pagelink/datestring/anchor (specific entry)
202
Roller roller = RollerFactory.getRoller();
203             UserManager userMgr = roller.getUserManager();
204             mWebsite = userMgr.getWebsiteByHandle(pathInfo[0]);
205             if (mWebsite != null)
206             {
207                 if ( pathInfo.length == 1 )
208                 {
209                     // we have the /username form of URL
210
mPage = mWebsite.getDefaultPage();
211                 }
212                 else if ( pathInfo.length == 2 )
213                 {
214                     mDate = parseDate(pathInfo[1]);
215                     if ( mDate == null ) // pre-jdk1.4 --> || mDate.getYear() <= 70 )
216
{
217                         // we have the /username/pagelink form of URL
218
mPageLink = pathInfo[1];
219                         mPage = mWebsite.getPageByLink(pathInfo[1]);
220                     }
221                     else
222                     {
223                         // we have the /username/datestring form of URL
224
mDateString = pathInfo[1];
225                         mPage = mWebsite.getDefaultPage();
226                         if (pathInfo[1].length() == 8) {
227                             mIsDaySpecified = true;
228                         } else {
229                             mIsMonthSpecified = true;
230                         }
231                     }
232                 }
233                 else if ( pathInfo.length == 3 )
234                 {
235                     mPageLink = pathInfo[1];
236                     mPage = mWebsite.getPageByLink(pathInfo[1]);
237                     
238                     mDate = parseDate(pathInfo[2]);
239                     if ( mDate == null ) // pre-jdk1.4 --> || mDate.getYear() <= 70 )
240
{
241                         // we have the /username/pagelink/anchor form of URL
242
try
243                         {
244                             WeblogManager weblogMgr = roller.getWeblogManager();
245                             mWeblogEntry = weblogMgr.getWeblogEntryByAnchor(
246                                 mWebsite, pathInfo[2]);
247                         }
248                         catch (Exception JavaDoc e)
249                         {
250                             mLogger.debug("Can't find entry by anchor", e);
251                         }
252                     }
253                     else
254                     {
255                         // we have the /username/pagelink/datestring form of URL
256
mDateString = pathInfo[2];
257                         if (pathInfo[1].length() == 8) {
258                             mIsDaySpecified = true;
259                         } else {
260                             mIsMonthSpecified = true;
261                         }
262                     }
263                 }
264                 else if ( pathInfo.length == 4 )
265                 {
266                     // we have the /username/pagelink/datestring/anchor form of URL
267
mPageLink = pathInfo[1];
268                     mPage = mWebsite.getPageByLink(pathInfo[1]);
269                     
270                     mDate = parseDate(pathInfo[2]);
271                     mDateString = pathInfo[2];
272                     if (pathInfo[1].length() == 8) {
273                         mIsDaySpecified = true;
274                     } else {
275                         mIsMonthSpecified = true;
276                     }
277
278                     // we have the /username/pagelink/date/anchor form of URL
279
WeblogManager weblogMgr = RollerFactory.getRoller().getWeblogManager();
280                     mWeblogEntry = weblogMgr.getWeblogEntryByAnchor(
281                                     mWebsite, pathInfo[3]);
282                 }
283             }
284             if (mDate == null && mWeblogEntry != null)
285             {
286                 mDate = mWeblogEntry.getPubTime();
287                 //mDateString = DateUtil.format8chars(mDate);
288
}
289         }
290         catch ( Exception JavaDoc ignored )
291         {
292             mLogger.debug("Exception parsing pathInfo",ignored);
293         }
294         
295         // NOTE: let the caller handle missing website/page instead
296
if ( mWebsite==null || mPage==null )
297         {
298             String JavaDoc msg = "Invalid pathInfo: "+StringUtils.join(pathInfo,"|");
299             throw new RollerException(msg);
300         }
301     }
302     
303     //------------------------------------------------------------------------
304
/** Parse user, page, and entry from request params if possible */
305     private void parseRequestParams()
306     {
307         try
308         {
309             // No path info means that we need to parse request params
310

311             // First, look for user in the request params
312
UserManager userMgr = RollerFactory.getRoller().getUserManager();
313             String JavaDoc userName = mRequest.getParameter(RequestConstants.USERNAME);
314             if ( userName == null )
315             {
316                 // then try remote user
317
userName = mRequest.getRemoteUser();
318             }
319             
320             String JavaDoc handle = mRequest.getParameter(RequestConstants.WEBLOG);
321             String JavaDoc websiteid = mRequest.getParameter(RequestConstants.WEBLOG_ID);
322             if (handle != null && mWebsite == null)
323             {
324                 mWebsite = userMgr.getWebsiteByHandle(handle);
325             }
326             else if (websiteid != null && mWebsite == null )
327             {
328                 mWebsite = userMgr.getWebsite(websiteid);
329             }
330             
331             // Look for page ID in request params
332
String JavaDoc pageId = mRequest.getParameter(RequestConstants.PAGE_ID);
333             if ( pageId != null )
334             {
335                 mPage = userMgr.getPage(pageId);
336             }
337             else if (mWebsite != null)
338             {
339                 mPage = mWebsite.getDefaultPage();
340             }
341                                        
342             // Look for day in request params
343
// no longer used
344
// String daystr = mRequest.getParameter(RollerConstants.WEBLOGDAY);
345
// if ( daystr != null )
346
// {
347
// mDate = parseDate(daystr);
348
// if ( mDate != null )
349
// {
350
// // we have the /username/datestring form of URL
351
// mDateString = daystr;
352
// mIsDaySpecified = true;
353
// }
354
// }
355
}
356         catch ( Exception JavaDoc ignored )
357         {
358             mLogger.debug("Exception parsing request params",ignored);
359         }
360     }
361
362     //------------------------------------------------------------------------
363
/** Get HttpServletmRequest that is wrapped by this RollerRequest */
364     public PageContext JavaDoc getPageContext()
365     {
366         return mPageContext;
367     }
368     
369     public void setPageContext(PageContext JavaDoc p)
370     {
371         mPageContext = p;
372     }
373
374     //------------------------------------------------------------------------
375
/** Get HttpServletmRequest that is wrapped by this RollerRequest */
376     public HttpServletRequest JavaDoc getRequest()
377     {
378         return mRequest;
379     }
380
381     //------------------------------------------------------------------------
382
/**
383      * Get the RollerRequest object that is stored in the request. Creates
384      * RollerRequest if one not found in mRequest.
385      */

386     public static RollerRequest getRollerRequest(
387         HttpServletRequest JavaDoc r, ServletContext JavaDoc ctx ) throws RollerException
388     {
389         RollerRequest ret= (RollerRequest)r.getAttribute(ROLLER_REQUEST);
390         if ( ret == null )
391         {
392             ret = new RollerRequest(r,ctx);
393             r.setAttribute( ROLLER_REQUEST, ret );
394         }
395         return ret;
396     }
397
398     //------------------------------------------------------------------------
399
/**
400      * Get the RollerRequest object that is stored in the request. Creates
401      * RollerRequest if one not found in mRequest.
402      */

403     public static RollerRequest getRollerRequest( HttpServletRequest JavaDoc r )
404     {
405         try
406         {
407             return getRollerRequest(r, RollerContext.getServletContext());
408         }
409         catch (Exception JavaDoc e)
410         {
411             mLogger.debug("Unable to create a RollerRequest", e);
412         }
413         return null;
414     }
415
416     //------------------------------------------------------------------------
417
/**
418      * Get the RollerRequest object that is stored in the request. Creates
419      * RollerRequest if one not found in mRequest.
420      */

421     public static RollerRequest getRollerRequest( PageContext JavaDoc p )
422             throws RollerException {
423         
424         HttpServletRequest JavaDoc r = (HttpServletRequest JavaDoc)p.getRequest();
425         RollerRequest ret = (RollerRequest)r.getAttribute(ROLLER_REQUEST);
426         if (ret == null)
427         {
428                 ret = new RollerRequest( p );
429                 r.setAttribute( ROLLER_REQUEST, ret );
430         }
431         else
432         {
433             ret.setPageContext( p );
434         }
435         return ret;
436     }
437
438     //------------------------------------------------------------------------
439
/**
440      * Get RollerRequest object for the current thread using EVIL MAGIC,
441      * do not use unless you absolutely, positively, cannot use on of the
442      * getRollerRequest() methods.
443      */

444     public static RollerRequest getRollerRequest()
445     {
446         return (RollerRequest)mRollerRequestTLS.get();
447     }
448
449     //------------------------------------------------------------------------
450
/**
451      * Get the RollerRequest object that is stored in the requeset.
452      * Creates RollerRequest if one not found in mRequest.
453      */

454     public ServletContext JavaDoc getServletContext()
455     {
456         return mContext;
457     }
458     
459     //-----------------------------------------------------------------------------
460

461     public boolean isDaySpecified()
462     {
463         return mIsDaySpecified;
464     }
465     
466     public boolean isMonthSpecified()
467     {
468         return mIsMonthSpecified;
469     }
470                 
471     //--------------------------------------------------- Date specified by request
472

473     /**
474      * Gets the date specified by the request, or null.
475      * @return Date
476      */

477     public Date JavaDoc getDate()
478     {
479         return getDate(false);
480     }
481     
482     /**
483      * Gets the date specified by the request
484      * @param orToday If no date specified, then use today's date.
485      * @return Date
486      */

487     public Date JavaDoc getDate( boolean orToday )
488     {
489         Date JavaDoc ret = null;
490         if ( mDate != null )
491         {
492             ret = mDate;
493         }
494         else if ( orToday )
495         {
496             ret = getToday();
497         }
498         return ret;
499     }
500  
501     /**
502      * Gets the current date based on Website's Locale & Timezone.
503      * @return
504      */

505     private Date JavaDoc getToday()
506     {
507         Calendar JavaDoc todayCal = Calendar.getInstance();
508         if (this.getWebsite() != null)
509         {
510             todayCal = Calendar.getInstance(
511                     this.getWebsite().getTimeZoneInstance(),
512                     this.getWebsite().getLocaleInstance());
513         }
514         todayCal.setTime( new Date JavaDoc() );
515         return todayCal.getTime();
516     }
517
518     /*
519      * Gets the YYYYMMDD or YYYYMM date string specified by the request, or null.
520      * @return String
521      */

522     public String JavaDoc getDateString1()
523     {
524         return mDateString;
525     }
526     
527     //------------------------------------------------------------------------
528
/**
529      * Gets the path-info specified by the request, or null.
530      * @return String
531      */

532     public String JavaDoc getPathInfo()
533     {
534         return mPathInfo;
535     }
536
537     //------------------------------------------------------------------------
538
/**
539      * Gets the page link name specified by the request, or null.
540      * @return String
541      */

542     public String JavaDoc getPageLink()
543     {
544         return mPageLink;
545     }
546
547     public int getWeblogEntryCount()
548     {
549         // Get count of entries to return, or 20 if null
550
int count = 20;
551         if ( mRequest.getParameter("count") != null )
552         {
553             count= Utilities.stringToInt(mRequest.getParameter("count"));
554             if ( count==0 || count>50 )
555             {
556                 count = 20;
557             }
558         }
559         return count;
560     }
561             
562     //------------------------------------------------------------------------
563
/**
564      * Gets the BookmarkData specified by the request, or null.
565      * @return BookmarkData
566      */

567     public BookmarkData getBookmark( )
568     {
569         if ( mBookmark == null )
570         {
571             String JavaDoc id = getFromRequest(RequestConstants.BOOKMARK_ID);
572             if ( id != null )
573             {
574                 try
575                 {
576                     mBookmark = RollerFactory.getRoller()
577                         .getBookmarkManager().getBookmark(id);
578                 }
579                 catch (RollerException e)
580                 {
581                     mLogger.error("Getting bookmark from request",e);
582                 }
583             }
584         }
585         return mBookmark;
586     }
587
588     //------------------------------------------------------------------------
589
/**
590      * Gets the WeblogCategoryData specified by the request, or null.
591      * @return
592      */

593     public WeblogCategoryData getWeblogCategory()
594     {
595         if ( mWeblogCategory == null )
596         {
597             String JavaDoc id = getFromRequest(RequestConstants.WEBLOGCATEGORY_ID);
598             if ( id != null )
599             {
600                 try
601                 {
602                     mWeblogCategory =
603                         RollerFactory.getRoller()
604                             .getWeblogManager().getWeblogCategory(id);
605                 }
606                 catch (RollerException e)
607                 {
608                     mLogger.error("Getting weblog category by id from request",e);
609                 }
610             }
611             else if (StringUtils.isNotEmpty(id = getFromRequest(RequestConstants.WEBLOGCATEGORY)))
612             {
613                 try
614                 {
615                     mWeblogCategory =
616                         RollerFactory.getRoller()
617                             .getWeblogManager().getWeblogCategoryByPath(
618                                     getWebsite(), null, id);
619                 }
620                 catch (RollerException e)
621                 {
622                     mLogger.error("Getting weblog category by name from request",e);
623                 }
624             }
625         }
626         return mWeblogCategory;
627     }
628
629     //------------------------------------------------------------------------
630
/**
631      * Gets the FolderData specified by the request, or null.
632      * @return FolderData
633      */

634     public FolderData getFolder( )
635     {
636         FolderData folder = null;
637         //if ( folder == null )
638
//{
639
String JavaDoc id = getFromRequest(RequestConstants.FOLDER_ID);
640             if ( id != null )
641             {
642                 try
643                 {
644                     folder = RollerFactory.getRoller()
645                         .getBookmarkManager().getFolder(id);
646                 }
647                 catch (RollerException e)
648                 {
649                     mLogger.error("Getting folder from request",e);
650                 }
651             }
652         //}
653
return folder;
654     }
655
656     //------------------------------------------------------------------------
657
/**
658      * Gets the WeblogTemplate specified by the request, or null.
659      * @return WeblogTemplate
660      */

661     public Template getPage()
662     {
663         if (mPage == null)
664         {
665             String JavaDoc id = getFromRequest(RequestConstants.PAGE_ID);
666             if ( id != null )
667             {
668                 try
669                 {
670                     mPage = RollerFactory.getRoller()
671                         .getUserManager().getPage(id);
672                 }
673                 catch (RollerException e)
674                 {
675                     mLogger.error("Getting page from request",e);
676                 }
677             }
678         }
679         return mPage;
680     }
681     
682     /**
683      * Allow comment servlet to inject page that it has chosen.
684      */

685     public void setPage(org.apache.roller.pojos.Template page)
686     {
687         mPage = page;
688     }
689     
690     //------------------------------------------------------------------------
691
/**
692      * Gets the Request URL specified by the request, or null.
693      * @return String
694      */

695     public String JavaDoc getRequestURL( )
696     {
697         return mRequest.getRequestURL().toString();
698     }
699     
700     //------------------------------------------------------------------------
701

702     /**
703      * Gets the Referer URL specified by the request, or null.
704      * @return String
705      */

706     public String JavaDoc getRefererURL( )
707     {
708         return mRequest.getHeader("referer");
709     }
710      
711     /**
712      * Gets the WebsiteData specified in the path info of the request URI, this is
713      * NOT the same thing as the "current website" (i.e. the one that the session's
714      * authenticated user is currently editing).
715      * @return WebsiteData object specified by request URI.
716      */

717     public WebsiteData getWebsite()
718     {
719         return mWebsite;
720     }
721     public void setWebsite(WebsiteData wd)
722     {
723         mWebsite = wd;
724     }
725     
726     /**
727      * Gets the WeblogEntryData specified by the request, or null.
728      *
729      * Why is this done lazily in the parseRequestParameters() method?
730      *
731      * Because: that method is called from init(), which is called from
732      * a ServletFilter, and sometimes request parameters are not available
733      * in a ServletFiler. They ARE available when the URL points to a JSP,
734      * but they ARE NOT available when the URL points to the PageServlet.
735      * This may be a Tomcat bug, I'm not sure.
736      *
737      * @return WeblogEntryData
738      */

739     public WeblogEntryData getWeblogEntry( )
740     {
741         if ( mWeblogEntry == null )
742         {
743             // Look for anchor or entry ID that identifies a specific entry
744
String JavaDoc anchor = mRequest.getParameter(RequestConstants.ANCHOR);
745             if (anchor == null) anchor = mRequest.getParameter(RequestConstants.ANCHOR);
746             String JavaDoc entryid = mRequest.getParameter(RequestConstants.WEBLOGENTRY_ID);
747             if (entryid == null)
748             {
749                 entryid = (String JavaDoc)mRequest.getAttribute(RequestConstants.WEBLOGENTRY_ID);
750             }
751             try
752             {
753                 if ( entryid != null )
754                 {
755                     WeblogManager weblogMgr = RollerFactory.getRoller().getWeblogManager();
756                     mWeblogEntry = weblogMgr.getWeblogEntry(entryid);
757                 
758                     // We can use entry to find the website, if we don't have one
759
if ( mWeblogEntry != null && mWebsite == null )
760                     {
761                         mWebsite = mWeblogEntry.getWebsite();
762                     }
763                 }
764                 else if ( mWebsite != null && anchor != null )
765                 {
766                     WeblogManager weblogMgr =
767                         RollerFactory.getRoller().getWeblogManager();
768                     mWeblogEntry = weblogMgr.getWeblogEntryByAnchor(
769                         mWebsite,anchor);
770                 }
771             }
772             catch (RollerException e)
773             {
774                 mLogger.error("EXCEPTION getting weblog entry",e);
775                 mLogger.error("anchor=" + anchor);
776                 mLogger.error("entryid=" + entryid);
777             }
778             if (mDate == null && mWeblogEntry != null)
779             {
780                 mDate = mWeblogEntry.getPubTime();
781                 mDateString = DateUtil.format8chars(mDate);
782             }
783         }
784         return mWeblogEntry;
785     }
786
787     //-----------------------------------------------------------------------------
788

789     /** Get attribute from mRequest, and if that fails try session */
790     private String JavaDoc getFromRequest( String JavaDoc key )
791     {
792         String JavaDoc ret = (String JavaDoc)mRequest.getAttribute( key );
793         if ( ret == null )
794         {
795             ret = mRequest.getParameter( key );
796             if (ret == null && mRequest.getSession(false) != null)
797             {
798                 ret = (String JavaDoc)mRequest.getSession().getAttribute( key );
799             }
800         }
801         return ret;
802     }
803
804     private Date JavaDoc parseDate( String JavaDoc dateString )
805     {
806         Date JavaDoc ret = null;
807         if ( dateString!=null
808             && dateString.length()==8
809             && StringUtils.isNumeric(dateString) )
810         {
811             ParsePosition JavaDoc pos = new ParsePosition JavaDoc(0);
812             ret = m8charDateFormat.parse( dateString, pos );
813             
814             // make sure the requested date is not in the future
815
Date JavaDoc today = getToday();
816             if (ret.after(today)) ret = today;
817             
818             // Do this later, once we know what timezone to use
819
// ret = DateUtil.getEndOfDay(ret);
820
}
821         if ( dateString!=null
822             && dateString.length()==6
823             && StringUtils.isNumeric(dateString) )
824         {
825             ParsePosition JavaDoc pos = new ParsePosition JavaDoc(0);
826             ret = m6charDateFormat.parse( dateString, pos );
827             
828             // make sure the requested date is not in the future
829
Date JavaDoc today = getToday();
830             if (ret.after(today)) ret = today;
831             
832             // Do this later, once we know what timezone to use
833
// ret = DateUtil.getEndOfMonth(ret);
834
}
835         return ret;
836     }
837     
838     /**
839      * @see org.apache.roller.pojos.ParsedRequest#isLinkbackEnabled()
840      */

841     public boolean isEnableLinkback()
842     {
843         return RollerRuntimeConfig.getBooleanProperty("site.linkbacks.enabled");
844     }
845
846 }
847
848
Popular Tags