BrightSide Workbench Full Report + Source Code
VCard.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;
19 
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Vector;
23 import org.turro.vcard.properties.Property;
24 import org.turro.vcard.properties.PropertyTag;
25 import org.turro.vcard.properties.Version;
26 
31 public class VCard {
32 
33  protected List<Property> properties;
34  protected Version version;
35 
36  public VCard(Version version) {
37  this.version = version;
38  properties = new Vector<Property>();
39  }
40 
41  public Version getVersion() {
42  return version;
43  }
44 
45  public String getVCard() {
46  StringBuilder sb = new StringBuilder();
47 
48  sb.append("BEGIN:VCARD\n");
50 
51  for(Property p : properties) {
52  p.renderProperty(sb);
53  }
54 
55  sb.append("END:VCARD\n");
56 
57  return sb.toString();
58  }
59 
60  public void addProperty(Property property) {
61  properties.add(property);
62  }
63 
65  for(Property p : properties) {
66  if(p.getTag().equals(tag)) {
67  return p;
68  }
69  }
70  return null;
71  }
72 
73  public List<Property> getProperties(PropertyTag tag) {
74  List<Property> props = new ArrayList<Property>();
75  for(Property p : properties) {
76  if(p.getTag().equals(tag)) {
77  props.add(p);
78  }
79  }
80  return props;
81  }
82 
83  public void readLines(List<String> lines) {
84  for(String l : lines) {
86  if(pt != null) {
87  properties.add(Property.getInstance(this, pt, l));
88  }
89  }
90  }
91 
92 }
93 
List< Property > properties
Definition: VCard.java:33
List< Property > getProperties(PropertyTag tag)
Definition: VCard.java:73
Property getProperty(PropertyTag tag)
Definition: VCard.java:64
void addProperty(Property property)
Definition: VCard.java:60
VCard(Version version)
Definition: VCard.java:36
void readLines(List< String > lines)
Definition: VCard.java:83
String getVCard()
Definition: VCard.java:45
Version getVersion()
Definition: VCard.java:41
static Property getInstance(VCard vcard, PropertyTag tag, String l)
Definition: Property.java:35
static PropertyTag getInstance(String l)
void renderVersion(StringBuilder sb)
Definition: Version.java:60