1 16 package org.apache.cocoon.portal.pluto; 17 18 import java.util.Collection ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 import java.util.Vector ; 22 23 import javax.portlet.PortletMode; 24 import javax.portlet.WindowState; 25 26 import org.apache.cocoon.Constants; 27 import org.apache.cocoon.environment.ObjectModelHelper; 28 import org.apache.cocoon.environment.Request; 29 import org.apache.pluto.services.information.PortalContextProvider; 30 31 38 public class PortalContextProviderImpl 39 implements PortalContextProvider { 40 41 42 protected String info; 43 44 45 protected Vector modes; 46 47 48 protected Vector states; 49 50 51 protected HashMap properties; 52 53 54 protected String hostNameHTTP; 55 56 57 protected String hostNameHTTPS; 58 59 60 protected String contextHTTP; 61 62 63 protected String contextHTTPS; 64 65 68 public PortalContextProviderImpl(Map objectModel) { 69 this.modes = this.getDefaultModes(); 71 this.states = this.getDefaultStates(); 73 this.info = "Apache Cocoon/" + Constants.VERSION; 75 this.properties = new HashMap (); 76 this.init(objectModel); 77 } 78 79 82 public String getProperty(String name) { 83 if (name == null) { 84 throw new IllegalArgumentException ("Property name == null"); 85 } 86 87 return(String ) properties.get(name); 88 } 89 90 91 94 public Collection getPropertyNames() { 95 return properties.keySet(); 96 } 97 98 99 102 public Collection getSupportedPortletModes() { 103 return this.modes; 104 } 105 106 107 110 public Collection getSupportedWindowStates() { 111 return this.states; 112 } 113 114 115 118 public String getPortalInfo() { 119 return this.info; 120 } 121 122 125 protected Vector getDefaultModes() { 126 Vector m = new Vector (); 127 128 m.add(new PortletMode("view")); 129 m.add(new PortletMode("edit")); 130 m.add(new PortletMode("help")); 131 m.add(new PortletMode("config")); 132 133 return m; 134 } 135 136 139 protected Vector getDefaultStates() { 140 Vector s = new Vector (); 141 142 s.add(new WindowState("normal")); 143 s.add(new WindowState("minimized")); 144 s.add(new WindowState("maximized")); 145 146 return s; 147 } 148 149 152 protected void init(Map objectModel) { 153 final Request request = ObjectModelHelper.getRequest(objectModel); 154 final String hostName = request.getServerName(); 155 final String contextRoot = request.getContextPath(); 156 final int hostPortHTTP = request.getServerPort(); 157 final int hostPortHTTPS = 443; 158 159 StringBuffer hostHTTP = new StringBuffer ("http://"); 160 hostHTTP.append(hostName); 161 if (hostPortHTTP != 80) { 162 hostHTTP.append(":"); 163 hostHTTP.append(hostPortHTTP); 164 } 165 this.hostNameHTTP = hostHTTP.toString(); 166 hostHTTP.append('/'); 167 hostHTTP.append(contextRoot); 168 this.contextHTTP = hostHTTP.toString(); 169 170 StringBuffer hostHTTPS = new StringBuffer ("https://"); 171 hostHTTPS.append(hostName); 172 if (hostPortHTTPS != 443) { 173 hostHTTPS.append(":"); 174 hostHTTPS.append(hostPortHTTPS); 175 } 176 this.hostNameHTTPS = hostHTTPS.toString(); 177 hostHTTPS.append('/'); 178 hostHTTPS.append(contextRoot); 179 this.contextHTTPS = hostHTTPS.toString(); 180 } 181 182 public String getBaseURLexcludeContext(boolean secure) { 183 return (secure?this.hostNameHTTPS : this.hostNameHTTP); 184 } 185 186 public String getBaseURL(boolean secure) { 187 return (secure?this.contextHTTPS : this.contextHTTP); 188 } 189 190 } 191 | Popular Tags |