KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > xml > types > CmsXmlColorValue


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/xml/types/CmsXmlColorValue.java,v $
3  * Date : $Date: 2005/06/23 11:11:23 $
4  * Version: $Revision: 1.14 $
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.types;
33
34 import org.opencms.xml.I_CmsXmlDocument;
35
36 import java.util.Locale JavaDoc;
37 import java.util.regex.Pattern JavaDoc;
38
39 import org.dom4j.Element;
40
41 /**
42  * Describes the XML content type "OpenCmsColor".<p>
43  *
44  * @author Andreas Zahner
45  *
46  * @version $Revision: 1.14 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsXmlColorValue extends A_CmsXmlValueTextBase {
51
52     /** The name of this type as used in the XML schema. */
53     public static final String JavaDoc TYPE_NAME = "OpenCmsColor";
54
55     /** The validation rule used for this schema type. */
56     public static final String JavaDoc TYPE_RULE = "#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?";
57
58     /** Pre-compiled regular expression pattern for this rule. */
59     private static final Pattern JavaDoc TYPE_PATTERN = Pattern.compile(TYPE_RULE);
60
61     /**
62      * Creates a new, empty schema type descriptor of type "OpenCmsColor".<p>
63      */

64     public CmsXmlColorValue() {
65
66         // empty constructor is required for class registration
67
}
68
69     /**
70      * Creates a new XML content value of type "OpenCmsColor".<p>
71      *
72      * @param document the XML content instance this value belongs to
73      * @param element the XML element that contains this value
74      * @param locale the locale this value is created for
75      * @param type the type instance to create the value for
76      */

77     public CmsXmlColorValue(I_CmsXmlDocument document, Element element, Locale JavaDoc locale, I_CmsXmlSchemaType type) {
78
79         super(document, element, locale, type);
80     }
81
82     /**
83      * Creates a new schema type descriptor for the type "OpenCmsColor".<p>
84      *
85      * @param name the name of the XML node containing the value according to the XML schema
86      * @param minOccurs minimum number of occurences of this type according to the XML schema
87      * @param maxOccurs maximum number of occurences of this type according to the XML schema
88      */

89     public CmsXmlColorValue(String JavaDoc name, String JavaDoc minOccurs, String JavaDoc maxOccurs) {
90
91         super(name, minOccurs, maxOccurs);
92     }
93
94     /**
95      * @see org.opencms.xml.types.A_CmsXmlContentValue#createValue(I_CmsXmlDocument, org.dom4j.Element, Locale)
96      */

97     public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale JavaDoc locale) {
98
99         return new CmsXmlColorValue(document, element, locale, this);
100     }
101
102     /**
103      * @see org.opencms.xml.types.A_CmsXmlContentValue#getDefault(Locale)
104      */

105     public String JavaDoc getDefault(Locale JavaDoc locale) {
106
107         if (m_defaultValue != null) {
108             return m_defaultValue;
109         }
110         return "#000000";
111     }
112
113     /**
114      * @see org.opencms.xml.types.I_CmsXmlSchemaType#getSchemaDefinition()
115      */

116     public String JavaDoc getSchemaDefinition() {
117
118         return "<xsd:simpleType name=\""
119             + TYPE_NAME
120             + "\"><xsd:restriction base=\"xsd:string\">"
121             + "<xsd:pattern value=\""
122             + TYPE_RULE
123             + "\" /></xsd:restriction></xsd:simpleType>";
124     }
125
126     /**
127      * @see org.opencms.xml.types.A_CmsXmlContentValue#getTypeName()
128      */

129     public String JavaDoc getTypeName() {
130
131         return TYPE_NAME;
132     }
133
134     /**
135      * @see org.opencms.xml.types.A_CmsXmlContentValue#newInstance(java.lang.String, java.lang.String, java.lang.String)
136      */

137     public I_CmsXmlSchemaType newInstance(String JavaDoc name, String JavaDoc minOccurs, String JavaDoc maxOccurs) {
138
139         return new CmsXmlColorValue(name, minOccurs, maxOccurs);
140     }
141
142     /**
143      * @see org.opencms.xml.types.I_CmsXmlSchemaType#validateValue(java.lang.String)
144      */

145     public boolean validateValue(String JavaDoc value) {
146
147         return TYPE_PATTERN.matcher(value).matches();
148     }
149 }
Popular Tags