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.commons.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 * Normal content. 122 */ 123 public Content() {} 124 125 /** 126 * Normal content. 127 * 128 * @param type The content type of this content. 129 */ 130 public Content(String type) { 131 super(type); 132 } 133 134 /** 135 * Bean property getter: <property>src</property>. 136 * 137 * <p> 138 * Returns the URI of externally-hosted content (out-of-line content). 139 * 140 * <p> 141 * When <c>src</c> is present, the content is not embedded in the feed but is instead 142 * referenced by URI. This is useful for large media files or content hosted elsewhere. 143 * 144 * @return The property value, or <jk>null</jk> if it is not set. 145 */ 146 @Xml(format = ATTR) 147 public URI getSrc() { return src; } 148 149 @Override /* Overridden from Common */ 150 public Content setBase(Object value) { 151 super.setBase(value); 152 return this; 153 } 154 155 @Override /* Overridden from Common */ 156 public Content setLang(String value) { 157 super.setLang(value); 158 return this; 159 } 160 161 /** 162 * Bean property setter: <property>src</property>. 163 * 164 * <p> 165 * Sets the URI of externally-hosted content (out-of-line content). 166 * 167 * <p> 168 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 169 * Strings must be valid URIs. 170 * 171 * <h5 class='section'>Example:</h5> 172 * <p class='bjava'> 173 * <jc>// Link to external video</jc> 174 * Content <jv>content</jv> = <jk>new</jk> Content() 175 * .setType(<js>"video/mp4"</js>) 176 * .setSrc(<js>"http://example.org/videos/intro.mp4"</js>); 177 * </p> 178 * 179 * @param value 180 * The new value for this property. 181 * <br>Can be <jk>null</jk> to unset the property. 182 * @return This object. 183 */ 184 public Content setSrc(Object value) { 185 this.src = toUri(value); 186 return this; 187 } 188 189 @Override /* Overridden from Text */ 190 public Content setText(String value) { 191 super.setText(value); 192 return this; 193 } 194 195 @Override /* Overridden from Text */ 196 public Content setType(String value) { 197 super.setType(value); 198 return this; 199 } 200}