| 1 | package ezvcard.io.scribe; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | import ezvcard.io.ParseContext; |
| 6 | import ezvcard.io.html.HCardElement; |
| 7 | import ezvcard.parameter.VCardParameters; |
| 8 | import ezvcard.property.Label; |
| 9 | |
| 10 | /* |
| 11 | Copyright (c) 2012-2023, Michael Angstadt |
| 12 | All rights reserved. |
| 13 | |
| 14 | Redistribution and use in source and binary forms, with or without |
| 15 | modification, are permitted provided that the following conditions are met: |
| 16 | |
| 17 | 1. Redistributions of source code must retain the above copyright notice, this |
| 18 | list of conditions and the following disclaimer. |
| 19 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 20 | this list of conditions and the following disclaimer in the documentation |
| 21 | and/or other materials provided with the distribution. |
| 22 | |
| 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 27 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
| 35 | /** |
| 36 | * Marshals {@link Label} properties. |
| 37 | * @author Michael Angstadt |
| 38 | */ |
| 39 | public class LabelScribe extends StringPropertyScribe<Label> { |
| 40 | public LabelScribe() { |
| 41 | super(Label.class, "LABEL"); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | protected Label _parseValue(String value) { |
| 46 | return new Label(value); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | protected Label _parseHtml(HCardElement element, ParseContext context) { |
| 51 | Label property = new Label(element.value()); |
| 52 | |
| 53 | List<String> types = element.types(); |
| 54 | property.getParameters().putAll(VCardParameters.TYPE, types); |
| 55 | |
| 56 | return property; |
| 57 | } |
| 58 | } |