View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.pluto.driver.core;
18  
19  import javax.portlet.PortletMode;
20  import javax.portlet.WindowState;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  import org.apache.pluto.container.PortletContainer;
25  import org.apache.pluto.container.PortletContainerException;
26  import org.apache.pluto.container.PortletWindow;
27  import org.apache.pluto.container.PortletWindowID;
28  import org.apache.pluto.container.driver.PlutoServices;
29  import org.apache.pluto.container.om.portlet.PortletDefinition;
30  import org.apache.pluto.driver.core.PortletWindowIDImpl;
31  import org.apache.pluto.driver.services.portal.PortletWindowConfig;
32  import org.apache.pluto.driver.url.PortalURL;
33  
34  /**
35   * Implementation of <code>PortletWindow</code> interface.
36   */
37  public class PortletWindowImpl implements PortletWindow {
38  
39      /** Logger. */
40      private static final Logger LOG = LoggerFactory.getLogger(PortletWindowImpl.class);
41      
42      // Private Member Variables ------------------------------------------------
43  
44      private PortletWindowConfig config;
45      private PortalURL portalURL;
46      private PortletWindowIDImpl objectIdImpl;
47      private PortletDefinition portlet;
48      private int _nLutecePortletId;
49  
50      // Constructor -------------------------------------------------------------
51  
52      /**
53       * Constructs an instance.
54       * @param config  the portlet window configuration.
55       * @param portalURL  the portal URL.
56       */
57      public PortletWindowImpl(PortletContainer container, PortletWindowConfig config, PortalURL portalURL, int nLutecePortletId) {
58          this.config = config;
59          this.portalURL = portalURL;
60          this._nLutecePortletId = nLutecePortletId;
61          try
62          {
63              String applicationName = config.getContextPath();
64              if (applicationName.length() >0 )
65              {
66                  applicationName = applicationName.substring(1);
67              }
68              this.portlet = PlutoServices.getServices().getPortletRegistryService().getPortlet(applicationName, config.getPortletName());
69          }
70          catch (PortletContainerException ex)
71          {
72              String message = "Unable to load Portlet App Deployment Descriptor:"+ ex.getMessage();
73              ex.printStackTrace();
74              LOG.error(message, ex);
75              throw new RuntimeException(message);
76          }
77      }
78  
79      public PortletWindowImpl(PortletContainer container, PortletWindowConfig config, PortalURL portalURL) {
80          this.config = config;
81          this.portalURL = portalURL;
82          try
83          {
84              String applicationName = config.getContextPath();
85              if (applicationName.length() >0 )
86              {
87                  applicationName = applicationName.substring(1);
88              }
89              this.portlet = PlutoServices.getServices().getPortletRegistryService().getPortlet(applicationName, config.getPortletName());
90          }
91          catch (PortletContainerException ex)
92          {
93              String message = "Unable to load Portlet App Deployment Descriptor:"+ ex.getMessage();
94              ex.printStackTrace();
95              LOG.error(message, ex);
96              throw new RuntimeException(message);
97          }
98      }
99  
100 
101     // PortletWindow Impl ------------------------------------------------------
102 
103     public String getContextPath() {
104         return config.getContextPath();
105     }
106 
107     public String getPortletName() {
108         return config.getPortletName();
109     }
110 
111     public WindowState getWindowState() {
112         return portalURL.getWindowState(getId().getStringId());
113     }
114     public void setWindowState(String strWindowState) {
115     	if(strWindowState != null)
116     	{
117     		WindowState windowState = new WindowState(strWindowState);
118             portalURL.setWindowState(getId().getStringId(), windowState);
119     	}    	
120     }
121 
122     public PortletMode getPortletMode() {
123         return portalURL.getPortletMode(getId().getStringId());
124     }
125     
126     public void setPortletMode(String strPortletMode) {
127     	if(strPortletMode != null)
128     	{
129     		PortletMode portletMode = new PortletMode(strPortletMode);
130             portalURL.setPortletMode(getId().getStringId(), portletMode );
131     	}    	
132     }
133 
134     public PortletWindowID getId() {
135         if (objectIdImpl == null) {
136             objectIdImpl = PortletWindowIDImpl.createFromString(config.getId());
137         }
138         return objectIdImpl;
139     }
140 
141     public PortletDefinition getPortletDefinition() {
142         return portlet;
143     }
144     
145     public int getLutecePortletID()
146     {
147     	return _nLutecePortletId;
148     }
149 }