KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > config > AdvancedSearchConfigElement


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.config;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.alfresco.config.ConfigElement;
23 import org.alfresco.config.ConfigException;
24 import org.alfresco.config.element.ConfigElementAdapter;
25
26 /**
27  * Custom config element that represents config values for advanced search
28  *
29  * @author Gavin Cornwell
30  */

31 public class AdvancedSearchConfigElement extends ConfigElementAdapter
32 {
33    public static final String JavaDoc CONFIG_ELEMENT_ID = "advanced-search";
34    
35    private List JavaDoc<String JavaDoc> contentTypes = null;
36    private List JavaDoc<CustomProperty> customProps = null;
37    
38    /**
39     * Default Constructor
40     */

41    public AdvancedSearchConfigElement()
42    {
43       super(CONFIG_ELEMENT_ID);
44    }
45    
46    /**
47     * Constructor
48     *
49     * @param name Name of the element this config element represents
50     */

51    public AdvancedSearchConfigElement(String JavaDoc name)
52    {
53       super(name);
54    }
55
56    /**
57     * @see org.alfresco.config.element.ConfigElementAdapter#getChildren()
58     */

59    @Override JavaDoc
60    public List JavaDoc<ConfigElement> getChildren()
61    {
62       throw new ConfigException("Reading the advanced search config via the generic interfaces is not supported");
63    }
64    
65    /**
66     * @see org.alfresco.config.element.ConfigElementAdapter#combine(org.alfresco.config.ConfigElement)
67     */

68    public ConfigElement combine(ConfigElement configElement)
69    {
70       AdvancedSearchConfigElement existingElement = (AdvancedSearchConfigElement)configElement;
71       AdvancedSearchConfigElement newElement = new AdvancedSearchConfigElement();
72       
73       // just copy the list of types and properties from this instance to the new one
74
if (this.contentTypes != null)
75       {
76          for (String JavaDoc type : this.contentTypes)
77          {
78             newElement.addContentType(type);
79          }
80       }
81       
82       if (this.customProps != null)
83       {
84          for (CustomProperty property : this.customProps)
85          {
86             newElement.addCustomProperty(property);
87          }
88       }
89       
90       // now add those types and custom properties from the element to be combined
91
if (existingElement.getContentTypes() != null)
92       {
93          for (String JavaDoc type : existingElement.getContentTypes())
94          {
95             newElement.addContentType(type);
96          }
97       }
98       
99       if (existingElement.getCustomProperties() != null)
100       {
101          for (CustomProperty property : existingElement.getCustomProperties())
102          {
103             newElement.addCustomProperty(property);
104          }
105       }
106       
107       return newElement;
108    }
109
110    /**
111     * @return Returns the contentTypes.
112     */

113    public List JavaDoc<String JavaDoc> getContentTypes()
114    {
115       return this.contentTypes;
116    }
117
118    /**
119     * @param contentTypes The contentTypes to set.
120     */

121    /*package*/ void setContentTypes(List JavaDoc<String JavaDoc> contentTypes)
122    {
123       this.contentTypes = contentTypes;
124    }
125    
126    /**
127     * @param contentType Adds the given content type to the list
128     */

129    /*package*/ void addContentType(String JavaDoc contentType)
130    {
131       if (this.contentTypes == null)
132       {
133          this.contentTypes = new ArrayList JavaDoc<String JavaDoc>(3);
134       }
135       
136       if (this.contentTypes.contains(contentType) == false)
137       {
138          this.contentTypes.add(contentType);
139       }
140    }
141    
142    /**
143     * @return Returns the customProps.
144     */

145    public List JavaDoc<CustomProperty> getCustomProperties()
146    {
147       return this.customProps;
148    }
149
150    /**
151     * @param customProps The customProps to set.
152     */

153    /*package*/ void setCustomProperties(List JavaDoc<CustomProperty> customProps)
154    {
155       this.customProps = customProps;
156    }
157    
158    /**
159     * @param property Adds the given custom property to the list
160     */

161    /*package*/ void addCustomProperty(CustomProperty property)
162    {
163       if (this.customProps == null)
164       {
165          this.customProps = new ArrayList JavaDoc<CustomProperty>(3);
166       }
167       
168       // TODO: Determine if the CustomProperty being added is already
169
// in the list
170

171       this.customProps.add(property);
172    }
173    
174    /**
175     * Simple wrapper class for custom advanced search property
176     * @author Kevin Roast
177     */

178    public static class CustomProperty
179    {
180       CustomProperty(String JavaDoc type, String JavaDoc aspect, String JavaDoc property, String JavaDoc labelId)
181       {
182          Type = type;
183          Aspect = aspect;
184          Property = property;
185          LabelId = labelId;
186       }
187       
188       public String JavaDoc Type;
189       public String JavaDoc Aspect;
190       public String JavaDoc Property;
191       public String JavaDoc LabelId;
192    }
193 }
194
Popular Tags