You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2009/08/07 15:46:47 UTC

svn commit: r802001 - in /lenya/branches/BRANCH_2_0_X/src/modules/sitetree: config/cocoon-xconf/ java/src/org/apache/lenya/cms/site/tree2/

Author: andreas
Date: Fri Aug  7 13:46:47 2009
New Revision: 802001

URL: http://svn.apache.org/viewvc?rev=802001&view=rev
Log:
Adding invariant check for sitetree revision.

Added:
    lenya/branches/BRANCH_2_0_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeRevisionVerifier.xconf
    lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeRevisionVerifier.java
Modified:
    lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SaxTreeBuilder.java
    lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java

Added: lenya/branches/BRANCH_2_0_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeRevisionVerifier.xconf
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeRevisionVerifier.xconf?rev=802001&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeRevisionVerifier.xconf (added)
+++ lenya/branches/BRANCH_2_0_X/src/modules/sitetree/config/cocoon-xconf/SiteTreeRevisionVerifier.xconf Fri Aug  7 13:46:47 2009
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<xconf xpath="/cocoon"
+  unless="/cocoon/component[@role = 'org.apache.lenya.cms.site.tree2.SiteTreeRevisionVerifier']">
+  
+  <component logger="content-janitor"
+    role="org.apache.lenya.cms.site.tree2.SiteTreeRevisionVerifier"
+    class="org.apache.lenya.cms.site.tree2.SiteTreeRevisionVerifier"/>
+	
+</xconf>

Modified: lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SaxTreeBuilder.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SaxTreeBuilder.java?rev=802001&r1=802000&r2=802001&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SaxTreeBuilder.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SaxTreeBuilder.java Fri Aug  7 13:46:47 2009
@@ -80,15 +80,16 @@
             throws SAXException {
         try {
             if (localName.equals(ELEM_SITE)) {
-                int revision = Integer.valueOf(attrs.getValue("revision")).intValue();
-                SiteTreeImpl tree = this.currentNode.getTree();
-                int latestRevision = tree.getRevision(tree.getRepositoryNode());
-                if (revision != latestRevision) {
-                    String message = "Trying to load outdated tree, revision should be "
-                            + latestRevision + " but is " + revision;
-                    getLogger().error(message);
+                final int treeRevision = Integer.valueOf(attrs.getValue("revision")).intValue();
+                final SiteTreeImpl tree = this.currentNode.getTree();
+                final int latestRevision = tree.getRevision(tree.getRepositoryNode());
+                if (treeRevision != latestRevision) {
+                    final String message = "Tree revision " + treeRevision + " does not match RC revision "
+                            + latestRevision + ". Actually this should never happen, but it is probably "
+                            + "nothing to worry about.";
+                    getLogger().warn(message);
                 }
-                tree.setRevision(revision);
+                tree.setRevision(treeRevision);
             }
             if (localName.equals(ELEM_NODE)) {
                 String id = attrs.getValue(ATTR_ID);

Modified: lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java?rev=802001&r1=802000&r2=802001&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeImpl.java Fri Aug  7 13:46:47 2009
@@ -46,6 +46,7 @@
  */
 public class SiteTreeImpl extends AbstractLogEnabled implements SiteStructure, SiteTree, Persistable {
 
+    protected static final String SITETREE_FILE_NAME = "sitetree.xml";
     private Area area;
     protected ServiceManager manager;
     private RootNode root;
@@ -73,7 +74,7 @@
     protected String getSourceUri() {
         if (this.sourceUri == null) {
             String baseUri = this.area.getPublication().getContentURI(this.area.getName());
-            this.sourceUri = baseUri + "/sitetree.xml";
+            this.sourceUri = baseUri + "/" + SITETREE_FILE_NAME;
         }
         return this.sourceUri;
     }
@@ -420,6 +421,7 @@
     }
 
     protected int getRevision() {
+        load();
         return this.revision;
     }
     

Added: lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeRevisionVerifier.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeRevisionVerifier.java?rev=802001&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeRevisionVerifier.java (added)
+++ lenya/branches/BRANCH_2_0_X/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree2/SiteTreeRevisionVerifier.java Fri Aug  7 13:46:47 2009
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.site.tree2;
+
+import org.apache.lenya.cms.observation.AbstractRepositoryListener;
+import org.apache.lenya.cms.observation.RepositoryEvent;
+import org.apache.lenya.cms.publication.Area;
+import org.apache.lenya.cms.publication.DocumentFactory;
+import org.apache.lenya.cms.publication.DocumentUtil;
+import org.apache.lenya.cms.repository.RepositoryUtil;
+import org.apache.lenya.cms.repository.Session;
+import org.apache.lenya.util.Reporting;
+
+public class SiteTreeRevisionVerifier extends AbstractRepositoryListener {
+
+    public void eventFired(RepositoryEvent event) {
+        String uri = event.getNodeUri();
+        if (uri.endsWith("/" + SiteTreeImpl.SITETREE_FILE_NAME)) {
+            // pubs/{pubId}/content/{area}/sitetree.xml
+            String[] steps = uri.split("/");
+            String pubId = steps[steps.length - 4];
+            String areaName = steps[steps.length - 2];
+            try {
+                Session session = RepositoryUtil.createSession(this.manager, null, false);
+                DocumentFactory factory = DocumentUtil.createDocumentFactory(this.manager, session);
+                Area area = factory.getPublication(pubId).getArea(areaName);
+                SiteTreeImpl tree = new SiteTreeImpl(this.manager, area, getLogger());
+                int treeRev = tree.getRevision();
+                int rcmlRev = tree.getRevision(tree.getRepositoryNode());
+                if (treeRev != rcmlRev) {
+                    throw new IllegalStateException("Tree revision " + treeRev
+                            + " does not match RCML revision " + rcmlRev + ". "
+                            + Reporting.REPORT_TO_COMMUNITY);
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org