001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.faces.beans;
034:
035: import com.flexive.faces.FxJsfUtils;
036: import com.flexive.shared.search.FxFoundType;
037: import com.flexive.shared.search.ResultLocation;
038: import com.flexive.shared.search.ResultViewType;
039: import com.flexive.shared.search.query.SqlQueryBuilder;
040: import com.flexive.shared.value.BinaryDescriptor;
041:
042: import javax.servlet.http.HttpSession;
043: import java.io.Serializable;
044: import java.util.ArrayList;
045: import java.util.Formatter;
046: import java.util.List;
047:
048: /**
049: * Wrapper class for all session data needed by a search result page.
050: *
051: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
052: * @version $Rev: 1 $
053: */
054: public class ResultSessionData implements Serializable {
055: private static final long serialVersionUID = -3471062917140804393L;
056:
057: private ResultLocation location;
058: private int clientSizeX;
059: private int clientSizeY;
060: private SqlQueryBuilder queryBuilder;
061: private BinaryDescriptor.PreviewSizes previewSize;
062: private long briefcaseId;
063: private ResultViewType viewType = ResultViewType.LIST;
064: private int startRow;
065: private int fetchRows = 25;
066: private long typeId = -1;
067: private List<FxFoundType> contentTypes = new ArrayList<FxFoundType>(
068: 0);
069:
070: // Keep a reference on the current session if not retrieved from a JSF context
071: private transient HttpSession session = null;
072:
073: /**
074: * Session key for storing the current search session data. The first parameter
075: * identifies the {@link com.flexive.shared.search.AdminResultLocations}
076: * for the current search result. Thus each "location" is independent from the state
077: * of others, but it is not possible to have two separate instances of the same location
078: * (i.e. two browser windows).
079: */
080: private static String SESSION_DATA_STORE = "SearchResultBean/%s";
081:
082: /**
083: * Creates an empty session data object.
084: *
085: * @param location the search result location
086: */
087: private ResultSessionData(ResultLocation location) {
088: this (location, -1, -1, new SqlQueryBuilder(),
089: BinaryDescriptor.PreviewSizes.PREVIEW2, -1);
090: }
091:
092: /**
093: * Copy constructor. Creates an independent copy of the given session data object.
094: *
095: * @param other the session data object to be copied
096: */
097: public ResultSessionData(ResultSessionData other) {
098: this (other.location, other.clientSizeX, other.clientSizeY,
099: new SqlQueryBuilder(other.queryBuilder),
100: other.previewSize, other.briefcaseId);
101: }
102:
103: private ResultSessionData(ResultLocation location, int clientSizeX,
104: int clientSizeY, SqlQueryBuilder queryBuilder,
105: BinaryDescriptor.PreviewSizes previewSize, long briefcaseId) {
106: this .location = location;
107: this .clientSizeX = clientSizeX;
108: this .clientSizeY = clientSizeY;
109: this .queryBuilder = queryBuilder;
110: this .previewSize = previewSize;
111: this .briefcaseId = briefcaseId;
112: }
113:
114: public static ResultSessionData getSessionData(HttpSession session,
115: ResultLocation location) {
116: ResultSessionData data = (ResultSessionData) session
117: .getAttribute(getSessionKey(location));
118: if (data == null) {
119: data = new ResultSessionData(location);
120: data.session = session;
121: data.saveInSession();
122: }
123: data.session = session;
124: return data;
125: }
126:
127: private static String getSessionKey(ResultLocation location) {
128: return new Formatter().format(
129: ResultSessionData.SESSION_DATA_STORE,
130: location.getName()).toString();
131: }
132:
133: private void saveInSession() {
134: (session == null ? FxJsfUtils.getSession() : session)
135: .setAttribute(getSessionKey(location), this );
136: }
137:
138: public ResultLocation getLocation() {
139: return location;
140: }
141:
142: public int getClientSizeX() {
143: return clientSizeX;
144: }
145:
146: public void setClientSizeX(int clientSizeX) {
147: this .clientSizeX = clientSizeX;
148: saveInSession();
149: }
150:
151: public int getClientSizeY() {
152: return clientSizeY;
153: }
154:
155: public void setClientSizeY(int clientSizeY) {
156: this .clientSizeY = clientSizeY;
157: saveInSession();
158: }
159:
160: public SqlQueryBuilder getQueryBuilder() {
161: return queryBuilder;
162: }
163:
164: public void setQueryBuilder(SqlQueryBuilder queryBuilder) {
165: this .queryBuilder = queryBuilder;
166: saveInSession();
167: }
168:
169: public BinaryDescriptor.PreviewSizes getPreviewSize() {
170: return previewSize;
171: }
172:
173: public void setPreviewSize(BinaryDescriptor.PreviewSizes previewSize) {
174: this .previewSize = previewSize;
175: saveInSession();
176: }
177:
178: public long getBriefcaseId() {
179: return briefcaseId;
180: }
181:
182: public void setBriefcaseId(long briefcaseId) {
183: this .briefcaseId = briefcaseId;
184: saveInSession();
185: }
186:
187: public ResultViewType getViewType() {
188: return viewType;
189: }
190:
191: public void setViewType(ResultViewType viewType) {
192: this .viewType = viewType;
193: saveInSession();
194: }
195:
196: public int getStartRow() {
197: return startRow;
198: }
199:
200: public void setStartRow(int startRow) {
201: this .startRow = startRow;
202: saveInSession();
203: }
204:
205: public int getFetchRows() {
206: return fetchRows;
207: }
208:
209: public void setFetchRows(int fetchRows) {
210: this .fetchRows = fetchRows;
211: saveInSession();
212: }
213:
214: public long getTypeId() {
215: return typeId;
216: }
217:
218: public void setTypeId(long typeId) {
219: this .typeId = typeId;
220: saveInSession();
221: }
222:
223: public List<FxFoundType> getContentTypes() {
224: return contentTypes;
225: }
226:
227: public void setContentTypes(List<FxFoundType> contentTypes) {
228: this.contentTypes = contentTypes;
229: saveInSession();
230: }
231: }
|