You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/07/11 15:33:46 UTC
svn commit: r420840 - in
/incubator/roller/branches/roller_3.0/src/org/apache/roller:
ui/authoring/struts/actions/ ui/authoring/tags/ ui/core/
ui/core/tags/calendar/ ui/rendering/model/ ui/rendering/util/
ui/rendering/velocity/deprecated/ util/
Author: snoopdave
Date: Tue Jul 11 06:33:44 2006
New Revision: 420840
URL: http://svn.apache.org/viewvc?rev=420840&view=rev
Log:
Calendar tag/model now uses new URLs
Added:
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/BigWeblogCalendarModel.java
- copied, changed from r420546, incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/BigWeblogCalendarModel.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java
- copied, changed from r420546, incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/WeblogCalendarModel.java
Removed:
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/BigWeblogCalendarModel.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/EditWeblogCalendarModel.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/WeblogCalendarModel.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/RenderDayPager.java
Modified:
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/ (props changed)
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryPageModel.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/RollerRequest.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarHelper.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/deprecated/ (props changed)
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/deprecated/OldPageHelper.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java
Propchange: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jul 11 06:33:44 2006
@@ -0,0 +1 @@
+.LCKWeblogEntryPageModel.java~
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryPageModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryPageModel.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryPageModel.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/WeblogEntryPageModel.java Tue Jul 11 06:33:44 2006
@@ -41,7 +41,6 @@
import org.apache.roller.ui.core.tags.calendar.CalendarModel;
import org.apache.roller.ui.authoring.struts.actions.WeblogEntryPageModel.PageMode;
import org.apache.roller.ui.authoring.struts.formbeans.WeblogEntryFormEx;
-import org.apache.roller.ui.authoring.tags.EditWeblogCalendarModel;
import org.apache.commons.lang.StringUtils;
//import com.swabunga.spell.event.SpellCheckEvent;
@@ -50,6 +49,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.roller.model.PluginManager;
import org.apache.roller.model.Roller;
+import org.apache.roller.ui.core.tags.calendar.WeblogCalendarModel;
/**
* All data needed to render the edit-weblog page.
@@ -251,19 +251,6 @@
editorPage = "editor-text.jsp";
}
return editorPage;
- }
-
- public CalendarModel getCalendarModel() throws Exception
- {
- // Determine URL to self
- ActionForward selfForward = getMapping().findForward("editWeblog");
- String selfUrl= getRequest().getContextPath()+selfForward.getPath();
-
- // Setup weblog calendar model
- CalendarModel model = new EditWeblogCalendarModel(
- rollerRequest.getRequest(), getResponse(),
- rollerRequest.getWebsite(), rollerRequest.getDate(true), selfUrl );
- return model;
}
public UserData getUser()
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/RollerRequest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/RollerRequest.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/RollerRequest.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/RollerRequest.java Tue Jul 11 06:33:44 2006
@@ -101,7 +101,7 @@
public static final String PAGELINK_KEY = "pagelink";
public static final String EXCERPTS_KEY = "excerpts";
public static final String WEBLOGENTRY_COUNT = "count";
- public static final String WEBLOGCATEGORYNAME_KEY = "catname";
+ public static final String WEBLOGCATEGORYNAME_KEY = "cat";
public static final String WEBLOGENTRIES_KEY = "entries";
public static final String WEBLOGDAY_KEY = "day";
Copied: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/BigWeblogCalendarModel.java (from r420546, incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/BigWeblogCalendarModel.java)
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/BigWeblogCalendarModel.java?p2=incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/BigWeblogCalendarModel.java&p1=incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/BigWeblogCalendarModel.java&r1=420546&r2=420840&rev=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/BigWeblogCalendarModel.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/BigWeblogCalendarModel.java Tue Jul 11 06:33:44 2006
@@ -1,21 +1,21 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
-package org.apache.roller.ui.authoring.tags;
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.roller.ui.core.tags.calendar;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -32,6 +32,7 @@
import org.apache.roller.model.WeblogManager;
import org.apache.roller.pojos.WeblogEntryData;
import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.ui.authoring.tags.*;
import org.apache.roller.ui.core.RollerContext;
import org.apache.roller.ui.core.RollerRequest;
import org.apache.roller.util.DateUtil;
@@ -40,129 +41,74 @@
* Model for big calendar that displays titles for each day.
* @author David M Johnson
*/
-public class BigWeblogCalendarModel extends WeblogCalendarModel
-{
- private static Log mLogger =
- LogFactory.getFactory().getInstance(BigWeblogCalendarModel.class);
+public class BigWeblogCalendarModel extends WeblogCalendarModel {
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(BigWeblogCalendarModel.class);
+
+ protected static final SimpleDateFormat mStarDateFormat =
+ DateUtil.get8charDateFormat();
+
+ protected static final SimpleDateFormat mSingleDayFormat =
+ new SimpleDateFormat("dd");
- protected static final SimpleDateFormat mStarDateFormat =
- DateUtil.get8charDateFormat();
-
- protected static final SimpleDateFormat mSingleDayFormat =
- new SimpleDateFormat("dd");
-
/**
* @param rreq
* @param res
* @param url
* @param cat
*/
- public BigWeblogCalendarModel(HttpServletRequest req, HttpServletResponse res,
- WebsiteData website, Date date, String url, String cat)
- {
- super(req, res, website, date, url, cat);
+ public BigWeblogCalendarModel(HttpServletRequest req, HttpServletResponse res, String cat) {
+ super(req, res, cat);
}
/**
* @param startDate
* @param endDate
*/
- protected void loadWeblogEntries(Date startDate, Date endDate, String catName)
- {
- try
- {
+ protected void loadWeblogEntries(Date startDate, Date endDate, String catName) {
+ try {
WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
- mMonthMap = mgr.getWeblogEntryObjectMap(
- mWebsite, // website
- startDate, // startDate
- endDate, // endDate
- catName, // catName
- WeblogEntryData.PUBLISHED, // status
- 0, -1
- );
- }
- catch (RollerException e)
- {
+ monthMap = mgr.getWeblogEntryObjectMap(
+ weblog, // website
+ startDate, // startDate
+ endDate, // endDate
+ catName, // cat
+ WeblogEntryData.PUBLISHED, // status
+ 0, -1
+ );
+ } catch (RollerException e) {
mLogger.error(e);
- mMonthMap = new HashMap();
+ monthMap = new HashMap();
}
}
-
- /**
- * Create URL for use on view-weblog page, ignores query-string.
- * @param day Day for URL
- * @param valid Always return a URL, never return null
- * @return URL for day, or null if no weblog entry on that day
- */
- public String computeUrl(Date day, boolean valid)
- {
- String url = null;
- try
- {
- if ( day == null )
- {
- url = mSelfUrl + mCatName;
- }
- else
- {
- // get the 8 char YYYYMMDD datestring for day, returns null
- // if no weblog entry on that day
- String dateString = null;
- List entries =
- (List)mMonthMap.get( day );
- if ( entries != null && day != null )
- {
- WeblogEntryData entry = (WeblogEntryData)entries.get(0);
- dateString =
- mStarDateFormat.format(entry.getPubTime());
-
- // append 8 char date string on end of selfurl
- url = mSelfUrl+"/"+dateString+mCatName;
- }
- else if ( entries != null )
- {
- url = mSelfUrl+"/"+mCatName;
- }
- else if ( valid )
- {
- // Make the date yyyyMMdd and append it to URL
- dateString = mStarDateFormat.format( day );
- url = mSelfUrl+"/"+dateString+mCatName;
- }
- }
- }
- catch (Exception e)
- {
- RollerRequest.getRollerRequest(mReq)
- .getServletContext().log("ERROR: creating URL",e);
- }
- return url;
- }
-
+
/**
* @see org.apache.roller.presentation.tags.calendar.CalendarModel#getContent(Date, boolean)
*/
- public String getContent(Date day)
- {
+ public String getContent(Date day) {
String content = null;
- try
- {
- RollerRequest rreq = RollerRequest.getRollerRequest(mReq);
- RollerContext rctx = RollerContext.getRollerContext();
+ try {
+ RollerRequest rreq = RollerRequest.getRollerRequest(request);
+ RollerContext rctx = RollerContext.getRollerContext();
StringBuffer sb = new StringBuffer();
- // get the 8 char YYYYMMDD datestring for day, returns null
+ // get the 8 char YYYYMMDD datestring for day, returns null
// if no weblog entry on that day
String dateString = null;
- List entries = (List)mMonthMap.get(day);
- if ( entries != null )
- {
- dateString = mStarDateFormat.format(
- ((WeblogEntryData)entries.get(0)).getPubTime());
-
+ List entries = (List)monthMap.get(day);
+ if ( entries != null ) {
+ dateString = mStarDateFormat.format(
+ ((WeblogEntryData)entries.get(0)).getPubTime());
+
// append 8 char date string on end of selfurl
- String dayUrl = mSelfUrl+"/"+ dateString+mCatName;
-
+ String dayUrl = null;
+ if (pageLink != null) {
+ dayUrl = weblog.getURL() + "/page/" + "?date=" + dateString + "&cat="+ cat;
+ } else {
+ dayUrl = weblog.getURL() + "/date/" + dateString + "?cat="+ cat;
+ }
+
+
sb.append("<div class=\"hCalendarDayTitleBig\">");
sb.append("<a href=\"");
sb.append( dayUrl );
@@ -170,42 +116,35 @@
sb.append( mSingleDayFormat.format( day ) );
sb.append("</a></div>");
- for ( int i=0; i<entries.size(); i++ )
- {
+ for ( int i=0; i<entries.size(); i++ ) {
sb.append("<div class=\"bCalendarDayContentBig\">");
sb.append("<a href=\"");
sb.append(rctx.createEntryPermalink(
- (WeblogEntryData)entries.get(i),mReq,false));
+ (WeblogEntryData)entries.get(i),request,false));
sb.append("\">");
String title = ((WeblogEntryData)entries.get(i)).getTitle().trim();
- if ( title.length()==0 )
- {
+ if ( title.length()==0 ) {
title = ((WeblogEntryData)entries.get(i)).getAnchor();
}
- if ( title.length() > 20 )
- {
+ if ( title.length() > 20 ) {
title = title.substring(0,20)+"...";
}
-
+
sb.append( title );
- sb.append("</a></div>");
- }
+ sb.append("</a></div>");
+ }
- }
- else
- {
+ } else {
sb.append("<div class=\"hCalendarDayTitleBig\">");
sb.append( mSingleDayFormat.format( day ) );
sb.append("</div>");
sb.append("<div class=\"bCalendarDayContentBig\"/>");
}
- content = sb.toString();
- }
- catch (Exception e)
- {
- RollerRequest.getRollerRequest(mReq)
- .getServletContext().log("ERROR: creating URL",e);
+ content = sb.toString();
+ } catch (Exception e) {
+ RollerRequest.getRollerRequest(request)
+ .getServletContext().log("ERROR: creating URL",e);
}
return content;
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarModel.java Tue Jul 11 06:33:44 2006
@@ -1,60 +1,60 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.ui.core.tags.calendar;
import java.util.Calendar;
import java.util.Date;
-/**
- * Model interface for the CalendarTag. The CalendarTag will set a day,
+/**
+ * Model interface for the CalendarTag. The CalendarTag will set a day,
* then use the computeUrl method to get the URLs it needs.
*/
-public interface CalendarModel
-{
+public interface CalendarModel {
public Calendar getCalendar();
- public void setDay( String month ) throws Exception;
+ public void setDay( String month ) throws Exception;
- public Date getDay();
+ public Date getDay();
public Date getNextMonth();
- public String computePrevMonthUrl();
-
- public String computeTodayMonthUrl();
-
+ public String computePrevMonthUrl();
+
+ public String computeTodayMonthUrl();
+
public String computeNextMonthUrl();
- /**
+ /**
* Create URL for use on edit-weblog page, preserves the request
* parameters used by the tabbed-menu tag for navigation.
- *
- * @param day Day for URL
- * @param valid Always return a URL, never return null
- * @return URL for day, or null if no weblog entry on that day
+ *
+ * @param day Day for URL
+ * @param monthURL True to return month URL (6-char date)
+ * @param valid Always return a URL, never return null
+ * @return URL for day, or null if no weblog entry on that day
*/
- public String computeUrl( java.util.Date day, boolean valid );
+ public String computeUrl( java.util.Date day, boolean monthURL, boolean valid );
- /**
+ /**
* Get calendar cell content or null if none.
- *
+ *
* @param day Day for URL
- * @param valid Always return a URL, never return null
+ * @param valid Always return a URL, never return null
* @return Calendar cell content or null if none.
*/
public String getContent( java.util.Date day );
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/CalendarTag.java Tue Jul 11 06:33:44 2006
@@ -222,7 +222,7 @@
// determine URL for this calendar day
Date tddate = cal.getTime();
- String url = model.computeUrl( tddate, false );
+ String url = model.computeUrl(tddate, false, false);
String content = model.getContent( tddate );
if // day is in calendar month
Copied: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java (from r420546, incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/WeblogCalendarModel.java)
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java?p2=incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java&p1=incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/WeblogCalendarModel.java&r1=420546&r2=420840&rev=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/tags/WeblogCalendarModel.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/core/tags/calendar/WeblogCalendarModel.java Tue Jul 11 06:33:44 2006
@@ -1,22 +1,22 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* under the Apache License, Version 2.0 (the "License"); you may not
-* use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
-package org.apache.roller.ui.authoring.tags;
+package org.apache.roller.ui.core.tags.calendar;
import java.net.URLEncoder;
import java.text.ParsePosition;
@@ -33,87 +33,75 @@
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.UserManager;
import org.apache.roller.model.WeblogManager;
import org.apache.roller.pojos.WeblogEntryData;
import org.apache.roller.pojos.WebsiteData;
import org.apache.roller.ui.core.RollerRequest;
-import org.apache.roller.ui.core.tags.calendar.CalendarModel;
+import org.apache.roller.ui.rendering.util.WeblogPageRequest;
import org.apache.roller.util.DateUtil;
-/**
+/**
* Calendar model for calendar intended for use on view-weblog page.
*/
-public class WeblogCalendarModel implements CalendarModel
-{
- private static Log mLogger =
- LogFactory.getFactory().getInstance(WeblogCalendarModel.class);
-
- protected HttpServletRequest mReq = null;
- protected HttpServletResponse mRes = null;
- protected Map mMonthMap;
- protected String mSelfUrl;
- protected Date mDay;
- protected String mCatName = null;
- protected Calendar mCalendar = null;
- protected WebsiteData mWebsite = null;
-
-
- public WeblogCalendarModel(HttpServletRequest req, HttpServletResponse res,
- WebsiteData website, Date date, String url, String cat)
- {
- mReq = req;
- mRes = res;
- mWebsite = website;
- mSelfUrl = url;
-
- setDay( date );
-
- // If category is specified in URL, then perpetuate it
- String catKey = RollerRequest.WEBLOGCATEGORYNAME_KEY;
- String catToUse = mReq.getParameter(catKey);
- if (mReq.getParameter(catKey) == null)
- {
- // If no cat in URL, then use method argument
- catToUse = cat;
- }
- if ( catToUse != null )
- {
- try
- {
- mCatName = "?"+catKey+"="+URLEncoder.encode(catToUse, "UTF-8");
- }
- catch (Throwable shouldNeverHappen)
- {
- mLogger.error(shouldNeverHappen);
- mCatName = "?"+catKey+"="+catToUse;
+public class WeblogCalendarModel implements CalendarModel {
+ private static Log log =
+ LogFactory.getFactory().getInstance(WeblogCalendarModel.class);
+
+ protected HttpServletRequest request = null;
+ protected HttpServletResponse response = null;
+ protected Map monthMap;
+ protected Date day;
+ protected String cat = null;
+ protected String pageLink = null;
+ protected Calendar calendar = null;
+ protected WebsiteData weblog = null;
+
+
+ public WeblogCalendarModel(
+ HttpServletRequest request, HttpServletResponse response, String catArgument) {
+
+ this.request = request;
+ this.response = response;
+ this.weblog = weblog;
+ WeblogPageRequest pageRequest = null;
+ try {
+ pageRequest = new WeblogPageRequest(request);
+
+ // lookup weblog specified by feed request
+ UserManager uMgr = RollerFactory.getRoller().getUserManager();
+ this.weblog = uMgr.getWebsiteByHandle(pageRequest.getWeblogHandle());
+
+ pageLink = pageRequest.getWeblogPage();
+
+ day = DateUtil.parseWeblogURLDateString(pageRequest.getWeblogDate(),
+ weblog.getTimeZoneInstance(), weblog.getLocaleInstance());
+ initDay(day);
+
+ if(weblog == null) {
+ throw new RollerException("unable to lookup weblog: "+
+ pageRequest.getWeblogHandle());
}
+ } catch (Exception e) {
+ // some kind of error parsing the request or looking up weblog
+ log.debug("ERROR: displaying calendar", e);
+ }
+
+ // Category method argument overrides category from URL
+ if (catArgument != null) {
+ cat = catArgument;
+ } else if (pageRequest.getWeblogCategory() != null) {
+ cat = pageRequest.getWeblogCategory();
}
- else
- {
- mCatName = "";
- }
- }
- /*
- public static WeblogCalendarModel getInstance(
- HttpServletRequest req, HttpServletResponse res, String url, String cat)
- {
- return new WeblogCalendarModel(RollerRequest.getRollerRequest(req), res, url, cat);
- }
-*/
- private void setDay(Date month)
- {
- mDay = month;
-
- // If category is specified in URL, then use it
- String catName =
- mReq.getParameter(RollerRequest.WEBLOGCATEGORYNAME_KEY);
+ }
- mCalendar = Calendar.getInstance(
- mWebsite.getTimeZoneInstance(),
- mWebsite.getLocaleInstance()
- );
+ private void initDay(Date month) {
+ this.day = day;
+ calendar = Calendar.getInstance(
+ weblog.getTimeZoneInstance(),
+ weblog.getLocaleInstance());
- Calendar cal = (Calendar)mCalendar.clone();
+ Calendar cal = (Calendar)calendar.clone();
// Compute first second of month
cal.setTime(month);
@@ -131,170 +119,141 @@
cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
Date endDate = cal.getTime();
-
- loadWeblogEntries(startDate, endDate, catName);
+
+ loadWeblogEntries(startDate, endDate);
}
-
- /**
+
+ /**
* @param startDate
* @param endDate
*/
- protected void loadWeblogEntries(Date startDate, Date endDate, String catName)
- {
- try
- {
+ protected void loadWeblogEntries(Date startDate, Date endDate) {
+ try {
WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
- mMonthMap = mgr.getWeblogEntryStringMap(
- mWebsite, // website
- startDate, // startDate
- endDate, // endDate
- catName, // catName
- WeblogEntryData.PUBLISHED, // status
- 0, -1
- );
- }
- catch (RollerException e)
- {
- mLogger.error(e);
- mMonthMap = new HashMap();
+ monthMap = mgr.getWeblogEntryStringMap(
+ weblog, // website
+ startDate, // startDate
+ endDate, // endDate
+ cat, // cat
+ WeblogEntryData.PUBLISHED, // status
+ 0, -1);
+ } catch (RollerException e) {
+ log.error(e);
+ monthMap = new HashMap();
}
}
- public void setDay(String month) throws Exception
- {
+ public void setDay(String month) throws Exception {
SimpleDateFormat fmt = DateUtil.get8charDateFormat();
- ParsePosition pos = new ParsePosition(0);
- setDay( fmt.parse( month, pos ) );
- }
-
- public Date getDay()
- {
- return (Date)mDay.clone();
- }
-
- public String getSelfUrl() throws Exception
- {
- return mSelfUrl;
- }
-
- public String getTargetUrl() throws Exception
- {
- return getSelfUrl();
- }
-
- public String getParameterName()
- {
- return RollerRequest.WEBLOGDAY_KEY;
- }
-
- public String getParameterValue( Date day )
- {
- return (String)mMonthMap.get( day );
- }
-
- /**
- * Create URL for use on view-weblog page, ignores query-string.
- * @param day Day for URL
- * @param valid Always return a URL, never return null
- * @return URL for day, or null if no weblog entry on that day
+ ParsePosition pos = new ParsePosition(0);
+ initDay( fmt.parse( month, pos ) );
+ }
+
+ public Date getDay() {
+ return (Date)day.clone();
+ }
+
+ public String getParameterName() {
+ return RollerRequest.WEBLOGDAY_KEY;
+ }
+
+ public String getParameterValue( Date day ) {
+ return (String)monthMap.get( day );
+ }
+
+ /**
+ * Create URL for use on view-weblog page
+ * @param day Day for URL or null if no entries on that day
+ * @param alwaysURL Always return a URL, never return null
+ * @return URL for day, or null if no weblog entry on that day
*/
- public String computeUrl(java.util.Date day, boolean valid)
- {
+ public String computeUrl(Date day, boolean monthURL, boolean alwaysURL) {
String url = null;
- try
- {
- if ( day == null )
- {
- url = mSelfUrl + mCatName;
- }
- else
- {
- // get the 8 char YYYYMMDD datestring for day, returns null
- // if no weblog entry on that day
- String dateString = (String)mMonthMap.get( day );
- if ( dateString != null )
- {
- // append 8 char date string on end of selfurl
- url = mSelfUrl+"/"+dateString+mCatName;
+ // get the 8 char YYYYMMDD datestring for day
+ String dateString = (String)monthMap.get(day);
+ if (dateString == null && !alwaysURL) return null;
+ else if (dateString == null && !monthURL) {
+ dateString = DateUtil.format8chars(day);
+ } else if (dateString == null && monthURL) {
+ dateString = DateUtil.format6chars(day);
+ }
+ try {
+ if (pageLink == null) { // create date URL
+ url = weblog.getURL() + "/date/" + dateString;
+ if (cat != null) {
+ url += "?cat=" + cat;
}
- else if ( valid )
- {
- // Make the date yyyyMMdd and append it to URL
- dateString = DateUtil.format8chars( day );
- url = mSelfUrl+"/"+dateString+mCatName;
+ } else { // create page URL
+ url = weblog.getURL() + "/page/" + pageLink;
+ if (cat != null) {
+ url += "?cat=" + cat;
}
}
- }
- catch (Exception e)
- {
- mLogger.error("ERROR: creating URL",e);
+ } catch (Exception e) {
+ log.error("ERROR: creating URL",e);
}
return url;
- }
+ }
/**
* @see org.apache.roller.presentation.tags.calendar.CalendarModel#getContent(Date, boolean)
*/
- public String getContent(Date day)
- {
+ public String getContent(Date day) {
return null;
}
- public Calendar getCalendar()
- {
- return (Calendar)mCalendar.clone();
+ public Calendar getCalendar() {
+ return (Calendar)calendar.clone();
}
- public Date getNextMonth()
- {
+ public Date getNextMonth() {
Calendar nextCal = getCalendar();
- nextCal.setTime( mDay );
+ nextCal.setTime( day );
nextCal.add( Calendar.MONTH, 1 );
return getFirstDayOfMonth(nextCal).getTime();
}
- protected Calendar getFirstDayOfMonth(Calendar cal)
- {
+ protected Calendar getFirstDayOfMonth(Calendar cal) {
int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, firstDay);
return cal;
}
- protected Calendar getLastDayOfMonth(Calendar cal)
- {
+ protected Calendar getLastDayOfMonth(Calendar cal) {
int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
cal.set(Calendar.DAY_OF_MONTH, lastDay);
return cal;
}
- public String computeNextMonthUrl()
- {
- // Create yyyyMMdd dates for next month, prev month and today
+ public String computeNextMonthUrl() {
+ // Create yyyyMMdd dates for next month, prev month and today
Calendar nextCal = getCalendar();
- nextCal.setTime( mDay );
+ nextCal.setTime( day );
nextCal.add( Calendar.MONTH, 1 );
- String nextMonth = computeUrl(nextCal.getTime(), true);
+ String nextMonth = computeUrl(nextCal.getTime(), true, true);
// and strip off last two digits to get a month URL
- return nextMonth.substring(0, nextMonth.length() - 2);
+ return nextMonth;
}
-
- public String computePrevMonthUrl()
- {
- // Create yyyyMMdd dates for prev month, prev month and today
+
+ public String computePrevMonthUrl() {
+ // Create yyyyMMdd dates for prev month, prev month and today
Calendar prevCal = getCalendar();
- prevCal.setTime( mDay );
- prevCal.add( Calendar.MONTH, -1 );
+ prevCal.setTime(day);
+ prevCal.add(Calendar.MONTH, -1);
//getLastDayOfMonth( prevCal );
- String prevMonth = computeUrl(prevCal.getTime(),true);
+ String prevMonth = computeUrl(prevCal.getTime(), true, true);
// and strip off last two digits to get a month URL
- return prevMonth.substring(0, prevMonth.length() - 2);
+ return prevMonth;
}
-
- public String computeTodayMonthUrl()
- {
- return computeUrl(null,true);
+
+ public String computeTodayMonthUrl() {
+ String url = weblog.getURL();
+ if (cat != null) {
+ url += "?cat=" + cat;
+ }
+ return url;
}
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarHelper.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarHelper.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarHelper.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/CalendarHelper.java Tue Jul 11 06:33:44 2006
@@ -23,14 +23,19 @@
import javax.servlet.jsp.PageContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.UserManager;
import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.pojos.wrapper.WebsiteDataWrapper;
-import org.apache.roller.ui.authoring.tags.BigWeblogCalendarModel;
-import org.apache.roller.ui.authoring.tags.WeblogCalendarModel;
+import org.apache.roller.ui.core.tags.calendar.BigWeblogCalendarModel;
+import org.apache.roller.ui.core.tags.calendar.WeblogCalendarModel;
import org.apache.roller.ui.core.LanguageUtil;
-import org.apache.roller.ui.core.RollerRequest;
import org.apache.roller.ui.core.tags.calendar.CalendarModel;
import org.apache.roller.ui.core.tags.calendar.CalendarTag;
+import org.apache.roller.ui.rendering.util.WeblogPageRequest;
+import org.apache.roller.util.DateUtil;
/**
* Displays weblog calendar by calling hybrid JSP tag.
@@ -38,7 +43,7 @@
public class CalendarHelper {
private PageContext pageContext;
- protected static Log logger =
+ protected static Log log =
LogFactory.getFactory().getInstance(CalendarHelper.class);
/**
@@ -48,32 +53,17 @@
this.pageContext = pageContext;
}
- public String emitWeblogCalendar(String cat, boolean big) {
-
+ public String emitWeblogCalendar(WebsiteDataWrapper websiteWrapper, String catArgument, boolean big) {
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
- HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
-
- // TODO 3.0: this needs to change, we cannot use RollerRequest anymore
- RollerRequest rreq = RollerRequest.getRollerRequest(request);
- WebsiteData weblog = rreq.getWebsite();
- String pageLink = rreq.getPageLink();
- Date date = rreq.getDate(true);
-
- if ("nil".equals(cat)) cat = null;
+ HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
+ if ("nil".equals(catArgument)) catArgument = null;
String ret = null;
try {
- String selfUrl = null;
- if (pageLink != null) {
- selfUrl = weblog.getURL() + "/page/" + pageLink;
- } else {
- selfUrl = weblog.getURL();
- }
-
CalendarModel model = null;
if (big) {
- model = new BigWeblogCalendarModel(request, response, weblog, date, selfUrl, cat);
+ model = new BigWeblogCalendarModel(request, response, catArgument);
} else {
- model = new WeblogCalendarModel(request, response, weblog, date, selfUrl, cat);
+ model = new WeblogCalendarModel(request, response, catArgument);
}
// save model in JSP page context so CalendarTag can find it
@@ -89,8 +79,10 @@
}
ret = calTag.emit();
} catch (Exception e) {
- logger.error("ERROR: initializing calendar tag",e);
+ log.error("ERROR: initializing calendar tag",e);
}
return ret;
}
}
+
+
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/model/PageRenderModel.java Tue Jul 11 06:33:44 2006
@@ -16,7 +16,7 @@
* directory of this distribution.
*/
-package org.apache.roller.ui.rendering.model;
+package org.apache.roller.ui.rendering.model;
import java.util.ArrayList;
import java.util.Date;
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/util/WeblogEntriesCollectionPager.java Tue Jul 11 06:33:44 2006
@@ -1,16 +1,22 @@
/*
- * WeblogEntriesCollectionPager.java
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * Created on June 29, 2006, 3:09 PM
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
*/
-
package org.apache.roller.ui.rendering.util;
-import java.text.ParsePosition;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -18,7 +24,6 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
@@ -81,7 +86,8 @@
Calendar cal = Calendar.getInstance();
// parse date string and figure out date
- thisDate = parseDate(dateString, weblog);
+ thisDate = DateUtil.parseWeblogURLDateString(dateString,
+ weblog.getTimeZoneInstance(), weblog.getLocaleInstance());
// single day
if(dateString.length() == 8) {
@@ -288,46 +294,7 @@
}
return entries;
- }
-
-
- /**
- * Parse data as either 6-char or 8-char format.
- */
- Date parseDate(String dateString, WebsiteData weblog) {
-
- Date ret = null;
- SimpleDateFormat char8DateFormat = DateUtil.get8charDateFormat();
- SimpleDateFormat char6DateFormat = DateUtil.get6charDateFormat();
-
- if (dateString != null
- && dateString.length()==8
- && StringUtils.isNumeric(dateString) ) {
- ParsePosition pos = new ParsePosition(0);
- ret = char8DateFormat.parse(dateString, pos);
-
- // make sure the requested date is not in the future
- Date today = getToday(weblog);
- if(ret.after(today)) {
- ret = today;
- }
-
- } else if(dateString != null
- && dateString.length()==6
- && StringUtils.isNumeric(dateString)) {
- ParsePosition pos = new ParsePosition(0);
- ret = char6DateFormat.parse(dateString, pos);
-
- // make sure the requested date is not in the future
- Date today = getToday(weblog);
- if(ret.after(today)) {
- ret = today;
- }
- }
-
- return ret;
- }
-
+ }
/**
* Return today based on current blog's timezone/locale.
Propchange: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/deprecated/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jul 11 06:33:44 2006
@@ -0,0 +1 @@
+.LCKOldPageHelper.java~
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/deprecated/OldPageHelper.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/deprecated/OldPageHelper.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/deprecated/OldPageHelper.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/deprecated/OldPageHelper.java Tue Jul 11 06:33:44 2006
@@ -50,8 +50,8 @@
import org.apache.roller.ui.core.tags.calendar.CalendarTag;
import org.apache.roller.ui.core.tags.menu.EditorNavigationBarTag;
import org.apache.roller.ui.core.tags.menu.MenuTag;
-import org.apache.roller.ui.authoring.tags.BigWeblogCalendarModel;
-import org.apache.roller.ui.authoring.tags.WeblogCalendarModel;
+import org.apache.roller.ui.core.tags.calendar.BigWeblogCalendarModel;
+import org.apache.roller.ui.core.tags.calendar.WeblogCalendarModel;
import org.apache.roller.ui.rendering.util.WeblogPageRequest;
@@ -277,10 +277,10 @@
Date date = mDate;
if ( big ) {
model = new BigWeblogCalendarModel(
- mRequest, response, mWebsite, date, selfUrl, cat);
+ mRequest, response, cat);
} else {
model = new WeblogCalendarModel(
- mRequest, response, mWebsite, date, selfUrl, cat);
+ mRequest, response, cat);
}
// save model in JSP page context so CalendarTag can find it
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java?rev=420840&r1=420839&r2=420840&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java Tue Jul 11 06:33:44 2006
@@ -1 +1 @@
-/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. The ASF licenses this file to You
* under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/
package org.apache.roller.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import org.apache.commons.lang.StringUtils;
/**
* General purpose date utilities.
* @author Mark Saarinen
* @author Lance Lavandowska
*/
public abstract class DateUtil extends Object {
public static final long millisInDay = 86400000;
// some static date formats
private static SimpleDateFormat[] mDateFormats = loadDateFormats();
private static final SimpleDateFormat mFormat8chars =
new SimpleDateFormat("yyyyMMdd");
private static final SimpleDateFormat mFormat6chars =
new SimpleDateFormat("yyyyMM");
private static final SimpleDateFormat mFormatIso8601Day =
new SimpleDateFormat("yyyy-MM-dd");
private static final SimpleDateFormat mFormatIso8601 =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
// http://www.w3.org/Protocols/rfc822/Overview.html#z28
// Using Locale.US to fix ROL-725 and ROL-628
private static final SimpleDateFormat
mFormatRfc822 =
new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
private static SimpleDateFormat[] loadDateFormats() {
SimpleDateFormat[] temp = {
//new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS a"),
new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy"), // standard Date.toString() results
new SimpleDateFormat("M/d/yy hh:mm:ss"),
new SimpleDateFormat("M/d/yyyy hh:mm:ss"),
new SimpleDateFormat("M/d/yy hh:mm a"),
new SimpleDateFormat("M/d/yyyy hh:mm a"),
new SimpleDateFormat("M/d/yy HH:mm"),
new SimpleDateFormat("M/d/yyyy HH:mm"),
new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"),
new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS"),
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"), // standard Timestamp.toString() results
new SimpleDateFormat("M-d-yy HH:mm"),
new SimpleDateFormat("M-d-yyyy HH:
mm"),
new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS"),
new SimpleDateFormat("M/d/yy"),
new SimpleDateFormat("M/d/yyyy"),
new SimpleDateFormat("M-d-yy"),
new SimpleDateFormat("M-d-yyyy"),
new SimpleDateFormat("MMMM d, yyyyy"),
new SimpleDateFormat("MMM d, yyyyy")
};
return temp;
}
//-----------------------------------------------------------------------
/**
* Gets the array of SimpleDateFormats that DateUtil knows about.
**/
private static SimpleDateFormat[] getFormats() {
return mDateFormats;
}
//-----------------------------------------------------------------------
/**
* Returns a Date set to the last possible millisecond of the day, just
* before midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getEndOfDay(Date day) {
return
getEndOfDay(day,Calendar.getInstance());
}
public static Date getEndOfDay(Date day,Calendar cal) {
if (day == null) day = new Date();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
return cal.getTime();
}
//-----------------------------------------------------------------------
/**
* Returns a Date set to the first possible millisecond of the month, just
* after midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getStartOfMonth(Date day) {
return getStartOfMonth(day, Calendar.getInstance());
}
public static Date getStartOfMonth(Date day, Calendar cal) {
if (day == null) day = new Date();
cal.setTime(day);
// set time to start of day
cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
// set time to first day of month
cal.set(Calendar.DAY_OF_MONTH, 1);
return cal.getTime();
}
/**
* Returns a Date set to the last possible millisecond of the month, just
* before midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getEndOfMonth(Date day) {
return getEndOfMonth(day, Calendar.getInstance());
}
public static Date getEndOfMonth(Date day,Calendar cal) {
if (day == null) day = new Date();
cal.setTime(day);
// set time to end of day
cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
// set time to first day of month
cal.set(Calendar.DAY_OF_MONTH, 1);
// add one month
cal.add(Calendar.MONTH, 1);
// back up one day
cal.add(Calendar.DAY_OF_MONTH, -1);
return cal.getTime();
}
//-----------------------------------------------------------------------
/**
* Returns a Date set to the first possible millisecond of the day, just
* after midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getStartOfDay(Date day) {
re
turn getStartOfDay(day, Calendar.getInstance());
}
/**
* Returns a Date set to the first possible millisecond of the day, just
* after midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getStartOfDay(Date day, Calendar cal) {
if (day == null) day = new Date();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
return cal.getTime();
}
/**
* Returns a Date set just to Noon, to the closest possible millisecond
* of the day. If a null day is passed in, a new Date is created.
* nnoon (00m 12h 00s)
*/
public static Date getNoonOfDay(Date day, Calendar cal) {
if (day
== null) day = new Date();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
return cal.getTime();
}
//-----------------------------------------------------------------------
public static Date parseFromFormats(String aValue) {
if (StringUtils.isEmpty(aValue)) return null;
// get DateUtil's formats
SimpleDateFormat formats[] = DateUtil.getFormats();
if (formats == null) return null;
// iterate over the array and parse
Date myDate = null;
for (int i = 0; i <formats.length; i++) {
try {
myDate = DateUtil.parse(aValue, formats[i]);
//if (myDate instanceof Date)
return myDate;
} catch (Exception e) {
// do nothing because we want to try the next
// format if current one fails
}
}
// haven't returned so couldn't parse
return null;
}
//-----------------------------------------------------------------------
public static java.sql.Timestamp parseTimestampFromFormats(String aValue) {
if (StringUtils.isEmpty(aValue)) return null;
// call the regular Date formatter
Date myDate = DateUtil.parseFromFormats(aValue);
if (myDate != null) return new java.sql.Timestamp(myDate.getTime());
return null;
}
//-----------------------------------------------------------------------
/**
* Returns a java.sql.Timestamp equal to the current time
**/
public static java.sql.Timestamp now() {
return new java.sql.Timestamp(new java.util.Date().getTime());
}
//------------------------------------
-----------------------------------
/**
* Returns a string the represents the passed-in date parsed
* according to the passed-in format. Returns an empty string
* if the date or the format is null.
**/
public static String format(Date aDate, SimpleDateFormat aFormat) {
if (aDate == null || aFormat == null ) { return ""; }
synchronized (aFormat) {
return aFormat.format(aDate);
}
}
//-----------------------------------------------------------------------
/**
* Tries to take the passed-in String and format it as a date string in the
* the passed-in format.
**/
public static String formatDateString(String aString, SimpleDateFormat aFormat) {
if (StringUtils.isEmpty(aString) || aFormat == null) return "";
try {
java.sql.Timestamp aDate = parseTimestampFromFormats(aString);
if (aDate != null) {
return DateUtil.format(aDate, a
Format);
}
} catch (Exception e) {
// Could not parse aString.
}
return "";
}
//-----------------------------------------------------------------------
/**
* Returns a Date using the passed-in string and format. Returns null if the string
* is null or empty or if the format is null. The string must match the format.
**/
public static Date parse(String aValue, SimpleDateFormat aFormat) throws ParseException {
if (StringUtils.isEmpty(aValue) || aFormat == null) {
return null;
}
return aFormat.parse(aValue);
}
//-----------------------------------------------------------------------
/**
* Returns true if endDate is after startDate or if startDate equals endDate
* or if they are the same date. Returns false if either value is null.
**/
public static boolean isValidDateRange(Date startDate, Date endDate) {
return isValidDateRange(startDate, endDate, true);
}
//-----------------------------------------------------------------------
/**
* Returns true if endDate is after startDate or if startDate equals endDate.
* Returns false if either value is null. If equalOK, returns true if the
* dates are equal.
**/
public static boolean isValidDateRange(Date startDate, Date endDate, boolean equalOK) {
// false if either value is null
if (startDate == null || endDate == null) { return false; }
if (equalOK) {
// true if they are equal
if (startDate.equals(endDate)) { return true; }
}
// true if endDate after startDate
if (endDate.after(startDate)) { return true; }
return false;
}
//-----------------------------------------------------------------------
// returns full timestamp format
public static java.text.SimpleDateForm
at defaultTimestampFormat() {
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
//-----------------------------------------------------------------------
// convenience method returns minimal date format
public static java.text.SimpleDateFormat get8charDateFormat() {
return DateUtil.mFormat8chars;
}
// convenience method returns minimal date format
public static java.text.SimpleDateFormat get6charDateFormat() {
return DateUtil.mFormat6chars;
}
//-----------------------------------------------------------------------
// convenience method returns minimal date format
public static java.text.SimpleDateFormat defaultDateFormat() {
return DateUtil.friendlyDateFormat(true);
}
//-----------------------------------------------------------------------
// convenience method
public static String defaultTimestamp(Date date) {
return DateUtil.format(da
te, DateUtil.defaultTimestampFormat());
}
//-----------------------------------------------------------------------
// convenience method
public static String defaultDate(Date date) {
return DateUtil.format(date, DateUtil.defaultDateFormat());
}
//-----------------------------------------------------------------------
// convenience method returns long friendly timestamp format
public static java.text.SimpleDateFormat friendlyTimestampFormat() {
return new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
}
//-----------------------------------------------------------------------
// convenience method returns long friendly formatted timestamp
public static String friendlyTimestamp(Date date) {
return DateUtil.format(date, DateUtil.friendlyTimestampFormat());
}
//-----------------------------------------------------------------------
// convenience method returns 8 char da
y stamp YYYYMMDD
public static String format8chars(Date date) {
return DateUtil.format(date, mFormat8chars);
}
//-----------------------------------------------------------------------
// convenience method returns 6 char month stamp YYYYMM
public static String format6chars(Date date) {
return DateUtil.format(date, mFormat6chars);
}
//-----------------------------------------------------------------------
// convenience method returns long friendly formatted timestamp
public static String formatIso8601Day(Date date) {
return DateUtil.format(date, mFormatIso8601Day);
}
//-----------------------------------------------------------------------
public static String formatRfc822(Date date) {
return DateUtil.format(date,mFormatRfc822);
}
//-----------------------------------------------------------------------
// This is a hack, but it seems to work
public static Str
ing formatIso8601(Date date) {
if (date == null) return "";
// Add a colon 2 chars before the end of the string
// to make it a valid ISO-8601 date.
String str = DateUtil.format(date,mFormatIso8601);
StringBuffer sb = new StringBuffer();
sb.append( str.substring(0,str.length()-2) );
sb.append( ":" );
sb.append( str.substring(str.length()-2) );
return sb.toString();
}
//-----------------------------------------------------------------------
// convenience method returns minimal date format
public static java.text.SimpleDateFormat minimalDateFormat() {
return DateUtil.friendlyDateFormat(true);
}
//-----------------------------------------------------------------------
// convenience method using minimal date format
public static String minimalDate(Date date) {
return DateUtil.format(date, DateUtil.minimalDateFormat());
}
//-----------------------------------------------------------------------
// convenience method that returns friendly data format
// using full month, day, year digits.
public static java.text.SimpleDateFormat fullDateFormat() {
return DateUtil.friendlyDateFormat(false);
}
//-----------------------------------------------------------------------
public static String fullDate(Date date) {
return DateUtil.format(date, DateUtil.fullDateFormat());
}
//-----------------------------------------------------------------------
/** Returns a "friendly" date format.
* @param mimimalFormat Should the date format allow single digits.
**/
public static java.text.SimpleDateFormat friendlyDateFormat(boolean minimalFormat) {
if (minimalFormat) {
return new java.text.SimpleDateFormat("d.M.yy");
}
return new java.text.SimpleDateFormat("dd.MM.yyyy");
}
//----
-------------------------------------------------------------------
/**
* Format the date using the "friendly" date format.
*/
public static String friendlyDate(Date date, boolean minimalFormat) {
return DateUtil.format(date, DateUtil.friendlyDateFormat(minimalFormat));
}
//-----------------------------------------------------------------------
// convenience method
public static String friendlyDate(Date date) {
return DateUtil.format(date, DateUtil.friendlyDateFormat(true));
}
public static Date parseIso8601(String value) throws Exception {
return ISO8601DateParser.parse(value);
}
}
\ No newline at end of file
+/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. The ASF licenses this file to You
* under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/
package org.apache.roller.util;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.C
alendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import org.apache.commons.lang.StringUtils;
/**
* General purpose date utilities.
* @author Mark Saarinen
* @author Lance Lavandowska
*/
public abstract class DateUtil extends Object {
public static final long millisInDay = 86400000;
// some static date formats
private static SimpleDateFormat[] mDateFormats = loadDateFormats();
private static final SimpleDateFormat mFormat8chars =
new SimpleDateFormat("yyyyMMdd");
private static final SimpleDateFormat mFormat6chars =
new SimpleDateFormat("yyyyMM");
private static final SimpleDateFormat mFormatIso8601Day =
new SimpleDateFormat("yyyy-MM-dd");
private static final SimpleDateFormat mFormatIso8601 =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
// http://www.w3.org/Protocols/rfc822/Overview.html#z28
// Using Locale.US to fix ROL
-725 and ROL-628
private static final SimpleDateFormat mFormatRfc822 =
new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
private static SimpleDateFormat[] loadDateFormats() {
SimpleDateFormat[] temp = {
//new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS a"),
new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy"), // standard Date.toString() results
new SimpleDateFormat("M/d/yy hh:mm:ss"),
new SimpleDateFormat("M/d/yyyy hh:mm:ss"),
new SimpleDateFormat("M/d/yy hh:mm a"),
new SimpleDateFormat("M/d/yyyy hh:mm a"),
new SimpleDateFormat("M/d/yy HH:mm"),
new SimpleDateFormat("M/d/yyyy HH:mm"),
new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"),
new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS"),
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"), // standard Timestamp.toString() results
new SimpleDateFormat("M-d
-yy HH:mm"),
new SimpleDateFormat("M-d-yyyy HH:mm"),
new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS"),
new SimpleDateFormat("M/d/yy"),
new SimpleDateFormat("M/d/yyyy"),
new SimpleDateFormat("M-d-yy"),
new SimpleDateFormat("M-d-yyyy"),
new SimpleDateFormat("MMMM d, yyyyy"),
new SimpleDateFormat("MMM d, yyyyy")
};
return temp;
}
//-----------------------------------------------------------------------
/**
* Gets the array of SimpleDateFormats that DateUtil knows about.
**/
private static SimpleDateFormat[] getFormats() {
return mDateFormats;
}
//-----------------------------------------------------------------------
/**
* Returns a Date set to the last possible millisecond of the day, just
* before midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getEndOfDay(Date day) {
return getEndOfDay(day,Calendar.getInstance());
}
public static Date getEndOfDay(Date day,Calendar cal) {
if (day == null) day = new Date();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
return cal.getTime();
}
//-----------------------------------------------------------------------
/**
* Returns a Date set to the first possible millisecond of the month, just
* after midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getStartOfMonth(Date day) {
return getStartOfMonth(day, Calendar.getInstance());
}
public
static Date getStartOfMonth(Date day, Calendar cal) {
if (day == null) day = new Date();
cal.setTime(day);
// set time to start of day
cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
// set time to first day of month
cal.set(Calendar.DAY_OF_MONTH, 1);
return cal.getTime();
}
/**
* Returns a Date set to the last possible millisecond of the month, just
* before midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getEndOfMonth(Date day) {
return getEndOfMonth(day, Calendar.getInstance());
}
public static Date getEndOfMonth(Date day,Calend
ar cal) {
if (day == null) day = new Date();
cal.setTime(day);
// set time to end of day
cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
// set time to first day of month
cal.set(Calendar.DAY_OF_MONTH, 1);
// add one month
cal.add(Calendar.MONTH, 1);
// back up one day
cal.add(Calendar.DAY_OF_MONTH, -1);
return cal.getTime();
}
//-----------------------------------------------------------------------
/**
* Returns a Date set to the first possible millisecond of the day, just
* after midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getStartOfDay(Date day) {
return getStartOfDay(day, Calendar.getInstance());
}
/**
* Returns a Date set to the first possible millisecond of the day, just
* after midnight. If a null day is passed in, a new Date is created.
* midnight (00m 00h 00s)
*/
public static Date getStartOfDay(Date day, Calendar cal) {
if (day == null) day = new Date();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
return cal.getTime();
}
/**
* Returns a Date set just to Noon, to the closest possible millisecond
* of the day. If a null day is passed in, a new Date is created.
* nnoon (00m 12h 00s)
*/
public static
Date getNoonOfDay(Date day, Calendar cal) {
if (day == null) day = new Date();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
return cal.getTime();
}
//-----------------------------------------------------------------------
public static Date parseFromFormats(String aValue) {
if (StringUtils.isEmpty(aValue)) return null;
// get DateUtil's formats
SimpleDateFormat formats[] = DateUtil.getFormats();
if (formats == null) return null;
// iterate over the array and parse
Date myDate = null;
for (int i = 0; i <formats.length; i++) {
try {
myDate = DateUtil.parse(aValue, formats[i]);
//if (myDat
e instanceof Date)
return myDate;
} catch (Exception e) {
// do nothing because we want to try the next
// format if current one fails
}
}
// haven't returned so couldn't parse
return null;
}
//-----------------------------------------------------------------------
public static java.sql.Timestamp parseTimestampFromFormats(String aValue) {
if (StringUtils.isEmpty(aValue)) return null;
// call the regular Date formatter
Date myDate = DateUtil.parseFromFormats(aValue);
if (myDate != null) return new java.sql.Timestamp(myDate.getTime());
return null;
}
//-----------------------------------------------------------------------
/**
* Returns a java.sql.Timestamp equal to the current time
**/
public static java.sql.Timestamp now() {
return new java.sql.Timestamp(new java.util.Date().getTim
e());
}
//-----------------------------------------------------------------------
/**
* Returns a string the represents the passed-in date parsed
* according to the passed-in format. Returns an empty string
* if the date or the format is null.
**/
public static String format(Date aDate, SimpleDateFormat aFormat) {
if (aDate == null || aFormat == null ) { return ""; }
synchronized (aFormat) {
return aFormat.format(aDate);
}
}
//-----------------------------------------------------------------------
/**
* Tries to take the passed-in String and format it as a date string in the
* the passed-in format.
**/
public static String formatDateString(String aString, SimpleDateFormat aFormat) {
if (StringUtils.isEmpty(aString) || aFormat == null) return "";
try {
java.sql.Timestamp aDate = parseTimestampFromFormats(aString);
if (aDate
!= null) {
return DateUtil.format(aDate, aFormat);
}
} catch (Exception e) {
// Could not parse aString.
}
return "";
}
//-----------------------------------------------------------------------
/**
* Returns a Date using the passed-in string and format. Returns null if the string
* is null or empty or if the format is null. The string must match the format.
**/
public static Date parse(String aValue, SimpleDateFormat aFormat) throws ParseException {
if (StringUtils.isEmpty(aValue) || aFormat == null) {
return null;
}
return aFormat.parse(aValue);
}
//-----------------------------------------------------------------------
/**
* Returns true if endDate is after startDate or if startDate equals endDate
* or if they are the same date. Returns false if either value is null.
**/
public static boolea
n isValidDateRange(Date startDate, Date endDate) {
return isValidDateRange(startDate, endDate, true);
}
//-----------------------------------------------------------------------
/**
* Returns true if endDate is after startDate or if startDate equals endDate.
* Returns false if either value is null. If equalOK, returns true if the
* dates are equal.
**/
public static boolean isValidDateRange(Date startDate, Date endDate, boolean equalOK) {
// false if either value is null
if (startDate == null || endDate == null) { return false; }
if (equalOK) {
// true if they are equal
if (startDate.equals(endDate)) { return true; }
}
// true if endDate after startDate
if (endDate.after(startDate)) { return true; }
return false;
}
//-----------------------------------------------------------------------
// returns full
timestamp format
public static java.text.SimpleDateFormat defaultTimestampFormat() {
return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
}
//-----------------------------------------------------------------------
// convenience method returns minimal date format
public static java.text.SimpleDateFormat get8charDateFormat() {
return DateUtil.mFormat8chars;
}
// convenience method returns minimal date format
public static java.text.SimpleDateFormat get6charDateFormat() {
return DateUtil.mFormat6chars;
}
//-----------------------------------------------------------------------
// convenience method returns minimal date format
public static java.text.SimpleDateFormat defaultDateFormat() {
return DateUtil.friendlyDateFormat(true);
}
//-----------------------------------------------------------------------
// convenience method
public static String defa
ultTimestamp(Date date) {
return DateUtil.format(date, DateUtil.defaultTimestampFormat());
}
//-----------------------------------------------------------------------
// convenience method
public static String defaultDate(Date date) {
return DateUtil.format(date, DateUtil.defaultDateFormat());
}
//-----------------------------------------------------------------------
// convenience method returns long friendly timestamp format
public static java.text.SimpleDateFormat friendlyTimestampFormat() {
return new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
}
//-----------------------------------------------------------------------
// convenience method returns long friendly formatted timestamp
public static String friendlyTimestamp(Date date) {
return DateUtil.format(date, DateUtil.friendlyTimestampFormat());
}
//--------------------------------------------------------
---------------
// convenience method returns 8 char day stamp YYYYMMDD
public static String format8chars(Date date) {
return DateUtil.format(date, mFormat8chars);
}
//-----------------------------------------------------------------------
// convenience method returns 6 char month stamp YYYYMM
public static String format6chars(Date date) {
return DateUtil.format(date, mFormat6chars);
}
//-----------------------------------------------------------------------
// convenience method returns long friendly formatted timestamp
public static String formatIso8601Day(Date date) {
return DateUtil.format(date, mFormatIso8601Day);
}
//-----------------------------------------------------------------------
public static String formatRfc822(Date date) {
return DateUtil.format(date,mFormatRfc822);
}
//-----------------------------------------------------------------------
//
This is a hack, but it seems to work
public static String formatIso8601(Date date) {
if (date == null) return "";
// Add a colon 2 chars before the end of the string
// to make it a valid ISO-8601 date.
String str = DateUtil.format(date,mFormatIso8601);
StringBuffer sb = new StringBuffer();
sb.append( str.substring(0,str.length()-2) );
sb.append( ":" );
sb.append( str.substring(str.length()-2) );
return sb.toString();
}
//-----------------------------------------------------------------------
// convenience method returns minimal date format
public static java.text.SimpleDateFormat minimalDateFormat() {
return DateUtil.friendlyDateFormat(true);
}
//-----------------------------------------------------------------------
// convenience method using minimal date format
public static String minimalDate(Date date) {
return DateUt
il.format(date, DateUtil.minimalDateFormat());
}
//-----------------------------------------------------------------------
// convenience method that returns friendly data format
// using full month, day, year digits.
public static java.text.SimpleDateFormat fullDateFormat() {
return DateUtil.friendlyDateFormat(false);
}
//-----------------------------------------------------------------------
public static String fullDate(Date date) {
return DateUtil.format(date, DateUtil.fullDateFormat());
}
//-----------------------------------------------------------------------
/** Returns a "friendly" date format.
* @param mimimalFormat Should the date format allow single digits.
**/
public static java.text.SimpleDateFormat friendlyDateFormat(boolean minimalFormat) {
if (minimalFormat) {
return new java.text.SimpleDateFormat("d.M.yy");
}
return new java
.text.SimpleDateFormat("dd.MM.yyyy");
}
//-----------------------------------------------------------------------
/**
* Format the date using the "friendly" date format.
*/
public static String friendlyDate(Date date, boolean minimalFormat) {
return DateUtil.format(date, DateUtil.friendlyDateFormat(minimalFormat));
}
//-----------------------------------------------------------------------
// convenience method
public static String friendlyDate(Date date) {
return DateUtil.format(date, DateUtil.friendlyDateFormat(true));
}
public static Date parseIso8601(String value) throws Exception {
return ISO8601DateParser.parse(value);
}
/**
* Parse data as either 6-char or 8-char format.
*/
public static Date parseWeblogURLDateString(String dateString, TimeZone tz, Locale locale) {
Date ret = new Date();
SimpleDateFormat char8DateFormat = DateUtil
.get8charDateFormat();
SimpleDateFormat char6DateFormat = DateUtil.get6charDateFormat();
if (dateString != null
&& dateString.length()==8
&& StringUtils.isNumeric(dateString) ) {
ParsePosition pos = new ParsePosition(0);
ret = char8DateFormat.parse(dateString, pos);
// make sure the requested date is not in the future
Date today = null;
Calendar todayCal = Calendar.getInstance();
todayCal = Calendar.getInstance(tz, locale);
todayCal.setTime(new Date());
today = todayCal.getTime();
if(ret.after(today)) {
ret = today;
}
} else if(dateString != null
&& dateString.length()==6
&& StringUtils.isNumeric(dateString)) {
ParsePosition pos = new ParsePosition(0);
ret = char6DateFormat.parse(dateString, pos);
// make sure the requested date is not in the future
Calendar todayCal = Calendar.getInstance();
todayCal = Calendar.getInstance(tz, locale);
todayCal.setTime(new Date());
Date today = todayCal.getTime();
if(ret.after(today)) {
ret = today;
}
}
return ret;
}
}
\ No newline at end of file