001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.xml.types;
029
030import org.opencms.file.CmsObject;
031import org.opencms.main.CmsIllegalArgumentException;
032import org.opencms.main.CmsRuntimeException;
033import org.opencms.xml.I_CmsXmlDocument;
034
035import java.util.Locale;
036
037import org.dom4j.Element;
038
039/**
040 * Describes the XML content type "OpenCmsVfsFile".<p>
041 *
042 * This type allows links to internal VFS resources only.<p>
043 *
044 * @since 7.0.0
045 */
046public class CmsXmlDynamicCategoryValue extends A_CmsXmlContentValue {
047
048    /** The name of this type as used in the XML schema. */
049    public static final String TYPE_NAME = "OpenCmsDynamicCategory";
050
051    /** The schema definition String is located in a text for easier editing. */
052    private static String m_schemaDefinition;
053
054    /** The String value of the element node. */
055    private String m_stringValue;
056
057    /**
058     * Creates a new, empty schema type descriptor of type "OpenCmsCategoryValue".<p>
059     */
060    public CmsXmlDynamicCategoryValue() {
061
062        // empty constructor is required for class registration
063    }
064
065    /**
066     * Creates a new XML content value of type "OpenCmsCategoryValue".<p>
067     *
068     * @param document the XML content instance this value belongs to
069     * @param element the XML element that contains this value
070     * @param locale the locale this value is created for
071     * @param type the type instance to create the value for
072     */
073    public CmsXmlDynamicCategoryValue(
074        I_CmsXmlDocument document,
075        Element element,
076        Locale locale,
077        I_CmsXmlSchemaType type) {
078
079        super(document, element, locale, type);
080    }
081
082    /**
083     * Creates a new schema type descriptor for the type "OpenCmsCategoryValue".<p>
084     *
085     * @param name the name of the XML node containing the value according to the XML schema
086     * @param minOccurs minimum number of occurrences of this type according to the XML schema
087     * @param maxOccurs maximum number of occurrences of this type according to the XML schema
088     */
089    public CmsXmlDynamicCategoryValue(String name, String minOccurs, String maxOccurs) {
090
091        super(name, minOccurs, maxOccurs);
092    }
093
094    /**
095     * @see org.opencms.xml.types.A_CmsXmlContentValue#createValue(I_CmsXmlDocument, org.dom4j.Element, Locale)
096     */
097    public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale locale) {
098
099        return new CmsXmlDynamicCategoryValue(document, element, locale, this);
100    }
101
102    /**
103     * @see org.opencms.xml.types.I_CmsXmlSchemaType#generateXml(org.opencms.file.CmsObject, org.opencms.xml.I_CmsXmlDocument, org.dom4j.Element, java.util.Locale)
104     */
105    @Override
106    public Element generateXml(CmsObject cms, I_CmsXmlDocument document, Element root, Locale locale) {
107
108        Element element = root.addElement(getName());
109        element.addComment("Categories are read dynamically");
110        return element;
111    }
112
113    /**
114     * @see org.opencms.xml.types.I_CmsXmlContentValue#getPlainText(org.opencms.file.CmsObject)
115     */
116    @Override
117    public String getPlainText(CmsObject cms) {
118
119        return getStringValue(cms);
120    }
121
122    /**
123     * @see org.opencms.xml.types.I_CmsXmlSchemaType#getSchemaDefinition()
124     */
125    public String getSchemaDefinition() {
126
127        if (m_schemaDefinition == null) {
128            m_schemaDefinition = readSchemaDefinition("org/opencms/xml/types/XmlDynamicCategoryValue.xsd");
129        }
130        return m_schemaDefinition;
131    }
132
133    /**
134     * @see org.opencms.xml.types.I_CmsXmlContentValue#getStringValue(CmsObject)
135     */
136    public String getStringValue(CmsObject cms) throws CmsRuntimeException {
137
138        return null == m_stringValue ? "" : m_stringValue;
139    }
140
141    /**
142     * @see org.opencms.xml.types.A_CmsXmlContentValue#getTypeName()
143     */
144    public String getTypeName() {
145
146        return TYPE_NAME;
147    }
148
149    /**
150     * @see org.opencms.xml.types.A_CmsXmlContentValue#isSearchable()
151     */
152    @Override
153    public boolean isSearchable() {
154
155        // there is no point in an empty node
156        return false;
157    }
158
159    /**
160     * @see org.opencms.xml.types.A_CmsXmlContentValue#newInstance(java.lang.String, java.lang.String, java.lang.String)
161     */
162    public I_CmsXmlSchemaType newInstance(String name, String minOccurs, String maxOccurs) {
163
164        return new CmsXmlDynamicCategoryValue(name, minOccurs, maxOccurs);
165    }
166
167    /**
168     * @see org.opencms.xml.types.A_CmsXmlContentValue#setStringValue(org.opencms.file.CmsObject, java.lang.String)
169     */
170    public void setStringValue(CmsObject cms, String value) throws CmsIllegalArgumentException {
171
172        m_stringValue = value;
173    }
174
175}