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