1 16 package org.apache.cocoon.portal.wsrp.consumer; 17 18 import oasis.names.tc.wsrp.v1.types.StateChange; 19 20 import org.apache.avalon.framework.parameters.Parameters; 21 import org.apache.cocoon.portal.PortalService; 22 import org.apache.cocoon.portal.coplet.CopletInstanceData; 23 import org.apache.cocoon.portal.wsrp.adapter.WSRPAdapter; 24 import org.apache.wsrp4j.consumer.PortletDriverRegistry; 25 import org.apache.wsrp4j.consumer.PortletRegistry; 26 import org.apache.wsrp4j.consumer.ProducerRegistry; 27 import org.apache.wsrp4j.consumer.SessionHandler; 28 import org.apache.wsrp4j.consumer.URLGenerator; 29 import org.apache.wsrp4j.consumer.URLRewriter; 30 import org.apache.wsrp4j.consumer.URLTemplateComposer; 31 import org.apache.wsrp4j.consumer.User; 32 import org.apache.wsrp4j.consumer.UserRegistry; 33 import org.apache.wsrp4j.consumer.driver.GenericConsumerEnvironment; 34 import org.apache.wsrp4j.consumer.util.ConsumerConstants; 35 import org.apache.wsrp4j.util.Constants; 36 import org.apache.wsrp4j.util.Modes; 37 import org.apache.wsrp4j.util.WindowStates; 38 39 47 public class ConsumerEnvironmentImpl 48 extends GenericConsumerEnvironment { 49 50 51 protected URLGenerator urlGenerator; 52 53 54 protected WSRPAdapter adapter; 55 56 63 public void init(PortalService service, 64 WSRPAdapter adapter) 65 throws Exception { 66 this.adapter = adapter; 67 Parameters params = adapter.getAdapterConfiguration(); 68 this.setConsumerAgent("not set"); 69 70 String [] supportedLocales = new String [1]; 74 supportedLocales[0] = Constants.LOCALE_EN_US; 75 this.setSupportedLocales(supportedLocales); 76 77 String [] supportedModes = new String [3]; 79 supportedModes[0] = Modes._view; 80 supportedModes[1] = Modes._help; 81 supportedModes[2] = Modes._edit; 82 this.setSupportedModes(supportedModes); 83 84 String [] supportedWindowStates = new String [3]; 86 supportedWindowStates[0] = WindowStates._normal; 87 supportedWindowStates[1] = WindowStates._maximized; 88 supportedWindowStates[2] = WindowStates._minimized; 89 this.setSupportedWindowStates(supportedWindowStates); 90 91 this.setPortletStateChange(StateChange.readWrite); 93 94 this.setMimeTypes(new String [] { Constants.MIME_TYPE_HTML }); 96 97 this.setCharacterEncodingSet(new String [] { Constants.UTF_8 }); 99 100 this.setUserAuthentication(ConsumerConstants.NONE); 102 103 this.setUserRegistry((UserRegistry)adapter.createObject(params.getParameter("user-registry-class", UserRegistryImpl.class.getName()))); 105 this.setSessionHandler((SessionHandler)adapter.createObject(params.getParameter("session-handler-class", SessionHandlerImpl.class.getName()))); 106 this.setProducerRegistry((ProducerRegistry)adapter.createObject(params.getParameter("producer-registry-class", ProducerRegistryImpl.class.getName()))); 107 this.setPortletRegistry((PortletRegistry)adapter.createObject(params.getParameter("portlet-registry-class", PortletRegistryImpl.class.getName()))); 108 109 this.setTemplateComposer((URLTemplateComposer)adapter.createObject(params.getParameter("url-template-composer-class", URLTemplateComposerImpl.class.getName()))); 110 this.setURLRewriter((URLRewriter)adapter.createObject(params.getParameter("url-rewriter-class", URLRewriterImpl.class.getName()))); 111 112 this.setPortletDriverRegistry((PortletDriverRegistry)adapter.createObject(params.getParameter("portlet-driver-registry-class", PortletDriverRegistryImpl.class.getName()))); 113 114 this.urlGenerator = (URLGenerator)adapter.createObject(params.getParameter("url-generator-class", URLGeneratorImpl.class.getName())); 115 this.getTemplateComposer().setURLGenerator(this.urlGenerator); 116 this.getURLRewriter().setURLGenerator(this.urlGenerator); 117 } 118 119 122 public URLGenerator getURLGenerator() { 123 return this.urlGenerator; 124 } 125 126 129 public String [] getSupportedLocales() { 130 CopletInstanceData coplet = this.adapter.getCurrentCopletInstanceData(); 131 User user = (User)coplet.getTemporaryAttribute(WSRPAdapter.ATTRIBUTE_NAME_USER); 132 133 return ((UserContextExtension)user.getUserContext()).getSupportedLocales(); 134 } 135 136 139 public String getUserAuthentication() { 140 CopletInstanceData coplet = this.adapter.getCurrentCopletInstanceData(); 141 User user = (User)coplet.getTemporaryAttribute(WSRPAdapter.ATTRIBUTE_NAME_USER); 142 143 return ((UserContextExtension)user.getUserContext()).getUserAuthentication(); 144 } 145 } 146 | Popular Tags |