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.html.*;
021
022/**
023 * Annotation that can be applied to classes, fields, and methods to tweak how they are handled by {@link HtmlSerializer}.
024 *
025 * <h5 class='section'>See Also:</h5>
026 * <ul>
027 *    <li class='link'>{@doc juneau-marshall.HtmlDetails.HtmlAnnotation}
028 * </ul>
029 */
030@Documented
031@Target({TYPE,FIELD,METHOD})
032@Retention(RUNTIME)
033@Inherited
034public @interface Html {
035
036   /**
037    * Use the specified anchor text when serializing a URI.
038    *
039    * <p>
040    * The text can contain any bean property values resolved through variables of the form <js>"{property-name}"</js>.
041    *
042    * <h5 class='figure'>Example:</h5>
043    * <p class='bcode w800'>
044    *    <jc>// Produces &lt;a href&#61;'...'&gt;drive&lt;/a&gt; when serialized to HTML.</jc>
045    *    <ja>@Html</ja>(anchorText=<js>"drive"</js>)
046    *    <ja>@URI</ja> <jc>// Treat property as a URL</jc>
047    *    <jk>public</jk> String getDrive() {...}
048    * </p>
049    *
050    * This overrides the behavior specified by {@link HtmlSerializer#HTML_uriAnchorText}.
051    */
052   String anchorText() default "";
053
054   /**
055    * Specifies what format to use for the HTML element.
056    */
057   HtmlFormat format() default HtmlFormat.HTML;
058
059   /**
060    * @deprecated - Use format=HtmlFormat.PLAINTEXT.
061    */
062   @Deprecated
063   boolean asPlainText() default false;
064
065   /**
066    * @deprecated - Use format=HtmlFormat.XML.
067    */
068   @Deprecated
069   boolean asXml() default false;
070
071   /**
072    * Adds a hyperlink to a bean property when rendered as HTML.
073    *
074    * <p>
075    * The text can contain any bean property values resolved through variables of the form <js>"{property-name}"</js>.
076    *
077    * <p>
078    * The URLs can be any of the following forms:
079    * <ul>
080    *    <li>Absolute - e.g. <js>"http://host:123/myContext/myServlet/myPath"</js>
081    *    <li>Context-root-relative - e.g. <js>"/myContext/myServlet/myPath"</js>
082    *    <li>Context-relative - e.g. <js>"context:/myServlet/myPath"</js>
083    *    <li>Servlet-relative - e.g. <js>"servlet:/myPath"</js>
084    *    <li>Path-info-relative - e.g. <js>"myPath"</js>
085    * </ul>
086    *
087    * <h5 class='figure'>Example:</h5>
088    * <p class='bcode w800'>
089    *    <jk>public class</jk> FileSpace {
090    *
091    *       <ja>@Html</ja>(link=<js>"servlet:/drive/{drive}"</js>)
092    *       <jk>public</jk> String getDrive() {
093    *          ...;
094    *       }
095    *    }
096    * </p>
097    */
098   String link() default "";
099
100   /**
101    * When <jk>true</jk>, don't add headers to tables.
102    *
103    * <h5 class='section'>See Also:</h5>
104    * <ul>
105    *    <li class='jf'>{@link HtmlSerializer#HTML_addKeyValueTableHeaders}
106    * </ul>
107    */
108   boolean noTableHeaders() default false;
109
110   /**
111    * When <jk>true</jk>, collections of beans should be rendered as trees instead of tables.
112    *
113    * <p>
114    * Default is <jk>false</jk>.
115    */
116   boolean noTables() default false;
117
118   /**
119    * Associates an {@link HtmlRender} with a bean property for custom HTML rendering of the property.
120    *
121    * <p>
122    * This annotation applies to bean properties and classes.
123    */
124   @SuppressWarnings("rawtypes")
125   Class<? extends HtmlRender> render() default HtmlRender.class;
126}