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 javax.servlet.http.HttpServletRequest;
009: import javax.servlet.http.HttpServletResponse;
010: import java.io.PrintWriter;
011: import java.util.*;
012: import java.util.logging.Logger;
013: import java.util.logging.Level;
014: import java.text.MessageFormat;
015: import java.io.IOException;
016:
017: import com.iplanet.jato.view.View;
018: import com.iplanet.jato.view.html.StaticTextField;
019: import com.iplanet.jato.view.ViewBean;
020: import com.iplanet.jato.view.ViewBeanBase;
021: import com.iplanet.jato.view.event.*;
022: import com.iplanet.jato.ViewBeanManager;
023: import com.iplanet.am.console.base.model.AMModelBase;
024: import com.iplanet.am.console.base.model.AMModel;
025: import com.iplanet.am.console.base.model.AMI18NUtils;
026: import com.iplanet.am.console.base.AMViewBeanBase;
027: import com.iplanet.am.util.BrowserEncoding;
028: import com.sun.portal.search.admin.resources.SearchResource;
029: import com.sun.portal.log.common.PortalLogger;
030: import com.iplanet.am.console.components.view.html.MessageBox;
031:
032: /**
033: * iPS admin console view bean: TODO
034: */
035: public class CSViewBeanBase extends AMViewBeanBase implements
036: CompassAdminConstants {
037: public static final String HEADER_VIEW = "HeaderView";
038: public static final String CHILD_MSGBOX = "MessageBox";
039: public static final String CN_REQUIRED = "NameRequired";
040: private AMModelBase ammodel = null;
041: protected java.util.Locale userLocale = null;
042: protected String errorMessage = null;
043: protected String warningMessage = null;
044: protected String infoMessage = null;
045: protected String questionMessage = null;
046:
047: // Create a logger for this class
048: private static Logger debugLogger = PortalLogger
049: .getLogger(CSViewBeanBase.class);
050:
051: /**
052: * constructor
053: *
054: * @param PageName of this view bean
055: * @param displayURL default display URL
056: */
057: public CSViewBeanBase(String page_name) {
058: super (page_name);
059: super .registerChildren();
060: registerChild(HEADER_VIEW, HeaderView.class);
061: registerChild(CHILD_MSGBOX, MessageBox.class);
062: registerChild(CN_REQUIRED, StaticTextField.class);
063:
064: }
065:
066: /**
067: * create child component
068: *
069: * @param name of component
070: * @return child component
071: */
072: protected View createChild(String name) {
073: AMModel model = getAMModel();
074: if (name.equals(HEADER_VIEW)) {
075: return new HeaderView(this , HEADER_VIEW);
076: } else if (name.equals(CHILD_MSGBOX)) {
077: return new MessageBox(this , CHILD_MSGBOX, "");
078: } else if (name.equals(CN_REQUIRED)) {
079: return new StaticTextField(this , CN_REQUIRED, "");
080: } else {
081: try {
082: return super .createChild(name);
083: } catch (Exception e) {
084: return null;
085: }
086: }
087: }
088:
089: public void setMessageBoxTitle(String title) {
090: MessageBox child = (MessageBox) getChild(this .CHILD_MSGBOX);
091: child.setTitle(title);
092: }
093:
094: public void addMessageBoxButton(String name, String url) {
095: MessageBox child = (MessageBox) getChild(this .CHILD_MSGBOX);
096: child.addButton(name, url);
097: }
098:
099: public boolean beginMessageBoxDisplay(ChildDisplayEvent event) {
100: debugLogger.log(Level.FINER, "PSSH_CSPSA0019", CHILD_MSGBOX);
101: MessageBox child = (MessageBox) getChild(this .CHILD_MSGBOX);
102: boolean isVisible = false;
103: if (errorMessage != null) {
104: child.setMessage(errorMessage);
105: isVisible = true;
106: child.setType(MessageBox.TYPE_ERROR);
107: } else if (warningMessage != null) {
108: child.setMessage(warningMessage);
109: isVisible = true;
110: child.setType(MessageBox.TYPE_WARNING);
111: } else if (infoMessage != null) {
112: child.setMessage(infoMessage);
113: isVisible = true;
114: child.setType(MessageBox.TYPE_INFORMATION);
115: } else if (questionMessage != null) {
116: child.setMessage(questionMessage);
117: isVisible = true;
118: child.setType(MessageBox.TYPE_QUESTION);
119: }
120: child.setEnabled(isVisible);
121: return isVisible;
122: }
123:
124: protected String getLocalizedString(String key) {
125: return SearchResource.geti18nString(key, getUserLocale());
126: }
127:
128: protected String getLocalizedString(String key,
129: boolean returnKeyIfNotFound) {
130: return SearchResource
131: .geti18nString(key, getUserLocale(), false);
132: }
133:
134: protected String[] getLocalizedStringArray(String key, String sep) {
135: return SearchResource.geti18nArray(key, sep, getUserLocale());
136: }
137:
138: protected String getLocalizedMessageFormat(String key, String arg1) {
139: String[] args = { arg1 };
140: return getLocalizedMessageFormat(key, args);
141: }
142:
143: protected String getLocalizedMessageFormat(String key, String arg1,
144: String arg2) {
145: String[] args = { arg1, arg2 };
146: return getLocalizedMessageFormat(key, args);
147: }
148:
149: protected String getLocalizedMessageFormat(String key, String arg1,
150: String arg2, String arg3) {
151: String[] args = { arg1, arg2, arg3 };
152: return getLocalizedMessageFormat(key, args);
153: }
154:
155: protected String getLocalizedMessageFormat(String key,
156: Object[] arguments) {
157: MessageFormat msgFormat = new MessageFormat("");
158: String pattern = getLocalizedString(key);
159: msgFormat.applyPattern(pattern);
160: return msgFormat.format(arguments);
161: }
162:
163: private AMModel getAMModel() {
164: if (ammodel == null) {
165: HttpServletRequest req = getRequestContext().getRequest();
166: HttpServletResponse res = getRequestContext().getResponse();
167: ammodel = new AMModelBase(req,
168: CompassAdminConstants.RESOURCE_BUNDLE_FILE);
169: }
170: return ammodel;
171: }
172:
173: protected Locale getUserLocale() {
174: if (userLocale == null) {
175: AMModel model = getAMModel();
176: if (model != null) {
177: userLocale = model.getUserLocale();
178: } else {
179: userLocale = Locale.getDefault();
180: }
181: }
182: return userLocale;
183: }
184:
185: /**
186: * Must be called in BeginDisplay of each viewbean
187: */
188: protected void setPageEncoding() {
189: HttpServletRequest req = getRequestContext().getRequest();
190: HttpServletResponse res = getRequestContext().getResponse();
191: AMModel model = getAMModel();
192: String lstr = getLangCountry(model);
193: debugLogger.log(Level.FINER, "PSSH_CSPSA0020", lstr);
194: Locale locale = model.getUserLocale();
195: debugLogger.log(Level.FINER, "PSSH_CSPSA0021", locale
196: .toString());
197:
198: String agentType = model.getClientType();
199: String contentType = AMI18NUtils.getContentType(agentType);
200: String charset = AMI18NUtils.getCharset(agentType, locale);
201: debugLogger.log(Level.FINER, "PSSH_CSPSA0022", new String[] {
202: contentType, charset });
203: res.setContentType(contentType + ";charset=" + charset);
204:
205: try {
206: res.getWriter();
207: } catch (IOException ex) {
208: /* Problem in handling charset Ignore it*/
209: res.setContentType(contentType);
210: }
211: String jCharset = BrowserEncoding.mapHttp2JavaCharset(charset);
212: setDisplayFieldValue(PAGE_ENCODING, jCharset);
213: setDisplayFieldValue(HELP_DOC_URL,
214: getLocalizedString("help.docurl"));
215: }
216:
217: private String getLangCountry(AMModel model) {
218: Locale locale = model.getUserLocale();
219: String lstr;
220: String lang = locale.getLanguage();
221: String country = locale.getCountry();
222:
223: if ((country == null) || (country.length() == 0)) {
224: lstr = lang;
225: } else {
226: lstr = lang + "_" + country;
227: }
228:
229: return lstr;
230: }
231:
232: /*
233: protected String getCharset(AMModel model) {
234: Locale locale = model.getUserLocale();
235: String agentType = model.getClientType();
236: String charset =model.getCharset(agentType,locale);
237: String jCharset = BrowserEncoding.mapHttp2JavaCharset (charset);
238: return jCharset;
239: }
240: */
241:
242: }
|