001: package com.sun.portal.providers.ctest;
002:
003: import java.util.Iterator;
004: import java.util.List;
005: import java.util.Map;
006: import java.util.ArrayList;
007: import java.util.Hashtable;
008: import java.util.HashMap;
009: import java.util.StringTokenizer;
010:
011: import javax.servlet.http.HttpServletRequest;
012: import javax.servlet.http.HttpServletResponse;
013:
014: import com.sun.portal.providers.containers.ContainerProviderAdapter;
015: import com.sun.portal.providers.ProviderException;
016: import com.sun.portal.providers.context.ProviderContextException;
017:
018: import com.sun.portal.desktop.context.ContextException;
019:
020: public class CTestProvider extends ContainerProviderAdapter {
021: public StringBuffer getContent(HttpServletRequest req,
022: HttpServletResponse res) throws ProviderException {
023: Hashtable tags = new Hashtable();
024:
025: tags.put("message", "Hello container test!!!<br><br>");
026:
027: StringBuffer content = new StringBuffer();
028:
029: String cmd = req.getParameter(getName() + ".cmd");
030: if (cmd != null) {
031: if (cmd.equals("setstring")) {
032: String name = req.getParameter("name");
033: String val = req.getParameter("value");
034: setStringProperty(name, val);
035: } else if (cmd.equals("setselected")) {
036: String s = req.getParameter("selected");
037: StringTokenizer sel = new StringTokenizer(s, ",");
038: List selected = new ArrayList();
039:
040: while (sel.hasMoreTokens()) {
041: String ch = sel.nextToken();
042: selected.add(ch);
043: }
044:
045: setSelectedChannels(selected);
046: } else if (cmd.equals("createchannel")) {
047: String name = req.getParameter("name");
048: String provider = req.getParameter("provider");
049: try {
050: getContainerProviderContext().createChannel(name,
051: provider);
052: } catch (ProviderContextException pce) {
053: throw new ProviderException(
054: "CTestProvider.getContent(): cannot create channel "
055: + name, pce);
056: }
057: } else if (cmd.equals("copychannel")) {
058: String src = req.getParameter("src");
059: String dst = req.getParameter("dst");
060: try {
061: getContainerProviderContext().copyChannel(src, dst);
062: } catch (ProviderContextException pce) {
063: throw new ProviderException(
064: "CTestProvider.getContent(): cannot copy channel "
065: + src + " to " + dst, pce);
066: }
067: }
068: }
069:
070: tags.put("properties", getProperties());
071: List selected = getSelectedChannels();
072: tags.put("selected", selected.toString());
073: List available = getAvailableChannels();
074: tags.put("available", available.toString());
075:
076: String channel = req.getParameter(getName() + ".contained");
077: if (channel != null) {
078: content.append("################ channel: ");
079: content.append(channel);
080: content.append("<br><br>");
081: content.append(getContainerProviderContext().getContent(
082: req, res, getName(), channel));
083: content.append("<br><br>################<br><br>");
084: } else {
085: Map contentMap = null;
086: contentMap = getContainerProviderContext().getContent(req,
087: res, getName(), selected, 30);
088:
089: for (Iterator i = contentMap.keySet().iterator(); i
090: .hasNext();) {
091: String name = (String) i.next();
092: content.append("################ channel: ");
093: content.append(name);
094: content.append("<br><br>");
095: content.append((StringBuffer) contentMap.get(name));
096: content.append("<br><br>################<br><br>");
097: }
098: }
099:
100: tags.put("content", content);
101: StringBuffer b = getTemplate("content.template", tags);
102:
103: return b;
104: }
105:
106: protected StringBuffer getProperties() throws ProviderException {
107: StringBuffer b = new StringBuffer();
108:
109: try {
110: Iterator i = getProviderContext().getNames(getName());
111:
112: for (; i.hasNext();) {
113: String name = (String) i.next();
114: Object val = getProviderContext().getProperty(
115: getName(), name);
116: b.append(name + "=" + val.toString() + "<br>");
117: }
118: } catch (ProviderContextException pce) {
119: throw new ProviderException(
120: "CTestProvider.getProperties(): ", pce);
121: }
122: return b;
123:
124: }
125: }
|