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.dwrp;
17:
18: import java.io.IOException;
19: import java.io.PrintWriter;
20:
21: import org.directwebremoting.extend.DwrConstants;
22: import org.directwebremoting.util.MimeConstants;
23:
24: /**
25: * A Marshaller that outputs plain Javascript.
26: * @author Joe Walker [joe at getahead dot ltd dot uk]
27: */
28: public class PlainCallMarshaller extends BaseCallMarshaller {
29: /* (non-Javadoc)
30: * @see org.directwebremoting.dwrp.BaseCallMarshaller#getOutboundMimeType()
31: */
32: @Override
33: protected String getOutboundMimeType() {
34: return MimeConstants.MIME_JS;
35: }
36:
37: /* (non-Javadoc)
38: * @see org.directwebremoting.dwrp.BaseCallMarshaller#sendOutboundScriptPrefix(java.io.PrintWriter, java.lang.String)
39: */
40: @Override
41: protected void sendOutboundScriptPrefix(PrintWriter out,
42: String batchId) throws IOException {
43: if (!allowScriptTagRemoting) {
44: synchronized (out) {
45: out.println(scriptTagProtection);
46: }
47: }
48: }
49:
50: /* (non-Javadoc)
51: * @see org.directwebremoting.dwrp.BaseCallMarshaller#sendOutboundScriptSuffix(java.io.PrintWriter, java.lang.String)
52: */
53: @Override
54: protected void sendOutboundScriptSuffix(PrintWriter out,
55: String batchId) throws IOException {
56: }
57:
58: /* (non-Javadoc)
59: * @see org.directwebremoting.dwrp.BaseCallMarshaller#sendScript(java.io.PrintWriter, java.lang.String)
60: */
61: @Override
62: protected void sendScript(PrintWriter out, String script)
63: throws IOException {
64: synchronized (out) {
65: out.println(script);
66: }
67: }
68:
69: /**
70: * Do we allow ScriptTag remoting?
71: * @param allowScriptTagRemoting The new value to set
72: */
73: public void setAllowScriptTagRemoting(boolean allowScriptTagRemoting) {
74: this .allowScriptTagRemoting = allowScriptTagRemoting;
75: }
76:
77: /**
78: * Do we allow ScriptTag remoting.
79: */
80: private boolean allowScriptTagRemoting = false;
81:
82: /**
83: * What is the string we use for script tag hack protection
84: * @param scriptTagProtection the scriptTagProtection to set
85: */
86: public void setScriptTagProtection(String scriptTagProtection) {
87: this .scriptTagProtection = scriptTagProtection;
88: }
89:
90: /**
91: * What is the string we use for script tag hack protection
92: */
93: private String scriptTagProtection = DwrConstants.SCRIPT_TAG_PROTECTION;
94: }
|