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.struts.config;
    18
    19  import java.io.InputStream;
    20
    21  import javax.portlet.PortletContext;
    22  import javax.portlet.PortletException;
    23
    24  import org.apache.commons.digester.Digester;
    25
    26  public class StrutsPortletConfig
    27  {
    28      private RenderContextAttributes renderContextAttributes;
    29      private PortletURLTypes portletURLTypes;
    30
    31      public void loadConfig(PortletContext portletContext,String config) throws PortletException
    32      {
    33          renderContextAttributes = new RenderContextAttributes();
    34          portletURLTypes = new PortletURLTypes();
    35
    36          InputStream input = portletContext.getResourceAsStream(config);
    37          if (input == null)
    38          {
    39              return;
    40          }
    41
    42          Digester digester = new Digester();
    43          digester.setClassLoader(Thread.currentThread().getContextClassLoader());
    44
    45          renderContextAttributes.configure(digester);
    46          portletURLTypes.configure(digester);
    47
    48          try
    49          {
    50              digester.parse(input);
    51          }
    52          catch (Exception e)
    53          {
    54              throw new PortletException("Error loading StrutsPortlet config " + config + ": " + e.getMessage(), e);
    55          }
    56          finally
    57          {
    58              try
    59              {
    60                  input.close();
    61              }
    62              catch (Exception e)
    63              {
    64              }
    65          }
    66      }
    67
    68      public RenderContextAttributes getRenderContextAttributes()
    69      {
    70          return renderContextAttributes;
    71      }
    72
    73      public PortletURLTypes getPortletURLTypes()
    74      {
    75          return portletURLTypes;
    76      }
    77  }