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.html.annotation; 014 015import static java.lang.annotation.ElementType.*; 016import static java.lang.annotation.RetentionPolicy.*; 017 018import java.lang.annotation.*; 019 020import org.apache.juneau.annotation.*; 021import org.apache.juneau.html.*; 022import org.apache.juneau.serializer.*; 023 024/** 025 * Annotation for specifying config properties defined in {@link HtmlSerializer}, {@link HtmlParser}, and {@link HtmlDocSerializer}. 026 * 027 * <p> 028 * Used primarily for specifying bean configuration properties on REST classes and methods. 029 */ 030@Documented 031@Target({TYPE,METHOD}) 032@Retention(RUNTIME) 033@Inherited 034@PropertyStoreApply(HtmlConfigApply.class) 035public @interface HtmlConfig { 036 037 /** 038 * Optional rank for this config. 039 * 040 * <p> 041 * Can be used to override default ordering and application of config annotations. 042 */ 043 int rank() default 0; 044 045 //------------------------------------------------------------------------------------------------------------------- 046 // HtmlCommon 047 //------------------------------------------------------------------------------------------------------------------- 048 049 /** 050 * Dynamically applies {@link Html @Html} annotations to specified classes/methods/fields. 051 * 052 * <p> 053 * Provides an alternate approach for applying annotations using {@link Html#on() @Html.on} to specify the names 054 * to apply the annotation to. 055 * 056 * <ul class='seealso'> 057 * <li class='link'>{@doc juneau-marshall.DynamicallyAppliedAnnotations} 058 * </ul> 059 */ 060 Html[] applyHtml() default {}; 061 062 /** 063 * Dynamically applies {@link HtmlLink @HtmlLink} annotations to specified classes. 064 * 065 * <p> 066 * Provides an alternate approach for applying annotations using {@link HtmlLink#on() @HtmlLink.on} to specify the names 067 * to apply the annotation to. 068 * 069 * <ul class='seealso'> 070 * <li class='link'>{@doc juneau-marshall.DynamicallyAppliedAnnotations} 071 * </ul> 072 */ 073 HtmlLink[] applyHtmlLink() default {}; 074 075 //------------------------------------------------------------------------------------------------------------------- 076 // HtmlSerializer 077 //------------------------------------------------------------------------------------------------------------------- 078 079 /** 080 * Configuration property: Add <js>"_type"</js> properties when needed. 081 * 082 * <p> 083 * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred 084 * through reflection. 085 * 086 * <p> 087 * When present, this value overrides the {@link Serializer#SERIALIZER_addBeanTypes} setting and is 088 * provided to customize the behavior of specific serializers in a {@link SerializerGroup}. 089 * 090 * <ul class='notes'> 091 * <li> 092 * Possible values: 093 * <ul> 094 * <li><js>"true"</js> 095 * <li><js>"false"</js> (default) 096 * </ul> 097 * <li> 098 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 099 * </ul> 100 * 101 * <ul class='seealso'> 102 * <li class='jf'>{@link HtmlSerializer#HTML_addBeanTypes} 103 * </ul> 104 */ 105 String addBeanTypes() default ""; 106 107 /** 108 * Configuration property: Add key/value headers on bean/map tables. 109 * 110 * <p> 111 * When enabled, <bc>key</bc> and <bc>value</bc> column headers are added to tables. 112 * 113 * <p> 114 * The following shows the difference between the two generated outputs: 115 * 116 * <table class='styled'> 117 * <tr> 118 * <th><c>withoutHeaders</c></th> 119 * <th><c>withHeaders</c></th> 120 * </tr> 121 * <tr> 122 * <td> 123 * <table class='unstyled'> 124 * <tr><td>f1</td><td>foo</td></tr> 125 * <tr><td>f2</td><td>bar</td></tr> 126 * </table> 127 * </td> 128 * <td> 129 * <table class='unstyled'> 130 * <tr><th>key</th><th>value</th></tr> 131 * <tr><td>f1</td><td>foo</td></tr> 132 * <tr><td>f2</td><td>bar</td></tr> 133 * </table> 134 * </td> 135 * </tr> 136 * </table> 137 * 138 * <ul class='notes'> 139 * <li> 140 * Possible values: 141 * <ul> 142 * <li><js>"true"</js> 143 * <li><js>"false"</js> (default) 144 * </ul> 145 * <li> 146 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 147 * </ul> 148 * 149 * <ul class='seealso'> 150 * <li class='jf'>{@link HtmlSerializer#HTML_addKeyValueTableHeaders} 151 * </ul> 152 */ 153 String addKeyValueTableHeaders() default ""; 154 155 /** 156 * Configuration property: Look for URLs in {@link String Strings}. 157 * 158 * <p> 159 * If a string looks like a URL (i.e. starts with <js>"http://"</js> or <js>"https://"</js>, then treat it like a URL 160 * and make it into a hyperlink based on the rules specified by {@link HtmlSerializer#HTML_uriAnchorText}. 161 * 162 * <p> 163 * The following shows the difference between the two generated outputs: 164 * 165 * <table class='styled'> 166 * <tr> 167 * <th><c>withLinks</c></th> 168 * <th><c>withoutLinks</c></th> 169 * </tr> 170 * <tr> 171 * <td> 172 * <table class='unstyled'> 173 * <tr><th>key</th><th>value</th></tr> 174 * <tr><td>f1</td><td><a href='http://www.apache.org'>http://www.apache.org</a></td></tr> 175 * </table> 176 * </td> 177 * <td> 178 * <table class='unstyled'> 179 * <tr><th>key</th><th>value</th></tr> 180 * <tr><td>f1</td><td>http://www.apache.org</td></tr> 181 * </table> 182 * </td> 183 * </tr> 184 * </table> 185 * 186 * <ul class='notes'> 187 * <li> 188 * Possible values: 189 * <ul> 190 * <li><js>"true"</js> (default) 191 * <li><js>"false"</js> 192 * </ul> 193 * <li> 194 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 195 * </ul> 196 * 197 * <ul class='seealso'> 198 * <li class='jf'>{@link HtmlSerializer#HTML_detectLinksInStrings} 199 * </ul> 200 */ 201 String detectLinksInStrings() default ""; 202 203 /** 204 * Configuration property: Link label parameter name. 205 * 206 * <p> 207 * The parameter name to look for when resolving link labels via {@link HtmlSerializer#HTML_detectLabelParameters}. 208 * 209 * <ul class='notes'> 210 * <li> 211 * Default value: <js>"label"</js> 212 * <li> 213 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 214 * </ul> 215 * 216 * <ul class='seealso'> 217 * <li class='jf'>{@link HtmlSerializer#HTML_labelParameter} 218 * </ul> 219 */ 220 String labelParameter() default ""; 221 222 /** 223 * Configuration property: Look for link labels in URIs. 224 * 225 * <p> 226 * If the URL has a label parameter (e.g. <js>"?label=foobar"</js>), then use that as the anchor text of the link. 227 * 228 * <p> 229 * The parameter name can be changed via the {@link HtmlSerializer#HTML_labelParameter} property. 230 * 231 * <p> 232 * The following shows the difference between the two generated outputs. 233 * <br>Note that they're both hyperlinks, but the anchor text differs: 234 * 235 * <table class='styled'> 236 * <tr> 237 * <th><c>withLabels</c></th> 238 * <th><c>withoutLabels</c></th> 239 * </tr> 240 * <tr> 241 * <td> 242 * <table class='unstyled'> 243 * <tr><th>key</th><th>value</th></tr> 244 * <tr><td>f1</td><td><a href='http://www.apache.org?label=Apache%20Foundation'>Apache Foundation</a></td></tr> 245 * </table> 246 * </td> 247 * <td> 248 * <table class='unstyled'> 249 * <tr><th>key</th><th>value</th></tr> 250 * <tr><td>f1</td><td><a href='http://www.apache.org?label=Apache%20Foundation'>http://www.apache.org?label=Apache%20Foundation</a></td></tr> 251 * </table> 252 * </td> 253 * </tr> 254 * </table> 255 * 256 * <ul class='notes'> 257 * <li> 258 * Possible values: 259 * <ul> 260 * <li><js>"true"</js> (default) 261 * <li><js>"false"</js> 262 * </ul> 263 * <li> 264 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 265 * </ul> 266 * 267 * <ul class='seealso'> 268 * <li class='jf'>{@link HtmlSerializer#HTML_detectLabelParameters} 269 * </ul> 270 */ 271 String detectLabelParameters() default ""; 272 273 /** 274 * Configuration property: Anchor text source. 275 * 276 * <p> 277 * When creating anchor tags (e.g. <code><xt><a</xt> <xa>href</xa>=<xs>'...'</xs> 278 * <xt>></xt>text<xt></a></xt></code>) in HTML, this setting defines what to set the inner text to. 279 * 280 * <ul class='notes'> 281 * <li> 282 * Possible values: 283 * <ul> 284 * <li><js>"TO_STRING"</js> - Set to whatever is returned by {@link #toString()} on the object. 285 * <li><js>"PROPERTY_NAME"</js> - Set to the bean property name. 286 * <li><js>"URI"</js> - Set to the URI value. 287 * <li><js>"LAST_TOKEN"</js> - Set to the last token of the URI value. 288 * <li><js>"URI_ANCHOR"</js> - Set to the anchor of the URL. 289 * <li><js>"CONTEXT_RELATIVE"</js> - Same as <js>"TO_STRING"</js> but assumes it's a context-relative path. 290 * <li><js>"SERVLET_RELATIVE"</js> - Same as <js>"TO_STRING"</js> but assumes it's a servlet-relative path. 291 * <li><js>"PATH_RELATIVE"</js> - Same as <js>"TO_STRING"</js> but assumes it's a path-relative path. 292 * </ul> 293 * <li> 294 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 295 * </ul> 296 * 297 * <ul class='seealso'> 298 * <li class='jf'>{@link HtmlSerializer#HTML_uriAnchorText} 299 * </ul> 300 */ 301 String uriAnchorText() default ""; 302}