001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.mail.search;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.kernel.dao.search.DisplayTerms;
025: import com.liferay.portal.kernel.util.GetterUtil;
026: import com.liferay.portal.kernel.util.ParamUtil;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.theme.ThemeDisplay;
029: import com.liferay.portal.util.PortalUtil;
030: import com.liferay.portal.util.WebKeys;
031:
032: import java.util.Calendar;
033: import java.util.Date;
034:
035: import javax.servlet.http.HttpServletRequest;
036:
037: /**
038: * <a href="MailDisplayTerms.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Alexander Chow
041: *
042: */
043: public class MailDisplayTerms extends DisplayTerms {
044:
045: public static String[] DATE_RANGE_OPTIONS = new String[] {
046: "any-day", "1-day", "3-days", "1-week", "2-weeks",
047: "1-month", "2-months", "6-months", "1-year" };
048:
049: public static String FOLDER_NAME = MailDisplayTerms.class.getName()
050: + "folderName";
051:
052: public static String FROM = MailDisplayTerms.class.getName()
053: + "from";
054:
055: public static String TO = MailDisplayTerms.class.getName() + "to";
056:
057: public static String SUBJECT = MailDisplayTerms.class.getName()
058: + "subject";
059:
060: public static String ENTIRE_MESSAGE = MailDisplayTerms.class
061: .getName()
062: + "entireMessage";
063:
064: public MailDisplayTerms(HttpServletRequest req) {
065: super (req);
066:
067: folderName = ParamUtil.getString(req, FOLDER_NAME);
068: from = ParamUtil.getString(req, FROM);
069: to = ParamUtil.getString(req, TO);
070: subject = ParamUtil.getString(req, SUBJECT);
071: entireMessage = ParamUtil.getString(req, ENTIRE_MESSAGE);
072:
073: try {
074: String range = ParamUtil.getString(req, "dateRange");
075:
076: if (Validator.isNotNull(range)
077: && !DATE_RANGE_OPTIONS[0].equals(range)) {
078:
079: ThemeDisplay themeDisplay = (ThemeDisplay) req
080: .getAttribute(WebKeys.THEME_DISPLAY);
081:
082: int dateMonth = ParamUtil.getInteger(req, "dateMonth");
083: int dateDay = ParamUtil.getInteger(req, "dateDay");
084: int dateYear = ParamUtil.getInteger(req, "dateYear");
085:
086: Date date = PortalUtil.getDate(dateMonth, dateDay,
087: dateYear, themeDisplay.getTimeZone(), null);
088:
089: Calendar startCal = Calendar.getInstance(themeDisplay
090: .getTimeZone(), themeDisplay.getLocale());
091:
092: startCal.setTime(date);
093:
094: Calendar endCal = (Calendar) startCal.clone();
095:
096: int ordinal = GetterUtil.getInteger(range.substring(0,
097: 1));
098:
099: if (ordinal > 0) {
100: if (range.indexOf("day") != -1) {
101: startCal.add(Calendar.DATE, -ordinal);
102: endCal.add(Calendar.DATE, ordinal);
103: } else if (range.indexOf("week") != -1) {
104: startCal.add(Calendar.WEEK_OF_YEAR, -ordinal);
105: endCal.add(Calendar.WEEK_OF_YEAR, ordinal);
106: } else if (range.indexOf("month") != -1) {
107: startCal.add(Calendar.MONTH, -ordinal);
108: endCal.add(Calendar.MONTH, ordinal);
109: } else if (range.indexOf("year") != -1) {
110: startCal.add(Calendar.YEAR, -ordinal);
111: endCal.add(Calendar.YEAR, ordinal);
112: }
113:
114: startDate = startCal.getTime();
115: endDate = endCal.getTime();
116: }
117: }
118: } catch (PortalException pe) {
119: }
120: }
121:
122: public String getFolderName() {
123: return folderName;
124: }
125:
126: public void setFolderName(String folderName) {
127: this .folderName = folderName;
128: }
129:
130: public String getFrom() {
131: return from;
132: }
133:
134: public String getTo() {
135: return to;
136: }
137:
138: public String getSubject() {
139: return subject;
140: }
141:
142: public String getEntireMessage() {
143: return entireMessage;
144: }
145:
146: public boolean hasDate() {
147: if (startDate != null) {
148: return true;
149: } else {
150: return false;
151: }
152: }
153:
154: public Date getStartDate() {
155: return startDate;
156: }
157:
158: public Date getEndDate() {
159: return endDate;
160: }
161:
162: protected String folderName;
163: protected String from;
164: protected String to;
165: protected String subject;
166: protected String entireMessage;
167: protected Date startDate;
168: protected Date endDate;
169:
170: }
|