1 16 package org.directwebremoting.convert; 17 18 import java.net.MalformedURLException ; 19 import java.net.URL ; 20 21 import org.directwebremoting.dwrp.SimpleOutboundVariable; 22 import org.directwebremoting.extend.Converter; 23 import org.directwebremoting.extend.InboundContext; 24 import org.directwebremoting.extend.InboundVariable; 25 import org.directwebremoting.extend.MarshallException; 26 import org.directwebremoting.extend.OutboundContext; 27 import org.directwebremoting.extend.OutboundVariable; 28 import org.directwebremoting.util.JavascriptUtil; 29 import org.directwebremoting.util.LocalUtil; 30 import org.directwebremoting.util.Logger; 31 32 37 public class URLConverter extends BaseV20Converter implements Converter 38 { 39 42 public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws MarshallException 43 { 44 String urlString = LocalUtil.decode(iv.getValue()); 45 try 46 { 47 return new URL (urlString); 48 } 49 catch (MalformedURLException ex) 50 { 51 log.warn("Failed to create URL from string '" + urlString + "'. Returning null"); 52 return null; 53 } 54 } 55 56 59 public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException 60 { 61 URL url = (URL ) data; 62 String escaped = JavascriptUtil.escapeJavaScript(url.toExternalForm()); 63 return new SimpleOutboundVariable('\"' + escaped + '\"', outctx, true); 64 } 65 66 69 private static final Logger log = Logger.getLogger(URLConverter.class); 70 } 71
| Popular Tags
|