001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.marshall.html;
018
019import org.apache.juneau.commons.collections.*;
020
021/**
022 * Serializes POJOs to HTTP responses as stripped HTML.
023 *
024 * <h5 class='topic'>Media types</h5>
025 *
026 * Handles <c>Accept</c> types:  <bc>text/html+stripped</bc>
027 * <p>
028 * Produces <c>Content-Type</c> types:  <bc>text/html</bc>
029 *
030 * <h5 class='topic'>Description</h5>
031 *
032 * Produces the same output as {@link HtmlDocSerializer}, but without the header and body tags and page title and
033 * description.
034 * Used primarily for JUnit testing the {@link HtmlDocSerializer} class.
035 *
036 * <h5 class='section'>Notes:</h5><ul>
037 *    <li class='note'>This class is thread safe and reusable.
038 * </ul>
039 *
040 * <h5 class='section'>See Also:</h5><ul>
041 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HtmlSupport">HTML</a>
042
043 * </ul>
044 */
045@SuppressWarnings({
046   "java:S110", // Inheritance depth acceptable for HtmlStrippedDocSerializer hierarchy
047   "java:S9149" // Per-format static factories intentionally shadow the parent's.
048})
049public class HtmlStrippedDocSerializer extends HtmlSerializer {
050
051   /**
052    * Builder class.
053    */
054   @SuppressWarnings({
055      "java:S119" // 'SELF' (CRTP self-type) is intentional and clearer than a single-letter name.
056   })
057   public abstract static class Builder<SELF extends Builder<SELF>> extends HtmlSerializer.Builder<SELF> {
058
059      private static final Cache<HashKey,HtmlStrippedDocSerializer> CACHE = Cache.of(HashKey.class, HtmlStrippedDocSerializer.class).build();
060
061      /**
062       * Constructor, default settings.
063       */
064      protected Builder() {
065         produces("text/html");
066         accept("text/html+stripped");
067      }
068
069      /**
070       * Copy constructor.
071       *
072       * @param copyFrom The builder to copy from.
073       */
074      protected Builder(Builder<?> copyFrom) {
075         super(copyFrom);
076      }
077
078      /**
079       * Copy constructor.
080       *
081       * @param copyFrom The bean to copy from.
082       */
083      protected Builder(HtmlStrippedDocSerializer copyFrom) {
084         super(copyFrom);
085      }
086
087      @Override /* Overridden from Context.Builder<?> */
088      public HtmlStrippedDocSerializer build() {
089         return cache(CACHE).build(HtmlStrippedDocSerializer.class);
090      }
091
092      @Override /* Overridden from Context.Builder<?> */
093      public abstract SELF copy();
094
095
096   }
097
098   /**
099    * Concrete default builder leaf for the non-subclassed {@link HtmlStrippedDocSerializer#create()} / {@link HtmlStrippedDocSerializer#copy()} path.
100    */
101   public static final class DefaultBuilder extends Builder<DefaultBuilder> {
102
103      DefaultBuilder() {}
104
105      DefaultBuilder(HtmlStrippedDocSerializer copyFrom) {
106         super(copyFrom);
107      }
108
109      DefaultBuilder(Builder<?> copyFrom) {
110         super(copyFrom);
111      }
112
113      @Override /* Overridden from Context.Builder<?> */
114      public DefaultBuilder copy() {
115         return new DefaultBuilder(this);
116      }
117   }
118
119   /** Default serializer, all default settings. */
120   public static final HtmlStrippedDocSerializer DEFAULT = new HtmlStrippedDocSerializer(create());
121
122   /**
123    * Creates a new builder for this object.
124    *
125    * @return A new builder.
126    */
127   @SuppressWarnings({
128      "java:S1452" // Builder<?> wildcard return intentional; callers chain via fluent API without needing the concrete type
129   })
130   public static Builder<?> create() {
131      return new DefaultBuilder();
132   }
133
134   /**
135    * Constructor.
136    *
137    * @param builder The builder for this object.
138    */
139   public HtmlStrippedDocSerializer(Builder<?> builder) {
140      super(builder);
141   }
142
143   @Override /* Overridden from Context */
144   public Builder<?> copy() {
145      return new DefaultBuilder(this);
146   }
147
148   @Override /* Overridden from Context */
149   public HtmlStrippedDocSerializerSession.Builder<?> createSession() {
150      return HtmlStrippedDocSerializerSession.create(this);
151   }
152
153   @Override /* Overridden from Context */
154   public HtmlStrippedDocSerializerSession getSession() { return createSession().build(); }
155}