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