KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > convert > StringConverter


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.convert;
17
18 import org.directwebremoting.dwrp.SimpleOutboundVariable;
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.OutboundContext;
24 import org.directwebremoting.extend.OutboundVariable;
25 import org.directwebremoting.util.JavascriptUtil;
26 import org.directwebremoting.util.LocalUtil;
27
28 /**
29  * An implementation of Converter for Strings.
30  * @author Joe Walker [joe at eireneh dot com]
31  * @version $Id: StringConverter.java,v 1.2 2004/11/04 15:54:07 joe_walker Exp $
32  */

33 public class StringConverter extends BaseV20Converter implements Converter
34 {
35     /* (non-Javadoc)
36      * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
37      */

38     public Object JavaDoc convertInbound(Class JavaDoc paramType, InboundVariable iv, InboundContext inctx) throws MarshallException
39     {
40         return LocalUtil.decode(iv.getValue());
41     }
42
43     /* (non-Javadoc)
44      * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
45      */

46     public OutboundVariable convertOutbound(Object JavaDoc data, OutboundContext outctx) throws MarshallException
47     {
48         String JavaDoc escaped = JavascriptUtil.escapeJavaScript(data.toString());
49         return new SimpleOutboundVariable('\"' + escaped + '\"', outctx, true);
50     }
51 }
52
Popular Tags