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 GmbH & Co. KG, 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.file.CmsObject; 031import org.opencms.main.CmsIllegalArgumentException; 032import org.opencms.main.CmsRuntimeException; 033import org.opencms.util.CmsStringUtil; 034import org.opencms.xml.I_CmsXmlDocument; 035 036import java.util.Locale; 037 038import org.dom4j.Element; 039 040/** 041 * Base class for XML content value implementations that require only a simple XML cdata text node.<p> 042 * 043 * @since 6.0.0 044 */ 045public abstract class A_CmsXmlValueCdataBase extends A_CmsXmlContentValue { 046 047 /** The String value of the element node. */ 048 protected String m_stringValue; 049 050 /** 051 * Default constructor for a xml content type 052 * that initializes some internal values.<p> 053 */ 054 protected A_CmsXmlValueCdataBase() { 055 056 super(); 057 } 058 059 /** 060 * Initializes the required members for this XML content value.<p> 061 * 062 * @param document the XML content instance this value belongs to 063 * @param element the XML element that contains this value 064 * @param locale the locale this value is created for 065 * @param type the type instance to create the value for 066 */ 067 protected A_CmsXmlValueCdataBase( 068 I_CmsXmlDocument document, 069 Element element, 070 Locale locale, 071 I_CmsXmlSchemaType type) { 072 073 super(document, element, locale, type); 074 m_stringValue = element.getText(); 075 } 076 077 /** 078 * Initializes the schema type descriptor values for this type descriptor.<p> 079 * 080 * @param name the name of the XML node containing the value according to the XML schema 081 * @param minOccurs minimum number of occurrences of this type according to the XML schema 082 * @param maxOccurs maximum number of occurrences of this type according to the XML schema 083 */ 084 protected A_CmsXmlValueCdataBase(String name, String minOccurs, String maxOccurs) { 085 086 super(name, minOccurs, maxOccurs); 087 } 088 089 /** 090 * @see org.opencms.xml.types.I_CmsXmlContentValue#getPlainText(org.opencms.file.CmsObject) 091 */ 092 @Override 093 public String getPlainText(CmsObject cms) { 094 095 return getStringValue(cms); 096 } 097 098 /** 099 * @see org.opencms.xml.types.I_CmsXmlContentValue#getStringValue(CmsObject) 100 */ 101 public String getStringValue(CmsObject cms) throws CmsRuntimeException { 102 103 return m_stringValue; 104 } 105 106 /** 107 * @see org.opencms.xml.types.I_CmsXmlContentValue#setStringValue(org.opencms.file.CmsObject, java.lang.String) 108 */ 109 public void setStringValue(CmsObject cms, String value) throws CmsIllegalArgumentException { 110 111 m_element.clearContent(); 112 if (CmsStringUtil.isNotEmpty(value)) { 113 m_element.addCDATA(value); 114 } 115 m_stringValue = value; 116 } 117}