001: package com.sun.portal.sra.desktop.commands;
002:
003: import java.io.IOException;
004:
005: import javax.servlet.http.HttpServletRequest;
006: import javax.servlet.http.HttpServletResponse;
007: import javax.servlet.http.HttpSession;
008: import java.util.HashMap;
009: import java.util.Iterator;
010: import com.sun.portal.proxylet.provider.SRAProxyletProvider;
011: import com.sun.portal.sra.beans.IProviderBean;
012: import com.sun.portal.sra.beans.ProviderBeanImpl;
013: import com.sun.portal.sra.test.provider.sraStandaloneSeparationProvider;
014:
015: public class HomePageCommand implements Command {
016: // This command is responsible for building the default home page
017: public HomePageCommand() {
018: }
019:
020: // Execute a provider to get its content.
021: // Instantiate a ProviderBean class and populate its content
022: // Put the bean in the session scope with a name PROVIDER_NAME_BEAN format
023:
024: public void execute(HttpServletRequest req,
025: HttpServletResponse res, HashMap providerMap)
026: throws IOException, CommandExecutionException {
027:
028: HttpSession session = req.getSession(true);
029:
030: for (Iterator iter = providerMap.keySet().iterator(); iter
031: .hasNext();) {
032: String providerkey = (String) iter.next();
033: String providerClass = (String) providerMap
034: .get(providerkey);
035:
036: Object provider;
037: try {
038: provider = Class.forName(providerClass).newInstance();
039: if (provider instanceof sraStandaloneSeparationProvider) {
040: IProviderBean bean = new ProviderBeanImpl();
041: StringBuffer sb = new StringBuffer();
042: String editLink = "<a href=\"/sra/dt?action=editNetlet\">Edit</a><br>";
043: sb.append(editLink);
044:
045: // Execute the provider
046:
047: /*
048:
049: sraStandaloneSeparationProvider sraStandalone =
050: (sraStandaloneSeparationProvider) provider;
051: Map propertiesMap = sraStandalone.getContent(req, res);
052:
053: // Fetch the values
054: for (Iterator iterator = propertiesMap.keySet().iterator();
055: iterator.hasNext();
056: )
057: {
058: String elementKey = (String) iterator.next();
059: StringBuffer elementValue = (StringBuffer) propertiesMap.get(elementKey);
060: sb.append(elementKey).append("=").append(elementValue).append("<br>");
061: }
062: */
063:
064: // Set the content into a bean
065: bean
066: .set_HtmlContent(sb
067: .append("This functionality is coming soon<br>"));
068:
069: // Put bean in session scope for the view to pick up.
070: session.setAttribute(
071: "SRA_SEPARATION_PROVIDER_BEAN", bean);
072: } else if (provider instanceof SRAProxyletProvider) {
073: IProviderBean bean = new ProviderBeanImpl();
074: StringBuffer sb = new StringBuffer();
075: StringBuffer editLink = new StringBuffer();
076: editLink.append("<a href=\""
077: + req.getAttribute("staticContext")
078: + "/dt?action=editProxylet\">Edit</a><br>");
079: sb.append(editLink);
080:
081: // Execute the provider
082: SRAProxyletProvider sraProxyletProvider = (SRAProxyletProvider) provider;
083: sraProxyletProvider.init("ProxyletProvider", req);
084: sb.append(sraProxyletProvider.getContent(req, res)
085: .toString());
086:
087: // Set the content into a bean
088: bean.set_HtmlContent(sb);
089:
090: // Put bean in session scope for the view to pick up.
091: session.setAttribute("SRA_PROXYLET_PROVIDER_BEAN",
092: bean);
093: }
094: } catch (Exception e) {
095: throw new CommandExecutionException(e);
096: }
097:
098: }
099:
100: }
101:
102: }
|