String path = resource.getPath();
final Registry registry;
try {
registry = getSecureRegistry(request);
} catch (RegistryException e) {
throw new ResponseContextException(new StackTraceResponseContext(e));
}
final String[] splitPath = (String[]) request.getAttribute(RequestContext.Scope.REQUEST,
"splitPath");
final String text = content.getText();
if (splitPath != null) {
if ("comments".equals(splitPath[1])) {
// Comment post
org.wso2.carbon.registry.core.Comment comment =
new org.wso2.carbon.registry.core.Comment(text);
try {
registry.editComment(path, text);
String commentPath = registry.addComment(path, comment);
comment.setPath(commentPath);
} catch (RegistryException e) {
throw new ResponseContextException(new StackTraceResponseContext(e));
}
return comment;
}
}
String name = request.getSlug();
if (name == null) {
if (title != null) {
// Following code replaces spaces with "_". Commenting out Sanitizer.sanitize and
// doing the same thing other
// replacing spaces with "_".
// slug = Sanitizer.sanitize(slug, "-", sanitizePattern);
name = title.replaceAll(sanitizePattern, "-");
} else {
name = generateResourceName();
}
} else {
// name = Sanitizer.sanitize(name, "-", sanitizePattern);
}
if (!path.endsWith("/")) {
path += "/";
}
if (APPConstants.IMPORT_MEDIA_TYPE.equals(request.getContentType().toString())) {
// This is an import.
String importURL = request.getParameter("importURL");
String suggestedPath = request.getSlug();
String location;
try {
final Registry secureRegistry = getSecureRegistry(request);
location = secureRegistry.importResource(suggestedPath,
importURL,
new ResourceImpl());
return secureRegistry.get(location);
} catch (RegistryException e) {
throw new ResponseContextException(new StackTraceResponseContext(e));
}
}
Entry entry;
try {
entry = (Entry) request.getDocument().getRoot();
} catch (IOException e) {
throw new ResponseContextException(new StackTraceResponseContext(e));
}
Resource ret;
try {
ret = registry.newResource();
fillResourceFromEntry(entry, ret);
registry.put(path + name, ret);
} catch (Exception e) {
throw new ResponseContextException(new StackTraceResponseContext(e));
}
((ResourceImpl) ret).setPath(path + name);
return ret;
}