| 1 |
package ezvcard.io.scribe; |
| 2 |
|
| 3 |
import java.util.HashMap; |
| 4 |
import java.util.Map; |
| 5 |
|
| 6 |
import javax.xml.namespace.QName; |
| 7 |
|
| 8 |
import ezvcard.VCardVersion; |
| 9 |
import ezvcard.property.RawProperty; |
| 10 |
import ezvcard.property.VCardProperty; |
| 11 |
import ezvcard.property.Xml; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public class ScribeIndex { |
| 77 |
|
| 78 |
private static final Map<String, VCardPropertyScribe<? extends VCardProperty>> standardByName = new HashMap<>(); |
| 79 |
private static final Map<Class<? extends VCardProperty>, VCardPropertyScribe<? extends VCardProperty>> standardByClass = new HashMap<>(); |
| 80 |
private static final Map<QName, VCardPropertyScribe<? extends VCardProperty>> standardByQName = new HashMap<>(); |
| 81 |
static { |
| 82 |
|
| 83 |
registerStandard(new AddressScribe()); |
| 84 |
registerStandard(new AgentScribe()); |
| 85 |
registerStandard(new AnniversaryScribe()); |
| 86 |
registerStandard(new BirthdayScribe()); |
| 87 |
registerStandard(new CalendarRequestUriScribe()); |
| 88 |
registerStandard(new CalendarUriScribe()); |
| 89 |
registerStandard(new CategoriesScribe()); |
| 90 |
registerStandard(new ClassificationScribe()); |
| 91 |
registerStandard(new ClientPidMapScribe()); |
| 92 |
registerStandard(new EmailScribe()); |
| 93 |
registerStandard(new FreeBusyUrlScribe()); |
| 94 |
registerStandard(new FormattedNameScribe()); |
| 95 |
registerStandard(new GenderScribe()); |
| 96 |
registerStandard(new GeoScribe()); |
| 97 |
registerStandard(new ImppScribe()); |
| 98 |
registerStandard(new KeyScribe()); |
| 99 |
registerStandard(new KindScribe()); |
| 100 |
registerStandard(new LabelScribe()); |
| 101 |
registerStandard(new LanguageScribe()); |
| 102 |
registerStandard(new LogoScribe()); |
| 103 |
registerStandard(new MailerScribe()); |
| 104 |
registerStandard(new MemberScribe()); |
| 105 |
registerStandard(new NicknameScribe()); |
| 106 |
registerStandard(new NoteScribe()); |
| 107 |
registerStandard(new OrganizationScribe()); |
| 108 |
registerStandard(new PhotoScribe()); |
| 109 |
registerStandard(new ProductIdScribe()); |
| 110 |
registerStandard(new ProfileScribe()); |
| 111 |
registerStandard(new RelatedScribe()); |
| 112 |
registerStandard(new RevisionScribe()); |
| 113 |
registerStandard(new RoleScribe()); |
| 114 |
registerStandard(new SortStringScribe()); |
| 115 |
registerStandard(new SoundScribe()); |
| 116 |
registerStandard(new SourceDisplayTextScribe()); |
| 117 |
registerStandard(new SourceScribe()); |
| 118 |
registerStandard(new StructuredNameScribe()); |
| 119 |
registerStandard(new TelephoneScribe()); |
| 120 |
registerStandard(new TimezoneScribe()); |
| 121 |
registerStandard(new TitleScribe()); |
| 122 |
registerStandard(new UidScribe()); |
| 123 |
registerStandard(new UrlScribe()); |
| 124 |
|
| 125 |
|
| 126 |
registerStandard(new XmlScribe()); |
| 127 |
|
| 128 |
|
| 129 |
registerStandard(new BirthplaceScribe()); |
| 130 |
registerStandard(new DeathdateScribe()); |
| 131 |
registerStandard(new DeathplaceScribe()); |
| 132 |
|
| 133 |
|
| 134 |
registerStandard(new ExpertiseScribe()); |
| 135 |
registerStandard(new OrgDirectoryScribe()); |
| 136 |
registerStandard(new InterestScribe()); |
| 137 |
registerStandard(new HobbyScribe()); |
| 138 |
} |
| 139 |
|
| 140 |
private final Map<String, VCardPropertyScribe<? extends VCardProperty>> extendedByName = new HashMap<>(0); |
| 141 |
private final Map<Class<? extends VCardProperty>, VCardPropertyScribe<? extends VCardProperty>> extendedByClass = new HashMap<>(0); |
| 142 |
private final Map<QName, VCardPropertyScribe<? extends VCardProperty>> extendedByQName = new HashMap<>(0); |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public VCardPropertyScribe<? extends VCardProperty> getPropertyScribe(String propertyName) { |
| 150 |
propertyName = propertyName.toUpperCase(); |
| 151 |
|
| 152 |
VCardPropertyScribe<? extends VCardProperty> scribe = extendedByName.get(propertyName); |
| 153 |
if (scribe != null) { |
| 154 |
return scribe; |
| 155 |
} |
| 156 |
|
| 157 |
return standardByName.get(propertyName); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public boolean hasPropertyScribe(VCardProperty property) { |
| 166 |
if (property instanceof RawProperty) { |
| 167 |
return true; |
| 168 |
} |
| 169 |
|
| 170 |
return getPropertyScribe(property.getClass()) != null; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
public VCardPropertyScribe<? extends VCardProperty> getPropertyScribe(Class<? extends VCardProperty> clazz) { |
| 179 |
VCardPropertyScribe<? extends VCardProperty> scribe = extendedByClass.get(clazz); |
| 180 |
if (scribe != null) { |
| 181 |
return scribe; |
| 182 |
} |
| 183 |
|
| 184 |
return standardByClass.get(clazz); |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public VCardPropertyScribe<? extends VCardProperty> getPropertyScribe(VCardProperty property) { |
| 193 |
if (property instanceof RawProperty) { |
| 194 |
RawProperty raw = (RawProperty) property; |
| 195 |
return new RawPropertyScribe(raw.getPropertyName()); |
| 196 |
} |
| 197 |
|
| 198 |
return getPropertyScribe(property.getClass()); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
public VCardPropertyScribe<? extends VCardProperty> getPropertyScribe(QName qname) { |
| 207 |
VCardPropertyScribe<? extends VCardProperty> scribe = extendedByQName.get(qname); |
| 208 |
if (scribe != null) { |
| 209 |
return scribe; |
| 210 |
} |
| 211 |
|
| 212 |
scribe = standardByQName.get(qname); |
| 213 |
if (scribe != null) { |
| 214 |
return scribe; |
| 215 |
} |
| 216 |
|
| 217 |
if (VCardVersion.V4_0.getXmlNamespace().equals(qname.getNamespaceURI())) { |
| 218 |
return new RawPropertyScribe(qname.getLocalPart().toUpperCase()); |
| 219 |
} |
| 220 |
|
| 221 |
return getPropertyScribe(Xml.class); |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
public void register(VCardPropertyScribe<? extends VCardProperty> scribe) { |
| 229 |
extendedByName.put(scribe.getPropertyName().toUpperCase(), scribe); |
| 230 |
extendedByClass.put(scribe.getPropertyClass(), scribe); |
| 231 |
extendedByQName.put(scribe.getQName(), scribe); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
public void unregister(VCardPropertyScribe<? extends VCardProperty> scribe) { |
| 239 |
extendedByName.remove(scribe.getPropertyName().toUpperCase()); |
| 240 |
extendedByClass.remove(scribe.getPropertyClass()); |
| 241 |
extendedByQName.remove(scribe.getQName()); |
| 242 |
} |
| 243 |
|
| 244 |
private static void registerStandard(VCardPropertyScribe<? extends VCardProperty> scribe) { |
| 245 |
standardByName.put(scribe.getPropertyName().toUpperCase(), scribe); |
| 246 |
standardByClass.put(scribe.getPropertyClass(), scribe); |
| 247 |
standardByQName.put(scribe.getQName(), scribe); |
| 248 |
} |
| 249 |
} |