KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/xml/types/CmsXmlLocaleValue.java,v $
3  * Date : $Date: 2006/03/27 14:53:03 $
4  * Version: $Revision: 1.16 $
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 "OpenCmsLocale".<p>
43  *
44  * @author Alexander Kandzior
45  *
46  * @version $Revision: 1.16 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsXmlLocaleValue extends A_CmsXmlValueTextBase {
51
52     /** The name of this type as used in the XML schema. */
53     public static final String JavaDoc TYPE_NAME = "OpenCmsLocale";
54
55     /** The validation rule used for this schema type. */
56     public static final String JavaDoc TYPE_RULE = "[a-z]{2,3}(_[A-Z]{2}(_[a-zA-Z0-9]+){0,1}){0,1}";
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 "OpenCmsLocale".<p>
63      */

64     public CmsXmlLocaleValue() {
65
66         // empty constructor is required for class registration
67
}
68
69     /**
70      * Creates a new XML content value of type "OpenCmsLocale".<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 CmsXmlLocaleValue(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 "OpenCmsLocale".<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 CmsXmlLocaleValue(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 CmsXmlLocaleValue(document, element, locale, this);
100     }
101
102     /**
103      * @see org.opencms.xml.types.I_CmsXmlSchemaType#getSchemaDefinition()
104      */

105     public String JavaDoc getSchemaDefinition() {
106
107         return "<xsd:simpleType name=\""
108             + TYPE_NAME
109             + "\"><xsd:restriction base=\"xsd:string\">"
110             + "<xsd:pattern value=\""
111             + TYPE_RULE
112             + "\" /></xsd:restriction></xsd:simpleType>";
113     }
114
115     /**
116      * @see org.opencms.xml.types.A_CmsXmlContentValue#getTypeName()
117      */

118     public String JavaDoc getTypeName() {
119
120         return TYPE_NAME;
121     }
122
123     /**
124      * @see org.opencms.xml.types.A_CmsXmlContentValue#newInstance(java.lang.String, java.lang.String, java.lang.String)
125      */

126     public I_CmsXmlSchemaType newInstance(String JavaDoc name, String JavaDoc minOccurs, String JavaDoc maxOccurs) {
127
128         return new CmsXmlLocaleValue(name, minOccurs, maxOccurs);
129     }
130
131     /**
132      * @see org.opencms.xml.types.I_CmsXmlSchemaType#validateValue(java.lang.String)
133      */

134     public boolean validateValue(String JavaDoc value) {
135
136         return TYPE_PATTERN.matcher(value).matches();
137     }
138 }
Popular Tags