* @throws org.wso2.carbon.registry.core.exceptions.RegistryException
* : If user is unable to open the URL connection
*/
private CollectionImpl createResourceFromFeed(Feed feed)
throws RegistryException {
CollectionImpl resource = new CollectionImpl();
org.wso2.carbon.registry.app.Properties properties =
feed.getExtension(PropertyExtensionFactory.PROPERTIES);
RemoteRegistry.createPropertiesFromExtensionElement(properties, resource);
if (feed.getAuthor() != null) {
resource.setAuthorUserName(feed.getAuthor().getName());
}
resource.setLastModified(feed.getUpdated());
String createdDate = feed.getSimpleExtension(
new QName(APPConstants.NAMESPACE, "createdTime"));
if (createdDate != null) {
resource.setCreatedTime(new Date(Long.parseLong(createdDate)));
}
String lastUpdatedUser = feed.getSimpleExtension(APPConstants.QN_LAST_UPDATER);
if (lastUpdatedUser != null) {
resource.setLastUpdaterUserName(lastUpdatedUser);
}
final Link pathLink = feed.getLink("path");
String path = (pathLink != null) ? pathLink.getHref().toString() : feed.getTitle();
path = URLDecoder.decode(path);
resource.setPath(path);
// This MUST be after path is set.
String snapshotID = feed.getSimpleExtension(APPConstants.QN_SNAPSHOT_ID);
if (snapshotID != null) {
resource.setMatchingSnapshotID(Long.parseLong(snapshotID));
}
String mediaType = feed.getSimpleExtension(new QName(APPConstants.NAMESPACE, "mediaType"));
if (mediaType != null) {
resource.setMediaType(mediaType);
}
resource.setDescription(feed.getSubtitle());
String state = feed.getSimpleExtension(new QName(APPConstants.NAMESPACE, "state"));
if (state != null && "Deleted".equals(state)) {
resource.setState(RegistryConstants.DELETED_STATE);
}
String childCount = feed.getSimpleExtension(APPConstants.QN_CHILD_COUNT);
if (childCount != null) {
resource.setChildCount(Integer.parseInt(childCount));
}
String isComments = feed.getSimpleExtension(APPConstants.QN_COMMENTS);
if (isComments != null) {
resource.setContent(getCommentsFromFeed(feed));
} else {
List entries = feed.getEntries();
if (entries != null) {
String[] childNodes = new String[entries.size()];
for (int i = 0; i < entries.size(); i++) {
Entry entry = (Entry) entries.get(i);
Link childLink = Utils.getLinkWithRel(entry, "path");
/*Link childLink = entry.getLink("path");
if (childLink == null) {
for (Link link : entry.getLinks()) {
if (link.getRel() != null &&
link.getRel().equals("path")) {
childLink = link;
break;
}
}
} */
childNodes[i] = URLDecoder.decode(childLink.getHref().toString());
}
resource.setContent(childNodes);
}
}
return resource;
}