01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.json;
17:
18: import org.directwebremoting.util.JavascriptUtil;
19:
20: /**
21: * The Json version of a String
22: * @author Joe Walker [joe at getahead dot ltd dot uk]
23: */
24: public class JsonString extends JsonValue {
25: /**
26: * All JsonStrings wrap a Java string
27: */
28: public JsonString(String value) {
29: this .value = value;
30: }
31:
32: /* (non-Javadoc)
33: * @see org.directwebremoting.json.JsonValue#getString()
34: */
35: @Override
36: public String getString() {
37: return value;
38: }
39:
40: /* (non-Javadoc)
41: * @see org.directwebremoting.json.JsonValue#toExternalRepresentation()
42: */
43: @Override
44: public String toExternalRepresentation() {
45: return "'" + JavascriptUtil.escapeJavaScript(value) + "'";
46: }
47:
48: /* (non-Javadoc)
49: * @see java.lang.Object#toString()
50: */
51: @Override
52: public String toString() {
53: return getString();
54: }
55:
56: /**
57: * The string value that we wrap
58: */
59: private final String value;
60: }
|