001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.dto.atom;
014
015import java.net.*;
016import java.util.*;
017
018import org.apache.juneau.*;
019
020/**
021 * Various useful static methods for creating ATOM elements.
022 *
023 * <p>
024 * Typically, you'll want to do a static import on this class and then call the methods like so...
025 * <p class='bjava'>
026 *    <jk>import static</jk> org.apache.juneau.dto.atom.AtomBuilder.*;
027 *
028 *    Feed <jv>feed</jv> =
029 *       <jsm>feed</jsm>(<js>"tag:juneau.sample.com,2013:1"</js>, <js>"Juneau ATOM specification"</js>,
030 *          <js>"2013-05-08T12:29:29Z"</js>)
031 *       .subtitle(<jsm>text</jsm>(<js>"html"</js>)
032 *          .children(<js>"A &lt;em&gt;lot&lt;/em&gt; of effort went into making this effortless"</js>))
033 *       .links(
034 *          <jsm>link</jsm>(<js>"alternate"</js>, <js>"text/html"</js>, <js>"http://www.sample.com/"</js>)
035 *             .hreflang(<js>"en"</js>),
036 *          <jsm>link</jsm>(<js>"self"</js>, <js>"application/atom+xml"</js>, <js>"http://www.sample.com/feed.atom"</js>)
037 *       );
038 * </p>
039 *
040 * <h5 class='section'>See Also:</h5><ul>
041 *    <li class='link'><a class="doclink" href="../../../../../index.html#jd.Atom">Overview &gt; juneau-dto &gt; Atom</a>
042 * </ul>
043 */
044public class AtomBuilder {
045
046   /**
047    * Creates a {@link Category} element with the specified {@link Category#setTerm(String)} attribute.
048    *
049    * @param term The {@link Category#setTerm(String)} attribute.
050    * @return The new element.
051    */
052   public static final Category category(String term) {
053      return new Category(term);
054   }
055
056   /**
057    * Creates a {@link Content} element with the specified {@link Content#setType(String)} attribute.
058    *
059    * @return The new element.
060    */
061   public static final Content content() {
062      return new Content();
063   }
064
065   /**
066    * Creates a {@link Content} element.
067    *
068    * @param type The {@link Content#setType(String)} attribute.
069    * @return The new element.
070    */
071   public static final Content content(String type) {
072      return new Content(type);
073   }
074
075   /**
076    * Creates an {@link Entry} element with the specified {@link Entry#setId(Id)}, {@link Entry#setTitle(Text)}, and
077    * {@link Entry#setUpdated(Calendar)} attributes.
078    *
079    * @param id The {@link Entry#setId(Id)} attribute.
080    * @param title The {@link Entry#setTitle(Text)} attribute.
081    * @param updated The {@link Entry#setUpdated(Calendar)} attribute.
082    * @return The new element.
083    */
084   public static final Entry entry(Id id, Text title, Calendar updated) {
085      return new Entry(id, title, updated);
086   }
087
088   /**
089    * Creates an {@link Entry} element with the specified {@link Entry#setId(Id)}, {@link Entry#setTitle(Text)}, and
090    * {@link Entry#setUpdated(Calendar)} attributes.
091    *
092    * @param id The {@link Entry#setId(Id)} attribute.
093    * @param title The {@link Entry#setTitle(Text)} attribute.
094    * @param updated The {@link Entry#setUpdated(Calendar)} attribute.
095    * @return The new element.
096    */
097   public static final Entry entry(String id, String title, String updated) {
098      return new Entry(id, title, updated);
099   }
100
101   /**
102    * Creates a {@link Feed} element with the specified {@link Feed#setId(Id)}, {@link Entry#setTitle(Text)}, and
103    * {@link Feed#setUpdated(Calendar)} attributes.
104    *
105    * @param id The {@link Feed#setId(Id)} attribute.
106    * @param title The {@link Feed#setTitle(Text)} attribute.
107    * @param updated The {@link Feed#setUpdated(Calendar)} attribute.
108    * @return The new element.
109    */
110   public static final Feed feed(Id id, Text title, Calendar updated) {
111      return new Feed(id, title, updated);
112   }
113
114   /**
115    * Creates a {@link Feed} element with the specified {@link Feed#setId(Id)}, {@link Entry#setTitle(Text)}, and
116    * {@link Feed#setUpdated(Calendar)} attributes.
117    *
118    * @param id The {@link Feed#setId(Id)} attribute.
119    * @param title The {@link Feed#setTitle(Text)} attribute.
120    * @param updated The {@link Feed#setUpdated(Calendar)} attribute.
121    * @return The new element.
122    */
123   public static final Feed feed(String id, String title, String updated) {
124      return new Feed(id, title, updated);
125   }
126
127   /**
128    * Creates a {@link Generator} element with the specified {@link Generator#setText(String)} child node.
129    *
130    * @param text The {@link Generator#setText(String)} child node.
131    * @return The new element.
132    */
133   public static final Generator generator(String text) {
134      return new Generator(text);
135   }
136
137   /**
138    * Creates an {@link Icon} element with the specified {@link Icon#setUri(Object)} attribute.
139    *
140    * <p>
141    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
142    * Strings must be valid URIs.
143    *
144    * <p>
145    * URIs defined by {@link UriResolver} can be used for values.
146    *
147    * @param uri The {@link Icon#setUri(Object)} attribute.
148    * @return The new element.
149    */
150   public static final Icon icon(Object uri) {
151      return new Icon(uri);
152   }
153
154   /**
155    * Creates an {@link Id} element with the specified {@link Id#setText(String)} child node.
156    *
157    * @param text The {@link Id#setText(String)} child node.
158    * @return The new element.
159    */
160   public static final Id id(String text) {
161      return new Id(text);
162   }
163
164   /**
165    * Creates a {@link Link} element with the specified {@link Link#setRel(String)}, {@link Link#setType(String)}, and
166    * {@link Link#setHref(String)} attributes.
167    *
168    * @param rel The {@link Link#setRel(String)} attribute.
169    * @param type The {@link Link#setType(String)} attribute.
170    * @param href The {@link Link#setHref(String)} attribute.
171    * @return The new element.
172    */
173   public static final Link link(String rel, String type, String href) {
174      return new Link(rel, type, href);
175   }
176
177   /**
178    * Creates a {@link Logo} element with the specified {@link Logo#setUri(Object)} attribute.
179    *
180    * <p>
181    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
182    * Strings must be valid URIs.
183    *
184    * <p>
185    * URIs defined by {@link UriResolver} can be used for values.
186    *
187    * @param uri The {@link Logo#setUri(Object)} attribute.
188    * @return The new element.
189    */
190   public static final Logo logo(Object uri) {
191      return new Logo(uri);
192   }
193
194   /**
195    * Creates a {@link Person} element with the specified {@link Person#setName(String)} attribute.
196    *
197    * @param name The {@link Person#setName(String)} attribute.
198    * @return The new element.
199    */
200   public static final Person person(String name) {
201      return new Person(name);
202   }
203
204   /**
205    * Creates a {@link Source} element.
206    *
207    * @return The new element.
208    */
209   public static final Source source() {
210      return new Source();
211   }
212
213   /**
214    * Creates a {@link Text} element.
215    *
216    * @return The new element.
217    */
218   public static final Text text() {
219      return new Text();
220   }
221
222   /**
223    * Creates a {@link Text} element with the specified {@link Text#setType(String)} attribute.
224    *
225    * @param type The {@link Text#setType(String)} attribute.
226    * @return The new element.
227    */
228   public static final Text text(String type) {
229      return new Text(type);
230   }
231}