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