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.svl.*; 020 021/** 022 * Defines an interface for resolvers of <js>"$W{...}"</js> string variables. 023 * 024 * <p> 025 * Widgets must provide one of the following public constructors: 026 * <ul> 027 * <li><code><jk>public</jk> Widget();</code> 028 * </ul> 029 * 030 * <p> 031 * Widgets can be defined as inner classes of REST resource classes. 032 * 033 * <h5 class='section'>See Also:</h5><ul> 034 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HtmlWidgets">Widgets</a> 035 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/HtmlBasics">HTML Basics</a> 036 * </ul> 037 */ 038public interface HtmlWidget { 039 040 /** 041 * The name for this widget. 042 * 043 * @return A unique identifying name for this widget. 044 */ 045 String getName(); 046 047 /** 048 * Resolves the HTML content for this widget. 049 * 050 * <p> 051 * A returned value of <jk>null</jk> will cause nothing to be added to the page. 052 * 053 * @param session The current serializer session. 054 * @return The HTML content of this widget. 055 */ 056 String getHtml(VarResolverSession session); 057 058 /** 059 * Resolves any Javascript that should be added to the <xt><head>/<script></xt> element. 060 * 061 * <p> 062 * A returned value of <jk>null</jk> will cause nothing to be added to the page. 063 * 064 * @param session The current serializer session. 065 * @return The Javascript needed by this widget. 066 */ 067 String getScript(VarResolverSession session); 068 069 /** 070 * Resolves any CSS styles that should be added to the <xt><head>/<style></xt> element. 071 * 072 * <p> 073 * A returned value of <jk>null</jk> will cause nothing to be added to the page. 074 * 075 * @param session The current serializer session. 076 * @return The CSS styles needed by this widget. 077 */ 078 String getStyle(VarResolverSession session); 079}