001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.bean.atom; 018 019import static org.apache.juneau.commons.utils.StringUtils.*; 020import static org.apache.juneau.xml.annotation.XmlFormat.*; 021 022import java.net.*; 023 024import org.apache.juneau.annotation.*; 025import org.apache.juneau.xml.annotation.*; 026 027/** 028 * Represents a category or tag associated with a feed or entry. 029 * 030 * <p> 031 * Categories provide a way to classify or tag feeds and entries, enabling better organization 032 * and discovery of content. Each category has a term (required) and optionally a scheme (for 033 * namespacing) and a human-readable label. 034 * 035 * <p> 036 * Categories are commonly used for: 037 * <ul class='spaced-list'> 038 * <li>Tagging entries by topic (e.g., "technology", "sports") 039 * <li>Classifying content by category schemes (e.g., subject taxonomies) 040 * <li>Enabling feed filtering and organization 041 * </ul> 042 * 043 * <h5 class='figure'>Schema</h5> 044 * <p class='bschema'> 045 * atomCategory = 046 * element atom:category { 047 * atomCommonAttributes, 048 * attribute term { text }, 049 * attribute scheme { atomUri }?, 050 * attribute label { text }?, 051 * undefinedContent 052 * } 053 * </p> 054 * 055 * <h5 class='section'>Example:</h5> 056 * <p class='bjava'> 057 * <jc>// Simple category</jc> 058 * Category <jv>cat1</jv> = <jk>new</jk> Category(<js>"technology"</js>); 059 * 060 * <jc>// Category with scheme and label</jc> 061 * Category <jv>cat2</jv> = <jk>new</jk> Category(<js>"tech"</js>) 062 * .setScheme(<js>"http://example.org/categories"</js>) 063 * .setLabel(<js>"Technology"</js>); 064 * 065 * <jc>// Add to entry</jc> 066 * Entry <jv>entry</jv> = <jk>new</jk> Entry(...) 067 * .setCategories(<jv>cat1</jv>, <jv>cat2</jv>); 068 * </p> 069 * 070 * <h5 class='section'>Specification:</h5> 071 * <p> 072 * Represents an <c>atomCategory</c> construct in the 073 * <a class="doclink" href="https://tools.ietf.org/html/rfc4287#section-4.2.2">RFC 4287 - Section 4.2.2</a> specification. 074 * 075 * <h5 class='section'>See Also:</h5><ul> 076 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanAtom">juneau-bean-atom</a> 077 * <li class='extlink'><a class="doclink" href="https://tools.ietf.org/html/rfc4287">RFC 4287 - The Atom Syndication Format</a> 078 * </ul> 079 */ 080@Bean(typeName = "category") 081public class Category extends Common { 082 083 private String term; 084 private URI scheme; 085 private String label; 086 087 /** Bean constructor. */ 088 public Category() {} 089 090 /** 091 * Normal constructor. 092 * 093 * @param term The category term. 094 */ 095 public Category(String term) { 096 setTerm(term); 097 } 098 099 /** 100 * Bean property getter: <property>label</property>. 101 * 102 * <p> 103 * The category label. 104 * 105 * @return The property value, or <jk>null</jk> if it is not set. 106 */ 107 @Xml(format = ATTR) 108 public String getLabel() { return label; } 109 110 /** 111 * Bean property getter: <property>scheme</property>. 112 * 113 * <p> 114 * The category scheme. 115 * 116 * @return The property value, or <jk>null</jk> if it is not set. 117 */ 118 @Xml(format = ATTR) 119 public URI getScheme() { return scheme; } 120 121 /** 122 * Bean property getter: <property>term</property>. 123 * 124 * <p> 125 * The category term. 126 * 127 * @return The property value, or <jk>null</jk> if it is not set. 128 */ 129 @Xml(format = ATTR) 130 public String getTerm() { return term; } 131 132 @Override /* Overridden from Common */ 133 public Category setBase(Object value) { 134 super.setBase(value); 135 return this; 136 } 137 138 /** 139 * Bean property setter: <property>scheme</property>. 140 * 141 * <p> 142 * The category label. 143 * 144 * @param value 145 * The new value for this property. 146 * <br>Can be <jk>null</jk> to unset the property. 147 * @return This object 148 */ 149 public Category setLabel(String value) { 150 label = value; 151 return this; 152 } 153 154 @Override /* Overridden from Common */ 155 public Category setLang(String value) { 156 super.setLang(value); 157 return this; 158 } 159 160 /** 161 * Bean property setter: <property>scheme</property>. 162 * 163 * <p> 164 * The category scheme. 165 * 166 * <p> 167 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 168 * Strings must be valid URIs. 169 * 170 * @param value 171 * The new value for this property. 172 * <br>Can be <jk>null</jk> to unset the property. 173 * @return This object 174 */ 175 public Category setScheme(Object value) { 176 this.scheme = toUri(value); 177 return this; 178 } 179 180 /** 181 * Bean property setter: <property>term</property>. 182 * 183 * <p> 184 * The category term. 185 * 186 * @param value 187 * The new value for this property. 188 * <br>Can be <jk>null</jk> to unset the property. 189 * @return This object 190 */ 191 @Xml(format = ATTR) 192 public Category setTerm(String value) { 193 term = value; 194 return this; 195 } 196}