001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012package org.apache.tapestry5.services; 013 014import org.apache.tapestry5.Block; 015import org.apache.tapestry5.alerts.Alert; 016import org.apache.tapestry5.commons.services.TypeCoercer; 017import org.apache.tapestry5.dom.Document; 018import org.apache.tapestry5.runtime.RenderCommand; 019 020/** 021 * 022 * Service that provides methods that render {@link Block}s ({@code <t:block>} in the template), 023 * component instances and {@link RenderCommand}s to a {@link String} or 024 * {@link Document org.apache.tapestry5.dom.Document} in a programatic way. 025 * 026 * 027 * This service was created for situations in which a page or component needs to generate some markup 028 * that wouldn't be rendered normally, but for external use, such as e-mails, returning 029 * HTML for AJAX requests or passing HTML instead of plain string for an {@link Alert}. 030 * 031 * 032 * The name of this interface comes from <a href="https://issues.apache.org/jira/browse/TAP5-938">TAP5-938</a>: 033 * <em>Expose ability to render a portion of a page (a Block, Component, etc.) without using internal services</em>. 034 * 035 * @since 5.4 036 */ 037public interface PartialTemplateRenderer 038{ 039 /** 040 * 041 * Renders an object, probably a {@link Block} or component instance, to a string. 042 * This method supposes any kind of initialization needed 043 * was already done. CSS and JavaScript inclusions or importings are ignored. 044 * The object must implement {@link RenderCommand} or being able to be coerced to it 045 * by {@link TypeCoercer}. 046 * 047 * @param object an object, probably a {@link Block} or component instance or {@link RenderCommand}. 048 * @throws IllegalArgumentException if the object isn't a {@link RenderCommand} and cannot be coerced to it by {@link TypeCoercer}. 049 */ 050 String render(Object object); 051 052 /** 053 * Renders an object to a {@link Document} following the same rules as {@link #render(Object)} 054 * This method supposes any kind of initialization needed 055 * was already done. CSS and JavaScript inclusions or importings are ignored. 056 * 057 * @param object to render, a {@link RenderCommand}, or {@linkplain TypeCoercer coercible} to one 058 * @return a {@link Document}. 059 */ 060 Document renderAsDocument(Object object); 061 062}