1 29 30 package com.caucho.el; 31 32 import com.caucho.vfs.WriteStream; 33 34 import javax.el.ELContext; 35 import javax.el.ELException; 36 import javax.el.MethodInfo; 37 import java.io.IOException ; 38 39 42 public class StringLiteral extends Expr { 43 private String _value; 44 45 public StringLiteral(String value) 46 { 47 _value = value; 48 } 49 50 53 @Override 54 public boolean isConstant() 55 { 56 return true; 57 } 58 59 62 @Override 63 public boolean isLiteralText() 64 { 65 return true; 66 } 67 68 75 @Override 76 public MethodInfo getMethodInfo(ELContext env, 77 Class <?> returnType, 78 Class <?> []argTypes) 79 throws ELException 80 { 81 return new MethodInfo(_value, returnType, argTypes); 82 } 83 84 91 @Override 92 public Object invoke(ELContext env, Class <?> []argTypes, Object []args) 93 throws ELException 94 { 95 return _value; 96 } 97 98 101 public String getValue() 102 { 103 return _value; 104 } 105 106 111 @Override 112 public Object getValue(ELContext env) 113 throws ELException 114 { 115 return _value; 116 } 117 118 123 @Override 124 public String evalString(ELContext env) 125 throws ELException 126 { 127 return _value; 128 } 129 130 133 @Override 134 public boolean print(WriteStream out, 135 ELContext env, 136 boolean isEscape) 137 throws IOException , ELException 138 { 139 if (isEscape) 140 toStreamEscaped(out, _value); 141 else 142 out.print(_value); 143 144 return false; 145 } 146 147 150 @Override 151 public void printCreate(WriteStream os) 152 throws IOException 153 { 154 os.print("new com.caucho.el.StringLiteral(\""); 155 printEscapedString(os, _value); 156 os.print("\")"); 157 } 158 159 162 public boolean equals(Object o) 163 { 164 if (! (o instanceof StringLiteral)) 165 return false; 166 167 StringLiteral literal = (StringLiteral) o; 168 169 return _value.equals(literal._value); 170 } 171 172 175 public String toString() 176 { 177 return "\"" + _value + "\""; 178 } 179 } 180 | Popular Tags |