1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 }