001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.sys.document.web.renderers;
017    
018    import java.io.IOException;
019    
020    import javax.servlet.jsp.JspException;
021    import javax.servlet.jsp.PageContext;
022    import javax.servlet.jsp.tagext.Tag;
023    
024    import org.springframework.web.util.HtmlUtils;
025    
026    /**
027     * Don't you love it when you've got to write silly code, just because of some arbitrary rule within the
028     * system?  Don't you love it even more when _you_ are the one who created that arbitrary rule?  All
029     * tag rendering occurs through Renderer implementations - even Strings, okay?
030     */
031    public class StringRenderer implements Renderer {
032        private String stringToRender;
033        
034        /**
035         * Clears out the stringToRender
036         * @see org.kuali.kfs.sys.document.web.renderers.Renderer#clear()
037         */
038        public void clear() {
039            stringToRender = null;
040        }
041    
042        /**
043         * Renders stringToRender
044         * @see org.kuali.kfs.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
045         */
046        public void render(PageContext pageContext, Tag parentTag) throws JspException {
047            if (stringToRender != null) {
048                try {
049                    pageContext.getOut().write(stringToRender);
050                }
051                catch (IOException ioe) {
052                    new JspException("Difficulty rendering...oh dear...difficulty rendering a plain String.  That's just sad.", ioe);
053                }
054            }
055        }
056    
057        /**
058         * Gets the stringToRender attribute. 
059         * @return Returns the stringToRender.
060         */
061        public String getStringToRender() {
062            return stringToRender;
063        }
064    
065        /**
066         * Sets the stringToRender attribute value.
067         * @param stringToRender The stringToRender to set.
068         */
069        public void setStringToRender(String stringToRender) {
070            this.stringToRender = stringToRender;
071        }
072    
073    }