001    // Copyright 2007, 2008 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    
015    package org.apache.tapestry5.corelib.components;
016    
017    import org.apache.tapestry5.ComponentResources;
018    import org.apache.tapestry5.MarkupWriter;
019    import org.apache.tapestry5.annotations.Parameter;
020    import 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     */
029    public class OutputRaw
030    {
031        /**
032         * The value to to render. If unbound, and a property of the container matches the component's id, then that
033         * property will be the source of the value.
034         */
035        @Parameter(required = true, autoconnect = true)
036        private String value;
037    
038        @Inject
039        private ComponentResources resources;
040    
041        boolean beginRender(MarkupWriter writer)
042        {
043            if (value != null && value.length() > 0) writer.writeRaw(value);
044    
045            // Abort the rest of the render.
046    
047            return false;
048        }
049    
050        // For testing:
051    
052        void setValue(String value)
053        {
054            this.value = value;
055        }
056    
057    }