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