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; 014 015import static org.apache.juneau.internal.ClassUtils.*; 016 017import org.apache.juneau.*; 018import org.apache.juneau.html.annotation.*; 019 020/** 021 * Metadata on classes specific to the HTML serializers and parsers pulled from the {@link Html @Html} annotation on 022 * the class. 023 */ 024public class HtmlClassMeta extends ClassMetaExtended { 025 026 private final Html html; 027 private final boolean noTables, noTableHeaders; 028 private final HtmlFormat format; 029 private final HtmlRender<?> render; 030 031 /** 032 * Constructor. 033 * 034 * @param cm The class that this annotation is defined on. 035 */ 036 public HtmlClassMeta(ClassMeta<?> cm) { 037 super(cm); 038 this.html = cm.getInfo().getAnnotation(Html.class); 039 if (html != null) { 040 format = html.format(); 041 noTables = html.noTables(); 042 noTableHeaders = html.noTableHeaders(); 043 render = castOrCreate(HtmlRender.class, html.render()); 044 } else { 045 format = HtmlFormat.HTML; 046 noTables = false; 047 noTableHeaders = false; 048 render = null; 049 } 050 } 051 052 /** 053 * Returns the {@link Html @Html} annotation defined on the class. 054 * 055 * @return The value of the annotation, or <jk>null</jk> if not specified. 056 */ 057 protected Html getAnnotation() { 058 return html; 059 } 060 061 /** 062 * Returns the {@link Html#format() @Html(format)} annotation defined on the class. 063 * 064 * @return The value of the annotation. 065 */ 066 protected HtmlFormat getFormat() { 067 return format; 068 } 069 070 /** 071 * Returns <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#XML}. 072 * 073 * @return <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#XML}. 074 */ 075 protected boolean isXml() { 076 return format == HtmlFormat.XML; 077 } 078 079 /** 080 * Returns <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#PLAIN_TEXT}. 081 * 082 * @return <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#PLAIN_TEXT}. 083 */ 084 protected boolean isPlainText() { 085 return format == HtmlFormat.PLAIN_TEXT; 086 } 087 088 /** 089 * Returns <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#HTML}. 090 * 091 * @return <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#HTML}. 092 */ 093 protected boolean isHtml() { 094 return format == HtmlFormat.HTML; 095 } 096 097 /** 098 * Returns <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#HTML_CDC}. 099 * 100 * @return <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#HTML_CDC}. 101 */ 102 protected boolean isHtmlCdc() { 103 return format == HtmlFormat.HTML_CDC; 104 } 105 106 /** 107 * Returns <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#HTML_SDC}. 108 * 109 * @return <jk>true</jk> if {@link #getFormat()} returns {@link HtmlFormat#HTML_SDC}. 110 */ 111 protected boolean isHtmlSdc() { 112 return format == HtmlFormat.HTML_SDC; 113 } 114 115 /** 116 * Returns the {@link Html#noTables() @Html(noTables)} annotation defined on the class. 117 * 118 * @return The value of the annotation. 119 */ 120 protected boolean isNoTables() { 121 return noTables; 122 } 123 124 /** 125 * Returns the {@link Html#noTableHeaders() @Html(noTableHeaders)} annotation defined on the class. 126 * 127 * @return The value of the annotation. 128 */ 129 public boolean isNoTableHeaders() { 130 return noTableHeaders; 131 } 132 133 /** 134 * Returns the {@link Html#render() @Html(render)} annotation defined on the class. 135 * 136 * @return The value of the annotation. 137 */ 138 public HtmlRender<?> getRender() { 139 return render; 140 } 141}