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 CmsXmlColorValue extends A_CmsXmlValueTextBase { 51 52 53 public static final String TYPE_NAME = "OpenCmsColor"; 54 55 56 public static final String TYPE_RULE = "#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?"; 57 58 59 private static final Pattern TYPE_PATTERN = Pattern.compile(TYPE_RULE); 60 61 64 public CmsXmlColorValue() { 65 66 } 68 69 77 public CmsXmlColorValue(I_CmsXmlDocument document, Element element, Locale locale, I_CmsXmlSchemaType type) { 78 79 super(document, element, locale, type); 80 } 81 82 89 public CmsXmlColorValue(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 CmsXmlColorValue(document, element, locale, this); 100 } 101 102 105 public String getDefault(Locale locale) { 106 107 if (m_defaultValue != null) { 108 return m_defaultValue; 109 } 110 return "#000000"; 111 } 112 113 116 public String 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 129 public String getTypeName() { 130 131 return TYPE_NAME; 132 } 133 134 137 public I_CmsXmlSchemaType newInstance(String name, String minOccurs, String maxOccurs) { 138 139 return new CmsXmlColorValue(name, minOccurs, maxOccurs); 140 } 141 142 145 public boolean validateValue(String value) { 146 147 return TYPE_PATTERN.matcher(value).matches(); 148 } 149 } | Popular Tags |