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 static org.apache.juneau.common.utils.StringUtils.*; 020import static org.apache.juneau.xml.annotation.XmlFormat.*; 021 022import java.net.*; 023 024import org.apache.juneau.xml.annotation.*; 025 026/** 027 * Represents the content of an Atom entry. 028 * 029 * <p> 030 * The content element contains or links to the complete content of an entry. It supports multiple 031 * content types and delivery methods: 032 * 033 * <ul class='spaced-list'> 034 * <li><b>Inline text content</b> - Plain text or HTML content embedded in the feed 035 * <li><b>Inline XHTML content</b> - Well-formed XHTML embedded in the feed 036 * <li><b>Inline other content</b> - Other media types (XML, base64-encoded binary, etc.) 037 * <li><b>Out-of-line content</b> - Link to external content via the <c>src</c> attribute 038 * </ul> 039 * 040 * <p> 041 * The <c>type</c> attribute indicates the media type of the content. Common values: 042 * <ul class='spaced-list'> 043 * <li><c>"text"</c> - Plain text (default) 044 * <li><c>"html"</c> - HTML, entity-escaped 045 * <li><c>"xhtml"</c> - XHTML wrapped in a div element 046 * <li>Other MIME types - For multimedia content or base64-encoded data 047 * </ul> 048 * 049 * <h5 class='figure'>Schema</h5> 050 * <p class='bschema'> 051 * atomContent = atomInlineTextContent 052 * | atomInlineXHTMLContent 053 * | atomInlineOtherContent 054 * | atomOutOfLineContent 055 * 056 * atomInlineTextContent = 057 * element atom:content { 058 * atomCommonAttributes, 059 * attribute type { "text" | "html" }?, 060 * (text)* 061 * } 062 * 063 * atomInlineXHTMLContent = 064 * element atom:content { 065 * atomCommonAttributes, 066 * attribute type { "xhtml" }, 067 * xhtmlDiv 068 * } 069 * 070 * atomInlineOtherContent = 071 * element atom:content { 072 * atomCommonAttributes, 073 * attribute type { atomMediaType }?, 074 * (text|anyElement)* 075 * } 076 * 077 * atomOutOfLineContent = 078 * element atom:content { 079 * atomCommonAttributes, 080 * attribute type { atomMediaType }?, 081 * attribute src { atomUri }, 082 * empty 083 * } 084 * </p> 085 * 086 * <h5 class='section'>Examples:</h5> 087 * <p class='bjava'> 088 * <jc>// Plain text content</jc> 089 * Content <jv>c1</jv> = <jk>new</jk> Content(<js>"text"</js>) 090 * .setText(<js>"This is plain text content"</js>); 091 * 092 * <jc>// HTML content</jc> 093 * Content <jv>c2</jv> = <jk>new</jk> Content(<js>"html"</js>) 094 * .setText(<js>"<p>This is <strong>HTML</strong> content</p>"</js>); 095 * 096 * <jc>// XHTML content</jc> 097 * Content <jv>c3</jv> = <jk>new</jk> Content(<js>"xhtml"</js>) 098 * .setText(<js>"<div xmlns='http://www.w3.org/1999/xhtml'><p>XHTML content</p></div>"</js>); 099 * 100 * <jc>// External content (out-of-line)</jc> 101 * Content <jv>c4</jv> = <jk>new</jk> Content() 102 * .setType(<js>"video/mp4"</js>) 103 * .setSrc(<js>"http://example.org/movie.mp4"</js>); 104 * </p> 105 * 106 * <h5 class='section'>Specification:</h5> 107 * <p> 108 * Represents an <c>atomContent</c> construct in the 109 * <a class="doclink" href="https://tools.ietf.org/html/rfc4287#section-4.1.3">RFC 4287 - Section 4.1.3</a> specification. 110 * 111 * <h5 class='section'>See Also:</h5><ul> 112 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanAtom">juneau-bean-atom</a> 113 * <li class='extlink'><a class="doclink" href="https://tools.ietf.org/html/rfc4287">RFC 4287 - The Atom Syndication Format</a> 114 * </ul> 115 */ 116public class Content extends Text { 117 118 private URI src; 119 120 121 /** 122 * Normal content. 123 * 124 * @param type The content type of this content. 125 */ 126 public Content(String type) { 127 super(type); 128 } 129 130 /** 131 * Normal content. 132 */ 133 public Content() { 134 } 135 136 137 //----------------------------------------------------------------------------------------------------------------- 138 // Bean properties 139 //----------------------------------------------------------------------------------------------------------------- 140 141 /** 142 * Bean property getter: <property>src</property>. 143 * 144 * <p> 145 * Returns the URI of externally-hosted content (out-of-line content). 146 * 147 * <p> 148 * When <c>src</c> is present, the content is not embedded in the feed but is instead 149 * referenced by URI. This is useful for large media files or content hosted elsewhere. 150 * 151 * @return The property value, or <jk>null</jk> if it is not set. 152 */ 153 @Xml(format=ATTR) 154 public URI getSrc() { 155 return src; 156 } 157 158 /** 159 * Bean property setter: <property>src</property>. 160 * 161 * <p> 162 * Sets the URI of externally-hosted content (out-of-line content). 163 * 164 * <p> 165 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 166 * Strings must be valid URIs. 167 * 168 * <h5 class='section'>Example:</h5> 169 * <p class='bjava'> 170 * <jc>// Link to external video</jc> 171 * Content <jv>content</jv> = <jk>new</jk> Content() 172 * .setType(<js>"video/mp4"</js>) 173 * .setSrc(<js>"http://example.org/videos/intro.mp4"</js>); 174 * </p> 175 * 176 * @param value 177 * The new value for this property. 178 * <br>Can be <jk>null</jk> to unset the property. 179 * @return This object. 180 */ 181 public Content setSrc(Object value) { 182 this.src = toURI(value); 183 return this; 184 } 185 186 187 //----------------------------------------------------------------------------------------------------------------- 188 // Overridden setters (to simplify method chaining) 189 //----------------------------------------------------------------------------------------------------------------- 190 191 @Override /* Text */ 192 public Content setText(String text) { 193 super.setText(text); 194 return this; 195 } 196 197 @Override /* Text */ 198 public Content setType(String type) { 199 super.setType(type); 200 return this; 201 } 202 203 @Override /* Overridden from Common */ 204 public Content setBase(Object value) { 205 super.setBase(value); 206 return this; 207 } 208 209 @Override /* Overridden from Common */ 210 public Content setLang(String value) { 211 super.setLang(value); 212 return this; 213 } 214}