collection.setAuthorUserName(username);
return collection;
}
public Resource get(String path) throws RegistryException {
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse;
String encodedPath;
// If the request is to fetch all comments for a given path, then encode ":" as well to
// avoid confusion with versioned paths.
if (path.endsWith(RegistryConstants.URL_SEPARATOR + APPConstants.PARAMETER_COMMENTS)) {
encodedPath = encodeURL(path);
if (encodedPath.indexOf(";version:") > -1) {
int index = encodedPath.lastIndexOf(";version:");
encodedPath = encodedPath.substring(0, index).replace(":", "%3A") +
encodedPath.substring(index);
} else {
encodedPath = encodedPath.replace(":", "%3A");
}
} else {
encodedPath = encodeURL(path);
}
if (!cache.isResourceCached(path)) {
clientResponse =
abderaClient.get(baseURI + "/atom" + encodedPath, getAuthorization());
} else {
clientResponse =
abderaClient.get(baseURI + "/atom" + encodedPath,
getAuthorizationForCaching(path));
}
if (clientResponse.getType() == Response.ResponseType.CLIENT_ERROR ||
clientResponse.getType() == Response.ResponseType.SERVER_ERROR) {
if (clientResponse.getStatus() == 404) {
abderaClient.teardown();
throw new ResourceNotFoundException(path);
}
abderaClient.teardown();
throw new RegistryException(clientResponse.getStatusText());
}
if (clientResponse.getStatus() == 304) {
abderaClient.teardown();
/*do caching here */
log.debug(
"Cached resource returned since no modification has been done on the resource");
return cache.getCachedResource(path);
}
String eTag = clientResponse.getHeader("ETag");
Element introspection = clientResponse.getDocument().getRoot();
ResourceImpl resource;
if (introspection instanceof Feed) {
// This is a collection
Feed feed = (Feed) introspection;
String state = feed.getSimpleExtension(new QName(APPConstants.NAMESPACE, "state"));
if (state != null && state.equals("Deleted")) {
abderaClient.teardown();
throw new ResourceNotFoundException(path);
}
resource = createResourceFromFeed(feed);
} else {
Entry entry = (Entry) introspection;
resource = createResourceFromEntry(entry);
}
/* if the resource is not Get before add it to cache before adding it check the max cache
or if the resource is modified then new resource is replacing the current resource in the cache
* size configured in registry.xml */
if (!cache.cacheResource(path, resource, eTag,
RegistryConstants.MAX_REG_CLIENT_CACHE_SIZE)) {
log.debug("Max Cache size exceeded the configured Cache size");
}
abderaClient.teardown();
// resource.setPath(path);
return resource;
}