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.annotation.*;
017import org.apache.juneau.serializer.*;
018
019/**
020 * Serializes POJOs to HTTP responses as stripped HTML.
021 *
022 * <h5 class='topic'>Media types</h5>
023 *
024 * Handles <c>Accept</c> types:  <bc>text/html+stripped</bc>
025 * <p>
026 * Produces <c>Content-Type</c> types:  <bc>text/html</bc>
027 *
028 * <h5 class='topic'>Description</h5>
029 *
030 * Produces the same output as {@link HtmlDocSerializer}, but without the header and body tags and page title and
031 * description.
032 * Used primarily for JUnit testing the {@link HtmlDocSerializer} class.
033 */
034@ConfigurableContext
035public class HtmlStrippedDocSerializer extends HtmlSerializer {
036
037   //-------------------------------------------------------------------------------------------------------------------
038   // Configurable properties
039   //-------------------------------------------------------------------------------------------------------------------
040
041   static final String PREFIX = "HtmlStrippedDocSerializer";
042
043   /**
044    * Constructor.
045    *
046    * @param ps The property store containing all the settings for this object.
047    */
048   public HtmlStrippedDocSerializer(PropertyStore ps) {
049      this(ps, "text/html", "text/html+stripped");
050   }
051
052   /**
053    * Constructor.
054    *
055    * @param ps
056    *    The property store containing all the settings for this object.
057    * @param produces
058    *    The media type that this serializer produces.
059    * @param accept
060    *    The accept media types that the serializer can handle.
061    *    <p>
062    *    Can contain meta-characters per the <c>media-type</c> specification of
063    *    {@doc RFC2616.section14.1}
064    *    <p>
065    *    If empty, then assumes the only media type supported is <c>produces</c>.
066    *    <p>
067    *    For example, if this serializer produces <js>"application/json"</js> but should handle media types of
068    *    <js>"application/json"</js> and <js>"text/json"</js>, then the arguments should be:
069    *    <p class='bcode w800'>
070    *    <jk>super</jk>(ps, <js>"application/json"</js>, <js>"application/json,text/json"</js>);
071    *    </p>
072    *    <br>...or...
073    *    <p class='bcode w800'>
074    *    <jk>super</jk>(ps, <js>"application/json"</js>, <js>"*&#8203;/json"</js>);
075    *    </p>
076    * <p>
077    * The accept value can also contain q-values.
078    */
079   public HtmlStrippedDocSerializer(PropertyStore ps, String produces, String accept) {
080      super(ps, produces, accept);
081   }
082
083   @Override /* Context */
084   public HtmlStrippedDocSerializerBuilder builder() {
085      return new HtmlStrippedDocSerializerBuilder(getPropertyStore());
086   }
087
088   /**
089    * Instantiates a new clean-slate {@link HtmlStrippedDocSerializerBuilder} object.
090    *
091    * <p>
092    * This is equivalent to simply calling <code><jk>new</jk> HtmlStrippedDocSerializerBuilder()</code>.
093    *
094    * <p>
095    * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies
096    * the settings of the object called on.
097    *
098    * @return A new {@link HtmlStrippedDocSerializerBuilder} object.
099    */
100   public static HtmlStrippedDocSerializerBuilder create() {
101      return new HtmlStrippedDocSerializerBuilder();
102   }
103
104   @Override /* Serializer */
105   public HtmlSerializerSession createSession() {
106      return createSession(createDefaultSessionArgs());
107   }
108
109   @Override /* Serializer */
110   public HtmlSerializerSession createSession(SerializerSessionArgs args) {
111      return new HtmlStrippedDocSerializerSession(this, args);
112   }
113
114   //-----------------------------------------------------------------------------------------------------------------
115   // Other methods
116   //-----------------------------------------------------------------------------------------------------------------
117
118   @Override /* Context */
119   public ObjectMap toMap() {
120      return super.toMap()
121         .append("HtmlStrippedDocSerializer", new DefaultFilteringObjectMap()
122         );
123   }
124}