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