1 31 32 package org.opencms.xml.types; 33 34 import org.opencms.xml.I_CmsXmlDocument; 35 36 import java.util.Locale ; 37 import java.util.regex.Pattern ; 38 39 import org.dom4j.Element; 40 41 50 public class CmsXmlLocaleValue extends A_CmsXmlValueTextBase { 51 52 53 public static final String TYPE_NAME = "OpenCmsLocale"; 54 55 56 public static final String TYPE_RULE = "[a-z]{2,3}(_[A-Z]{2}(_[a-zA-Z0-9]+){0,1}){0,1}"; 57 58 59 private static final Pattern TYPE_PATTERN = Pattern.compile(TYPE_RULE); 60 61 64 public CmsXmlLocaleValue() { 65 66 } 68 69 77 public CmsXmlLocaleValue(I_CmsXmlDocument document, Element element, Locale locale, I_CmsXmlSchemaType type) { 78 79 super(document, element, locale, type); 80 } 81 82 89 public CmsXmlLocaleValue(String name, String minOccurs, String maxOccurs) { 90 91 super(name, minOccurs, maxOccurs); 92 } 93 94 97 public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale locale) { 98 99 return new CmsXmlLocaleValue(document, element, locale, this); 100 } 101 102 105 public String 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 118 public String getTypeName() { 119 120 return TYPE_NAME; 121 } 122 123 126 public I_CmsXmlSchemaType newInstance(String name, String minOccurs, String maxOccurs) { 127 128 return new CmsXmlLocaleValue(name, minOccurs, maxOccurs); 129 } 130 131 134 public boolean validateValue(String value) { 135 136 return TYPE_PATTERN.matcher(value).matches(); 137 } 138 } | Popular Tags |