001: package com.sun.portal.wsrp.common;
002:
003: import java.util.List;
004: import java.util.Map;
005: import java.util.Iterator;
006: import com.sun.portal.container.*;
007:
008: //
009: // This needs to be moved to toString method of container
010: // classes TODO
011: //
012:
013: public class ContainerToString {
014: public static String toStringExecuteActionRequest(
015: ExecuteActionRequest request) {
016:
017: StringBuffer buffer = new StringBuffer();
018: buffer.append(toStringContainerRequest(request));
019: buffer.append("\nActionParm : "
020: + mapDump(1, request.getActionParameters()));
021: return buffer.toString();
022: }
023:
024: public static String toStringContainerRequest(
025: ContainerRequest request) {
026: StringBuffer buffer = new StringBuffer();
027: buffer.append("\nWindowState: " + request.getWindowState());
028: buffer.append("\nChannelMode: " + request.getChannelMode());
029: buffer.append("\nEntityId : " + request.getEntityID());
030: buffer.append("\nEntityId : " + request.getEntityID());
031: buffer.append("\nUserID : " + request.getUserID());
032: buffer.append("\nCharEnc : "
033: + request.getCharacterEncoding());
034: buffer.append("\nRoles : "
035: + listDump(1, request.getRoles()));
036: buffer.append("\nAllowWS : "
037: + listDump(1, request.getAllowableWindowState()));
038: buffer.append("\nAllowCM : "
039: + listDump(1, request.getAllowableChannelMode()));
040: buffer.append("\nAllowCM : "
041: + listDump(1, request.getAllowableContentType()));
042: buffer.append("\nUserInfo : "
043: + mapDump(1, request.getUserInfo()));
044:
045: return buffer.toString();
046: }
047:
048: public static String toStringGetMarkupRequest(
049: GetMarkupRequest request) {
050: StringBuffer buffer = new StringBuffer();
051: buffer.append(toStringContainerRequest(request));
052: buffer.append("\nRenderParm : "
053: + mapDump(1, request.getRenderParameters()));
054: buffer.append("\ngetIsTarget: " + request.getIsTarget());
055: return buffer.toString();
056: }
057:
058: public static String listDump(int level, List list) {
059:
060: StringBuffer buffer = new StringBuffer();
061: String spacer = getSpacer(level);
062:
063: if (list == null) {
064: buffer.append(spacer + null);
065: }
066:
067: Iterator iter = list.iterator();
068: int i = 0;
069: while (iter.hasNext()) {
070: buffer.append(spacer + iter.next());
071: }
072:
073: return buffer.toString();
074: }
075:
076: public static String mapDump(int level, Map map) {
077: StringBuffer buffer = new StringBuffer();
078: String spacer = getSpacer(level);
079:
080: if (map == null) {
081: buffer.append(spacer + null);
082: }
083:
084: Iterator iter = map.keySet().iterator();
085: while (iter.hasNext()) {
086: String key = (String) iter.next();
087: buffer.append(spacer + key + ":"
088: + stringOrStringArrayDump(level + 1, map.get(key)));
089: }
090:
091: return buffer.toString();
092:
093: }
094:
095: public static String stringOrStringArrayDump(int level,
096: Object strOrStringArray) {
097: StringBuffer buffer = new StringBuffer();
098: if (strOrStringArray == null) {
099: return null;
100: }
101:
102: if (strOrStringArray instanceof String) {
103: buffer.append(getSpacer(level) + strOrStringArray);
104: } else if (strOrStringArray instanceof String[]) {
105: String spacer = getSpacer(level);
106: String[] array = (String[]) strOrStringArray;
107: for (int i = 0; i < array.length; i++) {
108: buffer.append(spacer + array[i]);
109: }
110: }
111:
112: return buffer.toString();
113: }
114:
115: public static String getSpacer(int level) {
116: StringBuffer buffer = new StringBuffer().append("\n");
117: for (int i = 0; i < level; i++) {
118: buffer.append("\t");
119: }
120:
121: return buffer.toString();
122: }
123:
124: }
|