001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.xml.types; 029 030import org.opencms.util.CmsStringUtil; 031import org.opencms.util.CmsUUID; 032import org.opencms.xml.I_CmsXmlDocument; 033 034import java.util.Locale; 035 036import org.dom4j.Element; 037 038/** 039 * XML value type for display formatters.<p> 040 */ 041public class CmsXmlDisplayFormatterValue extends A_CmsXmlValueTextBase { 042 043 /** The value separator string. */ 044 public static final String SEPARATOR = ":"; 045 046 /** The XSD type name. */ 047 private static final String TYPE_NAME = "OpenCmsDisplayFormatter"; 048 049 /** 050 * Creates a new, empty schema type descriptor of type "OpenCmsDisplayFormatter".<p> 051 */ 052 public CmsXmlDisplayFormatterValue() { 053 054 // empty constructor is required for class registration 055 } 056 057 /** 058 * Creates a new XML content value of type "OpenCmsDisplayFormatter".<p> 059 * 060 * @param document the XML content instance this value belongs to 061 * @param element the XML element that contains this value 062 * @param locale the locale this value is created for 063 * @param type the type instance to create the value for 064 */ 065 public CmsXmlDisplayFormatterValue( 066 I_CmsXmlDocument document, 067 Element element, 068 Locale locale, 069 I_CmsXmlSchemaType type) { 070 071 super(document, element, locale, type); 072 } 073 074 /** 075 * Creates a new schema type descriptor for the type "OpenCmsDisplayFormatter".<p> 076 * 077 * @param name the name of the XML node containing the value according to the XML schema 078 * @param minOccurs minimum number of occurrences of this type according to the XML schema 079 * @param maxOccurs maximum number of occurrences of this type according to the XML schema 080 */ 081 public CmsXmlDisplayFormatterValue(String name, String minOccurs, String maxOccurs) { 082 083 super(name, minOccurs, maxOccurs); 084 } 085 086 /** 087 * @see org.opencms.xml.types.I_CmsXmlSchemaType#createValue(org.opencms.xml.I_CmsXmlDocument, org.dom4j.Element, java.util.Locale) 088 */ 089 public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale locale) { 090 091 return new CmsXmlDisplayFormatterValue(document, element, locale, this); 092 } 093 094 /** 095 * Returns the display resource type name.<p> 096 * 097 * @return the display resource type 098 */ 099 public String getDisplayType() { 100 101 String value = getStringValue(null); 102 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value)) { 103 return value.split(SEPARATOR)[0]; 104 } 105 return null; 106 } 107 108 /** 109 * Returns the formatter config id.<p> 110 * 111 * @return the formatter config id 112 */ 113 public CmsUUID getFormatterId() { 114 115 String value = getStringValue(null); 116 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value)) { 117 String[] parts = value.split(SEPARATOR); 118 if (parts.length == 2) { 119 return new CmsUUID(parts[1]); 120 } 121 } 122 return null; 123 } 124 125 /** 126 * @see org.opencms.xml.types.I_CmsXmlSchemaType#getSchemaDefinition() 127 */ 128 public String getSchemaDefinition() { 129 130 return "<xsd:simpleType name=\"" + TYPE_NAME + "\"><xsd:restriction base=\"xsd:string\" /></xsd:simpleType>"; 131 } 132 133 /** 134 * @see org.opencms.xml.types.A_CmsXmlContentValue#getTypeName() 135 */ 136 public String getTypeName() { 137 138 return TYPE_NAME; 139 } 140 141 /** 142 * @see org.opencms.xml.types.I_CmsXmlSchemaType#newInstance(java.lang.String, java.lang.String, java.lang.String) 143 */ 144 public I_CmsXmlSchemaType newInstance(String name, String minOccurs, String maxOccurs) { 145 146 return new CmsXmlDisplayFormatterValue(name, minOccurs, maxOccurs); 147 } 148 149}