001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin;
007:
008: import java.io.IOException;
009: import java.net.URL;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012:
013: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
014: import com.iplanet.jato.view.View;
015: import com.iplanet.jato.view.ViewBean;
016: import com.iplanet.jato.view.ViewBeanBase;
017: import com.iplanet.jato.view.TiledView;
018: import com.iplanet.jato.RequestHandler;
019: import com.iplanet.jato.model.*;
020: import com.iplanet.jato.view.event.DisplayEvent;
021: import com.iplanet.jato.view.event.RequestInvocationEvent;
022: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
023: import com.iplanet.jato.view.event.ChildDisplayEvent;
024: import com.iplanet.jato.view.html.StaticTextField;
025: import com.iplanet.jato.view.html.ComboBox;
026: import com.iplanet.jato.view.html.TextField;
027: import com.iplanet.jato.view.html.OptionList;
028: import com.iplanet.jato.view.html.CheckBox;
029: import com.iplanet.jato.view.html.HREF;
030: import com.iplanet.jato.view.html.HiddenField;
031: import com.iplanet.jato.model.DatasetModel;
032: import com.iplanet.jato.util.HtmlUtil;
033: import com.iplanet.jato.util.Encoder;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036:
037: import com.sun.portal.search.admin.resources.SearchResource;
038: import com.iplanet.am.console.components.view.html.IPlanetButton;
039:
040: import com.sun.portal.search.admin.model.RDListModel;
041: import com.sun.portal.search.db.SToken;
042: import com.sun.portal.log.common.PortalLogger;
043:
044: public class RDListView extends RequestHandlingTiledViewBase implements
045: TiledView, RequestHandler {
046: public static final String URL_TEXT = "Url";
047: public static final String TRUNCATEDURL_TEXT = "TruncatedUrl";
048: public static final String ENCODEDLURL_TEXT = "Base64EncodedUrl";
049: public static final String TITLE_TEXT = "Title";
050: public static final String EDIT_HREF = "EditAction";
051: public static final String DEL_CHECKBOX = "Delete";
052: private RDListModel model = null;
053: public static final int TRUNCATED_LEN = 60;
054:
055: // Create a Logger for this class
056: private static Logger debugLogger = PortalLogger
057: .getLogger(RDListView.class);
058:
059: public RDListView(View parent, String name) {
060: super (parent, name);
061: setPrimaryModelClass(RDListModel.class);
062: registerChildren();
063: }
064:
065: protected void registerChildren() {
066: registerChild(URL_TEXT, StaticTextField.class);
067: registerChild(TRUNCATEDURL_TEXT, StaticTextField.class);
068: registerChild(ENCODEDLURL_TEXT, HiddenField.class);
069: registerChild(TITLE_TEXT, StaticTextField.class);
070: registerChild(EDIT_HREF, HREF.class);
071: registerChild(DEL_CHECKBOX, CheckBox.class);
072:
073: }
074:
075: protected View createChild(String name) {
076: if (name.equals(URL_TEXT)) {
077: return new StaticTextField(this , getModel(), URL_TEXT,
078: RDListModel.FIELD_URL, "", null);
079: }
080: if (name.equals(TRUNCATEDURL_TEXT)) {
081: return new StaticTextField(this , TRUNCATEDURL_TEXT, "");
082: }
083: if (name.equals(ENCODEDLURL_TEXT)) {
084: return new HiddenField(this , getModel(), ENCODEDLURL_TEXT,
085: RDListModel.FIELD_ENCODED_URL, "", null);
086: }
087: if (name.equals(TITLE_TEXT)) {
088: return new StaticTextField(this , getModel(), TITLE_TEXT,
089: RDListModel.FIELD_TITLE, "", null);
090: }
091: if (name.equals(DEL_CHECKBOX)) {
092: return new CheckBox(this , getModel(), DEL_CHECKBOX,
093: RDListModel.FIELD_DELETE, "true", "false", false,
094: null);
095: }
096: if (name.equals(EDIT_HREF)) {
097: HREF child = new HREF(this , getModel(), EDIT_HREF,
098: RDListModel.FIELD_ENCODED_URL, "");
099: return child;
100: }
101: throw new IllegalArgumentException("Invalid child name: "
102: + name);
103: }
104:
105: public boolean beginHTTPLinkDisplay(ChildDisplayEvent event) {
106: String urlString = (String) getModel().getValue(
107: RDListModel.FIELD_URL);
108:
109: try {
110: URL u = new URL(urlString);
111: return true;
112: } catch (Exception e) {
113: }
114: return false;
115: }
116:
117: /**
118: *
119: *
120: */
121: public void beginDisplay(DisplayEvent event)
122: throws ModelControlException {
123: // Ensure the primary model is non-null; if null, it would cause
124: // havoc with the various methods dependent on the primary model
125: RDListModel model = (RDListModel) getPrimaryModel();
126: if (model == null) {
127: debugLogger.finer("PSSH_CSPSA0023");
128: throw new ModelControlException("Primary model is null");
129: }
130:
131: // The model will be executed automatically here by the base class
132: super .beginDisplay(event);
133: ViewBean pvb = getParentViewBean();
134: String editTimeStamp = (String) pvb
135: .getPageSessionAttribute("editTimeStamp");
136: debugLogger.log(Level.FINER, "PSSH_CSPSA0089", editTimeStamp);
137: if (editTimeStamp == null) {
138: editTimeStamp = getRequestContext().getRequest()
139: .getParameter("editTimeStamp");
140: debugLogger.log(Level.FINER, "PSSH_CSPSA0090",
141: editTimeStamp);
142: if (editTimeStamp != null) {
143: pvb.setPageSessionAttribute("editTimeStamp",
144: editTimeStamp);
145: }
146: }
147: resetTileIndex();
148: }
149:
150: private String getTruncatedText(String text, int len) {
151: if (text != null && text.length() > len) {
152: return text.substring(0, len - 5) + ".....";
153: }
154: return text;
155: }
156:
157: public boolean nextTile() throws ModelControlException {
158: boolean movedToRow = super .nextTile();
159: int ndx = getTileIndex();
160: if (movedToRow) {
161: HREF hrefChild = (HREF) getChild(EDIT_HREF);
162: String urlString = (String) getModel().getValue(
163: RDListModel.FIELD_ENCODED_URL);
164: long editTimeStamp = System.currentTimeMillis();
165: urlString += "&editTimeStamp="
166: + Long.toString(editTimeStamp);
167: // the 'target' window is the timestamp, avoiding user to open multiple window editing the same RD
168: hrefChild
169: .setExtraHtml("onClick=\"javascript:openRDForm('RDForm','"
170: + urlString
171: + "','"
172: + Long.toString(editTimeStamp)
173: + "');return false;\"");
174: setDisplayFieldValue(TITLE_TEXT, getTruncatedText(
175: getDisplayFieldStringValue(TITLE_TEXT),
176: TRUNCATED_LEN));
177: setDisplayFieldValue(TRUNCATEDURL_TEXT,
178: getTruncatedText(
179: getDisplayFieldStringValue(URL_TEXT),
180: TRUNCATED_LEN));
181: }
182: return movedToRow;
183: }
184:
185: /**
186: *
187: *
188: */
189: public Model[] getWebActionModels(int modelType) {
190: // Mark the BasicCustomModel instance we're bound to as auto-retrieving.
191: // This means it will automatically be executed via its retrieve()
192: // method when the tiled view begins display.
193:
194: switch (modelType) {
195: case MODEL_TYPE_RETRIEVE:
196: case MODEL_TYPE_DELETE:
197: RDListModel model = getModel();
198: return new Model[] { model };
199: }
200:
201: return new Model[0];
202: }
203:
204: /**
205: *
206: *
207: */
208: public RDListModel getModel() {
209: RDListModel model = (RDListModel) getRequestContext()
210: .getModelManager().getModel(RDListModel.class);
211: return model;
212: }
213:
214: // no need anymore. The href has onClick event handler to open edit form*/
215: public void handleEditActionRequest(RequestInvocationEvent event)
216: throws ModelControlException {
217: }
218:
219: public int doSearch(String database, int numPerPage, int currPage,
220: String queryString, int searchOption, SToken st) {
221: RDListModel model = getModel();
222: model.doSearch(database, numPerPage, currPage, queryString,
223: searchOption, st);
224: return model.RDM_Hits;
225: }
226:
227: public void setDatabase(String database) {
228: RDListModel model = getModel();
229: model.setDatabase(database);
230: }
231:
232: }
|