1 /*2 * Copyright 2005 Joe Walker3 *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 at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * 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 char arrays.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 CharArrayConverter extends BaseV20Converter implements Converter34 {35 /* (non-Javadoc)36 * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)37 */38 public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException39 {40 return LocalUtil.decode(iv.getValue()).toCharArray();41 }42 43 /* (non-Javadoc)44 * @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)45 */46 public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException47 {48 String output = new String ((char[]) data);49 String escaped = JavascriptUtil.escapeJavaScript(output);50 return new SimpleOutboundVariable('\"' + escaped + '\"', outctx, true);51 }52 }53