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 CmsXmlDateTimeValue extends A_CmsXmlValueTextBase { 51 52 53 public static final String TYPE_NAME = "OpenCmsDateTime"; 54 55 56 public static final String TYPE_RULE = "\\p{Digit}+"; 57 58 59 private static final Pattern TYPE_PATTERN = Pattern.compile(TYPE_RULE); 60 61 62 private long m_dateTime; 63 64 67 public CmsXmlDateTimeValue() { 68 69 } 71 72 80 public CmsXmlDateTimeValue(I_CmsXmlDocument document, Element element, Locale locale, I_CmsXmlSchemaType type) { 81 82 super(document, element, locale, type); 83 try { 84 m_dateTime = Long.valueOf(m_stringValue).longValue(); 85 } catch (NumberFormatException e) { 86 m_dateTime = 0; 87 } 88 } 89 90 97 public CmsXmlDateTimeValue(String name, String minOccurs, String maxOccurs) { 98 99 super(name, minOccurs, maxOccurs); 100 } 101 102 105 public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale locale) { 106 107 return new CmsXmlDateTimeValue(document, element, locale, this); 108 } 109 110 115 public long getDateTimeValue() { 116 117 return m_dateTime; 118 } 119 120 123 public String getDefault(Locale locale) { 124 125 if (m_defaultValue != null) { 126 return m_defaultValue; 127 } 128 return "0"; 129 } 130 131 134 public String getSchemaDefinition() { 135 136 return "<xsd:simpleType name=\"" + TYPE_NAME + "\"><xsd:restriction base=\"xsd:decimal\" /></xsd:simpleType>"; 137 } 138 139 142 public String getTypeName() { 143 144 return TYPE_NAME; 145 } 146 147 150 public I_CmsXmlSchemaType newInstance(String name, String minOccurs, String maxOccurs) { 151 152 return new CmsXmlDateTimeValue(name, minOccurs, maxOccurs); 153 } 154 155 158 public boolean validateValue(String value) { 159 160 return TYPE_PATTERN.matcher(value).matches(); 161 } 162 } | Popular Tags |