KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > xml > content > CmsXmlContentValueSequence


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/xml/content/CmsXmlContentValueSequence.java,v $
3  * Date : $Date: 2005/06/23 11:11:54 $
4  * Version: $Revision: 1.12 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.xml.content;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.xml.CmsXmlUtils;
36 import org.opencms.xml.types.I_CmsXmlContentValue;
37 import org.opencms.xml.types.I_CmsXmlSchemaType;
38
39 import java.util.List JavaDoc;
40 import java.util.Locale JavaDoc;
41
42 /**
43  * Describes the sequence of XML content values of a specific type in an XML content instance.<p>
44  *
45  * @author Alexander Kandzior
46  *
47  * @version $Revision: 1.12 $
48  *
49  * @since 6.0.0
50  */

51 public class CmsXmlContentValueSequence {
52
53     /** The XML content this sequence element is based on. */
54     private CmsXmlContent m_content;
55
56     /** The locale this sequence is based on. */
57     private Locale JavaDoc m_locale;
58
59     /** The Xpath this content value seqnence was generated for. */
60     private String JavaDoc m_path;
61
62     /** The XML schema type this sequence is based on. */
63     private I_CmsXmlSchemaType m_schemaType;
64
65     /** The list of XML content values for the selected schema type and locale in the XML content. */
66     private List JavaDoc m_values;
67
68     /**
69      * Generates a new content sequence element from the given type, content and content defintion.<p>
70      *
71      * @param path the path in the document to generate the value sequence for
72      * @param schemaType the schema type to generate the seqnence element for
73      * @param locale the locale to get the content values from
74      * @param content the XML content to generate the sequence element out of
75      */

76     public CmsXmlContentValueSequence(String JavaDoc path, I_CmsXmlSchemaType schemaType, Locale JavaDoc locale, CmsXmlContent content) {
77
78         m_schemaType = schemaType;
79         m_locale = locale;
80         m_content = content;
81         m_values = m_content.getValues(path, m_locale);
82         m_path = CmsXmlUtils.removeXpathIndex(path);
83     }
84
85     /**
86      * Adds a value element of the sequence type at the seleted index to the XML content document.<p>
87      *
88      * @param cms the current users OpenCms context
89      * @param index the index where to add the new value element
90      *
91      * @return the added XML content value element
92      *
93      * @see CmsXmlContent#addValue(CmsObject, String, Locale, int)
94      */

95     public I_CmsXmlContentValue addValue(CmsObject cms, int index) {
96
97         I_CmsXmlContentValue newValue = m_content.addValue(cms, getPath(), getLocale(), index);
98
99         // re-initialize the value list
100
m_values = m_content.getValues(getPath(), getLocale());
101
102         return newValue;
103     }
104
105     /**
106      * Returns the count of XML content values for the selected schema type and locale in the XML content.<p>
107      *
108      * @return the count of XML content values for the selected schema type and locale in the XML content
109      */

110     public int getElementCount() {
111
112         return m_values.size();
113     }
114
115     /**
116      * Returns the XML element node name of this sequence element in the current schema.<p>
117      *
118      * The XML element node name can be configured in the schema.
119      * For example, the node name could be <code>"Title"</code>,
120      * <code>"Teaser"</code> or <code>"Text"</code>. The XML schema controls
121      * what node names are allowed.<p>
122      *
123      * @return the XML node name of this sequence element in the current schema
124      *
125      * @see I_CmsXmlSchemaType#getName()
126      */

127     public String JavaDoc getElementName() {
128
129         return m_schemaType.getName();
130     }
131
132     /**
133      * Returns the locale this sequence is based on.<p>
134      *
135      * @return the locale this sequence is based on
136      */

137     public Locale JavaDoc getLocale() {
138
139         return m_locale;
140     }
141
142     /**
143      * Returns the maximum occurences of this type in the XML content schema.<p>
144      *
145      * @return the maximum occurences of this type in the XML content schema
146      *
147      * @see I_CmsXmlSchemaType#getMaxOccurs()
148      */

149     public int getMaxOccurs() {
150
151         return m_schemaType.getMaxOccurs();
152     }
153
154     /**
155      * Returns the minimum occurences of this type in the XML content schema.<p>
156      *
157      * @return the minimum occurences of this type in the XML content schema
158      *
159      * @see I_CmsXmlSchemaType#getMinOccurs()
160      */

161     public int getMinOccurs() {
162
163         return m_schemaType.getMinOccurs();
164     }
165
166     /**
167      * Returns the (simplified) Xpath expression that identifies the root node
168      * of this content value sequence.<p>
169      *
170      * @return the (simplified) Xpath expression that identifies the root node
171      * of this content value sequence
172      */

173     public String JavaDoc getPath() {
174
175         return m_path;
176     }
177
178     /**
179      * Returns the XML content values from the index position of this seqnence.<p>
180      *
181      * @param index the index position to get the value from
182      *
183      * @return the XML content values from the index position of this seqnence
184      */

185     public I_CmsXmlContentValue getValue(int index) {
186
187         return (I_CmsXmlContentValue)m_values.get(index);
188     }
189
190     /**
191      * Returns the list of XML content values for the selected schema type and locale in the XML content.<p>
192      *
193      * @return the list of XML content values for the selected schema type and locale in the XML content
194      *
195      * @see CmsXmlContentValueSequence#getValue(int)
196      */

197     public List JavaDoc getValues() {
198
199         return m_values;
200     }
201
202     /**
203      * Return the XML schema type of this sequence element.<p>
204      *
205      * @return the XML schema type of this sequence element
206      */

207     public I_CmsXmlSchemaType getXmlSchemaType() {
208
209         return m_schemaType;
210     }
211
212     /**
213      * Returns <code>true</code> if more elements of this type can be added to the XML content.<p>
214      *
215      * @return <code>true</code> if more elements of this type can be added to the XML content
216      */

217     public boolean isExtendable() {
218
219         return getElementCount() < getMaxOccurs();
220     }
221
222     /**
223      * Returns <code>true</code> if elements of this type can be removed from the XML content.<p>
224      *
225      * @return <code>true</code> if elements of this type can be removed from the XML content
226      */

227     public boolean isReducable() {
228
229         return getElementCount() > getMinOccurs();
230     }
231
232     /**
233      * Returns <code>true</code> if this is a simple type, or <code>false</code>
234      * if this type is a nested schema.<p>
235      *
236      * If a value is a nested schema, it must be an instance of {@link org.opencms.xml.types.CmsXmlNestedContentDefinition}.<p>
237      *
238      * @return true if this is a simple type, or false if this type is a nested schema
239      *
240      * @see org.opencms.xml.types.CmsXmlNestedContentDefinition
241      */

242     public boolean isSimpleType() {
243
244         return m_schemaType.isSimpleType();
245     }
246
247     /**
248      * Removes the value element of the sequence type at the seleted index from XML content document.<p>
249      *
250      * @param index the index where to remove the value element
251      *
252      * @see CmsXmlContent#removeValue(String, Locale, int)
253      */

254     public void removeValue(int index) {
255
256         m_content.removeValue(getPath(), getLocale(), index);
257
258         // re-initialize the value list
259
m_values = m_content.getValues(getPath(), getLocale());
260     }
261 }
Popular Tags