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.html; 018 019import org.apache.juneau.html.annotation.*; 020import org.apache.juneau.serializer.*; 021 022/** 023 * Allows custom rendering of bean property values when serialized as HTML. 024 * 025 * <p> 026 * Associated with bean properties using the {@link Html#render() @Html(render)} annotation. 027 * 028 * <p> 029 * Using this class, you can alter the CSS style and HTML content of the bean property. 030 * 031 * <h5 class='section'>See Also:</h5><ul> 032 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HtmlRenderAnnotation">@Html(render) Annotation</a> 033 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HtmlBasics">HTML Basics</a> 034 * </ul> 035 * 036 * @param <T> The bean property type. 037 */ 038public abstract class HtmlRender<T> { 039 040 /** 041 * Returns the CSS style of the element containing the bean property value. 042 * 043 * @param session 044 * The current serializer session. 045 * Can be used to retrieve properties and session-level information. 046 * @param value The bean property value. 047 * @return The CSS style string, or <jk>null</jk> if no style should be added. 048 */ 049 public String getStyle(SerializerSession session, T value) { 050 return null; 051 } 052 053 /** 054 * Returns the delegate value for the specified bean property value. 055 * 056 * <p> 057 * The default implementation simply returns the same value. 058 * A typical use is to return an HTML element using one of the HTML5 DOM beans. 059 * 060 * @param session 061 * The current serializer session. 062 * Can be used to retrieve properties and session-level information. 063 * @param value The bean property value. 064 * @return The new bean property value. 065 */ 066 public Object getContent(SerializerSession session, T value) { 067 return value; 068 } 069}