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