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