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.xml.*; 025import org.apache.juneau.xml.annotation.*; 026 027/** 028 * Base class for all Atom elements, providing common attributes. 029 * 030 * <p> 031 * This abstract class defines attributes that can appear on any Atom element. Per RFC 4287, 032 * all Atom elements may have <c>xml:base</c> and <c>xml:lang</c> attributes for managing 033 * URIs and language context. 034 * 035 * <p> 036 * Common attributes: 037 * <ul class='spaced-list'> 038 * <li><b>xml:base</b> - Establishes a base URI for resolving relative references 039 * <li><b>xml:lang</b> - Indicates the natural language of the element's content 040 * </ul> 041 * 042 * <p> 043 * This class is extended by all Atom bean classes ({@link Feed}, {@link Entry}, {@link Link}, 044 * {@link Person}, {@link Category}, {@link Text}, etc.). 045 * 046 * <h5 class='figure'>Schema</h5> 047 * <p class='bschema'> 048 * atomCommonAttributes = 049 * attribute xml:base { atomUri }?, 050 * attribute xml:lang { atomLanguageTag }?, 051 * undefinedAttribute* 052 * </p> 053 * 054 * <h5 class='section'>Examples:</h5> 055 * <p class='bjava'> 056 * <jc>// Set base URI for relative link resolution</jc> 057 * Feed <jv>feed</jv> = <jk>new</jk> Feed(...) 058 * .setBase(<js>"http://example.org/"</js>); 059 * 060 * <jc>// Set language</jc> 061 * Text <jv>title</jv> = <jk>new</jk> Text(<js>"text"</js>) 062 * .setText(<js>"My Feed"</js>) 063 * .setLang(<js>"en"</js>); 064 * </p> 065 * 066 * <h5 class='section'>Specification:</h5> 067 * <p> 068 * Represents <c>atomCommonAttributes</c> in the 069 * <a class="doclink" href="https://tools.ietf.org/html/rfc4287#section-2">RFC 4287 - Section 2</a> specification. 070 * 071 * <h5 class='section'>See Also:</h5><ul> 072 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanAtom">juneau-bean-atom</a> 073 * <li class='extlink'><a class="doclink" href="https://tools.ietf.org/html/rfc4287">RFC 4287 - The Atom Syndication Format</a> 074 * </ul> 075 */ 076public abstract class Common { 077 078 private URI base; 079 private String lang; 080 081 /** 082 * Bean property getter: <property>base</property>. 083 * 084 * <p> 085 * Returns the base URI for resolving relative URI references (xml:base attribute). 086 * 087 * <p> 088 * This attribute, defined by XML Base, establishes a base URI for resolving any 089 * relative references within the scope of this element. This is particularly useful 090 * when aggregating content from multiple sources. 091 * 092 * @return The property value, or <jk>null</jk> if it is not set. 093 */ 094 @Xml(prefix = "xml", format = ATTR) 095 public URI getBase() { return base; } 096 097 /** 098 * Bean property getter: <property>lang</property>. 099 * 100 * <p> 101 * Returns the natural language of the element's content (xml:lang attribute). 102 * 103 * <p> 104 * The language tag should be a language identifier as defined by RFC 3066. This attribute 105 * is inherited by child elements, so it need only be specified on the highest-level 106 * element where it applies. 107 * 108 * @return The property value, or <jk>null</jk> if it is not set. 109 */ 110 @Xml(prefix = "xml", format = ATTR) 111 public String getLang() { return lang; } 112 113 /** 114 * Bean property setter: <property>base</property>. 115 * 116 * <p> 117 * Sets the base URI for resolving relative URI references (xml:base attribute). 118 * 119 * <p> 120 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 121 * Strings must be valid URIs. 122 * 123 * <h5 class='section'>Example:</h5> 124 * <p class='bjava'> 125 * Feed <jv>feed</jv> = <jk>new</jk> Feed(...) 126 * .setBase(<js>"http://example.org/"</js>); 127 * </p> 128 * 129 * @param value 130 * The new value for this property. 131 * <br>Can be <jk>null</jk> to unset the property. 132 * @return This object. 133 */ 134 public Common setBase(Object value) { 135 this.base = toUri(value); 136 return this; 137 } 138 139 /** 140 * Bean property setter: <property>lang</property>. 141 * 142 * <p> 143 * Sets the natural language of the element's content (xml:lang attribute). 144 * 145 * <h5 class='section'>Example:</h5> 146 * <p class='bjava'> 147 * Text <jv>title</jv> = <jk>new</jk> Text(<js>"text"</js>) 148 * .setText(<js>"Mon Blog"</js>) 149 * .setLang(<js>"fr"</js>); 150 * </p> 151 * 152 * @param value 153 * The new value for this property (e.g., "en", "fr", "de", "en-US"). 154 * <br>Can be <jk>null</jk> to unset the property. 155 * @return This object. 156 */ 157 public Common setLang(String value) { 158 lang = value; 159 return this; 160 } 161 162 @Override /* Overridden from Object */ 163 public String toString() { 164 return XmlSerializer.DEFAULT_SQ.toString(this); 165 } 166}