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 asXml, noTables, noTableHeaders, asPlainText;
027   private final HtmlRender<?> render;
028
029   /**
030    * Constructor.
031    * 
032    * @param cm The class that this annotation is defined on.
033    */
034   public HtmlClassMeta(ClassMeta<?> cm) {
035      super(cm);
036      this.html = ReflectionUtils.getAnnotation(Html.class, getInnerClass());
037      if (html != null) {
038         asXml = html.asXml();
039         noTables = html.noTables();
040         noTableHeaders = html.noTableHeaders();
041         asPlainText = html.asPlainText();
042         render = cm.getBeanContext().newInstance(HtmlRender.class, html.render());
043      } else {
044         asXml = false;
045         noTables = false;
046         noTableHeaders = false;
047         asPlainText = 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#asXml() @Html.asXml()} annotation defined on the class.
063    * 
064    * @return The value of the annotation.
065    */
066   protected boolean isAsXml() {
067      return asXml;
068   }
069
070   /**
071    * Returns the {@link Html#asPlainText() @Html.asPlainText()} annotation defined on the class.
072    * 
073    * @return The value of the annotation.
074    */
075   protected boolean isAsPlainText() {
076      return asPlainText;
077   }
078
079   /**
080    * Returns the {@link Html#noTables() @Html.noTables()} annotation defined on the class.
081    * 
082    * @return The value of the annotation.
083    */
084   protected boolean isNoTables() {
085      return noTables;
086   }
087
088   /**
089    * Returns the {@link Html#noTableHeaders() @Html.noTableHeaders()} annotation defined on the class.
090    * 
091    * @return The value of the annotation.
092    */
093   public boolean isNoTableHeaders() {
094      return noTableHeaders;
095   }
096
097   /**
098    * Returns the {@link Html#render() @Html.render()} annotation defined on the class.
099    * 
100    * @return The value of the annotation.
101    */
102   public HtmlRender<?> getRender() {
103      return render;
104   }
105}