[Yanel-commits] rev 57258 - public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources
michi at wyona.com
michi at wyona.com
Thu Mar 10 11:25:00 CET 2011
Author: michi
Date: 2011-03-10 11:25:00 +0100 (Thu, 10 Mar 2011)
New Revision: 57258
Modified:
public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
Log:
commentable implemented
Modified: public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java
===================================================================
--- public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java 2011-03-10 10:24:21 UTC (rev 57257)
+++ public/yanel/trunk/src/resources/xml/src/java/org/wyona/yanel/impl/resources/XMLResource.java 2011-03-10 10:25:00 UTC (rev 57258)
@@ -38,6 +38,7 @@
import org.wyona.yanel.core.Path;
import org.wyona.yanel.core.Resource;
import org.wyona.yanel.core.api.attributes.AnnotatableV1;
+import org.wyona.yanel.core.api.attributes.CommentableV1;
import org.wyona.yanel.core.api.attributes.CreatableV2;
import org.wyona.yanel.core.api.attributes.IntrospectableV1;
import org.wyona.yanel.core.api.attributes.ModifiableV2;
@@ -46,6 +47,7 @@
import org.wyona.yanel.core.api.attributes.ViewableV1;
import org.wyona.yanel.core.api.attributes.ViewableV2;
import org.wyona.yanel.core.api.attributes.WorkflowableV1;
+import org.wyona.yanel.core.attributes.commentable.CommentManagerV1;
import org.wyona.yanel.core.attributes.translatable.TranslationException;
import org.wyona.yanel.core.attributes.translatable.TranslationManager;
import org.wyona.yanel.core.attributes.versionable.RevisionInformation;
@@ -64,7 +66,7 @@
/**
* Generic resource handling XML data and transforming it using XSLT, etc.
*/
-public class XMLResource extends BasicXMLResource implements ModifiableV2, VersionableV2, CreatableV2, IntrospectableV1, TranslatableV1, WorkflowableV1, AnnotatableV1 {
+public class XMLResource extends BasicXMLResource implements ModifiableV2, VersionableV2, CreatableV2, IntrospectableV1, TranslatableV1, WorkflowableV1, AnnotatableV1, CommentableV1 {
private static Logger log = Logger.getLogger(XMLResource.class);
@@ -90,7 +92,6 @@
* Get initial content as XML
*/
private InputStream getContentXML(Repository repo, String yanelPath, String revisionName) throws Exception {
- // TODO: Add annotations to XML root element using a namespace
if (yanelPath != null) {
if (log.isDebugEnabled()) log.debug("Yanel Path: " + yanelPath);
@@ -148,6 +149,37 @@
} else {
node = repo.getNode(getPath());
}
+
+ // TODO: Add annotations to XML root element using a namespace
+
+ String checkComments = getResourceConfigProperty("check-comments");
+ if (checkComments != null && checkComments.equals("true")) {
+ CommentManagerV1 cMan = getCommentManager();
+ if (cMan.hasComments(getRealm(), getPath())) {
+ // TODO: Differentiate between users who have access to all comments and only public comments
+ //java.util.List comments = cMan.getPublicComments(realm, getPath()).getComments();
+ java.util.List comments = cMan.getAllComments(realm, getPath()).getComments();
+ log.warn("DEBUG: Resource '" + getPath() + "' has comments: " + comments.size());
+ // TODO: Add comments to XML root element using a namespace
+ Document mainDoc = XMLHelper.readDocument(node.getInputStream());
+ String aggregateComments = getResourceConfigProperty("aggregate-comments");
+ if (aggregateComments != null && aggregateComments.equals("true")) {
+ Document commentsDoc = org.wyona.yarep.util.YarepXMLBindingUtil.getDocFromJAXBDataObject(cMan.getAllComments(realm, getPath()));
+ log.warn("DEBUG: Aggregate comments ...");
+ //org.w3c.dom.Node importedNode = mainDoc.getDocumentElement().getOwnerDocument().importNode(commentsDoc.getDocumentElement(), true);
+ //mainDoc.getDocumentElement().appendChild(importedNode);
+ //org.w3c.dom.Node importedNode = mainDoc.importNode(commentsDoc.getDocumentElement(), true);
+ mainDoc.getDocumentElement().appendChild(mainDoc.importNode(commentsDoc.getDocumentElement(), true));
+ } else {
+ XMLHelper.appendFragment(mainDoc.getDocumentElement(), "<comments:has-comments xmlns:comments=\"http://www.wyona.org/yanel/comments/1.0\">" + comments.size() + "</comments:has-comments>");
+ }
+ return XMLHelper.getInputStream(mainDoc, false, true, null);
+ } else {
+ log.debug("Resource '" + getPath() + "' has no comments yet.");
+ }
+ } else {
+ //log.debug("Do not aggregate comments");
+ }
return node.getInputStream();
}
@@ -774,4 +806,11 @@
}
getRealm().getRepository().getNode(getPath()).setProperty("annotations", sb.toString());
}
+
+ /**
+ * @see org.wyona.yanel.core.api.attributes.CommentableV1#getCommentManager()
+ */
+ public CommentManagerV1 getCommentManager() throws Exception {
+ return new org.wyona.yanel.impl.comments.CommentManagerV1Impl();
+ }
}
More information about the Yanel-commits
mailing list