BrightSide Workbench Full Report + Source Code
Property.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.vcard.properties;
19 
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.turro.vcard.VCard;
23 
28 public class Property {
29 
30  private PropertyTag tag;
31  private String value;
32  private List<String> types = new ArrayList<String>();
33  private VCard vcard;
34 
35  public static Property getInstance(VCard vcard, PropertyTag tag, String l) {
36  int p = l.indexOf(":");
37  if(p == -1) return null;
38 
39  Property property = new Property(tag, vcard);
40 
41  vcard.getVersion().readTypes(l.substring(tag.getTag().length(), p), property.getTypes());
42  property.setValue(l.substring(p + 1));
43 
44  return property;
45  }
46 
47  public Property(PropertyTag tag, VCard vcard) {
48  this(tag, vcard, null);
49  }
50 
51  public Property(PropertyTag tag, VCard vcard, String value) {
52  this.tag = tag;
53  this.vcard = vcard;
54  this.value = value;
55  }
56 
57  public String getValue() {
58  return value;
59  }
60 
61  public String getValue(int index) {
62  String v[] = value.split(";");
63  return v.length <= index ? "" : v[index];
64  }
65 
66  public String[] getValues() {
67  return value.split(";");
68  }
69 
70  public void setValue(String value) {
71  this.value = value;
72  }
73 
74  public void setValues(String[] values) {
75  this.value = null;
76  for(String v : values) {
77  if(value == null) {
78  value = v;
79  } else {
80  value += ";" + v;
81  }
82  }
83  }
84 
85  public PropertyTag getTag() {
86  return tag;
87  }
88 
89  public List<String> getTypes() {
90  return types;
91  }
92 
93  public void addType(String type) {
94  types.add(type);
95  }
96 
97  public void renderProperty(StringBuilder sb) {
98  sb.append(tag.getTag());
99  vcard.getVersion().renderTypes(sb, types);
100  sb.append(":" + value + "\n");
101  }
102 
103 }
Version getVersion()
Definition: VCard.java:41
void setValues(String[] values)
Definition: Property.java:74
static Property getInstance(VCard vcard, PropertyTag tag, String l)
Definition: Property.java:35
Property(PropertyTag tag, VCard vcard)
Definition: Property.java:47
void renderProperty(StringBuilder sb)
Definition: Property.java:97
Property(PropertyTag tag, VCard vcard, String value)
Definition: Property.java:51
void renderTypes(StringBuilder sb, List< String > types)
Definition: Version.java:46
void readTypes(String s, List< String > types)
Definition: Version.java:70