001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * for use in the design, construction, operation or maintenance of
035: * any nuclear facility.
036: */
037: package com.sun.portal.siebelportlet.util;
038:
039: import java.util.Enumeration;
040: import java.util.Vector;
041: import java.util.Hashtable;
042: import java.io.IOException;
043: import java.io.Writer;
044: import java.util.logging.*;
045:
046: import javax.portlet.*;
047:
048: /**
049: *
050: * This class provides the utility methods to get parse the Siebel response
051: *
052: * @version 1.0
053: * @author Deepak H P
054: * @date 16 June 2005
055: *
056: **/
057: public class SiebelProcessActionUtils {
058:
059: static Logger logger = SiebelLogger.getLogger();
060:
061: public static void processAction(ActionRequest request,
062: ActionResponse response) throws PortletException,
063: IOException {
064:
065: String reqType = request.getParameter("RequestType");
066:
067: debug("processAction()", reqType);
068: if (reqType != null) {
069: response.setRenderParameter("RequestType", reqType);
070: }
071:
072: if ((reqType != null) && (reqType.equals("SiebelPreferences"))) {
073: setSiebelPortletPreferences(request);
074: response.setPortletMode(PortletMode.VIEW);
075: } else {
076: setResponseParameters(request, response);
077: String detailsAction = request
078: .getParameter("DetailsActionButton");
079: if (detailsAction != null) {
080: response.setRenderParameter("DetailsActionButton",
081: detailsAction);
082: processDetailsAction(request, response, detailsAction);
083: }
084: }
085: }
086:
087: private static void setSiebelPortletPreferences(
088: ActionRequest request) {
089: try {
090: debug("setSiebelPortletPreferences()",
091: "setting preferences");
092: setSiebelPortletPreference(request, "AccountRowPreference",
093: SiebelConfigUtils.getDefaultAccountRowCount());
094: setSiebelPortletPreference(request, "ContactRowPreference",
095: SiebelConfigUtils.getDefaultContactRowCount());
096: setSiebelPortletPreference(request,
097: "ActivityRowPreference", SiebelConfigUtils
098: .getDefaultActivityRowCount());
099: setSiebelPortletPreference(request,
100: "OpportunityRowPreference", SiebelConfigUtils
101: .getDefaultOpportunityRowCount());
102: setSiebelPortletPreference(request, "InvoiceRowPreference",
103: SiebelConfigUtils.getDefaultInvoiceRowCount());
104: setSiebelPortletPreference(request,
105: "ForecastRowPreference", SiebelConfigUtils
106: .getDefaultForecastRowCount());
107: debug("setSiebelPortletPreferences()", "set preferences ");
108: } catch (Exception ex) {
109: debug("setSiebelPortletPreferences()", ex.toString());
110: }
111: }
112:
113: public static void addSiebelPortletPreferencesToRequest(
114: RenderRequest request) {
115: PortletPreferences prefs = request.getPreferences();
116: String row = prefs.getValue("AccountRowPreference",
117: SiebelConfigUtils.getDefaultAccountRowCount());
118: request.setAttribute("AccountRowPreference", row);
119: row = prefs.getValue("ContactRowPreference", SiebelConfigUtils
120: .getDefaultContactRowCount());
121: request.setAttribute("ContactRowPreference", row);
122: row = prefs.getValue("ActivityRowPreference", SiebelConfigUtils
123: .getDefaultActivityRowCount());
124: request.setAttribute("ActivityRowPreference", row);
125: row = prefs.getValue("OpportunityRowPreference",
126: SiebelConfigUtils.getDefaultOpportunityRowCount());
127: request.setAttribute("OpportunityRowPreference", row);
128: row = prefs.getValue("InvoiceRowPreference", SiebelConfigUtils
129: .getDefaultInvoiceRowCount());
130: request.setAttribute("InvoiceRowPreference", row);
131: row = prefs.getValue("ForecastRowPreference", SiebelConfigUtils
132: .getDefaultForecastRowCount());
133: request.setAttribute("ForecastRowPreference", row);
134: }
135:
136: private static void setSiebelPortletPreference(
137: ActionRequest request, String name, String defaultValue) {
138:
139: try {
140: String value = request.getParameter(name);
141: debug("setSiebelPortletPreference()", "name :" + name
142: + " value :" + value);
143: PortletPreferences prefs = request.getPreferences();
144:
145: if (value == null) {
146: value = defaultValue;
147: } else if (value.equalsIgnoreCase("null")) {
148: value = defaultValue;
149: }
150: debug("setSiebelPortletPreference()", "name :" + name
151: + " value :" + value);
152: prefs.setValue(name, value);
153: prefs.store();
154: } catch (Exception ex) {
155: debug("setSiebelPortletPreference()", ex.toString());
156: }
157: }
158:
159: private static void setResponseParameters(ActionRequest request,
160: ActionResponse response) {
161:
162: String queryField = request.getParameter("QueryField");
163: String queryValue = request.getParameter("QueryValue");
164: String linkType = request.getParameter("LinkType");
165: String accountName = request.getParameter("AccountName");
166: String curSumPage = request.getParameter("CurrentSummaryPage");
167: String curPage = request.getParameter("CurrentPage");
168: String tableSize = request.getParameter("TableSize");
169: String paginationType = request.getParameter("PaginationType");
170: String sortTable = request.getParameter("SortTable");
171: String sortOrder = request.getParameter("SortOrder");
172: String sortColumn = request.getParameter("SortColumn");
173: String sortElementType = request
174: .getParameter("SortElementType");
175: String currentQuery = request.getParameter("CurrentQuery");
176:
177: debug("setResponseParameters()", "CurrentSummaryPage : "
178: + curSumPage);
179: debug("setResponseParameters()", "CurrentPage : " + curPage);
180:
181: if (queryField != null) {
182: response.setRenderParameter("QueryField", queryField);
183: }
184:
185: if (queryValue != null) {
186: response.setRenderParameter("QueryValue", queryValue);
187: }
188:
189: if (linkType != null) {
190: response.setRenderParameter("LinkType", linkType);
191: }
192:
193: if (accountName != null) {
194: response.setRenderParameter("AccountName", accountName);
195: }
196:
197: if (curSumPage != null) {
198: response.setRenderParameter("CurrentSummaryPage",
199: curSumPage);
200: }
201:
202: if (curPage != null) {
203: response.setRenderParameter("CurrentPage", curPage);
204: }
205:
206: if (tableSize != null) {
207: response.setRenderParameter("TableSize", tableSize);
208: }
209:
210: if (paginationType != null) {
211: response.setRenderParameter("PaginationType",
212: paginationType);
213: }
214:
215: if (sortTable != null) {
216: response.setRenderParameter("SortTable", sortTable);
217: }
218:
219: if (sortOrder != null) {
220: response.setRenderParameter("SortOrder", sortOrder);
221: }
222:
223: if (sortColumn != null) {
224: response.setRenderParameter("SortColumn", sortColumn);
225: }
226:
227: if (sortElementType != null) {
228: response.setRenderParameter("SortElementType",
229: sortElementType);
230: }
231:
232: if (currentQuery != null) {
233: response.setRenderParameter("CurrentQuery", currentQuery);
234: }
235: }
236:
237: private static void processDetailsAction(ActionRequest request,
238: ActionResponse response, String detailsAction) {
239:
240: if (detailsAction.equals("OK")) {
241:
242: debug("processAction()", "Setting detailsAction param");
243:
244: String accountID = request.getParameter("AccountID");
245: if (accountID != null) {
246: response.setRenderParameter("AccountID", accountID);
247: }
248:
249: String address = request.getParameter("ADDRESS");
250: if (address != null) {
251: response.setRenderParameter("ADDRESS", address);
252: }
253:
254: String site = request.getParameter("SITE");
255: if (site != null) {
256: response.setRenderParameter("SITE", site);
257: }
258:
259: String city = request.getParameter("CITY");
260: if (city != null) {
261: response.setRenderParameter("CITY", city);
262: }
263:
264: String state = request.getParameter("STATE");
265: if (state != null) {
266: response.setRenderParameter("STATE", state);
267: }
268:
269: String zip = request.getParameter("ZIP");
270: if (zip != null) {
271: response.setRenderParameter("ZIP", zip);
272: }
273:
274: String territory = request.getParameter("TERRITORY");
275: if (territory != null) {
276: response.setRenderParameter("TERRITORY", territory);
277: }
278:
279: String country = request.getParameter("COUNTRY");
280: if (country != null) {
281: response.setRenderParameter("COUNTRY", country);
282: }
283:
284: String phone = request.getParameter("PHONE");
285: if (phone != null) {
286: response.setRenderParameter("PHONE", phone);
287: }
288:
289: String fax = request.getParameter("FAX");
290: if (fax != null) {
291: response.setRenderParameter("FAX", fax);
292: }
293:
294: String url = request.getParameter("URL");
295: if (url != null) {
296: response.setRenderParameter("URL", url);
297: }
298:
299: String industry = request.getParameter("INDUSTRY");
300: if (industry != null) {
301: response.setRenderParameter("INDUSTRY", industry);
302: }
303: }
304: }
305:
306: /**
307: * This method will print the log the messages.
308: **/
309: private static void debug(String methodName, String msg) {
310: logger.log(Level.INFO,
311: "com.sun.portal.siebelportlet.util.SiebelProcessActionUtils:"
312: + methodName + ":" + msg);
313: }
314: }
|