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.marshall.html; 018 019import static org.apache.juneau.commons.utils.Shorts.*; 020 021import java.lang.annotation.*; 022 023import org.apache.juneau.commons.*; 024 025/** 026 * Utility classes and methods for the {@link Html @Html} annotation. 027 * 028 * <h5 class='section'>See Also:</h5><ul> 029 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HtmlSupport">HTML</a> 030 * </ul> 031 */ 032@SuppressWarnings({ 033 "rawtypes" // Raw types necessary for annotation handler registration 034}) 035public class HtmlAnnotation { 036 037 /** 038 * Prevents instantiation. 039 */ 040 private HtmlAnnotation() {} 041 /** 042 * Builder class. 043 * 044 * <h5 class='section'>See Also:</h5><ul> 045 * <li class='jm'>{@link org.apache.juneau.marshall.MarshallingContext.Builder#annotations(Annotation...)} 046 * </ul> 047 */ 048 public static class Builder extends AnnotationObject.Builder { 049 050 private String[] description = {}; 051 private String anchorText = ""; 052 private String link = ""; 053 private String style = ""; 054 private HtmlFormat format = HtmlFormat.HTML; 055 private boolean noTableHeaders; 056 private boolean noTables; 057 private Class<? extends HtmlRender> render = HtmlRender.class; 058 059 /** 060 * Constructor. 061 */ 062 protected Builder() { 063 super(Html.class); 064 } 065 066 /** 067 * Sets the {@link Html#anchorText()} property on this annotation. 068 * 069 * @param value The new value for this property. 070 * @return This object. 071 */ 072 public Builder anchorText(String value) { 073 anchorText = value; 074 return this; 075 } 076 077 /** 078 * Instantiates a new {@link Html @Html} object initialized with this builder. 079 * 080 * @return A new {@link Html @Html} object. 081 */ 082 public Html build() { 083 return new Object(this); 084 } 085 086 /** 087 * Sets the description property on this annotation. 088 * 089 * @param value The new value for this property. 090 * @return This object. 091 */ 092 public Builder description(String...value) { 093 description = value; 094 return this; 095 } 096 097 /** 098 * Sets the {@link Html#format()} property on this annotation. 099 * 100 * @param value The new value for this property. 101 * @return This object. 102 */ 103 public Builder format(HtmlFormat value) { 104 format = value; 105 return this; 106 } 107 108 /** 109 * Sets the {@link Html#link()} property on this annotation. 110 * 111 * @param value The new value for this property. 112 * @return This object. 113 */ 114 public Builder link(String value) { 115 link = value; 116 return this; 117 } 118 119 /** 120 * Sets the {@link Html#noTableHeaders()} property on this annotation. 121 * 122 * @param value The new value for this property. 123 * @return This object. 124 */ 125 public Builder noTableHeaders(boolean value) { 126 noTableHeaders = value; 127 return this; 128 } 129 130 /** 131 * Sets the {@link Html#noTables()} property on this annotation. 132 * 133 * @param value The new value for this property. 134 * @return This object. 135 */ 136 public Builder noTables(boolean value) { 137 noTables = value; 138 return this; 139 } 140 141 /** 142 * Sets the {@link Html#render()} property on this annotation. 143 * 144 * @param value The new value for this property. 145 * @return This object. 146 */ 147 public Builder render(Class<? extends HtmlRender> value) { 148 render = value; 149 return this; 150 } 151 152 /** 153 * Sets the {@link Html#style()} property on this annotation. 154 * 155 * @param value The new value for this property. 156 * @return This object. 157 */ 158 public Builder style(String value) { 159 style = value; 160 return this; 161 } 162 163 } 164 165 @SuppressWarnings({ 166 "java:S2160" // equals() inherited from AnnotationObject compares all annotation interface methods; subclass fields are accessed via those methods 167 }) 168 private static class Object extends AnnotationObject implements Html { 169 170 private final String[] description; 171 private final boolean noTableHeaders; 172 private final boolean noTables; 173 private final Class<? extends HtmlRender> render; 174 private final String anchorText; 175 private final String link; 176 private final String style; 177 private final HtmlFormat format; 178 179 Object(HtmlAnnotation.Builder b) { 180 super(b); 181 description = cp(b.description); 182 anchorText = b.anchorText; 183 format = b.format; 184 link = b.link; 185 noTableHeaders = b.noTableHeaders; 186 noTables = b.noTables; 187 render = b.render; 188 style = b.style; 189 } 190 191 @Override /* Overridden from Html */ 192 public String anchorText() { 193 return anchorText; 194 } 195 196 @Override /* Overridden from Html */ 197 public HtmlFormat format() { 198 return format; 199 } 200 201 @Override /* Overridden from Html */ 202 public String link() { 203 return link; 204 } 205 206 @Override /* Overridden from Html */ 207 public boolean noTableHeaders() { 208 return noTableHeaders; 209 } 210 211 @Override /* Overridden from Html */ 212 public boolean noTables() { 213 return noTables; 214 } 215 216 @Override /* Overridden from Html */ 217 public Class<? extends HtmlRender> render() { 218 return render; 219 } 220 221 @Override /* Overridden from Html */ 222 public String style() { 223 return style; 224 } 225 226 @Override /* Overridden from Html */ 227 public String[] description() { 228 return description; 229 } 230 } 231 232 /** Default value */ 233 public static final Html DEFAULT = create().build(); 234 235 /** 236 * Instantiates a new builder for this class. 237 * 238 * @return A new builder object. 239 */ 240 public static Builder create() { 241 return new Builder(); 242 } 243}