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 jsx3.xml;
17:
18: import org.directwebremoting.convert.BaseV20Converter;
19: import org.directwebremoting.extend.Converter;
20: import org.directwebremoting.extend.InboundContext;
21: import org.directwebremoting.extend.InboundVariable;
22: import org.directwebremoting.extend.MarshallException;
23: import org.directwebremoting.extend.NonNestedOutboundVariable;
24: import org.directwebremoting.extend.OutboundContext;
25: import org.directwebremoting.extend.OutboundVariable;
26: import org.directwebremoting.util.JavascriptUtil;
27:
28: /**
29: * An implementation of Converter for DOM objects.
30: * @author Joe Walker [joe at eireneh dot com]
31: */
32: public class CdfDocumentConverter extends BaseV20Converter implements
33: Converter {
34: /* (non-Javadoc)
35: * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
36: */
37: public Object convertInbound(Class<?> paramType,
38: InboundVariable iv, InboundContext inctx)
39: throws MarshallException {
40: // String value = LocalUtil.decode(iv.getValue());
41:
42: try {
43: throw new MarshallException(paramType);
44: } catch (MarshallException ex) {
45: throw ex;
46: } catch (Exception ex) {
47: throw new MarshallException(paramType, ex);
48: }
49: }
50:
51: /* (non-Javadoc)
52: * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
53: */
54: public OutboundVariable convertOutbound(Object data,
55: OutboundContext outctx) throws MarshallException {
56: try {
57: // Using XSLT to convert to a stream. Setup the source
58: if (!(data instanceof CdfDocument)) {
59: throw new MarshallException(data.getClass());
60: }
61:
62: CdfDocument document = (CdfDocument) data;
63: String xmlout = JavascriptUtil.escapeJavaScript(document
64: .toXml());
65:
66: String script = "dwr.gi._loadXml(\"" + xmlout + "\")";
67: OutboundVariable ov = new NonNestedOutboundVariable(script);
68:
69: outctx.put(data, ov);
70:
71: return ov;
72: } catch (MarshallException ex) {
73: throw ex;
74: } catch (Exception ex) {
75: throw new MarshallException(data.getClass(), ex);
76: }
77: }
78: }
|