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.portals.bridges.groovy;
    18
    19  import java.io.IOException;
    20
    21  import javax.portlet.PortletException;
    22
    23  import org.codehaus.groovy.control.CompilationFailedException;
    24
    25  import org.apache.jetspeed.portlet.SupportsHeaderPhase;
    26  import org.apache.jetspeed.portlet.PortletHeaderRequest;
    27  import org.apache.jetspeed.portlet.PortletHeaderResponse;
    28
    29  /***
    30   * <p>
    31   * GroovyPortletHeaderPhaseSupport parses and invokes a groovy-scripted portlet. A groovy-scripted
    32   * portlet just need to be implemented like any other Java-based portlet. So, a
    33   * groovy-scripted portlet does not support only full features of JSR-168 portlet, but
    34   * it also supports JSR-286 header phase.
    35   *
    36   * @author <a href="mailto:woon_san@yahoo.com">Woonsan Ko</a>
    37   * @Id@
    38   */
    39  public class GroovyPortletHeaderPhaseSupport extends GroovyPortlet implements SupportsHeaderPhase
    40  {
    41      protected SupportsHeaderPhase scriptPortletInstanceWithHeaderPhase;
    42
    43      public GroovyPortletHeaderPhaseSupport()
    44      {
    45          super();
    46      }
    47
    48      public void doHeader(PortletHeaderRequest request, PortletHeaderResponse response) throws PortletException
    49      {
    50          refreshPortletInstance();
    51
    52          if (this.scriptPortletInstanceWithHeaderPhase != null)
    53          {
    54              this.scriptPortletInstanceWithHeaderPhase.doHeader(request, response);
    55          }
    56      }
    57
    58      protected void createScriptPortletInstance() throws CompilationFailedException, InstantiationException,
    59              IOException, IllegalAccessException, PortletException
    60      {
    61          super.createScriptPortletInstance();
    62
    63          if (scriptPortletInstance instanceof SupportsHeaderPhase)
    64          {
    65              this.scriptPortletInstanceWithHeaderPhase = (SupportsHeaderPhase) scriptPortletInstance;
    66          }
    67      }
    68  }