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 java.io.IOException; 016import java.lang.reflect.*; 017import java.nio.charset.*; 018import java.util.*; 019import java.util.function.*; 020 021import org.apache.juneau.*; 022import org.apache.juneau.httppart.*; 023import org.apache.juneau.internal.*; 024import org.apache.juneau.serializer.*; 025import org.apache.juneau.svl.*; 026 027/** 028 * Session object that lives for the duration of a single use of {@link HtmlStrippedDocSerializer}. 029 * 030 * <h5 class='section'>Notes:</h5><ul> 031 * <li class='warn'>This class is not thread safe and is typically discarded after one use. 032 * </ul> 033 * 034 * <h5 class='section'>See Also:</h5><ul> 035 * <li class='link'><a class="doclink" href="../../../../index.html#jm.HtmlDetails">HTML Details</a> 036 * </ul> 037 */ 038public class HtmlStrippedDocSerializerSession extends HtmlSerializerSession { 039 040 //----------------------------------------------------------------------------------------------------------------- 041 // Static 042 //----------------------------------------------------------------------------------------------------------------- 043 044 /** 045 * Creates a new builder for this object. 046 * 047 * @param ctx The context creating this session. 048 * @return A new builder. 049 */ 050 public static Builder create(HtmlStrippedDocSerializer ctx) { 051 return new Builder(ctx); 052 } 053 054 //----------------------------------------------------------------------------------------------------------------- 055 // Builder 056 //----------------------------------------------------------------------------------------------------------------- 057 058 /** 059 * Builder class. 060 */ 061 @FluentSetters 062 public static class Builder extends HtmlSerializerSession.Builder { 063 064 HtmlStrippedDocSerializer ctx; 065 066 /** 067 * Constructor 068 * 069 * @param ctx The context creating this session. 070 */ 071 protected Builder(HtmlStrippedDocSerializer ctx) { 072 super(ctx); 073 this.ctx = ctx; 074 } 075 076 @Override 077 public HtmlStrippedDocSerializerSession build() { 078 return new HtmlStrippedDocSerializerSession(this); 079 } 080 081 // <FluentSetters> 082 083 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 084 public <T> Builder apply(Class<T> type, Consumer<T> apply) { 085 super.apply(type, apply); 086 return this; 087 } 088 089 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 090 public Builder debug(Boolean value) { 091 super.debug(value); 092 return this; 093 } 094 095 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 096 public Builder properties(Map<String,Object> value) { 097 super.properties(value); 098 return this; 099 } 100 101 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 102 public Builder property(String key, Object value) { 103 super.property(key, value); 104 return this; 105 } 106 107 @Override /* GENERATED - org.apache.juneau.ContextSession.Builder */ 108 public Builder unmodifiable() { 109 super.unmodifiable(); 110 return this; 111 } 112 113 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 114 public Builder locale(Locale value) { 115 super.locale(value); 116 return this; 117 } 118 119 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 120 public Builder localeDefault(Locale value) { 121 super.localeDefault(value); 122 return this; 123 } 124 125 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 126 public Builder mediaType(MediaType value) { 127 super.mediaType(value); 128 return this; 129 } 130 131 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 132 public Builder mediaTypeDefault(MediaType value) { 133 super.mediaTypeDefault(value); 134 return this; 135 } 136 137 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 138 public Builder timeZone(TimeZone value) { 139 super.timeZone(value); 140 return this; 141 } 142 143 @Override /* GENERATED - org.apache.juneau.BeanSession.Builder */ 144 public Builder timeZoneDefault(TimeZone value) { 145 super.timeZoneDefault(value); 146 return this; 147 } 148 149 @Override /* GENERATED - org.apache.juneau.serializer.SerializerSession.Builder */ 150 public Builder javaMethod(Method value) { 151 super.javaMethod(value); 152 return this; 153 } 154 155 @Override /* GENERATED - org.apache.juneau.serializer.SerializerSession.Builder */ 156 public Builder resolver(VarResolverSession value) { 157 super.resolver(value); 158 return this; 159 } 160 161 @Override /* GENERATED - org.apache.juneau.serializer.SerializerSession.Builder */ 162 public Builder schema(HttpPartSchema value) { 163 super.schema(value); 164 return this; 165 } 166 167 @Override /* GENERATED - org.apache.juneau.serializer.SerializerSession.Builder */ 168 public Builder schemaDefault(HttpPartSchema value) { 169 super.schemaDefault(value); 170 return this; 171 } 172 173 @Override /* GENERATED - org.apache.juneau.serializer.SerializerSession.Builder */ 174 public Builder uriContext(UriContext value) { 175 super.uriContext(value); 176 return this; 177 } 178 179 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializerSession.Builder */ 180 public Builder fileCharset(Charset value) { 181 super.fileCharset(value); 182 return this; 183 } 184 185 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializerSession.Builder */ 186 public Builder streamCharset(Charset value) { 187 super.streamCharset(value); 188 return this; 189 } 190 191 @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializerSession.Builder */ 192 public Builder useWhitespace(Boolean value) { 193 super.useWhitespace(value); 194 return this; 195 } 196 197 // </FluentSetters> 198 } 199 200 //----------------------------------------------------------------------------------------------------------------- 201 // Instance 202 //----------------------------------------------------------------------------------------------------------------- 203 204 /** 205 * Constructor. 206 * 207 * @param builder The builder for this object. 208 */ 209 protected HtmlStrippedDocSerializerSession(Builder builder) { 210 super(builder); 211 } 212 213 @Override /* SerializerSession */ 214 protected void doSerialize(SerializerPipe out, Object o) throws IOException, SerializeException { 215 try (HtmlWriter w = getHtmlWriter(out)) { 216 if (o == null 217 || (o instanceof Collection && ((Collection<?>)o).size() == 0) 218 || (o.getClass().isArray() && Array.getLength(o) == 0)) 219 w.sTag(1, "p").append("No Results").eTag("p").nl(1); 220 else 221 super.doSerialize(out, o); 222 } 223 } 224}