1 43 44 package org.jfree.xml.factory.objects; 45 46 import java.net.URL ; 47 48 import org.jfree.io.IOUtils; 49 import org.jfree.util.Log; 50 import org.jfree.xml.Parser; 51 52 57 public class URLObjectDescription extends AbstractObjectDescription { 58 59 62 public URLObjectDescription() { 63 super(URL .class); 64 setParameterDefinition("value", String .class); 65 } 66 67 72 public Object createObject() { 73 final String o = (String ) getParameter("value"); 74 final String baseURL = getConfig().getConfigProperty(Parser.CONTENTBASE_KEY); 75 try { 76 try { 77 final URL bURL = new URL (baseURL); 78 return new URL (bURL, o); 79 } 80 catch (Exception e) { 81 Log.warn("BaseURL is invalid: ", e); 82 } 83 return new URL (o); 84 } 85 catch (Exception e) { 86 return null; 87 } 88 } 89 90 97 public void setParameterFromObject(final Object o) throws ObjectFactoryException { 98 if (!(o instanceof URL )) { 99 throw new ObjectFactoryException("Is no instance of java.net.URL"); 100 } 101 102 final URL comp = (URL ) o; 103 final String baseURL = getConfig().getConfigProperty(Parser.CONTENTBASE_KEY); 104 try { 105 final URL bURL = new URL (baseURL); 106 setParameter("value", IOUtils.getInstance().createRelativeURL(comp, bURL)); 107 } 108 catch (Exception e) { 109 Log.warn("BaseURL is invalid: ", e); 110 } 111 setParameter("value", comp.toExternalForm()); 112 } 113 114 } 115 | Popular Tags |