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: import com.sun.portal.iwayutil.config.*;
049: import com.sun.portal.iwayutil.connection.*;
050:
051: /**
052: *
053: * This class provides the utility methods to get parse the Siebel response
054: *
055: * @version 1.0
056: * @author Deepak H P
057: * @date 25 Feb 2005
058: *
059: **/
060: public class SiebelResponseUtils {
061:
062: static Logger logger = SiebelLogger.getLogger();
063:
064: /**
065: * This method parses the Siebel response to a vector containing
066: * the Account Summary
067: */
068: public static Vector getAccountSummary(String resStr) {
069: String[] fields = SiebelAccountRequestUtils.accountSummaryFields;
070: return getRecords(resStr, fields);
071: }
072:
073: /**
074: * This method parses the Siebel response to a vector containing
075: * the Account Details
076: */
077: public static Vector getAccountDetails(String resStr) {
078: String[] fields = SiebelAccountRequestUtils.accountDetailsFields;
079: return getRecords(resStr, fields);
080: }
081:
082: /**
083: * This method parses the Siebel response to a vector containing
084: * the Contact Details
085: */
086: public static Vector getContactDetails(String resStr) {
087: String[] fields = SiebelContactRequestUtils.queryFields;
088: return getRecords(resStr, fields);
089: }
090:
091: /**
092: * This method parses the Siebel response to a vector containing
093: * the Activity Details
094: */
095: public static Vector getActivityDetails(String resStr) {
096: String[] fields = SiebelActivityRequestUtils.queryFields;
097: return getRecords(resStr, fields);
098: }
099:
100: /**
101: * This method parses the Siebel response to a vector containing
102: * the Opportunity Details
103: */
104: public static Vector getOpportunityDetails(String resStr) {
105: String[] fields = SiebelOpportunityRequestUtils.queryFields;
106: return getRecords(resStr, fields);
107: }
108:
109: /**
110: * This method parses the Siebel response to a vector containing
111: * the Invoice Details
112: */
113: public static Vector getInvoiceDetails(String resStr) {
114: String[] fields = SiebelInvoiceRequestUtils.queryFields;
115: return getRecords(resStr, fields);
116: }
117:
118: /**
119: * This method parses the Siebel response to a vector containing
120: * the Revenue Forecast Details
121: */
122: public static Vector getForecastDetails(String resStr) {
123: String[] fields = SiebelForecastRequestUtils.queryFields;
124: return getRecords(resStr, fields);
125: }
126:
127: /**
128: * This method parses the Siebel response to a vector containing
129: * the hashtable. The keys of the hashtable are specified by fields
130: */
131: private static Vector getRecords(String outStr, String[] fields) {
132:
133: Vector records = new Vector();
134: String output = outStr;
135: String tag = "record";
136: String recordStr = null;
137: int index = output.indexOf("</record>");
138:
139: while (index > -1) {
140: recordStr = getFieldValue(output, tag);
141: Hashtable record = getRecord(recordStr, fields);
142: records.addElement(record);
143: output = output.substring(index + 9, output.length());
144: index = output.indexOf("</record>");
145: }
146: return records;
147: }
148:
149: /**
150: * This method parses the Siebel response to a hashtable.
151: * The keys of the hashtable are specified by fields
152: */
153: private static Hashtable getRecord(String recordStr, String[] fields) {
154:
155: String tag = null;
156: String value = null;
157:
158: Hashtable record = new Hashtable();
159:
160: for (int i = 0; i < fields.length; i++) {
161:
162: tag = fields[i].replaceAll(" ", "_spc");
163: tag = tag.replaceAll("#", "_pnd");
164: insertCellData(record, recordStr, tag);
165: }
166: return record;
167: }
168:
169: /**
170: * This method extracts a tag value from the record and inserts it in to
171: * the hashtable.
172: */
173: private static void insertCellData(Hashtable row, String record,
174: String tag) {
175:
176: String value = getFieldValue(record, tag);
177: if (value == null) {
178: value = "-";
179: }
180: row.put(tag, value);
181: }
182:
183: /**
184: * This method returns the value within a XML tag
185: */
186: private static String getFieldValue(String oStr, String tag) {
187:
188: String retVal = null;
189: String sStr = "<" + tag + ">";
190: String eStr = "</" + tag + ">";
191: int sIndex = oStr.indexOf(sStr);
192: int eIndex = oStr.indexOf(eStr);
193:
194: if (sIndex < 0) {
195: return retVal;
196: }
197: if (eIndex < sIndex) {
198: return retVal;
199: }
200: sIndex = sIndex + sStr.length();
201: retVal = oStr.substring(sIndex, eIndex).trim();
202: return retVal;
203: }
204:
205: /**
206: * This method will print the log the messages.
207: **/
208: private static void debug(String methodName, String msg) {
209: logger.log(Level.INFO,
210: "com.sun.portal.siebelportlet.util.SiebelResponseUtils:"
211: + methodName + ":" + msg);
212: }
213: }
|