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