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 java.lang.annotation.*; 016import java.lang.reflect.*; 017 018import org.apache.juneau.*; 019import org.apache.juneau.html.*; 020import org.apache.juneau.reflect.*; 021 022/** 023 * A concrete implementation of the {@link Html} annotation. 024 * 025 * <ul class='seealso'> 026 * <li class='jm'>{@link BeanContextBuilder#annotations(Annotation...)} 027 * </ul> 028 */ 029@SuppressWarnings("rawtypes") 030public class HtmlAnnotation implements Html { 031 032 private String 033 on = "", 034 anchorText = "", 035 link = ""; 036 private HtmlFormat 037 format = HtmlFormat.HTML; 038 private boolean 039 noTableHeaders = false, 040 noTables = false; 041 private Class<? extends HtmlRender> 042 render = HtmlRender.class; 043 044 /** 045 * Constructor. 046 * 047 * @param on The initial value for the <c>on</c> property. 048 * <br>See {@link Html#on()} 049 */ 050 public HtmlAnnotation(String on) { 051 on(on); 052 } 053 054 /** 055 * Constructor. 056 * 057 * @param on The initial value for the <c>on</c> property. 058 * <br>See {@link Html#on()} 059 */ 060 public HtmlAnnotation(Class<?> on) { 061 on(on); 062 } 063 064 /** 065 * Constructor. 066 * 067 * @param on The initial value for the <c>on</c> property. 068 * <br>See {@link Html#on()} 069 */ 070 public HtmlAnnotation(Method on) { 071 on(on); 072 } 073 074 /** 075 * Constructor. 076 * 077 * @param on The initial value for the <c>on</c> property. 078 * <br>See {@link Html#on()} 079 */ 080 public HtmlAnnotation(Field on) { 081 on(on); 082 } 083 084 @Override 085 public Class<? extends Annotation> annotationType() { 086 return Html.class; 087 } 088 089 @Override 090 public String anchorText() { 091 return anchorText; 092 } 093 094 /** 095 * Sets the <c>anchorText</c> property on this annotation. 096 * 097 * @param value The new value for this property. 098 * @return This object (for method chaining). 099 */ 100 public HtmlAnnotation anchorText(String value) { 101 this.anchorText = value; 102 return this; 103 } 104 105 @Override 106 public HtmlFormat format() { 107 return format; 108 } 109 110 /** 111 * Sets the <c>format</c> property on this annotation. 112 * 113 * @param value The new value for this property. 114 * @return This object (for method chaining). 115 */ 116 public HtmlAnnotation format(HtmlFormat value) { 117 this.format = value; 118 return this; 119 } 120 121 @Override 122 public String link() { 123 return link; 124 } 125 126 /** 127 * Sets the <c>xxx</c> property on this annotation. 128 * 129 * @param value The new value for this property. 130 * @return This object (for method chaining). 131 */ 132 public HtmlAnnotation link(String value) { 133 this.link = value; 134 return this; 135 } 136 137 @Override 138 public boolean noTableHeaders() { 139 return noTableHeaders; 140 } 141 142 /** 143 * Sets the <c>noTableHeaders</c> property on this annotation. 144 * 145 * @param value The new value for this property. 146 * @return This object (for method chaining). 147 */ 148 public HtmlAnnotation noTableHeaders(boolean value) { 149 this.noTableHeaders = value; 150 return this; 151 } 152 153 @Override 154 public boolean noTables() { 155 return noTables; 156 } 157 158 /** 159 * Sets the <c>noTables</c> property on this annotation. 160 * 161 * @param value The new value for this property. 162 * @return This object (for method chaining). 163 */ 164 public HtmlAnnotation noTables(boolean value) { 165 this.noTables = value; 166 return this; 167 } 168 169 @Override 170 public String on() { 171 return on; 172 } 173 174 /** 175 * Sets the <c>on</c> property on this annotation. 176 * 177 * @param value The new value for this property. 178 * @return This object (for method chaining). 179 */ 180 public HtmlAnnotation on(String value) { 181 this.on = value; 182 return this; 183 } 184 185 /** 186 * Sets the <c>on</c> property on this annotation. 187 * 188 * @param value The new value for this property. 189 * @return This object (for method chaining). 190 */ 191 public HtmlAnnotation on(Class<?> value) { 192 this.on = value.getName(); 193 return this; 194 } 195 196 /** 197 * Sets the <c>on</c> property on this annotation. 198 * 199 * @param value The new value for this property. 200 * @return This object (for method chaining). 201 */ 202 public HtmlAnnotation on(Method value) { 203 this.on = MethodInfo.of(value).getFullName(); 204 return this; 205 } 206 207 /** 208 * Sets the <c>on</c> property on this annotation. 209 * 210 * @param value The new value for this property. 211 * @return This object (for method chaining). 212 */ 213 public HtmlAnnotation on(Field value) { 214 this.on = value.getName(); 215 return this; 216 } 217 218 @Override 219 public Class<? extends HtmlRender> render() { 220 return render; 221 } 222 223 /** 224 * Sets the <c>render</c> property on this annotation. 225 * 226 * @param value The new value for this property. 227 * @return This object (for method chaining). 228 */ 229 public HtmlAnnotation render(Class<? extends HtmlRender> value) { 230 this.render = value; 231 return this; 232 } 233}