001    package echopoint.template;
002    /* 
003     * This file is part of the Echo Point Project.  This project is a collection
004     * of Components that have extended the Echo Web Application Framework.
005     *
006     * Version: MPL 1.1/GPL 2.0/LGPL 2.1
007     *
008     * The contents of this file are subject to the Mozilla Public License Version
009     * 1.1 (the "License"); you may not use this file except in compliance with
010     * the License. You may obtain a copy of the License at
011     * http://www.mozilla.org/MPL/
012     *
013     * Software distributed under the License is distributed on an "AS IS" basis,
014     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015     * for the specific language governing rights and limitations under the
016     * License.
017     *
018     * Alternatively, the contents of this file may be used under the terms of
019     * either the GNU General Public License Version 2 or later (the "GPL"), or
020     * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
021     * in which case the provisions of the GPL or the LGPL are applicable instead
022     * of those above. If you wish to allow use of your version of this file only
023     * under the terms of either the GPL or the LGPL, and not to allow others to
024     * use your version of this file under the terms of the MPL, indicate your
025     * decision by deleting the provisions above and replace them with the notice
026     * and other provisions required by the GPL or the LGPL. If you do not delete
027     * the provisions above, a recipient may use your version of this file under
028     * the terms of any one of the MPL, the GPL or the LGPL.
029     */
030    import echopoint.util.io.StringInputStream;
031    
032    import java.io.IOException;
033    import java.io.InputStream;
034    
035    
036    
037    /**
038     * <code>StringTemplateDataSource</code> takes it template
039     * data from a String object.
040     */
041    public class StringTemplateDataSource extends AbstractTemplateDataSource {
042            private String string;
043            
044            /**
045             * Creates a <code>StringTemplateDataSource</code> with 
046             * Unicode character encoding.
047             */
048            public StringTemplateDataSource(String s) {
049                    super(DEFAULT_ENCODING);
050                    this.string = s;
051            }
052            
053            /**
054             * Constructs a <code>StringTemplateDataSource</code>
055             * with no String template data.
056             */
057            public StringTemplateDataSource() {
058                    this(null);
059            }
060            
061            /**
062             * @see echopoint.template.TemplateDataSource#getCanonicalName()
063             */
064            public String getCanonicalName() {
065                    return "String@" + System.identityHashCode(this.string);
066            }
067            /**
068             * @see echopoint.template.TemplateDataSource#getInputStream()
069             */
070            public InputStream getInputStream() throws IOException {
071                    return new StringInputStream(this.string);
072            }
073            /**
074             * @return Returns the string.
075             */
076            public String getString() {
077                    return string;
078            }
079            /**
080             * @param string The string to set.
081             */
082            public void setString(String string) {
083                    this.string = string;
084            }
085    }