001 package ezvcard.types; 002 003 import java.util.List; 004 005 import ezvcard.VCardVersion; 006 import ezvcard.io.CompatibilityMode; 007 import ezvcard.util.HCardElement; 008 import ezvcard.util.VCardStringUtils; 009 import ezvcard.util.XCardElement; 010 011 /* 012 Copyright (c) 2012, Michael Angstadt 013 All rights reserved. 014 015 Redistribution and use in source and binary forms, with or without 016 modification, are permitted provided that the following conditions are met: 017 018 1. Redistributions of source code must retain the above copyright notice, this 019 list of conditions and the following disclaimer. 020 2. Redistributions in binary form must reproduce the above copyright notice, 021 this list of conditions and the following disclaimer in the documentation 022 and/or other materials provided with the distribution. 023 024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 025 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 028 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 034 035 The views and conclusions contained in the software and documentation are those 036 of the authors and should not be interpreted as representing official policies, 037 either expressed or implied, of the FreeBSD Project. 038 */ 039 040 /** 041 * Represents a type whose value is just a regular text value. 042 * @author Michael Angstadt 043 */ 044 public class TextType extends VCardType { 045 protected String value; 046 047 /** 048 * @param name the type name (e.g. "NOTE") 049 */ 050 public TextType(String name) { 051 this(name, null); 052 } 053 054 /** 055 * @param name the type name (e.g. "NOTE") 056 * @param value the type value 057 */ 058 public TextType(String name, String value) { 059 super(name); 060 this.value = value; 061 } 062 063 /** 064 * Gets the value of this type. 065 * @return the value 066 */ 067 public String getValue() { 068 return value; 069 } 070 071 /** 072 * Sets the value of this type. 073 * @param value the new value 074 */ 075 public void setValue(String value) { 076 this.value = value; 077 } 078 079 @Override 080 protected void doMarshalText(StringBuilder sb, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode) { 081 sb.append(VCardStringUtils.escape(value)); 082 } 083 084 @Override 085 protected void doUnmarshalText(String value, VCardVersion version, List<String> warnings, CompatibilityMode compatibilityMode) { 086 this.value = VCardStringUtils.unescape(value); 087 } 088 089 @Override 090 protected void doMarshalXml(XCardElement parent, List<String> warnings, CompatibilityMode compatibilityMode) { 091 parent.text(value); 092 } 093 094 @Override 095 protected void doUnmarshalXml(XCardElement element, List<String> warnings, CompatibilityMode compatibilityMode) { 096 setValue(element.text()); 097 } 098 099 @Override 100 protected void doUnmarshalHtml(HCardElement element, List<String> warnings) { 101 setValue(element.value()); 102 } 103 }