1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.util.descriptor;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.commons.digester.Rule;
23 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
24 import org.apache.jetspeed.om.preference.impl.PrefsPreference;
25 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
26 import org.xml.sax.Attributes;
27
28 /***
29 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
30 */
31 public class PortletPreferenceRule extends Rule
32 {
33
34
35 protected PortletDefinitionComposite portlet;
36
37 protected String name;
38 protected boolean readOnly;
39 protected List values;
40
41 /***
42 * <p>
43 * begin
44 * </p>
45 *
46 * @see org.apache.commons.digester.Rule#begin(java.lang.String, java.lang.String, org.xml.sax.Attributes)
47 * @param arg0
48 * @param arg1
49 * @param arg2
50 * @throws java.lang.Exception
51 */
52 public void begin( String arg0, String arg1, Attributes arg2 ) throws Exception
53 {
54 Object peeked = digester.peek();
55 portlet = (PortletDefinitionComposite) peeked;
56 portlet.setPortletApplicationDefinition((PortletApplicationDefinition) digester.getRoot());
57
58
59
60 values = new ArrayList();
61 readOnly = false;
62
63 TempValueObject temp = new TempValueObject();
64 digester.push(temp);
65 }
66 /***
67 * <p>
68 * end
69 * </p>
70 *
71 * @see org.apache.commons.digester.Rule#end(java.lang.String, java.lang.String)
72 * @param arg0
73 * @param arg1
74 * @throws java.lang.Exception
75 */
76 public void end( String arg0, String arg1 ) throws Exception
77 {
78 PrefsPreference pref = new PrefsPreference(portlet, name);
79 pref.setValues(values);
80 pref.setReadOnly(readOnly);
81 digester.pop();
82 }
83
84 public class TempValueObject
85 {
86 public void setName(String name)
87 {
88 PortletPreferenceRule.this.name = name;
89 }
90
91 public void setReadOnly(boolean readOnly)
92 {
93 PortletPreferenceRule.this.readOnly = readOnly;
94 }
95
96 public void addValue(String value)
97 {
98 PortletPreferenceRule.this.values.add(value);
99 }
100 }
101
102 /***
103 * <p>
104 * finish
105 * </p>
106 *
107 * @see org.apache.commons.digester.Rule#finish()
108 * @throws java.lang.Exception
109 */
110 public void finish() throws Exception
111 {
112 if(values != null)
113 {
114 values.clear();
115 }
116 super.finish();
117 }
118 }