1 16 package org.apache.cocoon.portal.wsrp.adapter; 17 18 import java.io.IOException ; 19 import java.util.Enumeration ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 import javax.servlet.ServletConfig ; 25 26 import oasis.names.tc.wsrp.v1.types.BlockingInteractionResponse; 27 import oasis.names.tc.wsrp.v1.types.MarkupContext; 28 import oasis.names.tc.wsrp.v1.types.MarkupResponse; 29 import oasis.names.tc.wsrp.v1.types.MarkupType; 30 import oasis.names.tc.wsrp.v1.types.PortletContext; 31 import oasis.names.tc.wsrp.v1.types.PortletDescription; 32 import oasis.names.tc.wsrp.v1.types.SessionContext; 33 import oasis.names.tc.wsrp.v1.types.UpdateResponse; 34 35 import org.apache.avalon.framework.activity.Disposable; 36 import org.apache.avalon.framework.activity.Initializable; 37 import org.apache.avalon.framework.configuration.Configuration; 38 import org.apache.avalon.framework.configuration.ConfigurationException; 39 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; 40 import org.apache.avalon.framework.container.ContainerUtil; 41 import org.apache.avalon.framework.context.Context; 42 import org.apache.avalon.framework.context.ContextException; 43 import org.apache.avalon.framework.context.Contextualizable; 44 import org.apache.avalon.framework.parameters.ParameterException; 45 import org.apache.avalon.framework.parameters.Parameterizable; 46 import org.apache.avalon.framework.parameters.Parameters; 47 import org.apache.avalon.framework.service.ServiceException; 48 import org.apache.avalon.framework.service.ServiceManager; 49 import org.apache.avalon.framework.service.Serviceable; 50 import org.apache.cocoon.ProcessingException; 51 import org.apache.cocoon.environment.ObjectModelHelper; 52 import org.apache.cocoon.environment.Session; 53 import org.apache.cocoon.environment.wrapper.RequestParameters; 54 import org.apache.cocoon.portal.PortalManagerAspect; 55 import org.apache.cocoon.portal.PortalManagerAspectPrepareContext; 56 import org.apache.cocoon.portal.PortalManagerAspectRenderContext; 57 import org.apache.cocoon.portal.PortalService; 58 import org.apache.cocoon.portal.coplet.CopletData; 59 import org.apache.cocoon.portal.coplet.CopletInstanceData; 60 import org.apache.cocoon.portal.coplet.adapter.impl.AbstractCopletAdapter; 61 import org.apache.cocoon.portal.coplet.status.SizingStatus; 62 import org.apache.cocoon.portal.event.EventManager; 63 import org.apache.cocoon.portal.event.Receiver; 64 import org.apache.cocoon.portal.event.impl.ChangeCopletInstanceAspectDataEvent; 65 import org.apache.cocoon.portal.event.impl.FullScreenCopletEvent; 66 import org.apache.cocoon.portal.layout.Layout; 67 import org.apache.cocoon.portal.serialization.IncludingHTMLSerializer; 68 import org.apache.cocoon.portal.util.HtmlSaxParser; 69 import org.apache.cocoon.portal.wsrp.consumer.ConsumerEnvironmentImpl; 70 import org.apache.cocoon.portal.wsrp.consumer.ProducerDescription; 71 import org.apache.cocoon.portal.wsrp.consumer.ProducerRegistryImpl; 72 import org.apache.cocoon.portal.wsrp.consumer.Request; 73 import org.apache.cocoon.portal.wsrp.consumer.RequestImpl; 74 import org.apache.cocoon.portal.wsrp.consumer.RequiresConsumerEnvironment; 75 import org.apache.cocoon.portal.wsrp.consumer.RequiresPortalService; 76 import org.apache.cocoon.portal.wsrp.consumer.RequiresWSRPAdapter; 77 import org.apache.cocoon.portal.wsrp.consumer.SimplePortletWindowSession; 78 import org.apache.cocoon.portal.wsrp.consumer.UserContextProvider; 79 import org.apache.cocoon.portal.wsrp.consumer.WSRPRequestImpl; 80 import org.apache.cocoon.portal.wsrp.logging.WSRPLogManager; 81 import org.apache.cocoon.portal.wsrp.logging.WSRPLogger; 82 import org.apache.cocoon.servlet.CocoonServlet; 83 import org.apache.cocoon.util.ClassUtils; 84 import org.apache.cocoon.xml.AbstractXMLPipe; 85 import org.apache.cocoon.xml.AttributesImpl; 86 import org.apache.cocoon.xml.XMLUtils; 87 import org.apache.commons.lang.exception.NestableRuntimeException; 88 import org.apache.excalibur.source.Source; 89 import org.apache.excalibur.source.SourceResolver; 90 import org.apache.wsrp4j.consumer.GroupSession; 91 import org.apache.wsrp4j.consumer.PortletDriver; 92 import org.apache.wsrp4j.consumer.PortletKey; 93 import org.apache.wsrp4j.consumer.PortletSession; 94 import org.apache.wsrp4j.consumer.Producer; 95 import org.apache.wsrp4j.consumer.SessionHandler; 96 import org.apache.wsrp4j.consumer.User; 97 import org.apache.wsrp4j.consumer.UserSession; 98 import org.apache.wsrp4j.consumer.WSRPPortlet; 99 import org.apache.wsrp4j.consumer.driver.PortletKeyImpl; 100 import org.apache.wsrp4j.consumer.driver.UserImpl; 101 import org.apache.wsrp4j.consumer.driver.WSRPPortletImpl; 102 import org.apache.wsrp4j.exception.ErrorCodes; 103 import org.apache.wsrp4j.exception.WSRPException; 104 import org.apache.wsrp4j.log.LogManager; 105 import org.apache.wsrp4j.util.Constants; 106 import org.apache.wsrp4j.util.WindowStates; 107 import org.xml.sax.Attributes ; 108 import org.xml.sax.ContentHandler ; 109 import org.xml.sax.SAXException ; 110 import org.xml.sax.ext.LexicalHandler ; 111 112 122 public class WSRPAdapter 123 extends AbstractCopletAdapter 124 implements Contextualizable, 125 PortalManagerAspect, 126 Serviceable, 127 Initializable, 128 Disposable, 129 Parameterizable, 130 Receiver { 131 132 133 public static final String ATTRIBUTE_NAME_CONSUMER_MAP = "wsrp-consumer-map"; 134 135 136 public static final String ATTRIBUTE_NAME_PORTLET_INSTANCE_KEY = "wsrp-portlet-instance-key"; 137 138 139 public static final String ATTRIBUTE_NAME_PORTLET_KEY = "wsrp-portletkey"; 140 141 142 public static final String ATTRIBUTE_NAME_USER = "wsrp-user"; 143 144 145 public static final String ATTRIBUTE_NAME_LAYOUT = "wsrp-layout"; 146 147 148 public static final String ATTRIBUTE_NAME_PORTLET_TITLE = "wsrp-title"; 149 150 151 public static final String ATTRIBUTE_NAME_PORTLET_MODES = "wsrp-modes"; 152 153 154 public static final String ATTRIBUTE_NAME_PORTLET_WINDOWSTATES = "wsrp-window-states"; 155 156 157 public static final String CONSUMER_URL = "http://cocoon.apache.org/portal/wsrp-consumer"; 158 159 160 public static final String consumerAgent = "Apache Cocoon Portal." + org.apache.cocoon.Constants.VERSION; 161 162 163 protected Context context; 164 165 166 protected ConsumerEnvironmentImpl consumerEnvironment; 167 168 169 protected final ThreadLocal copletInstanceData = new ThreadLocal (); 170 171 172 protected ServletConfig servletConfig; 173 174 175 protected ServiceManager manager; 176 177 178 protected PortalService service; 179 180 181 protected UserContextProvider userContextProvider; 182 183 184 protected String wsrpConfigLocation; 185 186 187 protected boolean initialized = false; 188 189 190 protected Configuration wsrpConfiguration; 191 192 193 protected Parameters parameters; 194 195 198 public void contextualize(Context context) throws ContextException { 199 this.context = context; 200 try { 201 this.servletConfig = (ServletConfig ) context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG); 202 this.servletConfig.getServletContext().setAttribute(WSRPAdapter.class.getName(), this); 206 } catch (ContextException ignore) { 207 this.getLogger().warn("The wsrp support is disabled as the servlet context is not available.", ignore); 211 } 212 } 213 214 217 public void service(ServiceManager manager) throws ServiceException { 218 this.manager = manager; 219 EventManager eventManager = null; 220 try { 221 eventManager = (EventManager)this.manager.lookup(EventManager.ROLE); 222 eventManager.subscribe(this); 223 } finally { 224 this.manager.release(eventManager); 225 } 226 this.service = (PortalService)this.manager.lookup(PortalService.ROLE); 227 this.userContextProvider = (UserContextProvider)this.manager.lookup(UserContextProvider.ROLE); 228 } 229 230 233 public void parameterize(Parameters params) throws ParameterException { 234 this.wsrpConfigLocation = params.getParameter("wsrp-config"); 235 this.parameters = params; 236 } 237 238 243 public void initialize() throws Exception { 244 LogManager.setLogManager(new WSRPLogManager(new WSRPLogger(this.getLogger()))); 245 this.consumerEnvironment = new ConsumerEnvironmentImpl(); 246 this.consumerEnvironment.init(this.service, 247 this); 248 consumerEnvironment.setConsumerAgent(consumerAgent); 249 } 250 251 256 public void dispose() { 257 258 consumerEnvironment.getPortletRegistry().removeAllPortlets(); 259 260 Iterator producers = consumerEnvironment.getProducerRegistry().getAllProducers(); 261 Producer producer; 262 while (producers.hasNext()) { 263 producer = (Producer) producers.next(); 264 try { 265 producer.deregister(); 266 } catch (WSRPException e) { 267 this.getLogger().error("deregister() producer: " + producer.getName()); 268 } 269 } 270 consumerEnvironment.getProducerRegistry().removeAllProducers(); 271 272 consumerEnvironment.getUserRegistry().removeAllUsers(); 273 274 if ( this.manager != null ) { 275 EventManager eventManager = null; 276 try { 277 eventManager = (EventManager)this.manager.lookup(EventManager.ROLE); 278 eventManager.unsubscribe(this); 279 } catch (Exception ignore) { 280 } finally { 282 this.manager.release(eventManager); 283 } 284 this.manager.release(this.service); 285 this.manager.release(this.userContextProvider); 286 this.service = null; 287 this.userContextProvider = null; 288 this.manager = null; 289 } 290 try { 291 ContainerUtil.dispose(this.consumerEnvironment); 292 this.consumerEnvironment = null; 293 } catch (Throwable t) { 294 this.getLogger().error("Destruction failed!", t); 295 } 296 297 if ( this.servletConfig != null ) { 298 this.servletConfig.getServletContext().removeAttribute(WSRPAdapter.class.getName()); 299 this.servletConfig = null; 300 } 301 } 302 303 310 public void login(CopletInstanceData coplet) { 311 super.login(coplet); 312 313 final CopletData copletData = coplet.getCopletData(); 314 315 final String producerId = (String ) copletData.getAttribute("producer-id"); 317 if ( producerId == null ) { 318 this.getLogger().error("Producer not configured in wsrp coplet " + copletData.getId()); 320 return; 321 } 322 final Producer producer = consumerEnvironment.getProducerRegistry().getProducer(producerId); 323 if ( producer == null ) { 324 this.getLogger().error("Producer with id " + producerId + " not found."); 326 return; 327 } 328 329 final String currentUserID = this.service.getComponentManager().getProfileManager().getUser().getUserName(); 331 User user = this.consumerEnvironment.getUserRegistry().getUser(currentUserID); 332 if ( user == null ) { 333 user = new UserImpl(currentUserID); 335 user.setUserContext(this.userContextProvider.createUserContext(currentUserID)); 336 this.consumerEnvironment.getUserRegistry().addUser(user); 337 } 338 coplet.setTemporaryAttribute(ATTRIBUTE_NAME_USER, user); 339 340 final String portletHandle = (String ) copletData.getAttribute("portlet-handle"); 342 if ( portletHandle == null ) { 343 this.getLogger().error("Portlet handle not configured in wsrp coplet " + copletData.getId()); 345 return; 346 } 347 348 final PortletKey portletKey = new PortletKeyImpl(portletHandle, producerId); 350 WSRPPortlet wsrpportlet = this.consumerEnvironment.getPortletRegistry().getPortlet(portletKey); 351 if ( wsrpportlet == null ) { 352 wsrpportlet = new WSRPPortletImpl(portletKey); 353 final PortletContext portletContext = new PortletContext(null, portletKey.getPortletHandle(), null); 354 wsrpportlet.setPortletContext(portletContext); 355 try { 356 consumerEnvironment.getPortletRegistry().addPortlet(wsrpportlet); 357 } catch (WSRPException we) { 358 this.getLogger().error("Exception adding wsrp portlet.", we); 359 return; 360 } 361 } 362 coplet.setTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_KEY, portletKey); 363 final Session session = ObjectModelHelper.getRequest(this.service.getObjectModel()).getSession(); 364 final String portletInstanceKey = this.getPortletInstanceKey(portletKey, coplet, session.getId()); 365 coplet.setTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_INSTANCE_KEY, portletInstanceKey); 366 367 final Map addParams = new HashMap (); 369 addParams.put(Constants.PORTLET_INSTANCE_KEY, portletInstanceKey); 370 coplet.setTemporaryAttribute(ATTRIBUTE_NAME_CONSUMER_MAP, addParams); 371 372 SimplePortletWindowSession windowSession; 374 wsrpportlet = consumerEnvironment.getPortletRegistry().getPortlet(portletKey); 375 376 try { 377 windowSession = getSimplePortletWindowSession(wsrpportlet, 381 portletInstanceKey, 382 user); 383 final PortletDescription desc = producer.getPortletDescription(portletHandle); 384 coplet.setTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_TITLE, 385 desc.getTitle()); 386 final MarkupType markupType = desc.getMarkupTypes(0); 387 coplet.setTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_MODES, markupType.getModes()); 388 coplet.setTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_WINDOWSTATES, markupType.getWindowStates()); 389 390 } catch (WSRPException e) { 391 this.getLogger().error("Invoking getServiceDescription()", e); 392 } 393 } 394 395 401 public void streamContent(CopletInstanceData coplet, ContentHandler contentHandler) 402 throws SAXException { 403 try { 404 this.setCurrentCopletInstanceData(coplet); 407 408 final PortletKey portletKey = (PortletKey)coplet.getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_KEY); 410 if ( portletKey == null ) { 411 throw new SAXException ("WSRP configuration is missing: portlet key."); 412 } 413 final User user = (User)coplet.getTemporaryAttribute(ATTRIBUTE_NAME_USER); 414 if ( user == null ) { 415 throw new SAXException ("WSRP configuration is missing: user."); 416 } 417 418 final String portletInstanceKey = (String )coplet.getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_INSTANCE_KEY); 419 420 final WSRPPortlet wsrpportlet = consumerEnvironment.getPortletRegistry().getPortlet(portletKey); 422 423 SimplePortletWindowSession windowSession = getSimplePortletWindowSession(wsrpportlet, portletInstanceKey, user); 424 final MarkupContext markupContext = this.getMarkupContext(wsrpportlet, windowSession, user); 425 if ( markupContext == null || markupContext.getMarkupString() == null ) { 426 throw new SAXException ("No markup received from wsrp coplet " + coplet.getId()); 427 } 428 final String content = markupContext.getMarkupString(); 429 430 final Boolean usePipeline; 431 final boolean usesGet; 432 final Producer producer = this.consumerEnvironment.getProducerRegistry().getProducer(portletKey.getProducerId()); 434 final PortletDescription desc = producer.getPortletDescription(portletKey.getPortletHandle()); 435 if ( desc.getUsesMethodGet() != null && desc.getUsesMethodGet().booleanValue() ) { 436 usePipeline = Boolean.TRUE; 437 usesGet = true; 438 } else { 439 usePipeline = (Boolean )this.getConfiguration(coplet, "use-pipeline", Boolean.FALSE); 440 usesGet = false; 441 } 442 if ( usePipeline.booleanValue() ) { 443 if ( usesGet ) { 444 contentHandler = new FormRewritingHandler(contentHandler); 445 } 446 HtmlSaxParser.parseString(content, HtmlSaxParser.getContentFilter(contentHandler)); 447 } else { 448 IncludingHTMLSerializer.addPortlet(portletInstanceKey, content); 450 contentHandler.startPrefixMapping("portal", IncludingHTMLSerializer.NAMESPACE); 451 final AttributesImpl attr = new AttributesImpl(); 452 attr.addCDATAAttribute("portlet", portletInstanceKey); 453 contentHandler.startElement(IncludingHTMLSerializer.NAMESPACE, 454 "include", 455 "portal:include", 456 attr); 457 contentHandler.endElement(IncludingHTMLSerializer.NAMESPACE, 458 "include", 459 "portal:include"); 460 contentHandler.endPrefixMapping("portal"); 461 } 462 } catch (WSRPException e) { 463 throw new SAXException ("Exception during getMarkup of wsrp coplet: " + coplet.getId(), e); 464 } catch (SAXException se) { 465 throw se; 466 } finally { 467 this.setCurrentCopletInstanceData(null); 468 } 469 } 470 471 476 public void logout(CopletInstanceData coplet) { 477 super.logout(coplet); 478 479 PortletKey portletKey = (PortletKey)coplet.getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_KEY); 480 User user = (User)coplet.getTemporaryAttribute(ATTRIBUTE_NAME_USER); 481 final String portletInstanceKey = (String )coplet.getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_INSTANCE_KEY); 482 Producer producer = consumerEnvironment.getProducerRegistry().getProducer(portletKey.getProducerId()); 483 484 try { 486 UserSession userSession = consumerEnvironment.getSessionHandler().getUserSession(portletKey.getProducerId(), user.getUserID()); 487 PortletDescription portletDescription = producer.getPortletDescription(portletKey.getPortletHandle()); 488 GroupSession groupSession = userSession.getGroupSession(portletDescription.getGroupID()); 489 PortletSession portletSession = groupSession.getPortletSession(portletInstanceKey); 490 SessionContext sessionContext = portletSession.getSessionContext(); 491 WSRPPortlet wsrpportlet = consumerEnvironment.getPortletRegistry().getPortlet(portletKey); 492 PortletDriver portletDriver = consumerEnvironment.getPortletDriverRegistry().getPortletDriver(wsrpportlet); 493 494 if (sessionContext != null) { 495 String [] sessions = new String [1]; 496 sessions[0] = new String (sessionContext.getSessionID()); 497 portletDriver.releaseSessions(sessions, user.getUserID()); 498 } 499 500 userSession.removeGroupSession(portletDescription.getGroupID()); 501 } catch (WSRPException e) { 502 this.getLogger().error("session deregister()", e); 503 } 504 } 505 506 515 public SimplePortletWindowSession getSimplePortletWindowSession(WSRPPortlet portlet, 516 String portletInstanceKey, 517 User user) 518 throws WSRPException { 519 SimplePortletWindowSession windowSession = null; 520 521 SessionHandler sessionHandler = consumerEnvironment.getSessionHandler(); 523 UserSession userSession = sessionHandler.getUserSession(portlet.getPortletKey().getProducerId(), user.getUserID()); 524 525 if (userSession != null) { 526 String groupID = null; 528 try { 529 Producer producer = consumerEnvironment.getProducerRegistry().getProducer(portlet.getPortletKey().getProducerId()); 530 PortletDescription portletDescription = producer.getPortletDescription(portlet.getPortletKey().getPortletHandle()); 534 535 if (portletDescription != null) { 536 groupID = portletDescription.getGroupID(); 537 } 538 } catch (WSRPException e) { 539 groupID = "default_group_id"; 540 this.getLogger().info("using default-group"); 541 } 542 543 GroupSession groupSession = userSession.getGroupSession(groupID); 544 545 if (groupSession != null) { 546 PortletSession portletSession = groupSession.getPortletSession(portlet.getPortletKey().getPortletHandle()); 547 548 if (portletSession != null) { 549 windowSession = (SimplePortletWindowSession) portletSession.getPortletWindowSession(portletInstanceKey); 550 } else { 551 this.getLogger().error("WSRP-Errorcode: " + Integer.toString(ErrorCodes.PORTLET_SESSION_NOT_FOUND)); 552 } 553 } else { 554 this.getLogger().error("WSRP-Errorcode: " + Integer.toString(ErrorCodes.GROUP_SESSION_NOT_FOUND)); 555 } 556 } else { 557 this.getLogger().error("WSRP-Errorcode: " + Integer.toString(ErrorCodes.USER_SESSION_NOT_FOUND)); 558 } 559 return windowSession; 560 } 561 562 576 protected void performBlockingInteraction(WSRPPortlet portlet, 577 SimplePortletWindowSession windowSession, 578 User user, 579 Request request) { 580 try { 581 PortletDriver portletDriver = consumerEnvironment.getPortletDriverRegistry().getPortletDriver(portlet); 582 BlockingInteractionResponse response = portletDriver.performBlockingInteraction( 583 new WSRPRequestImpl(windowSession, request, consumerEnvironment), user.getUserID()); 584 585 if (response != null) { 586 UpdateResponse update = response.getUpdateResponse(); 587 if (update != null) { 588 windowSession.getPortletSession().setSessionContext(update.getSessionContext()); 590 591 MarkupContext markupContext = update.getMarkupContext(); 592 if (markupContext != null) { 593 windowSession.updateMarkupCache(markupContext); 594 } 595 596 windowSession.setNavigationalState(update.getNavigationalState()); 597 598 String windowState = null; 599 if ((windowState = update.getNewWindowState()) != null) { 600 windowSession.setWindowState(windowState); 601 } 602 603 String windowMode = null; 604 if ((windowMode = update.getNewMode()) != null) { 605 windowSession.setMode(windowMode); 606 } 607 } else if (response.getRedirectURL() != null) { 608 this.getLogger().debug("response.getRedirectURL() != null"); 609 } 610 } 611 } catch (WSRPException e) { 612 this.getLogger().error("Error occured during performInteraction!", e); 613 } 614 } 615 616 624 protected MarkupContext getMarkupContext(WSRPPortlet portlet, 625 SimplePortletWindowSession windowSession, 626 User user) 627 throws WSRPException { 628 WSRPRequestImpl wsrpRequest = new WSRPRequestImpl(windowSession, null, this.consumerEnvironment); 629 630 PortletDriver portletDriver = consumerEnvironment.getPortletDriverRegistry().getPortletDriver(portlet); 631 MarkupResponse response = portletDriver.getMarkup(wsrpRequest, user.getUserID()); 632 633 if (response != null) { 634 SessionContext sessionContext = response.getSessionContext(); 635 if (sessionContext != null && windowSession != null) { 636 windowSession.getPortletSession().setSessionContext(sessionContext); 637 } 638 639 return response.getMarkupContext(); 640 } 641 return null; 642 } 643 644 652 protected String getPortletInstanceKey(PortletKey key, 653 CopletInstanceData coplet, 654 String userName) { 655 final StringBuffer buffer = new StringBuffer (key.getProducerId()); 656 buffer.append('_').append(key.getPortletHandle()).append('_'); 657 buffer.append(coplet.getId()).append('_').append(userName); 658 return buffer.toString(); 659 } 660 661 670 public void inform(WSRPEvent event, PortalService service) { 671 final CopletInstanceData coplet = (CopletInstanceData)event.getTarget(); 672 this.setCurrentCopletInstanceData(coplet); 673 674 try { 675 PortletKey portletKey = (PortletKey)coplet.getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_KEY); 676 final String portletInstanceKey = (String )coplet.getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_INSTANCE_KEY); 677 WSRPPortlet wsrpPortlet = consumerEnvironment.getPortletRegistry().getPortlet(portletKey); 678 User user = (User) coplet.getTemporaryAttribute(ATTRIBUTE_NAME_USER); 679 680 org.apache.cocoon.environment.Request requestObject = ObjectModelHelper.getRequest(service.getObjectModel()); 681 java.util.Enumeration formParameter = requestObject.getParameterNames(); 682 683 Request request = new RequestImpl(); 684 String portletMode = requestObject.getParameter(Constants.PORTLET_MODE); 685 String windowState = requestObject.getParameter(Constants.WINDOW_STATE); 686 687 request.setInteractionState(requestObject.getParameter(Constants.INTERACTION_STATE)); 688 SimplePortletWindowSession windowSession = getSimplePortletWindowSession(wsrpPortlet, portletInstanceKey, user); 689 windowSession.setNavigationalState(requestObject.getParameter(Constants.NAVIGATIONAL_STATE)); 690 691 if (portletMode != null) { 692 windowSession.setMode(portletMode); 693 } 694 if (windowState != null) { 695 if ( !windowState.equals(windowSession.getWindowState()) ) { 696 final Layout layout = (Layout)coplet.getTemporaryAttribute(ATTRIBUTE_NAME_LAYOUT); 697 final Layout fullScreenLayout = service.getEntryLayout(null); 698 if ( fullScreenLayout != null 699 && fullScreenLayout.equals( layout ) 700 && !windowState.equals(WindowStates._maximized) ) { 701 FullScreenCopletEvent e = new FullScreenCopletEvent( coplet, null ); 702 service.getComponentManager().getEventManager().send(e); 703 } 704 if ( windowState.equals(WindowStates._minimized) ) { 705 ChangeCopletInstanceAspectDataEvent e = new ChangeCopletInstanceAspectDataEvent(coplet, "size", SizingStatus.STATUS_MINIMIZED); 706 service.getComponentManager().getEventManager().send(e); 707 } 708 if ( windowState.equals(WindowStates._normal) ) { 709 ChangeCopletInstanceAspectDataEvent e = new ChangeCopletInstanceAspectDataEvent(coplet, "size", SizingStatus.STATUS_MAXIMIZED); 710 service.getComponentManager().getEventManager().send(e); 711 } 712 if ( windowState.equals(WindowStates._maximized) ) { 713 FullScreenCopletEvent e = new FullScreenCopletEvent( coplet, layout ); 714 service.getComponentManager().getEventManager().send(e); 715 } 716 windowSession.setWindowState(windowState); 717 } 718 } 719 if (requestObject.getParameter(Constants.URL_TYPE).equals(Constants.URL_TYPE_BLOCKINGACTION)) { 720 String parameter; 722 while (formParameter.hasMoreElements()) { 723 parameter = (String ) formParameter.nextElement(); 724 request.addFormParameter(parameter, requestObject.getParameter(parameter)); 725 } 726 performBlockingInteraction(wsrpPortlet, windowSession, user, request); 727 728 } 729 730 } catch (WSRPException e) { 731 this.getLogger().error("Error during processing wsrp event.", e); 732 } finally { 733 this.setCurrentCopletInstanceData(null); 734 } 735 } 736 737 740 public void prepare(PortalManagerAspectPrepareContext aspectContext, 741 PortalService service) 742 throws ProcessingException { 743 aspectContext.invokeNext(); 745 } 746 747 750 public void render(PortalManagerAspectRenderContext aspectContext, 751 PortalService service, 752 ContentHandler ch, 753 Parameters parameters) 754 throws SAXException { 755 aspectContext.invokeNext(ch, parameters); 756 } 757 758 761 public ConsumerEnvironmentImpl getConsumerEnvironment() { 762 return consumerEnvironment; 763 } 764 765 771 public boolean addProducer(ProducerDescription desc) { 772 return ((ProducerRegistryImpl)this.consumerEnvironment.getProducerRegistry()).addProducer(desc); 773 } 774 775 780 public void setCurrentCopletInstanceData(CopletInstanceData coplet) { 781 this.copletInstanceData.set(coplet); 782 } 783 784 789 public CopletInstanceData getCurrentCopletInstanceData() { 790 return (CopletInstanceData)this.copletInstanceData.get(); 791 } 792 793 798 public static final class FormRewritingHandler extends AbstractXMLPipe { 799 800 public FormRewritingHandler(ContentHandler ch) { 801 this.setContentHandler(ch); 802 if ( ch instanceof LexicalHandler ) { 803 this.setLexicalHandler((LexicalHandler )ch); 804 } 805 } 806 807 810 public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException { 811 if ( loc.equalsIgnoreCase("form") && a.getValue("method").equalsIgnoreCase("get") ) { 812 final String action = a.getValue("action"); 813 int pos = action.indexOf('?'); 814 if ( pos != -1 ) { 815 AttributesImpl ai = new AttributesImpl(a); 816 a = ai; 817 final String queryString = action.substring(pos+1); 818 ai.removeAttribute("action"); 819 ai.addCDATAAttribute("action", action.substring(0, pos)); 820 super.startElement(uri, loc, raw, a); 821 RequestParameters rp = new RequestParameters(queryString); 822 823 final Enumeration e = rp.getParameterNames(); 824 while ( e.hasMoreElements() ) { 825 final String key = (String )e.nextElement(); 826 final String value = rp.getParameter(key); 827 AttributesImpl attributes = new AttributesImpl(); 828 attributes.addCDATAAttribute("type", "hidden"); 829 attributes.addCDATAAttribute("name", key); 830 attributes.addCDATAAttribute("value", value); 831 XMLUtils.createElement(this.contentHandler, "input", attributes); 832 } 833 return; 834 } 835 } 836 super.startElement(uri, loc, raw, a); 837 } 838 839 } 840 841 845 protected void checkInitialized() { 846 if ( !this.initialized ) { 847 synchronized (this) { 848 if (! this.initialized ) { 849 this.initialized = true; 850 SourceResolver resolver = null; 851 Source source = null; 852 try { 853 resolver = (SourceResolver)this.manager.lookup(SourceResolver.ROLE); 854 source = resolver.resolveURI(this.wsrpConfigLocation); 855 DefaultConfigurationBuilder dcb = new DefaultConfigurationBuilder(); 856 this.wsrpConfiguration = dcb.build(source.getInputStream()); 857 } catch (ConfigurationException ce) { 858 this.getLogger().error("Unable to read wsrp configuration: " + this.wsrpConfigLocation, ce); 859 } catch (IOException ioe) { 860 this.getLogger().error("Unable to read wsrp configuration: " + this.wsrpConfigLocation, ioe); 861 } catch (SAXException sae) { 862 this.getLogger().error("Unable to read wsrp configuration: " + this.wsrpConfigLocation, sae); 863 } catch (ServiceException se) { 864 throw new NestableRuntimeException("Unable to get source resolver.", se); 865 } finally { 866 if ( resolver != null ) { 867 resolver.release(source); 868 } 869 this.manager.release(resolver); 870 } 871 } 872 } 873 } 874 } 875 876 879 public Configuration getWsrpConfiguration() { 880 this.checkInitialized(); 881 return this.wsrpConfiguration; 882 } 883 884 887 public Parameters getAdapterConfiguration() { 888 return this.parameters; 889 } 890 891 894 public Object createObject(String className) 895 throws Exception { 896 final Object component = ClassUtils.newInstance(className); 897 ContainerUtil.enableLogging(component, this.getLogger()); 898 if (component instanceof RequiresConsumerEnvironment) { 899 ((RequiresConsumerEnvironment)component).setConsumerEnvironment(this.consumerEnvironment); 900 } 901 if (component instanceof RequiresWSRPAdapter) { 902 ((RequiresWSRPAdapter)component).setWSRPAdapter(this); 903 } 904 if (component instanceof RequiresPortalService) { 905 ((RequiresPortalService)component).setPortalService(this.service); 906 } 907 ContainerUtil.contextualize(component, context); 908 ContainerUtil.service(component, manager); 909 ContainerUtil.initialize(component); 910 911 return component; 912 } 913 914 } 915 | Popular Tags |