Revision 1315
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/impl/coercion/CoerceToURI.java | ||
---|---|---|
26 | 26 |
import java.net.URI; |
27 | 27 |
import java.net.URISyntaxException; |
28 | 28 |
|
29 |
import org.apache.commons.lang3.StringUtils; |
|
30 |
|
|
29 | 31 |
import org.gvsig.tools.dataTypes.CoercionException; |
30 | 32 |
import org.gvsig.tools.dataTypes.DataTypesManager.Coercion; |
31 | 33 |
|
32 | 34 |
|
35 |
/** |
|
36 |
* |
|
37 |
*/ |
|
33 | 38 |
public class CoerceToURI implements Coercion { |
34 | 39 |
|
35 | 40 |
public Object coerce(Object value) throws CoercionException { |
... | ... | |
39 | 44 |
if( ! (value instanceof URI) ) { |
40 | 45 |
if( value instanceof String ) { |
41 | 46 |
try { |
42 |
value = new URI((String) value); |
|
47 |
//No est? claro comerse los espacios en blanco en el value, pero para proyectos antiguos no se nos ocurre otra solucion |
|
48 |
value = new URI(StringUtils.trim((String) value)); |
|
43 | 49 |
} catch (URISyntaxException e) { |
44 | 50 |
throw new CoercionException(e); |
45 | 51 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/persistence/impl/AbstractPersistentState.java | ||
---|---|---|
189 | 189 |
} |
190 | 190 |
|
191 | 191 |
public File getFile(String name) throws PersistenceException { |
192 |
return (File) get(name); |
|
192 |
Object obj = get(name); |
|
193 |
if(obj instanceof String){ |
|
194 |
return new File((String)obj); |
|
195 |
} |
|
196 |
return (File) obj; |
|
193 | 197 |
} |
194 | 198 |
|
195 | 199 |
public URL getURL(String name) throws PersistenceException { |
196 |
return (URL) get(name); |
|
200 |
Object obj = get(name); |
|
201 |
if(obj instanceof String){ |
|
202 |
try { |
|
203 |
return new URL((String)obj); |
|
204 |
} catch (MalformedURLException e) { |
|
205 |
throw new PersistenceException("Can't create URL from '"+(String)obj+"'", e); |
|
206 |
} |
|
207 |
} |
|
208 |
return (URL) obj; |
|
197 | 209 |
} |
198 | 210 |
|
199 | 211 |
public URI getURI(String name) throws PersistenceException { |
200 |
return (URI) get(name); |
|
212 |
Object obj = get(name); |
|
213 |
if(obj instanceof String){ |
|
214 |
try { |
|
215 |
return new URI((String)obj); |
|
216 |
} catch (URISyntaxException e) { |
|
217 |
throw new PersistenceException("Can't create URI from '"+(String)obj+"'", e); |
|
218 |
} |
|
219 |
} |
|
220 |
return (URI) obj; |
|
201 | 221 |
} |
202 | 222 |
|
203 | 223 |
public Date getDate(String name) throws PersistenceException { |
... | ... | |
893 | 913 |
} else if (field.getType() == DataTypes.URI) { |
894 | 914 |
try { |
895 | 915 |
URI value = aState.getURI(field.getName()); |
896 |
if (value.getScheme() == null || "FILE".equalsIgnoreCase(value.getScheme())) {
|
|
916 |
if ((value != null) && (value.getScheme() == null || "FILE".equalsIgnoreCase(value.getScheme()))) {
|
|
897 | 917 |
if (!value.isAbsolute() || !value.getPath().startsWith("/")) { |
898 | 918 |
File file; |
899 | 919 |
file = new File(value.getPath()); |
Also available in: Unified diff