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 java.net.*;
020import java.util.*;
021
022import org.apache.juneau.*;
023
024/**
025 * Various useful static methods for creating ATOM elements.
026 *
027 * <p>
028 * Typically, you'll want to do a static import on this class and then call the methods like so...
029 * <p class='bjava'>
030 *    <jk>import static</jk> org.apache.juneau.bean.atom.AtomBuilder.*;
031 *
032 *    Feed <jv>feed</jv> =
033 *       <jsm>feed</jsm>(<js>"tag:juneau.sample.com,2013:1"</js>, <js>"Juneau ATOM specification"</js>,
034 *          <js>"2013-05-08T12:29:29Z"</js>)
035 *       .subtitle(<jsm>text</jsm>(<js>"html"</js>)
036 *          .children(<js>"A &lt;em&gt;lot&lt;/em&gt; of effort went into making this effortless"</js>))
037 *       .links(
038 *          <jsm>link</jsm>(<js>"alternate"</js>, <js>"text/html"</js>, <js>"http://www.sample.com/"</js>)
039 *             .hreflang(<js>"en"</js>),
040 *          <jsm>link</jsm>(<js>"self"</js>, <js>"application/atom+xml"</js>, <js>"http://www.sample.com/feed.atom"</js>)
041 *       );
042 * </p>
043 *
044 * <h5 class='section'>See Also:</h5><ul>
045 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanAtom">juneau-bean-atom</a>
046 * </ul>
047 */
048public class AtomBuilder {
049
050   /**
051    * Creates a {@link Category} element with the specified {@link Category#setTerm(String)} attribute.
052    *
053    * @param term The {@link Category#setTerm(String)} attribute.
054    * @return The new element.
055    */
056   public static final Category category(String term) {
057      return new Category(term);
058   }
059
060   /**
061    * Creates a {@link Content} element with the specified {@link Content#setType(String)} attribute.
062    *
063    * @return The new element.
064    */
065   public static final Content content() {
066      return new Content();
067   }
068
069   /**
070    * Creates a {@link Content} element.
071    *
072    * @param type The {@link Content#setType(String)} attribute.
073    * @return The new element.
074    */
075   public static final Content content(String type) {
076      return new Content(type);
077   }
078
079   /**
080    * Creates an {@link Entry} element with the specified {@link Entry#setId(Id)}, {@link Entry#setTitle(Text)}, and
081    * {@link Entry#setUpdated(Calendar)} attributes.
082    *
083    * @param id The {@link Entry#setId(Id)} attribute.
084    * @param title The {@link Entry#setTitle(Text)} attribute.
085    * @param updated The {@link Entry#setUpdated(Calendar)} attribute.
086    * @return The new element.
087    */
088   public static final Entry entry(Id id, Text title, Calendar updated) {
089      return new Entry(id, title, updated);
090   }
091
092   /**
093    * Creates an {@link Entry} element with the specified {@link Entry#setId(Id)}, {@link Entry#setTitle(Text)}, and
094    * {@link Entry#setUpdated(Calendar)} attributes.
095    *
096    * @param id The {@link Entry#setId(Id)} attribute.
097    * @param title The {@link Entry#setTitle(Text)} attribute.
098    * @param updated The {@link Entry#setUpdated(Calendar)} attribute.
099    * @return The new element.
100    */
101   public static final Entry entry(String id, String title, String updated) {
102      return new Entry(id, title, updated);
103   }
104
105   /**
106    * Creates a {@link Feed} element with the specified {@link Feed#setId(Id)}, {@link Entry#setTitle(Text)}, and
107    * {@link Feed#setUpdated(Calendar)} attributes.
108    *
109    * @param id The {@link Feed#setId(Id)} attribute.
110    * @param title The {@link Feed#setTitle(Text)} attribute.
111    * @param updated The {@link Feed#setUpdated(Calendar)} attribute.
112    * @return The new element.
113    */
114   public static final Feed feed(Id id, Text title, Calendar updated) {
115      return new Feed(id, title, updated);
116   }
117
118   /**
119    * Creates a {@link Feed} element with the specified {@link Feed#setId(Id)}, {@link Entry#setTitle(Text)}, and
120    * {@link Feed#setUpdated(Calendar)} attributes.
121    *
122    * @param id The {@link Feed#setId(Id)} attribute.
123    * @param title The {@link Feed#setTitle(Text)} attribute.
124    * @param updated The {@link Feed#setUpdated(Calendar)} attribute.
125    * @return The new element.
126    */
127   public static final Feed feed(String id, String title, String updated) {
128      return new Feed(id, title, updated);
129   }
130
131   /**
132    * Creates a {@link Generator} element with the specified {@link Generator#setText(String)} child node.
133    *
134    * @param text The {@link Generator#setText(String)} child node.
135    * @return The new element.
136    */
137   public static final Generator generator(String text) {
138      return new Generator(text);
139   }
140
141   /**
142    * Creates an {@link Icon} element with the specified {@link Icon#setUri(Object)} attribute.
143    *
144    * <p>
145    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
146    * Strings must be valid URIs.
147    *
148    * <p>
149    * URIs defined by {@link UriResolver} can be used for values.
150    *
151    * @param uri The {@link Icon#setUri(Object)} attribute.
152    * @return The new element.
153    */
154   public static final Icon icon(Object uri) {
155      return new Icon(uri);
156   }
157
158   /**
159    * Creates an {@link Id} element with the specified {@link Id#setText(String)} child node.
160    *
161    * @param text The {@link Id#setText(String)} child node.
162    * @return The new element.
163    */
164   public static final Id id(String text) {
165      return new Id(text);
166   }
167
168   /**
169    * Creates a {@link Link} element with the specified {@link Link#setRel(String)}, {@link Link#setType(String)}, and
170    * {@link Link#setHref(String)} attributes.
171    *
172    * @param rel The {@link Link#setRel(String)} attribute.
173    * @param type The {@link Link#setType(String)} attribute.
174    * @param href The {@link Link#setHref(String)} attribute.
175    * @return The new element.
176    */
177   public static final Link link(String rel, String type, String href) {
178      return new Link(rel, type, href);
179   }
180
181   /**
182    * Creates a {@link Logo} element with the specified {@link Logo#setUri(Object)} attribute.
183    *
184    * <p>
185    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
186    * Strings must be valid URIs.
187    *
188    * <p>
189    * URIs defined by {@link UriResolver} can be used for values.
190    *
191    * @param uri The {@link Logo#setUri(Object)} attribute.
192    * @return The new element.
193    */
194   public static final Logo logo(Object uri) {
195      return new Logo(uri);
196   }
197
198   /**
199    * Creates a {@link Person} element with the specified {@link Person#setName(String)} attribute.
200    *
201    * @param name The {@link Person#setName(String)} attribute.
202    * @return The new element.
203    */
204   public static final Person person(String name) {
205      return new Person(name);
206   }
207
208   /**
209    * Creates a {@link Source} element.
210    *
211    * @return The new element.
212    */
213   public static final Source source() {
214      return new Source();
215   }
216
217   /**
218    * Creates a {@link Text} element.
219    *
220    * @return The new element.
221    */
222   public static final Text text() {
223      return new Text();
224   }
225
226   /**
227    * Creates a {@link Text} element with the specified {@link Text#setType(String)} attribute.
228    *
229    * @param type The {@link Text#setType(String)} attribute.
230    * @return The new element.
231    */
232   public static final Text text(String type) {
233      return new Text(type);
234   }
235
236   /**
237    * Constructor.
238    */
239   protected AtomBuilder() {}
240}