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.util.*; 018 019import org.apache.juneau.*; 020import org.apache.juneau.serializer.*; 021 022/** 023 * Session object that lives for the duration of a single use of {@link HtmlStrippedDocSerializer}. 024 * 025 * <p> 026 * This class is NOT thread safe. It is meant to be discarded after one-time use. 027 */ 028public class HtmlStrippedDocSerializerSession extends HtmlSerializerSession { 029 030 /** 031 * Create a new session using properties specified in the context. 032 * 033 * @param ctx 034 * The context creating this session object. 035 * The context contains all the configuration settings for this object. 036 * @param args 037 * Runtime arguments. 038 */ 039 protected HtmlStrippedDocSerializerSession(HtmlStrippedDocSerializer ctx, SerializerSessionArgs args) { 040 super(ctx, args); 041 } 042 043 @Override /* SerializerSession */ 044 protected void doSerialize(SerializerPipe out, Object o) throws IOException, SerializeException { 045 try (HtmlWriter w = getHtmlWriter(out)) { 046 if (o == null 047 || (o instanceof Collection && ((Collection<?>)o).size() == 0) 048 || (o.getClass().isArray() && Array.getLength(o) == 0)) 049 w.sTag(1, "p").append("No Results").eTag("p").nl(1); 050 else 051 super.doSerialize(out, o); 052 } 053 } 054 055 //----------------------------------------------------------------------------------------------------------------- 056 // Other methods 057 //----------------------------------------------------------------------------------------------------------------- 058 059 @Override /* Session */ 060 public ObjectMap toMap() { 061 return super.toMap() 062 .append("HtmlStrippedDocSerializerSession", new DefaultFilteringObjectMap() 063 ); 064 } 065}