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='bcode w800'>
026 *    <jk>import static</jk> org.apache.juneau.dto.atom.AtomBuilder.*;
027 *
028 *    Feed feed =
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>
041 * <ul class='doctree'>
042 *    <li class='link'>{@doc juneau-dto.Atom}
043 *    <li class='jp'>{@doc package-summary.html#TOC}
044 * </ul>
045 */
046public class AtomBuilder {
047
048   /**
049    * Creates a {@link Category} element with the specified {@link Category#term(String)} attribute.
050    *
051    * @param term The {@link Category#term(String)} attribute.
052    * @return The new element.
053    */
054   public static final Category category(String term) {
055      return new Category(term);
056   }
057
058   /**
059    * Creates a {@link Content} element with the specified {@link Content#type(String)} attribute.
060    *
061    * @return The new element.
062    */
063   public static final Content content() {
064      return new Content();
065   }
066
067   /**
068    * Creates a {@link Content} element.
069    *
070    * @param type The {@link Content#type(String)} attribute.
071    * @return The new element.
072    */
073   public static final Content content(String type) {
074      return new Content(type);
075   }
076
077   /**
078    * Creates an {@link Entry} element with the specified {@link Entry#id(Id)}, {@link Entry#title(Text)}, and
079    * {@link Entry#updated(Calendar)} attributes.
080    *
081    * @param id The {@link Entry#id(Id)} attribute.
082    * @param title The {@link Entry#title(Text)} attribute.
083    * @param updated The {@link Entry#updated(Calendar)} attribute.
084    * @return The new element.
085    */
086   public static final Entry entry(Id id, Text title, Calendar updated) {
087      return new Entry(id, title, updated);
088   }
089
090   /**
091    * Creates an {@link Entry} element with the specified {@link Entry#id(Id)}, {@link Entry#title(Text)}, and
092    * {@link Entry#updated(Calendar)} attributes.
093    *
094    * @param id The {@link Entry#id(Id)} attribute.
095    * @param title The {@link Entry#title(Text)} attribute.
096    * @param updated The {@link Entry#updated(Calendar)} attribute.
097    * @return The new element.
098    */
099   public static final Entry entry(String id, String title, String updated) {
100      return new Entry(id, title, updated);
101   }
102
103   /**
104    * Creates a {@link Feed} element with the specified {@link Feed#id(Id)}, {@link Entry#title(Text)}, and
105    * {@link Feed#updated(Calendar)} attributes.
106    *
107    * @param id The {@link Feed#id(Id)} attribute.
108    * @param title The {@link Feed#title(Text)} attribute.
109    * @param updated The {@link Feed#updated(Calendar)} attribute.
110    * @return The new element.
111    */
112   public static final Feed feed(Id id, Text title, Calendar updated) {
113      return new Feed(id, title, updated);
114   }
115
116   /**
117    * Creates a {@link Feed} element with the specified {@link Feed#id(Id)}, {@link Entry#title(Text)}, and
118    * {@link Feed#updated(Calendar)} attributes.
119    *
120    * @param id The {@link Feed#id(Id)} attribute.
121    * @param title The {@link Feed#title(Text)} attribute.
122    * @param updated The {@link Feed#updated(Calendar)} attribute.
123    * @return The new element.
124    */
125   public static final Feed feed(String id, String title, String updated) {
126      return new Feed(id, title, updated);
127   }
128
129   /**
130    * Creates a {@link Generator} element with the specified {@link Generator#text(String)} child node.
131    *
132    * @param text The {@link Generator#text(String)} child node.
133    * @return The new element.
134    */
135   public static final Generator generator(String text) {
136      return new Generator(text);
137   }
138
139   /**
140    * Creates an {@link Icon} element with the specified {@link Icon#uri(Object)} attribute.
141    *
142    * <p>
143    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
144    * Strings must be valid URIs.
145    *
146    * <p>
147    * URIs defined by {@link UriResolver} can be used for values.
148    *
149    * @param uri The {@link Icon#uri(Object)} attribute.
150    * @return The new element.
151    */
152   public static final Icon icon(Object uri) {
153      return new Icon(uri);
154   }
155
156   /**
157    * Creates an {@link Id} element with the specified {@link Id#text(String)} child node.
158    *
159    * @param text The {@link Id#text(String)} child node.
160    * @return The new element.
161    */
162   public static final Id id(String text) {
163      return new Id(text);
164   }
165
166   /**
167    * Creates a {@link Link} element with the specified {@link Link#rel(String)}, {@link Link#type(String)}, and
168    * {@link Link#href(String)} attributes.
169    *
170    * @param rel The {@link Link#rel(String)} attribute.
171    * @param type The {@link Link#type(String)} attribute.
172    * @param href The {@link Link#href(String)} attribute.
173    * @return The new element.
174    */
175   public static final Link link(String rel, String type, String href) {
176      return new Link(rel, type, href);
177   }
178
179   /**
180    * Creates a {@link Logo} element with the specified {@link Logo#uri(Object)} attribute.
181    *
182    * <p>
183    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
184    * Strings must be valid URIs.
185    *
186    * <p>
187    * URIs defined by {@link UriResolver} can be used for values.
188    *
189    * @param uri The {@link Logo#uri(Object)} attribute.
190    * @return The new element.
191    */
192   public static final Logo logo(Object uri) {
193      return new Logo(uri);
194   }
195
196   /**
197    * Creates a {@link Person} element with the specified {@link Person#name(String)} attribute.
198    *
199    * @param name The {@link Person#name(String)} attribute.
200    * @return The new element.
201    */
202   public static final Person person(String name) {
203      return new Person(name);
204   }
205
206   /**
207    * Creates a {@link Source} element.
208    *
209    * @return The new element.
210    */
211   public static final Source source() {
212      return new Source();
213   }
214
215   /**
216    * Creates a {@link Text} element.
217    *
218    * @return The new element.
219    */
220   public static final Text text() {
221      return new Text();
222   }
223
224   /**
225    * Creates a {@link Text} element with the specified {@link Text#type(String)} attribute.
226    *
227    * @param type The {@link Text#type(String)} attribute.
228    * @return The new element.
229    */
230   public static final Text text(String type) {
231      return new Text(type);
232   }
233}