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