View Javadoc

1   package org.apache.portals.bridges.struts.config;
2   
3   import java.io.InputStream;
4   
5   import javax.portlet.PortletContext;
6   import javax.portlet.PortletException;
7   
8   import org.apache.commons.digester.Digester;
9   
10  public class StrutsPortletConfig
11  {
12      private RenderContextAttributes renderContextAttributes;
13      private PortletURLTypes portletURLTypes;
14      
15      public void loadConfig(PortletContext portletContext,String config) throws PortletException
16      {        
17          renderContextAttributes = new RenderContextAttributes();
18          portletURLTypes = new PortletURLTypes();
19          
20          InputStream input = portletContext.getResourceAsStream(config);
21          if (input == null)
22          {
23              return;
24          }
25          
26          Digester digester = new Digester();
27          digester.setClassLoader(Thread.currentThread().getContextClassLoader());
28  
29          renderContextAttributes.configure(digester);
30          portletURLTypes.configure(digester);
31          
32          try
33          {
34              digester.parse(input);            
35          }
36          catch (Exception e)
37          {
38              throw new PortletException("Error loading StrutsPortlet config " + config + ": " + e.getMessage(), e);
39          }
40          finally
41          {
42              try
43              {
44                  input.close();
45              }
46              catch (Exception e)
47              {
48              }
49          }
50      }
51      
52      public RenderContextAttributes getRenderContextAttributes()
53      {
54          return renderContextAttributes;
55      }
56  
57      public PortletURLTypes getPortletURLTypes()
58      {
59          return portletURLTypes;
60      }
61  }