001// Copyright 2007, 2008, 2011 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// 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
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.corelib.components;
016
017import org.apache.tapestry5.ComponentResources;
018import org.apache.tapestry5.MarkupWriter;
019import org.apache.tapestry5.annotations.Parameter;
020import org.apache.tapestry5.ioc.annotations.Inject;
021
022/**
023 * Used to output raw markup to the client. Unlike, say, an expansion, the output from OutputRaw is unfiltered, with any
024 * special characters or entities left exactly as is. This is used in situations where the markup is provided
025 * externally, rather than constructed within Tapestry.
026 *
027 * @see MarkupWriter#writeRaw(String)
028 * @tapestrydoc
029 */
030public class OutputRaw
031{
032    /**
033     * The value to to render. If unbound, and a property of the container matches the component's id, then that
034     * property will be the source of the value.
035     */
036    @Parameter(required = true, autoconnect = true)
037    private String value;
038
039    @Inject
040    private ComponentResources resources;
041
042    boolean beginRender(MarkupWriter writer)
043    {
044        if (value != null && value.length() > 0) writer.writeRaw(value);
045
046        // Abort the rest of the render.
047
048        return false;
049    }
050
051    // For testing:
052
053    void setValue(String value)
054    {
055        this.value = value;
056    }
057
058}