1 5 package org.exoplatform.portlets.wsrp.component; 6 7 import java.util.*; 8 import javax.faces.context.FacesContext; 9 import javax.portlet.PortletConfig; 10 import javax.portlet.PortletMode; 11 import javax.portlet.WindowState; 12 import org.apache.commons.logging.Log; 13 import org.exoplatform.container.PortalContainer; 14 import org.exoplatform.faces.FacesConstants; 15 import org.exoplatform.faces.application.ExoFacesMessage; 16 import org.exoplatform.faces.core.component.Node; 17 import org.exoplatform.faces.core.component.UISimpleForm; 18 import org.exoplatform.faces.core.component.UIStringInput; 19 import org.exoplatform.faces.core.component.UITextArea; 20 import org.exoplatform.faces.core.component.model.*; 21 import org.exoplatform.portlet.faces.context.ExternalContextImpl; 22 import org.exoplatform.services.portletcontainer.PortletContainerService; 23 import org.exoplatform.services.wsrp.consumer.ConsumerEnvironment; 24 import org.exoplatform.services.wsrp.consumer.Producer; 25 import org.exoplatform.services.wsrp.consumer.ProducerRegistry; 26 import org.exoplatform.services.wsrp.type.RegistrationData; 27 33 public class UIProducerForm extends UISimpleForm implements Node { 34 protected static Log log_ = getLog("org.exoplatform.portlets.wsrp") ; 35 public static final String COMPONENT_TYPE = "UIProducerForm"; 36 public static final String VIEW_ID = "producer-form"; 37 38 private String tabTitle_ ; 39 private UIStringInput producerName_ ; 40 private UIStringInput producerURL_ ; 41 private UIStringInput markupIntfEndPoint_ ; 42 private UIStringInput pmIntfEndPoint_ ; 43 private UIStringInput registrationIntfEndPoint_ ; 44 private UIStringInput serviceDescIntfEndPoint_ ; 45 private UITextArea description_ ; 46 private String [] consumerModes_ ; 47 private String [] consumerStates_ ; 48 private String consumerName_ ; 49 private String consumerAgent_ ; 50 51 private String registerProducerFailMesg_ ; 52 private String registerProducerSucessMesg_ ; 53 private ConsumerEnvironment consumerEnvironment_ ; 54 55 public UIProducerForm(ResourceBundle res, ConsumerEnvironment consumerEnvironment) { 56 super("producerForm", "post", null) ; 57 setId(VIEW_ID); 58 tabTitle_ = "Create Producer" ; 59 consumerEnvironment_ = consumerEnvironment ; 60 61 registerProducerFailMesg_ = res.getString("UIProducerForm.msg.register-producer-fail"); 62 registerProducerSucessMesg_ = res.getString("UIProducerForm.msg.register-producer-success"); 63 64 PortletContainerService portletContainer = 65 (PortletContainerService) PortalContainer.getInstance(). 66 getComponentInstanceOfType(PortletContainerService.class); 67 Collection modes = portletContainer.getSupportedPortletModes(); 68 Collection states = portletContainer.getSupportedWindowStates(); 69 consumerModes_ = new String [modes.size()] ; 70 Iterator iterator= modes.iterator() ; 71 int j = 0 ; 72 while (iterator.hasNext()) { 73 PortletMode mode = (PortletMode) iterator.next() ; 74 consumerModes_[j] = "wsrp:" + mode.toString() ; 75 j++ ; 76 } 77 78 consumerStates_ = new String [states.size()] ; 79 iterator= states.iterator() ; 80 j= 0 ; 81 while (iterator.hasNext()) { 82 WindowState state = (WindowState) iterator.next() ; 83 consumerStates_[j] = "wsrp:" + state.toString() ; 84 j++ ; 85 } 86 ExternalContextImpl eContext = 87 (ExternalContextImpl) FacesContext.getCurrentInstance().getExternalContext() ; 88 PortletConfig config = eContext.getConfig() ; 89 consumerName_ = config.getInitParameter("consumer-name") ; 90 consumerAgent_ = config.getInitParameter("consumer-agent") ; 91 92 String saveButton = "#{UIProducerForm.button.save}" ; 93 String resetButton = "#{UIProducerForm.button.reset}" ; 94 producerName_ = new UIStringInput("producerName", ""); 95 producerURL_ = new UIStringInput("producerURL", ""); 96 markupIntfEndPoint_ = new UIStringInput("markupIntfEndPoint", "") ; 97 pmIntfEndPoint_ = new UIStringInput("pmIntfEndPoint", "") ; 98 registrationIntfEndPoint_ = new UIStringInput("registrationIntfEndPoint", ""); 99 serviceDescIntfEndPoint_ = new UIStringInput("serviceDescIntfEndPoint", "") ; 100 description_ = new UITextArea("description", ""); 101 102 add(new HeaderRow(). 103 add(new Cell("#{UIProducerForm.header.new-producer}"). 104 addColspan("2"))); 105 add(new Row(). 106 add(new LabelCell("#{UIProducerForm.label.producer-name}")). 107 add(new ComponentCell(this, producerName_))); 108 add(new Row(). 109 add(new LabelCell("#{UIProducerForm.label.producer-url}")). 110 add(new ComponentCell(this, producerURL_))); 111 add(new Row(). 112 add(new LabelCell("#{UIProducerForm.label.markup-interface-end-point}")). 113 add(new ComponentCell(this, markupIntfEndPoint_ ))); 114 add(new Row(). 115 add(new LabelCell("#{UIProducerForm.label.portlet-management-interface-end-point}")). 116 add(new ComponentCell(this, pmIntfEndPoint_ ))); 117 add(new Row(). 118 add(new LabelCell("#{UIProducerForm.label.registration-interface-end-point}")). 119 add(new ComponentCell(this, pmIntfEndPoint_ ))); 120 add(new Row(). 121 add(new LabelCell("#{UIProducerForm.label.service-description-end-point}")). 122 add(new ComponentCell(this, serviceDescIntfEndPoint_ ))); 123 add(new Row(). 124 add(new LabelCell("#{UIProducerForm.label.description}")). 125 add(new ComponentCell(this, description_ ))); 126 add(new Row(). 127 add(new ListComponentCell(). 128 add(new FormButton(saveButton, SAVE_ACTION)). 129 add(new FormButton(resetButton, "reset")). 130 addColspan("2").addAlign("center"))) ; 131 reset() ; 132 } 133 134 private void reset() { 135 producerName_.setValue("exo producer") ; 136 producerURL_.setValue("http://localhost:8080/wsrp/services/") ; 137 markupIntfEndPoint_.setValue("WSRPBaseService") ; ; 138 pmIntfEndPoint_.setValue("WSRPPortletManagementService") ; 139 registrationIntfEndPoint_.setValue("WSRPRegistrationService") ; 140 serviceDescIntfEndPoint_.setValue("WSRPServiceDescriptionService") ; 141 description_.setValue("") ; 142 } 143 144 public String getComponentType() { return COMPONENT_TYPE; } 145 146 public void decode(FacesContext context) { 147 Map paramMap = context.getExternalContext().getRequestParameterMap() ; 148 String action = (String ) paramMap.get(FacesConstants.ACTION) ; 149 if(CANCEL_ACTION.equals(action)) { 150 return ; 151 } 152 153 if("reset".equals(action)) { 154 reset() ; 155 context.renderResponse() ; 156 return ; 157 } 158 159 if(SAVE_ACTION.equals(action)) { 160 if(hasError()) { 161 } else { 162 try { 163 String pURL = producerURL_.getValue() ; 164 String producerId = "producer" + Integer.toString(pURL.hashCode()) ; 165 ProducerRegistry pregistry = consumerEnvironment_.getProducerRegistry() ; 166 Producer producer = pregistry.createProducerInstance() ; 167 producer.setID(producerId); 168 producer.setName(producerName_.getValue()); 169 producer.setMarkupInterfaceEndpoint(pURL +markupIntfEndPoint_.getValue()); 170 producer.setPortletManagementInterfaceEndpoint(pURL + pmIntfEndPoint_.getValue()); 171 producer.setRegistrationInterfaceEndpoint(pURL + registrationIntfEndPoint_.getValue()); 172 producer.setServiceDescriptionInterfaceEndpoint(pURL + serviceDescIntfEndPoint_.getValue()); 173 producer.setDescription(description_.getValue()); 174 producer.setDesiredLocales(new String [] {"en"}); 175 if (producer.isRegistrationRequired()) { 176 String [] CONSUMER_SCOPES = {"chunk_data"}; 177 String [] CONSUMER_CUSTOM_PROFILES = {"what_more"}; 178 RegistrationData registrationData = new RegistrationData(); 179 registrationData.setConsumerName(consumerName_); 180 registrationData.setConsumerAgent(consumerAgent_); 181 registrationData.setMethodGetSupported(false); 182 registrationData.setConsumerModes(consumerModes_); 183 registrationData.setConsumerWindowStates(consumerStates_); 184 registrationData.setConsumerUserScopes(CONSUMER_SCOPES); 185 registrationData.setCustomUserProfileData(CONSUMER_CUSTOM_PROFILES); 186 producer.register(registrationData); 187 } 188 pregistry.addProducer(producer) ; 189 } catch (Exception ex) { 190 log_.error("Error: ", ex) ; 191 } 192 } 193 } 194 } 195 196 public String getName() { 197 return tabTitle_; 198 } 199 200 public String getIcon() { 201 return "no-icon" ; 202 } 203 204 public String getDescription() { 205 return "no description"; 206 } 207 208 209 } | Popular Tags |