View Javadoc
1   package org.exoplatform.wcm.webui.selector.content;
2   
3   import javax.jcr.Node;
4   import javax.portlet.PortletPreferences;
5   
6   import org.exoplatform.portal.webui.util.Util;
7   import org.exoplatform.services.wcm.core.NodeIdentifier;
8   import org.exoplatform.services.wcm.core.NodeLocation;
9   import org.exoplatform.services.wcm.publication.NotInWCMPublicationException;
10  import org.exoplatform.services.wcm.publication.WCMPublicationService;
11  import org.exoplatform.webui.application.portlet.PortletRequestContext;
12  import org.exoplatform.webui.config.annotation.ComponentConfig;
13  import org.exoplatform.webui.config.annotation.EventConfig;
14  import org.exoplatform.webui.core.UIContainer;
15  import org.exoplatform.webui.event.Event;
16  import org.exoplatform.webui.event.EventListener;
17  
18  /**
19   * Author : TAN DUNG DANG
20   *          dzungdev@gmail.com
21   * Feb 12, 2009
22   */
23  
24  @ComponentConfig (
25      template="classpath:groovy/wcm/webui/selector/content/UIContentResultViewer.gtmpl",
26      events = {
27          @EventConfig(listeners = UIContentResultViewer.SelectActionListener.class)
28      }
29  )
30  
31  public class UIContentResultViewer extends UIContainer {
32  
33    private NodeLocation presentNodeLocation;
34  
35    public String[] getActions() {
36      return new String[] {"Select"};
37    }
38  
39    public static class SelectActionListener extends EventListener<UIContentResultViewer> {
40      public void execute(Event<UIContentResultViewer> event) throws Exception {
41        UIContentResultViewer contentResultView = event.getSource();
42        Node presentNode = NodeLocation.getNodeByLocation(contentResultView.presentNodeLocation);
43        Node webContent = presentNode;
44        NodeIdentifier nodeIdentifier = NodeIdentifier.make(webContent);
45        PortletRequestContext pContext = (PortletRequestContext) event.getRequestContext();
46        PortletPreferences prefs = pContext.getRequest().getPreferences();
47        prefs.setValue("repository", nodeIdentifier.getRepository());
48        prefs.setValue("workspace", nodeIdentifier.getWorkspace());
49        prefs.setValue("nodeIdentifier", nodeIdentifier.getUUID());
50        prefs.store();
51  
52        String remoteUser = Util.getPortalRequestContext().getRemoteUser();
53        String currentSite = Util.getPortalRequestContext().getPortalOwner();
54  
55        WCMPublicationService wcmPublicationService = contentResultView.getApplicationComponent(WCMPublicationService.class);
56  
57        try {
58          wcmPublicationService.isEnrolledInWCMLifecycle(webContent);
59        } catch (NotInWCMPublicationException e){
60          wcmPublicationService.unsubcribeLifecycle(webContent);
61          wcmPublicationService.enrollNodeInLifecycle(webContent, currentSite, remoteUser);
62        }
63      }
64    }
65  }