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   // HtmlSerializer
047   //-------------------------------------------------------------------------------------------------------------------
048
049   /**
050    * Configuration property:  Add <js>"_type"</js> properties when needed.
051    *
052    * <p>
053    * If <jk>true</jk>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred
054    * through reflection.
055    *
056    * <p>
057    * When present, this value overrides the {@link Serializer#SERIALIZER_addBeanTypes} setting and is
058    * provided to customize the behavior of specific serializers in a {@link SerializerGroup}.
059    *
060    * <ul class='notes'>
061    *    <li>
062    *       Possible values:
063    *       <ul>
064    *          <li><js>"true"</js>
065    *          <li><js>"false"</js> (default)
066    *       </ul>
067    *    <li>
068    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
069    *    <li>
070    *       A default global value can be set via the system property <js>"HtmlSerializer.addBeanTypes.b"</js>.
071    * </ul>
072    *
073    * <ul class='seealso'>
074    *    <li class='jf'>{@link HtmlSerializer#HTML_addBeanTypes}
075    * </ul>
076    */
077   String addBeanTypes() default "";
078
079   /**
080    * Configuration property:  Add key/value headers on bean/map tables.
081    *
082    * <p>
083    * When enabled, <bc>key</bc> and <bc>value</bc> column headers are added to tables.
084    *
085    * <p>
086    * The following shows the difference between the two generated outputs:
087    *
088    * <table class='styled'>
089    *    <tr>
090    *       <th><c>withoutHeaders</c></th>
091    *       <th><c>withHeaders</c></th>
092    *    </tr>
093    *    <tr>
094    *       <td>
095    *          <table class='unstyled'>
096    *             <tr><td>f1</td><td>foo</td></tr>
097    *             <tr><td>f2</td><td>bar</td></tr>
098    *          </table>
099    *       </td>
100    *       <td>
101    *          <table class='unstyled'>
102    *             <tr><th>key</th><th>value</th></tr>
103    *             <tr><td>f1</td><td>foo</td></tr>
104    *             <tr><td>f2</td><td>bar</td></tr>
105    *          </table>
106    *       </td>
107    *    </tr>
108    * </table>
109    *
110    * <ul class='notes'>
111    *    <li>
112    *       Possible values:
113    *       <ul>
114    *          <li><js>"true"</js>
115    *          <li><js>"false"</js> (default)
116    *       </ul>
117    *    <li>
118    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
119    *    <li>
120    *       A default global value can be set via the system property <js>"HtmlSerializer.addKeyValueTableHeaders.b"</js>.
121    * </ul>
122    *
123    * <ul class='seealso'>
124    *    <li class='jf'>{@link HtmlSerializer#HTML_addKeyValueTableHeaders}
125    * </ul>
126    */
127   String addKeyValueTableHeaders() default "";
128
129   /**
130    * Configuration property:  Look for URLs in {@link String Strings}.
131    *
132    * <p>
133    * If a string looks like a URL (i.e. starts with <js>"http://"</js> or <js>"https://"</js>, then treat it like a URL
134    * and make it into a hyperlink based on the rules specified by {@link HtmlSerializer#HTML_uriAnchorText}.
135    *
136    * <p>
137    * The following shows the difference between the two generated outputs:
138    *
139    * <table class='styled'>
140    *    <tr>
141    *       <th><c>withLinks</c></th>
142    *       <th><c>withoutLinks</c></th>
143    *    </tr>
144    *    <tr>
145    *       <td>
146    *          <table class='unstyled'>
147    *             <tr><th>key</th><th>value</th></tr>
148    *             <tr><td>f1</td><td><a href='http://www.apache.org'>http://www.apache.org</a></td></tr>
149    *          </table>
150    *       </td>
151    *       <td>
152    *          <table class='unstyled'>
153    *             <tr><th>key</th><th>value</th></tr>
154    *             <tr><td>f1</td><td>http://www.apache.org</td></tr>
155    *          </table>
156    *       </td>
157    *    </tr>
158    * </table>
159    *
160    * <ul class='notes'>
161    *    <li>
162    *       Possible values:
163    *       <ul>
164    *          <li><js>"true"</js> (default)
165    *          <li><js>"false"</js>
166    *       </ul>
167    *    <li>
168    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
169    *    <li>
170    *       A default global value can be set via the system property <js>"HtmlSerializer.detectLinksInStrings.b"</js>.
171    * </ul>
172    *
173    * <ul class='seealso'>
174    *    <li class='jf'>{@link HtmlSerializer#HTML_detectLinksInStrings}
175    * </ul>
176    */
177   String detectLinksInStrings() default "";
178
179   /**
180    * Configuration property:  Link label parameter name.
181    *
182    * <p>
183    * The parameter name to look for when resolving link labels via {@link HtmlSerializer#HTML_detectLabelParameters}.
184    *
185    * <ul class='notes'>
186    *    <li>
187    *       Default value: <js>"label"</js>
188    *    <li>
189    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
190    *    <li>
191    *       A default global value can be set via the system property <js>"HtmlSerializer.labelParameter.s"</js>.
192    * </ul>
193    *
194    * <ul class='seealso'>
195    *    <li class='jf'>{@link HtmlSerializer#HTML_labelParameter}
196    * </ul>
197    */
198   String labelParameter() default "";
199
200   /**
201    * Configuration property:  Look for link labels in URIs.
202    *
203    * <p>
204    * If the URL has a label parameter (e.g. <js>"?label=foobar"</js>), then use that as the anchor text of the link.
205    *
206    * <p>
207    * The parameter name can be changed via the {@link HtmlSerializer#HTML_labelParameter} property.
208    *
209    * <p>
210    * The following shows the difference between the two generated outputs.
211    * <br>Note that they're both hyperlinks, but the anchor text differs:
212    *
213    * <table class='styled'>
214    *    <tr>
215    *       <th><c>withLabels</c></th>
216    *       <th><c>withoutLabels</c></th>
217    *    </tr>
218    *    <tr>
219    *       <td>
220    *          <table class='unstyled'>
221    *             <tr><th>key</th><th>value</th></tr>
222    *             <tr><td>f1</td><td><a href='http://www.apache.org?label=Apache%20Foundation'>Apache Foundation</a></td></tr>
223    *          </table>
224    *       </td>
225    *       <td>
226    *          <table class='unstyled'>
227    *             <tr><th>key</th><th>value</th></tr>
228    *             <tr><td>f1</td><td><a href='http://www.apache.org?label=Apache%20Foundation'>http://www.apache.org?label=Apache%20Foundation</a></td></tr>
229    *          </table>
230    *       </td>
231    *    </tr>
232    * </table>
233    *
234    * <ul class='notes'>
235    *    <li>
236    *       Possible values:
237    *       <ul>
238    *          <li><js>"true"</js> (default)
239    *          <li><js>"false"</js>
240    *       </ul>
241    *    <li>
242    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
243    *    <li>
244    *       A default global value can be set via the system property <js>"HtmlSerializer.detectLabelParameters.b"</js>.
245    * </ul>
246    *
247    * <ul class='seealso'>
248    *    <li class='jf'>{@link HtmlSerializer#HTML_detectLabelParameters}
249    * </ul>
250    */
251   String detectLabelParameters() default "";
252
253   /**
254    * Configuration property:  Anchor text source.
255    *
256    * <p>
257    * When creating anchor tags (e.g. <code><xt>&lt;a</xt> <xa>href</xa>=<xs>'...'</xs>
258    * <xt>&gt;</xt>text<xt>&lt;/a&gt;</xt></code>) in HTML, this setting defines what to set the inner text to.
259    *
260    * <ul class='notes'>
261    *    <li>
262    *       Possible values:
263    *       <ul>
264    *          <li><js>"TO_STRING"</js> - Set to whatever is returned by {@link #toString()} on the object.
265    *          <li><js>"PROPERTY_NAME"</js> - Set to the bean property name.
266    *          <li><js>"URI"</js> - Set to the URI value.
267    *          <li><js>"LAST_TOKEN"</js> - Set to the last token of the URI value.
268    *          <li><js>"URI_ANCHOR"</js> - Set to the anchor of the URL.
269    *          <li><js>"CONTEXT_RELATIVE"</js> - Same as <js>"TO_STRING"</js> but assumes it's a context-relative path.
270    *          <li><js>"SERVLET_RELATIVE"</js> - Same as <js>"TO_STRING"</js> but assumes it's a servlet-relative path.
271    *          <li><js>"PATH_RELATIVE"</js> - Same as <js>"TO_STRING"</js> but assumes it's a path-relative path.
272    *       </ul>
273    *    <li>
274    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
275    *    <li>
276    *       A default global value can be set via the system property <js>"HtmlSerializer.uriAnchorText.s"</js>.
277    * </ul>
278    *
279    * <ul class='seealso'>
280    *    <li class='jf'>{@link HtmlSerializer#HTML_uriAnchorText}
281    * </ul>
282    */
283   String uriAnchorText() default "";
284}