Debian Codegraph @

src/test/java/ezvcard/io/MyFormattedNameProperty.java

raw symbols SCIP
1 package ezvcard.io;
2
3 import ezvcard.VCardDataType;
4 import ezvcard.VCardVersion;
5 import ezvcard.io.html.HCardElement;
6 import ezvcard.io.json.JCardValue;
7 import ezvcard.io.scribe.VCardPropertyScribe;
8 import ezvcard.io.text.WriteContext;
9 import ezvcard.io.xml.XCardElement;
10 import ezvcard.parameter.VCardParameters;
11 import ezvcard.property.VCardProperty;
12
13 /*
14 Copyright (c) 2012-2023, Michael Angstadt
15 All rights reserved.
16
17 Redistribution and use in source and binary forms, with or without
18 modification, are permitted provided that the following conditions are met:
19
20 1. Redistributions of source code must retain the above copyright notice, this
21 list of conditions and the following disclaimer.
22 2. Redistributions in binary form must reproduce the above copyright notice,
23 this list of conditions and the following disclaimer in the documentation
24 and/or other materials provided with the distribution.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
30 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
33 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
37 The views and conclusions contained in the software and documentation are those
38 of the authors and should not be interpreted as representing official policies,
39 either expressed or implied, of the FreeBSD Project.
40 */
41
42 /**
43 * @author Michael Angstadt
44 */
45 public class MyFormattedNameProperty extends VCardProperty {
46 public String value;
47
48 public MyFormattedNameProperty(String value) {
49 this.value = value;
50 }
51
52 public static class MyFormattedNameScribe extends VCardPropertyScribe<MyFormattedNameProperty> {
53 public MyFormattedNameScribe() {
54 super(MyFormattedNameProperty.class, "FN");
55 }
56
57 @Override
58 protected VCardDataType _defaultDataType(VCardVersion version) {
59 return VCardDataType.get("name");
60 }
61
62 @Override
63 protected String _writeText(MyFormattedNameProperty property, WriteContext context) {
64 return property.value.toUpperCase();
65 }
66
67 @Override
68 protected MyFormattedNameProperty _parseText(String value, VCardDataType dataType, VCardParameters parameters, ParseContext context) {
69 return new MyFormattedNameProperty(value.toUpperCase());
70 }
71
72 @Override
73 protected void _writeXml(MyFormattedNameProperty property, XCardElement parent) {
74 parent.append("name", property.value);
75 }
76
77 @Override
78 protected MyFormattedNameProperty _parseXml(XCardElement element, VCardParameters parameters, ParseContext context) {
79 return new MyFormattedNameProperty(element.first("name").toUpperCase());
80 }
81
82 @Override
83 protected MyFormattedNameProperty _parseHtml(HCardElement element, ParseContext context) {
84 return new MyFormattedNameProperty(element.value().toUpperCase());
85 }
86
87 @Override
88 protected JCardValue _writeJson(MyFormattedNameProperty property) {
89 return JCardValue.single(property.value.toUpperCase());
90 }
91
92 @Override
93 protected MyFormattedNameProperty _parseJson(JCardValue value, VCardDataType dataType, VCardParameters parameters, ParseContext context) {
94 return new MyFormattedNameProperty(value.asSingle().toUpperCase());
95 }
96 }
97 }