public static MetadataBean populate(String purePath, UserRegistry registry) throws Exception {
ResourcePath path = new ResourcePath(purePath);
Resource resource = registry.get(path.getPathWithVersion());
MetadataBean bean = new MetadataBean();
bean.setAuthor(resource.getAuthorUserName());
bean.setCollection(resource instanceof Collection);
bean.setDescription(resource.getDescription());
bean.setLastUpdater(resource.getLastUpdaterUserName());
bean.setMediaType(resource.getMediaType());
bean.setPath(resource.getPath());
bean.setFormattedCreatedOn(CommonUtil.formatDate(resource.getCreatedTime()));
bean.setFormattedLastModified(CommonUtil.formatDate(resource.getLastModified()));
bean.setActiveResourcePath(path.getPath());
if (path.parameterExists("version")) {
bean.setVersionView(true);
bean.setPermalink(path.getCompletePath());
} else {
bean.setVersionView(false);
bean.setPermalink(resource.getPermanentPath());
}
if ((resource.getProperty("registry.link") != null) || (resource.getProperty("registry.mount") != null)) {
bean.setPermalink("hide");
}
bean.setNavigatablePaths(constructNavigatablePaths(path.getCompletePath()));
bean.setContentPath(path.getCompletePath());
bean.setServerBaseURL("carbon registry base URL.");
String versionPath;
if (path.parameterExists("version")) {
versionPath = path.getPath() + RegistryConstants.URL_SEPARATOR + "version" +
RegistryConstants.URL_PARAMETER_SEPARATOR + path.getParameterValue("version");
} else {
versionPath = path.getPath();
}
bean.setPathWithVersion(versionPath);
String userName = registry.getUserName();
AuthorizationManager authorizer = registry.getUserRealm().getAuthorizationManager();
boolean putAllowed = authorizer.
isUserAuthorized(userName, path.getPath(), ActionConstants.PUT);
bean.setPutAllowed(putAllowed);
return bean;
}