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