001: package com.sun.portal.taskadmin.test;
002:
003: import java.util.*;
004:
005: import java.net.URL;
006:
007: import javax.servlet.http.HttpServletRequest;
008: import javax.servlet.http.HttpServletResponse;
009:
010: import com.sun.portal.providers.ProfileProviderAdapter;
011: import com.sun.portal.providers.ProviderException;
012: import com.sun.portal.providers.context.PropertiesFilter;
013: import com.sun.portal.providers.context.ProviderContext;
014: import com.sun.portal.providers.context.ProviderContextException;
015:
016: import com.sun.portal.taskadmin.ChannelTaskAdmin;
017: import com.sun.portal.taskadmin.TaskAdminException;
018: import com.sun.portal.taskadmin.TaskAdminConstants;
019: import com.sun.portal.desktop.dp.DPTypes;
020: import com.sun.portal.desktop.ROC;
021:
022: public class TaskAdminTestProvider extends ProfileProviderAdapter {
023:
024: private ChannelTaskAdmin cta = null;
025: private static final String LIST_SEPARATOR = "|";
026: protected static final String LOCALE_STRING = "localeString";
027:
028: public void init(String n, HttpServletRequest req)
029: throws ProviderException {
030: super .init(n, req);
031: }
032:
033: public StringBuffer getContent(HttpServletRequest req,
034: HttpServletResponse res) throws ProviderException {
035:
036: Hashtable tags = new Hashtable();
037:
038: try {
039: List pflist = getProviderContext()
040: .getClientPropertiesFilters();
041: String node = getStringProperty("node");
042: cta = new ChannelTaskAdmin(req, node);
043: Set roles = cta.getBaseDNs();
044: String container = getStringProperty("containerName");
045: tags.put("roles", "Roles:" + getCollectionAsString(roles));
046: tags.put("ExistingChannels", "ExistingChannels:"
047: + getCollectionAsString(cta
048: .getExistingChannels(false)));
049: tags.put("ExistingContainers", "ExistingContainers:"
050: + getCollectionAsString(cta
051: .getExistingContainers(false)));
052: tags.put("AssignableChannels", "AssignableChannels:"
053: + getCollectionAsString(cta
054: .getAssignableChannels(container)));
055: tags.put("AvailableChannels", "AvailableChannels:"
056: + getCollectionAsString(cta
057: .getAvailableChannels(container)));
058: tags.put("SelectedChannels", "SelectedChannels:"
059: + getCollectionAsString(cta
060: .getSelectedChannels(container)));
061: tags
062: .put("ExistingProviders", "ExistingProviders:"
063: + getCollectionAsString(cta
064: .getExistingProviders()));
065: tags.put("ExistingContainerProviders",
066: "ExistingContainerProviders:"
067: + getCollectionAsString(cta
068: .getExistingContainerProviders()));
069: tags.put("ChannelPropertyNames", "ChannelPropertyNames:"
070: + getCollectionAsString(cta.getPropertyNames(
071: "SampleXML", pflist, false)));
072:
073: tags.put("getPropertyType", "getPropertyType: "
074: + getTypeAsString(cta.getPropertyType("SampleJSP",
075: "description")));
076:
077: cta.setStringProperty("MyFrontPageTabPanelContainer",
078: "title", "New Front Page title-1", null);
079: cta.setIntegerProperty("MyFrontPageTabPanelContainer",
080: "timeout", 80, null);
081: cta.setBooleanProperty("MyFrontPageTabPanelContainer",
082: "parallelChannelsInit", false, null);
083:
084: List list = new ArrayList();
085: list.add("abc");
086: list.add("xyz");
087:
088: cta.setListProperty("MyFrontPageTabPanelContainer",
089: "categories", list, null);
090: cta.store();
091: tags.put("getStringProperty", "getStringProperty: "
092: + cta.getStringProperty(
093: "MyFrontPageTabPanelContainer", "title",
094: null));
095:
096: tags.put("getIntegerProperty", "getIntegerProperty: "
097: + cta.getIntegerProperty(
098: "MyFrontPageTabPanelContainer", "timeout",
099: null));
100:
101: tags.put("getBooleanProperty", "getBooleanProperty: "
102: + cta.getBooleanProperty(
103: "MyFrontPageTabPanelContainer",
104: "parallelChannelsInit", null));
105:
106: tags.put("getListProperty", "getListProperty: "
107: + getCollectionAsString(cta.getListProperty(
108: "MyFrontPageTabPanelContainer",
109: "categories", null)));
110:
111: tags.put("getMapProperty", "getMapProperty: "
112: + cta.getMapProperty(
113: "MyFrontPageTabPanelContainer",
114: "categories", null).toString());
115:
116: cta.getPropertyNames("MyFrontPageTabPanelContainer",
117: "cate", false);
118: tags.put("searchProperty", "searchProperty: "
119: + getCollectionAsString(cta.getPropertyNames(
120: "MyFrontPageTabPanelContainer", "cate",
121: false)));
122:
123: String localeString = null;
124: if (ROC.containsObject(LOCALE_STRING)) {
125: localeString = (String) ROC.getObject(LOCALE_STRING);
126: }
127:
128: } catch (TaskAdminException tae) {
129: throw new ProviderException(
130: "TaskAdminException in testprovider", tae);
131: } catch (ProviderContextException pce) {
132: throw new ProviderException(
133: "ProviderContextException. Cannot get client filters",
134: pce);
135: }
136: StringBuffer b = getTemplate("content.template", tags);
137: return b;
138:
139: }
140:
141: private String getCollectionAsString(Collection c) {
142: StringBuffer sb = new StringBuffer();
143: Iterator i = c.iterator();
144: while (i.hasNext()) {
145: String s = (String) i.next();
146: sb.append(s).append(LIST_SEPARATOR);
147:
148: }
149: return sb.toString();
150: }
151:
152: private String getTypeAsString(short typeValue) {
153: //Return value are 1 for string, 3 for integer, 4 for boolean, 14 for collection
154:
155: if (typeValue == DPTypes.STRING_DP) {
156: return "String";
157: } else if (typeValue == DPTypes.INTEGER_DP) {
158: return "Integer";
159: } else if (typeValue == DPTypes.BOOLEAN_DP) {
160: return "Boolean";
161: } else if (typeValue == DPTypes.COLLECTION_DP) {
162: return "Boolean";
163: } else {
164: return "Unknown";
165: }
166:
167: }
168:
169: protected static Locale initLocale(String stringformat) {
170: if (stringformat == null) {
171: return null;
172: }
173:
174: StringTokenizer tokenizer = new StringTokenizer(stringformat,
175: "_");
176: String lang = "";
177: String country = "";
178: String variant = "";
179: if (tokenizer.hasMoreTokens()) {
180: lang = tokenizer.nextToken();
181: }
182: if (tokenizer.hasMoreTokens()) {
183: country = tokenizer.nextToken();
184: }
185: if (tokenizer.hasMoreTokens()) {
186: variant = tokenizer.nextToken();
187: }
188:
189: return new Locale(lang, country, variant);
190: }
191:
192: }
|