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 2012/03/09 18:06:33 UTC

svn commit: r1298927 - in /lenya/branches/BRANCH_2_1_X/src/modules-core/versioning: config/cocoon-xconf/ config/cocoon-xconf/revision-module.xconf java/src/org/apache/lenya/versioning/RevisionModule.java

Author: andreas
Date: Fri Mar  9 17:06:33 2012
New Revision: 1298927

URL: http://svn.apache.org/viewvc?rev=1298927&view=rev
Log:
Adding revision module.

Added:
    lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/config/cocoon-xconf/
    lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/config/cocoon-xconf/revision-module.xconf
    lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/java/src/org/apache/lenya/versioning/RevisionModule.java

Added: lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/config/cocoon-xconf/revision-module.xconf
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/config/cocoon-xconf/revision-module.xconf?rev=1298927&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/config/cocoon-xconf/revision-module.xconf (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/config/cocoon-xconf/revision-module.xconf Fri Mar  9 17:06:33 2012
@@ -0,0 +1,24 @@
+<?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/input-modules" unless="/cocoon/input-modules/component-instance[@name = 'revision']">
+
+  <component-instance logger="core.modules.input.revision" name="revision"
+    class="org.apache.lenya.versioning.RevisionModule"/>
+  
+</xconf>

Added: lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/java/src/org/apache/lenya/versioning/RevisionModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/java/src/org/apache/lenya/versioning/RevisionModule.java?rev=1298927&view=auto
==============================================================================
--- lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/java/src/org/apache/lenya/versioning/RevisionModule.java (added)
+++ lenya/branches/BRANCH_2_1_X/src/modules-core/versioning/java/src/org/apache/lenya/versioning/RevisionModule.java Fri Mar  9 17:06:33 2012
@@ -0,0 +1,52 @@
+package org.apache.lenya.versioning;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.components.modules.input.AbstractInputModule;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.lenya.cms.publication.Document;
+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.ServletHelper;
+
+public class RevisionModule extends AbstractInputModule implements Serviceable {
+
+    private ServiceManager manager;
+
+    @Override
+    public Object getAttribute(String name, Configuration modeConf, Map objectModel)
+            throws ConfigurationException {
+        if ("current".equals(name)) {
+            final Request request = ObjectModelHelper.getRequest(objectModel);
+            return Integer.toString(getRevision(request));
+        }
+        throw new IllegalArgumentException("Unknow attribute: " + name);
+    }
+
+    protected int getRevision(final Request request) {
+        final String webappUrl = ServletHelper.getWebappURI(request);
+        try {
+            final Session session = RepositoryUtil.getSession(this.manager, request);
+            final DocumentFactory docFactory = DocumentUtil.createDocumentFactory(this.manager,
+                    session);
+            final Document document = docFactory.getFromURL(webappUrl);
+            return document.getRepositoryNode().getHistory().getLatestRevision().getNumber();
+        } catch (Exception e) {
+            throw new RuntimeException("Error getting document from webapp URL [" + webappUrl
+                    + "]: " + e.getMessage(), e);
+        }
+    }
+
+    public void service(ServiceManager mgr) throws ServiceException {
+        this.manager = mgr;
+    }
+
+}



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