001    package railo.runtime.interpreter.ref.literal;
002    
003    import java.util.ArrayList;
004    import java.util.Iterator;
005    
006    import railo.runtime.exp.PageException;
007    import railo.runtime.interpreter.ref.Ref;
008    import railo.runtime.interpreter.ref.RefSupport;
009    import railo.runtime.interpreter.ref.util.RefUtil;
010    import railo.runtime.op.Caster;
011    
012    /**
013     * Literal String
014     *
015     */
016    public final class LStringBuffer extends RefSupport implements Literal {
017        
018        private ArrayList refs=new ArrayList();
019        private StringBuffer sb=new StringBuffer();
020    
021            //private PageContext pc;
022    
023        /**
024         * constructor of the class
025         * @param str 
026         */
027        public LStringBuffer(String str) {
028            sb.append(str);
029            //this.pc=pc;
030        }
031        /**
032         * constructor of the class
033         * @param str 
034         */
035        public LStringBuffer() {
036            //this.pc=pc;
037        }
038        
039    
040        /**
041         * @throws PageException 
042         * @see railo.runtime.interpreter.ref.Ref#getValue()
043         */
044        public Object getValue() throws PageException {
045            if(refs.size()==0) return sb.toString();
046            
047            StringBuffer tmp=new StringBuffer();
048            Iterator it = refs.iterator();
049            while(it.hasNext()) {
050                tmp.append(Caster.toString(((Ref)it.next()).getValue()));
051            }
052            if(sb.length()>0)tmp.append(sb);
053            
054            
055            return tmp.toString();
056        } 
057        
058        public void append(Ref ref) {
059            if(sb.length()>0) {
060                refs.add(new LString(sb.toString()));
061                sb=new StringBuffer();
062            }
063            refs.add(ref);
064        }
065    
066        public void append(char c) {
067            sb.append(c);
068        }
069        public void append(String str) {
070            sb.append(str);
071        }
072        
073        public boolean isEmpty() {
074            return sb.length()+refs.size()==0;
075        }
076    
077        /**
078         * @see railo.runtime.interpreter.ref.Ref#getTypeName()
079         */
080        public String getTypeName() {
081            return "literal";
082        }
083        
084        /**
085         * @throws PageException 
086         * @see railo.runtime.interpreter.ref.literal.Literal#getString()
087         */
088        public String getString() throws PageException {
089            return (String) getValue();
090        }
091    
092            /**
093             * @see railo.runtime.interpreter.ref.Ref#eeq(railo.runtime.interpreter.ref.Ref)
094             */
095            public boolean eeq(Ref other) throws PageException {
096                    return RefUtil.eeq(this,other);
097            }
098    }