001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.util.descriptor;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.apache.commons.digester.Rule;
023: import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
024: import org.apache.jetspeed.om.preference.impl.PrefsPreference;
025: import org.apache.pluto.om.portlet.PortletApplicationDefinition;
026: import org.xml.sax.Attributes;
027:
028: /**
029: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
030: */
031: public class PortletPreferenceRule extends Rule {
032:
033: protected PortletDefinitionComposite portlet;
034:
035: protected String name;
036: protected boolean readOnly;
037: protected List values;
038:
039: /**
040: * <p>
041: * begin
042: * </p>
043: *
044: * @see org.apache.commons.digester.Rule#begin(java.lang.String, java.lang.String, org.xml.sax.Attributes)
045: * @param arg0
046: * @param arg1
047: * @param arg2
048: * @throws java.lang.Exception
049: */
050: public void begin(String arg0, String arg1, Attributes arg2)
051: throws Exception {
052: Object peeked = digester.peek();
053: portlet = (PortletDefinitionComposite) peeked;
054: portlet
055: .setPortletApplicationDefinition((PortletApplicationDefinition) digester
056: .getRoot());
057:
058: // reset properties to default values
059: // as the same instance of this rule can be used multiple times
060: values = new ArrayList();
061: readOnly = false;
062:
063: TempValueObject temp = new TempValueObject();
064: digester.push(temp);
065: }
066:
067: /**
068: * <p>
069: * end
070: * </p>
071: *
072: * @see org.apache.commons.digester.Rule#end(java.lang.String, java.lang.String)
073: * @param arg0
074: * @param arg1
075: * @throws java.lang.Exception
076: */
077: public void end(String arg0, String arg1) throws Exception {
078: PrefsPreference pref = new PrefsPreference(portlet, name);
079: pref.setValues(values);
080: pref.setReadOnly(readOnly);
081: digester.pop();
082: }
083:
084: public class TempValueObject {
085: public void setName(String name) {
086: PortletPreferenceRule.this .name = name;
087: }
088:
089: public void setReadOnly(boolean readOnly) {
090: PortletPreferenceRule.this .readOnly = readOnly;
091: }
092:
093: public void addValue(String value) {
094: PortletPreferenceRule.this .values.add(value);
095: }
096: }
097:
098: /**
099: * <p>
100: * finish
101: * </p>
102: *
103: * @see org.apache.commons.digester.Rule#finish()
104: * @throws java.lang.Exception
105: */
106: public void finish() throws Exception {
107: if (values != null) {
108: values.clear();
109: }
110: super.finish();
111: }
112: }
|