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.xml.annotation.XmlFormat.*; 020 021import org.apache.juneau.xml.annotation.*; 022 023/** 024 * Represents human-readable text in an Atom document. 025 * 026 * <p> 027 * Text constructs are used throughout Atom for elements that contain human-readable text 028 * such as titles, summaries, rights statements, and subtitles. They support three content types: 029 * 030 * <ul class='spaced-list'> 031 * <li><c>"text"</c> - Plain text with no markup (default) 032 * <li><c>"html"</c> - HTML markup, entity-escaped 033 * <li><c>"xhtml"</c> - Well-formed XHTML in a div container 034 * </ul> 035 * 036 * <p> 037 * Text constructs are the base class for {@link Content} and are used directly for: 038 * <ul class='spaced-list'> 039 * <li><c>atom:title</c> - Entry and feed titles 040 * <li><c>atom:subtitle</c> - Feed subtitles 041 * <li><c>atom:summary</c> - Entry summaries 042 * <li><c>atom:rights</c> - Copyright and rights statements 043 * </ul> 044 * 045 * <h5 class='figure'>Schema</h5> 046 * <p class='bschema'> 047 * atomTextConstruct = atomPlainTextConstruct | atomXHTMLTextConstruct 048 * 049 * atomPlainTextConstruct = 050 * atomCommonAttributes, 051 * attribute type { "text" | "html" }?, 052 * text 053 * 054 * atomXHTMLTextConstruct = 055 * atomCommonAttributes, 056 * attribute type { "xhtml" }, 057 * xhtmlDiv 058 * 059 * xhtmlDiv = element xhtml:div { 060 * (attribute * { text } 061 * | text 062 * | anyXHTML)* 063 * } 064 * </p> 065 * 066 * <h5 class='section'>Examples:</h5> 067 * <p class='bjava'> 068 * <jc>// Plain text</jc> 069 * Text <jv>t1</jv> = <jk>new</jk> Text(<js>"text"</js>) 070 * .setText(<js>"Plain text title"</js>); 071 * 072 * <jc>// HTML (entity-escaped)</jc> 073 * Text <jv>t2</jv> = <jk>new</jk> Text(<js>"html"</js>) 074 * .setText(<js>"Title with <em>emphasis</em>"</js>); 075 * 076 * <jc>// XHTML</jc> 077 * Text <jv>t3</jv> = <jk>new</jk> Text(<js>"xhtml"</js>) 078 * .setText(<js>"<div xmlns='http://www.w3.org/1999/xhtml'><p>XHTML title</p></div>"</js>); 079 * </p> 080 * 081 * <h5 class='section'>Specification:</h5> 082 * <p> 083 * Represents an <c>atomTextConstruct</c> in the 084 * <a class="doclink" href="https://tools.ietf.org/html/rfc4287#section-3.1">RFC 4287 - Section 3.1</a> specification. 085 * 086 * <h5 class='section'>See Also:</h5><ul> 087 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanAtom">juneau-bean-atom</a> 088 * <li class='extlink'><a class="doclink" href="https://tools.ietf.org/html/rfc4287">RFC 4287 - The Atom Syndication Format</a> 089 * </ul> 090 */ 091public class Text extends Common { 092 093 private String type; 094 private String text; // NOSONAR - Intentional naming. 095 096 /** 097 * Normal content. 098 * 099 * @param type The content type of this content. 100 */ 101 public Text(String type) { 102 setType(type); 103 } 104 105 /** Bean constructor. */ 106 public Text() {} 107 108 109 //----------------------------------------------------------------------------------------------------------------- 110 // Bean properties 111 //----------------------------------------------------------------------------------------------------------------- 112 113 /** 114 * Bean property getter: <property>type</property>. 115 * 116 * <p> 117 * The content type of this content. 118 * 119 * @return The property value, or <jk>null</jk> if it is not set. 120 */ 121 @Xml(format=ATTR) 122 public String getType() { 123 return type; 124 } 125 126 /** 127 * Bean property setter: <property>type</property>. 128 * 129 * <p> 130 * The content type of this content. 131 * 132 * <p> 133 * Must be one of the following: 134 * <ul> 135 * <li><js>"text"</js> 136 * <li><js>"html"</js> 137 * <li><js>"xhtml"</js> 138 * <li><jk>null</jk> (defaults to <js>"text"</js>) 139 * </ul> 140 * 141 * @param value 142 * The new value for this property. 143 * <br>Can be <jk>null</jk> to unset the property. 144 * @return This object 145 */ 146 public Text setType(String value) { 147 this.type = value; 148 return this; 149 } 150 151 /** 152 * Bean property getter: <property>text</property>. 153 * 154 * <p> 155 * The content of this content. 156 * 157 * @return The property value, or <jk>null</jk> if it is not set. 158 */ 159 @Xml(format=XMLTEXT) 160 public String getText() { 161 return text; 162 } 163 164 /** 165 * Bean property setter: <property>text</property>. 166 * 167 * <p> 168 * The content of this content. 169 * 170 * @param value 171 * The new value for this property. 172 * <br>Can be <jk>null</jk> to unset the property. 173 * @return This object 174 */ 175 public Text setText(String value) { 176 this.text = value; 177 return this; 178 } 179 180 //----------------------------------------------------------------------------------------------------------------- 181 // Overridden setters (to simplify method chaining) 182 //----------------------------------------------------------------------------------------------------------------- 183 184 @Override /* Overridden from Common */ 185 public Text setBase(Object value) { 186 super.setBase(value); 187 return this; 188 } 189 190 @Override /* Overridden from Common */ 191 public Text setLang(String value) { 192 super.setLang(value); 193 return this; 194 } 195}