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