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.serializer.*;
017
018/**
019 * Serializes POJO metamodels to HTML.
020 * 
021 * <h5 class='topic'>Media types</h5>
022 * 
023 * Handles <code>Accept</code> types:  <code><b>text/html+schema</b></code>
024 * <p>
025 * Produces <code>Content-Type</code> types:  <code><b>text/html</b></code>
026 * 
027 * <h5 class='topic'>Description</h5>
028 * 
029 * Essentially the same as {@link HtmlSerializer}, except serializes the POJO metamodel instead of the model itself.
030 * 
031 * <p>
032 * Produces output that describes the POJO metamodel similar to an XML schema document.
033 * 
034 * <p>
035 * The easiest way to create instances of this class is through the {@link HtmlSerializer#getSchemaSerializer()},
036 * which will create a schema serializer with the same settings as the originating serializer.
037 */
038public final class HtmlSchemaDocSerializer extends HtmlDocSerializer {
039
040   /**
041    * Constructor.
042    * 
043    * @param ps
044    *    The property store to use for creating the context for this serializer.
045    */
046   public HtmlSchemaDocSerializer(PropertyStore ps) {
047      this(ps, "text/html", "text/html+schema");
048   }
049
050   /**
051    * Constructor.
052    * 
053    * @param ps
054    *    The property store containing all the settings for this object.
055    * @param produces
056    *    The media type that this serializer produces.
057    * @param accept
058    *    The accept media types that the serializer can handle.
059    *    <p>
060    *    Can contain meta-characters per the <code>media-type</code> specification of
061    *    <a class="doclink" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1">RFC2616/14.1</a>
062    *    <p>
063    *    If empty, then assumes the only media type supported is <code>produces</code>.
064    *    <p>
065    *    For example, if this serializer produces <js>"application/json"</js> but should handle media types of
066    *    <js>"application/json"</js> and <js>"text/json"</js>, then the arguments should be:
067    *    <p class='bcode'>
068    *    <jk>super</jk>(ps, <js>"application/json"</js>, <js>"application/json"</js>, <js>"text/json"</js>);
069    *    </p>
070    *    <br>...or...
071    *    <p class='bcode'>
072    *    <jk>super</jk>(ps, <js>"application/json"</js>, <js>"*&#8203;/json"</js>);
073    *    </p>
074    */
075   public HtmlSchemaDocSerializer(PropertyStore ps, String produces, String...accept) {
076      super(
077         ps.builder()
078            .set(SERIALIZER_detectRecursions, true)
079            .set(SERIALIZER_ignoreRecursions, true)
080            .build(), 
081         produces, 
082         accept
083      );
084   }
085
086   @Override /* Serializer */
087   public HtmlSchemaDocSerializerSession createSession(SerializerSessionArgs args) {
088      return new HtmlSchemaDocSerializerSession(this, args);
089   }
090}