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.util.CmsHtmlExtractor; 032import org.opencms.xml.I_CmsXmlDocument; 033 034import java.util.Locale; 035 036import org.dom4j.Element; 037 038/** 039 * Describes the XML content type "OpenCmsPlainTextString".<p> 040 * 041 * @since 7.5.2 042 */ 043public class CmsXmlPlainTextStringValue extends A_CmsXmlValueCdataBase { 044 045 /** The name of this type as used in the XML schema. */ 046 public static final String TYPE_NAME = "OpenCmsPlainTextString"; 047 048 /** 049 * Creates a new, empty schema type descriptor of type "OpenCmsString".<p> 050 */ 051 public CmsXmlPlainTextStringValue() { 052 053 // empty constructor is required for class registration 054 } 055 056 /** 057 * Creates a new XML content value of type "OpenCmsString".<p> 058 * 059 * @param document the XML content instance this value belongs to 060 * @param element the XML element that contains this value 061 * @param locale the locale this value is created for 062 * @param type the type instance to create the value for 063 */ 064 public CmsXmlPlainTextStringValue( 065 I_CmsXmlDocument document, 066 Element element, 067 Locale locale, 068 I_CmsXmlSchemaType type) { 069 070 super(document, element, locale, type); 071 } 072 073 /** 074 * Creates a new schema type descriptor for the type "OpenCmsString".<p> 075 * 076 * @param name the name of the XML node containing the value according to the XML schema 077 * @param minOccurs minimum number of occurrences of this type according to the XML schema 078 * @param maxOccurs maximum number of occurrences of this type according to the XML schema 079 */ 080 public CmsXmlPlainTextStringValue(String name, String minOccurs, String maxOccurs) { 081 082 super(name, minOccurs, maxOccurs); 083 } 084 085 /** 086 * @see org.opencms.xml.types.A_CmsXmlContentValue#createValue(I_CmsXmlDocument, org.dom4j.Element, Locale) 087 */ 088 public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale locale) { 089 090 return new CmsXmlPlainTextStringValue(document, element, locale, this); 091 } 092 093 /** 094 * @see org.opencms.xml.types.I_CmsXmlContentValue#getPlainText(org.opencms.file.CmsObject) 095 */ 096 @Override 097 public String getPlainText(CmsObject cms) { 098 099 try { 100 return CmsHtmlExtractor.extractText(getStringValue(cms), m_document.getEncoding()); 101 } catch (Exception exc) { 102 return null; 103 } 104 } 105 106 /** 107 * @see org.opencms.xml.types.I_CmsXmlSchemaType#getSchemaDefinition() 108 */ 109 public String getSchemaDefinition() { 110 111 return "<xsd:simpleType name=\"" + TYPE_NAME + "\"><xsd:restriction base=\"xsd:string\" /></xsd:simpleType>"; 112 } 113 114 /** 115 * @see org.opencms.xml.types.A_CmsXmlContentValue#getTypeName() 116 */ 117 public String getTypeName() { 118 119 return TYPE_NAME; 120 } 121 122 /** 123 * @see org.opencms.xml.types.A_CmsXmlContentValue#newInstance(java.lang.String, java.lang.String, java.lang.String) 124 */ 125 public I_CmsXmlSchemaType newInstance(String name, String minOccurs, String maxOccurs) { 126 127 return new CmsXmlPlainTextStringValue(name, minOccurs, maxOccurs); 128 } 129}