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