01: package com.sun.portal.taskadmin.test;
02:
03: import java.util.*;
04:
05: import java.net.URL;
06:
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: import com.sun.portal.providers.ProfileProviderAdapter;
11: import com.sun.portal.providers.ProviderException;
12: import com.sun.portal.providers.context.PropertiesFilter;
13: import com.sun.portal.providers.context.ProviderContext;
14: import com.sun.portal.providers.context.ProviderContextException;
15:
16: import com.sun.portal.taskadmin.PortletTaskAdmin;
17: import com.sun.portal.taskadmin.TaskAdminException;
18: import com.sun.portal.taskadmin.TaskAdminConstants;
19: import com.sun.portal.desktop.ROC;
20:
21: public class TaskAdminPortletTestProvider extends
22: ProfileProviderAdapter {
23:
24: private PortletTaskAdmin pta = null;
25: private static final String LIST_SEPARATOR = "|";
26: protected static final String LOCALE_STRING = "localeString";
27:
28: public void init(String n, HttpServletRequest req)
29: throws ProviderException {
30: super .init(n, req);
31: }
32:
33: public StringBuffer getContent(HttpServletRequest req,
34: HttpServletResponse res) throws ProviderException {
35: Hashtable tags = new Hashtable();
36: try {
37: String node = getStringProperty("node");
38: pta = new PortletTaskAdmin(req, node);
39: tags.put("ExistingChannels", "ExistingChannels:"
40: + getCollectionAsString(pta.getExistingPortlets()));
41: pta.createPortletChannel("myPortletChannel",
42: "portletsamples.JSPPortlet");
43: pta.store();
44: tags.put("CreatePortletChannel",
45: "CreatePortletChannel: successful");
46: pta.deleteChannel("myPortletChannel", null);
47: pta.store();
48: tags.put("DeletePortletChannel",
49: "DeletePortletChannel: successful");
50: String localeString = null;
51: if (ROC.containsObject(LOCALE_STRING)) {
52: localeString = (String) ROC.getObject(LOCALE_STRING);
53: }
54:
55: } catch (TaskAdminException tae) {
56: throw new ProviderException(
57: "TaskAdminException in TaskAsminPortletTestprovider",
58: tae);
59: }
60: StringBuffer b = getTemplate("content.template", tags);
61: return b;
62: }
63:
64: private String getCollectionAsString(Collection c) {
65: StringBuffer sb = new StringBuffer();
66: Iterator i = c.iterator();
67: while (i.hasNext()) {
68: String s = (String) i.next();
69: sb.append(s).append(LIST_SEPARATOR);
70:
71: }
72: return sb.toString();
73: }
74:
75: protected static Locale initLocale(String stringformat) {
76: if (stringformat == null) {
77: return null;
78: }
79:
80: StringTokenizer tokenizer = new StringTokenizer(stringformat,
81: "_");
82: String lang = "";
83: String country = "";
84: String variant = "";
85: if (tokenizer.hasMoreTokens()) {
86: lang = tokenizer.nextToken();
87: }
88: if (tokenizer.hasMoreTokens()) {
89: country = tokenizer.nextToken();
90: }
91: if (tokenizer.hasMoreTokens()) {
92: variant = tokenizer.nextToken();
93: }
94:
95: return new Locale(lang, country, variant);
96: }
97:
98: }
|