/** * Returns the language associated with the category label (or {@code null} * if undefined). */ public String getLabelLang() { return getAttributeValue(XML_LANG); }
@Override public int hashCode() { int result = 17; String scheme = getScheme(); result = 37 * result + ((scheme != null) ? scheme.hashCode() : 0); String term = getTerm(); result = 37 * result + ((term != null) ? term.hashCode() : 0); String label = getLabel(); result = 37 * result + ((label != null) ? label.hashCode() : 0); return result; } }
/** * Returns the GData kind of a target entity by checking for the * {@code gd:kind} attribute or a kind {@link Category} element. If both * are present, the kind attribute value will have precedence and be returned. * * @param source source feed or entry element to check * @return kind value or {@code null} if no kind information is found. */ static String getElementKind(Element source) { String term = source.getAttributeValue(GdAttributes.KIND); if (term != null) { return term; } for (Category category : source.getElements(Category.KEY)) { if (Namespaces.gKind.equals(category.getScheme())) { return category.getTerm(); } } return null; }
/** * Sets the category label. A value of {@code null} indicates that there is * no label. * @param label category label value. */ public void setLabel(String label) { setAttributeValue(LABEL, label); }
/** * Constructs a new category from a Category string. The format of * the String is the same as the one used to represent a category in * a GData query: an optional scheme surrounded by braces, followed * by a term. * * @param category the category string */ public Category(String category) { this(); Matcher m = categoryPattern.matcher(category); if (!m.matches()) { throw new IllegalArgumentException("Invalid category: " + category); } if (m.group(2) != null) { setScheme(m.group(2)); } setTerm(m.group(3)); }
/** * Returns the GData kind of a target entity by checking for the * {@code gd:kind} attribute or a kind {@link Category} element. If both * are present, the kind attribute value will have precedence and be returned. * * @param source source feed or entry element to check * @return kind value or {@code null} if no kind information is found. */ static String getElementKind(Element source) { String term = source.getAttributeValue(GdAttributes.KIND); if (term != null) { return term; } for (Category category : source.getElements(Category.KEY)) { if (Namespaces.gKind.equals(category.getScheme())) { return category.getTerm(); } } return null; }
/** * Sets the language associated with the category label (or {@code nulll} if * undefined). * @param lang label language. */ public void setLabelLang(String lang) { setAttributeValue(XML_LANG, lang); }
/** * Constructs a new category from a Category string. The format of * the String is the same as the one used to represent a category in * a GData query: an optional scheme surrounded by braces, followed * by a term. * * @param category the category string */ public Category(String category) { this(); Matcher m = categoryPattern.matcher(category); if (!m.matches()) { throw new IllegalArgumentException("Invalid category: " + category); } if (m.group(2) != null) { setScheme(m.group(2)); } setTerm(m.group(3)); }
@Override public int hashCode() { int result = 17; String scheme = getScheme(); result = 37 * result + ((scheme != null) ? scheme.hashCode() : 0); String term = getTerm(); result = 37 * result + ((term != null) ? term.hashCode() : 0); String label = getLabel(); result = 37 * result + ((label != null) ? label.hashCode() : 0); return result; } }
/** * Narrows this entry using categories with an appropriate kind value. * This will loop through the categories, checking if they represent kinds, * and adapting the entry to that kind of an appropriate adaptation was * found. This will return the most specific subtype of the narrowed type * that could be found. */ @Override protected Element narrow(ElementMetadata<?, ?> metadata, ValidationContext vc) { Element narrowed = super.narrow(metadata, vc); for (Category category : getCategories()) { if (Namespaces.gKind.equals(category.getScheme())) { narrowed = adapt(narrowed, metadata, category.getTerm()); } } return narrowed; } }
/** * Returns the language associated with the category label (or {@code null} * if undefined). */ public String getLabelLang() { return getAttributeValue(XML_LANG); }
/** * Sets the category scheme. A value of {@code null} indicates that there is * no category scheme. * @param scheme category scheme URI. */ public void setScheme(String scheme) { setAttributeValue(SCHEME, scheme); }
/** * Constructs a new category from a Category string. The format of * the String is the same as the one used to represent a category in * a GData query: an optional scheme surrounded by braces, followed * by a term. * * @param category the category string */ public Category(String category) { this(); Matcher m = categoryPattern.matcher(category); if (!m.matches()) { throw new IllegalArgumentException("Invalid category: " + category); } if (m.group(2) != null) { setScheme(m.group(2)); } setTerm(m.group(3)); }
@Override public int hashCode() { int result = 17; String scheme = getScheme(); result = 37 * result + ((scheme != null) ? scheme.hashCode() : 0); String term = getTerm(); result = 37 * result + ((term != null) ? term.hashCode() : 0); String label = getLabel(); result = 37 * result + ((label != null) ? label.hashCode() : 0); return result; } }
/** * Narrows this feed using categories with an appropriate kind value. * This will loop through the categories, checking if they represent kinds, * and adapting the feed to that kind if an appropriate adaptation was * found. This will return the most specific subtype of the narrowed type. */ @Override protected Element narrow(ElementMetadata<?,?> meta, ValidationContext vc) { Element narrowed = this; for (Category category : getCategories()) { if (Namespaces.gKind.equals(category.getScheme())) { narrowed = adapt(narrowed, meta, category.getTerm()); } } if (narrowed == this) { narrowed = super.narrow(meta, vc); } return narrowed; }