use of ezvcard.property.Categories in project ez-vcard by mangstadt.
the class CategoriesScribe method _parseHtml.
@Override
protected Categories _parseHtml(HCardElement element, ParseContext context) {
String value = element.attr("rel");
if (value.length() == 0) {
value = element.value();
}
Categories property = _newInstance();
property.getValues().add(value);
return property;
}
use of ezvcard.property.Categories in project ez-vcard by mangstadt.
the class VCard method setCategories.
/**
* <p>
* Sets the list of "keywords" or "tags" that can be used to describe the
* person.
* </p>
* <p>
* <b>Property name:</b> {@code CATEGORIES}<br>
* <b>Supported versions:</b> {@code 3.0, 4.0}
* </p>
* @param categories the categories (e.g. "swimmer", "biker", "knitter") or
* an empty arguments list to remove
* @return the property object that was created
* @see <a href="http://tools.ietf.org/html/rfc6350#page-43">RFC 6350
* p.43</a>
* @see <a href="http://tools.ietf.org/html/rfc2426#page-20">RFC 2426
* p.20</a>
*/
public Categories setCategories(String... categories) {
Categories type = null;
if (categories.length > 0) {
type = new Categories();
type.getValues().addAll(Arrays.asList(categories));
}
setCategories(type);
return type;
}
use of ezvcard.property.Categories in project ez-vcard by mangstadt.
the class HCardParser method visit.
private void visit(Element element) {
boolean visitChildren = true;
Set<String> classNames = element.classNames();
for (String className : classNames) {
className = className.toLowerCase();
// give special treatment to certain URLs
if (urlPropertyName.equals(className)) {
String href = element.attr("href");
if (href.length() > 0) {
if (!classNames.contains(emailName) && href.matches("(?i)mailto:.*")) {
className = emailName;
} else if (!classNames.contains(telName) && href.matches("(?i)tel:.*")) {
className = telName;
} else {
// try parsing as IMPP
VCardPropertyScribe<? extends VCardProperty> scribe = index.getPropertyScribe(Impp.class);
context.getWarnings().clear();
context.setPropertyName(scribe.getPropertyName());
try {
VCardProperty property = scribe.parseHtml(new HCardElement(element), context);
vcard.addProperty(property);
warnings.addAll(context.getWarnings());
continue;
} catch (SkipMeException e) {
// URL is not an instant messenger URL
} catch (CannotParseException e) {
// URL is not an instant messenger URL
}
}
}
}
// hCard uses a different name for the CATEGORIES property
if ("category".equals(className)) {
className = categoriesName;
}
VCardPropertyScribe<? extends VCardProperty> scribe = index.getPropertyScribe(className);
if (scribe == null) {
// if no scribe is found, and the class name doesn't start with "x-", then it must be an arbitrary CSS class that has nothing to do with vCard
if (!className.startsWith("x-")) {
continue;
}
scribe = new RawPropertyScribe(className);
}
context.getWarnings().clear();
context.setPropertyName(scribe.getPropertyName());
VCardProperty property;
try {
property = scribe.parseHtml(new HCardElement(element), context);
warnings.addAll(context.getWarnings());
// LABELs must be treated specially so they can be matched up with their ADRs
if (property instanceof Label) {
labels.add((Label) property);
continue;
}
// add all NICKNAMEs to the same type object
if (property instanceof Nickname) {
Nickname nn = (Nickname) property;
if (nickname == null) {
nickname = nn;
vcard.addProperty(nickname);
} else {
nickname.getValues().addAll(nn.getValues());
}
continue;
}
// add all CATEGORIES to the same type object
if (property instanceof Categories) {
Categories c = (Categories) property;
if (categories == null) {
categories = c;
vcard.addProperty(categories);
} else {
categories.getValues().addAll(c.getValues());
}
continue;
}
} catch (SkipMeException e) {
// @formatter:off
warnings.add(new ParseWarning.Builder(context).message(22, e.getMessage()).build());
// @formatter:on
continue;
} catch (CannotParseException e) {
// @formatter:off
warnings.add(new ParseWarning.Builder(context).message(e).build());
// @formatter:on
property = new RawProperty(className, element.outerHtml());
} catch (EmbeddedVCardException e) {
if (isChildOf(element, embeddedVCards)) {
// prevents multiple-nested embedded elements from overwriting each other
continue;
}
property = e.getProperty();
embeddedVCards.add(element);
HCardParser embeddedReader = new HCardParser(element, pageUrl);
try {
VCard embeddedVCard = embeddedReader.readNext();
e.injectVCard(embeddedVCard);
} finally {
warnings.addAll(embeddedReader.getWarnings());
IOUtils.closeQuietly(embeddedReader);
}
visitChildren = false;
}
vcard.addProperty(property);
}
if (visitChildren) {
for (Element child : element.children()) {
visit(child);
}
}
}
Aggregations