URL url;
try {
if (sourceURL != null && sourceURL.toLowerCase().startsWith("file:")) {
String msg = "The source URL must not be file in the server's local file system";
throw new RegistryException(msg);
}
url = new URL(sourceURL);
} catch (MalformedURLException e) {
String msg = "Given source URL is not valid.";
throw new RegistryException(msg, e);
}
try {
URLConnection uc = url.openConnection();
InputStream in = uc.getInputStream();
String mediaType = metaResource.getMediaType();
if (mediaType == null) {
mediaType = uc.getContentType();
}
metaResource.setMediaType(mediaType);
metaResource.setDescription(metaResource.getDescription());
metaResource.setContentStream(in);
put(purePath, metaResource);
} catch (IOException e) {
String msg = "Could not read from the given URL: " + sourceURL;
throw new RegistryException(msg, e);
}
return purePath;
}