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 2007/01/04 16:05:20 UTC
svn commit: r492591 - in /lenya/trunk/src:
java/org/apache/lenya/cms/repository/
modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/
modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/
modules-core/usecase/java/src/or...
Author: andreas
Date: Thu Jan 4 07:05:19 2007
New Revision: 492591
URL: http://svn.apache.org/viewvc?view=rev&rev=492591
Log:
Refactoring source node classes, attach repo session to http session instead of request (avoid clash because session is also stored in usecase proxy)
Added:
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/ModifiableMetaDataHandler.java
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java
lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java
lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseProxy.java
lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/MetaSourceWrapper.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java
lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java
lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml
Modified: lenya/trunk/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repository/RepositoryUtil.java Thu Jan 4 07:05:19 2007
@@ -35,11 +35,12 @@
*/
public static Session getSession(ServiceManager manager, Request request)
throws RepositoryException {
- Session session = (Session) request.getAttribute(Session.class.getName());
+ org.apache.cocoon.environment.Session cocoonSession = request.getSession();
+ Session session = (Session) cocoonSession.getAttribute(Session.class.getName());
if (session == null) {
Identity identity = getIdentity(request);
session = createSession(manager, identity);
- request.setAttribute(Session.class.getName(), session);
+ cocoonSession.setAttribute(Session.class.getName(), session);
} else if (session.getIdentity() == null) {
Identity identity = getIdentity(request);
if (identity != null) {
Modified: lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java (original)
+++ lenya/trunk/src/modules-core/observation-impl/java/test/org/apache/lenya/cms/observation/ObservationTest.java Thu Jan 4 07:05:19 2007
@@ -64,6 +64,9 @@
testChanged(doc, docListener);
testChanged(doc, allListener);
+ testMetaDataChanged(doc, docListener);
+ testMetaDataChanged(doc, allListener);
+
}
finally {
if (registry != null) {
@@ -78,6 +81,15 @@
listener.reset();
NamespaceHelper xml = new NamespaceHelper("http://apache.org/lenya/test", "", "test");
SourceUtil.writeDOM(xml.getDocument(), doc.getSourceURI(), getManager());
+
+ assertFalse(listener.wasChanged());
+ doc.getRepositoryNode().getSession().commit();
+ Thread.currentThread().sleep(100);
+ assertTrue(listener.wasChanged());
+ }
+
+ protected void testMetaDataChanged(Document doc, TestListener listener) throws Exception {
+ listener.reset();
String mimeType = doc.getMimeType();
doc.setMimeType("");
Modified: lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseProxy.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseProxy.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseProxy.java (original)
+++ lenya/trunk/src/modules-core/usecase-impl/java/src/org/apache/lenya/cms/usecase/UsecaseProxy.java Thu Jan 4 07:05:19 2007
@@ -22,8 +22,6 @@
import java.util.Map;
import java.util.Set;
-import org.apache.lenya.cms.repository.Session;
-
/**
* Proxy which holds the parameters of a usecase. It is used to restore the usecase after the
* flowscript is re-entered and to pass the usecase parameters to a JX template.
@@ -36,7 +34,6 @@
private String name;
private String sourceUrl;
private UsecaseView view;
- private Session session;
/**
* Ctor.
@@ -54,7 +51,6 @@
this.infoMessages = usecase.getInfoMessages();
this.sourceUrl = usecase.getSourceURL();
this.view = usecase.getView();
- this.session = usecase.getSession();
}
/**
@@ -62,7 +58,6 @@
* @param usecase The usecase.
*/
public void setup(Usecase usecase) {
- usecase.setSession(this.session);
usecase.setName(this.name);
usecase.setSourceURL(this.sourceUrl);
usecase.setView(this.view);
Modified: lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java (original)
+++ lenya/trunk/src/modules-core/usecase/java/src/org/apache/lenya/cms/usecase/Usecase.java Thu Jan 4 07:05:19 2007
@@ -196,11 +196,6 @@
Session getSession();
/**
- * @param session The repository session.
- */
- void setSession(Session session);
-
- /**
* @param enabled if the transaction should be committed. Set to <code>false</code> for tests.
*/
void setCommitEnabled(boolean enabled);
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/MetaSourceWrapper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/MetaSourceWrapper.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/MetaSourceWrapper.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/MetaSourceWrapper.java Thu Jan 4 07:05:19 2007
@@ -19,13 +19,14 @@
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataException;
import org.apache.lenya.cms.metadata.MetaDataOwner;
/**
* Provides access to a meta data source.
*/
-public class MetaSourceWrapper extends SourceWrapper {
+public class MetaSourceWrapper extends SourceWrapper implements MetaDataOwner {
protected static final String LENYA_META_SUFFIX = "meta";
@@ -36,26 +37,20 @@
* @param manager
* @param logger
*/
- public MetaSourceWrapper(SourceNode node, String sourceURI, ServiceManager manager, Logger logger) {
+ public MetaSourceWrapper(SourceNode node, String sourceURI, ServiceManager manager,
+ Logger logger) {
super(node, sourceURI + "." + LENYA_META_SUFFIX, manager, logger);
+ this.handler = new ModifiableMetaDataHandler(manager, this);
}
-
- private SourceNodeMetaDataHandler metaDataHandler = null;
- protected SourceNodeMetaDataHandler getMetaDataHandler() {
- if (this.metaDataHandler == null) {
- this.metaDataHandler = new SourceNodeMetaDataHandler(this.manager, getRealSourceUri());
- }
- return this.metaDataHandler;
+ private ModifiableMetaDataHandler handler;
+
+ public MetaData getMetaData(String namespaceUri) throws MetaDataException {
+ return this.handler.getMetaData(namespaceUri);
}
- /**
- * @return All supported meta data namespace URIs.
- * @throws MetaDataException if an error occurs.
- * @see MetaDataOwner#getMetaDataNamespaceUris()
- */
public String[] getMetaDataNamespaceUris() throws MetaDataException {
- return getMetaDataHandler().getMetaDataNamespaceUris();
+ return this.handler.getMetaDataNamespaceUris();
}
-
+
}
Added: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/ModifiableMetaDataHandler.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/ModifiableMetaDataHandler.java?view=auto&rev=492591
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/ModifiableMetaDataHandler.java (added)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/ModifiableMetaDataHandler.java Thu Jan 4 07:05:19 2007
@@ -0,0 +1,116 @@
+/*
+ * 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.repository;
+
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.lenya.cms.metadata.MetaDataException;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.w3c.dom.Element;
+
+/**
+ * Modifiable meta data handler.
+ */
+public class ModifiableMetaDataHandler extends SourceNodeMetaDataHandler {
+
+ private MetaSourceWrapper sourceWrapper;
+
+ /**
+ * @param manager The service manager.
+ * @param sourceWrapper The soure wrapper.
+ */
+ public ModifiableMetaDataHandler(ServiceManager manager, MetaSourceWrapper sourceWrapper) {
+ super(manager, sourceWrapper.getRealSourceUri());
+ this.sourceWrapper = sourceWrapper;
+ }
+
+
+ protected void saveMetaData() throws MetaDataException {
+ try {
+ NamespaceHelper helper = new NamespaceHelper(META_DATA_NAMESPACE, "", ELEMENT_METADATA);
+ Collection namespaces = this.namespace2metamap.keySet();
+ for (Iterator i = namespaces.iterator(); i.hasNext();) {
+ String namespace = (String) i.next();
+
+ Element setElement = helper.createElement(ELEMENT_SET);
+ setElement.setAttribute(ATTRIBUTE_NAMESPACE, namespace);
+ helper.getDocument().getDocumentElement().appendChild(setElement);
+
+ Map map = getMetaDataMap(namespace);
+ Collection keys = map.keySet();
+ for (Iterator keyIterator = keys.iterator(); keyIterator.hasNext();) {
+ String key = (String) keyIterator.next();
+
+ Element elementElement = helper.createElement(ELEMENT_ELEMENT);
+ elementElement.setAttribute(ATTRIBUTE_KEY, key);
+
+ List values = (List) map.get(key);
+ for (Iterator valueIterator = values.iterator(); valueIterator.hasNext();) {
+ String value = (String) valueIterator.next();
+ if (!value.equals("")) {
+ Element valueElement = helper.createElement(ELEMENT_VALUE, value);
+ elementElement.appendChild(valueElement);
+ }
+ }
+ if (elementElement.hasChildNodes()) {
+ setElement.appendChild(elementElement);
+ }
+ }
+ }
+ OutputStream oStream = this.sourceWrapper.getOutputStream();
+ DocumentHelper.writeDocument(helper.getDocument(), oStream);
+ if (oStream != null) {
+ oStream.flush();
+ try {
+ oStream.close();
+ } catch (Throwable t) {
+ throw new RuntimeException("Could not write meta XML: ", t);
+ }
+ }
+ } catch (Exception e) {
+ throw new MetaDataException(e);
+ }
+ }
+
+ protected void addValue(String namespaceUri, String key, String value) throws MetaDataException {
+ List values = getValueList(namespaceUri, key);
+ values.add(value);
+ saveMetaData();
+ }
+
+ protected void removeAllValues(String namespaceUri, String key) throws MetaDataException {
+ List values = getValueList(namespaceUri, key);
+ values.clear();
+ saveMetaData();
+ }
+
+
+ protected void setValue(String namespaceUri, String key, String value) throws MetaDataException {
+ List values = getValueList(namespaceUri, key);
+ values.clear();
+ values.add(value);
+ saveMetaData();
+ }
+
+}
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNode.java Thu Jan 4 07:05:19 2007
@@ -373,7 +373,7 @@
}
public MetaData getMetaData(String namespaceUri) throws MetaDataException {
- return this.metaSource.getMetaDataHandler().getMetaData(namespaceUri);
+ return this.metaSource.getMetaData(namespaceUri);
}
public boolean exists() throws RepositoryException {
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaData.java Thu Jan 4 07:05:19 2007
@@ -42,16 +42,17 @@
* @param handler The meta data handler.
* @param manager The service manager.
*/
- public SourceNodeMetaData(String namespaceUri, SourceNodeMetaDataHandler handler, ServiceManager manager) {
+ public SourceNodeMetaData(String namespaceUri, SourceNodeMetaDataHandler handler,
+ ServiceManager manager) {
this.namespaceUri = namespaceUri;
this.handler = handler;
this.manager = manager;
}
-
+
protected String getNamespaceUri() {
return this.namespaceUri;
}
-
+
protected SourceNodeMetaDataHandler getHandler() {
return this.handler;
}
@@ -107,8 +108,7 @@
public void setValue(String key, String value) throws MetaDataException {
checkKey(key);
- getHandler().removeAllValues(this.namespaceUri, key);
- addValue(key, value);
+ getHandler().setValue(this.namespaceUri, key, value);
}
public void addValue(String key, String value) throws MetaDataException {
@@ -130,8 +130,7 @@
for (int j = 0; j < values.length; j++) {
addValue(key, values[j]);
}
- }
- else if (elements[i].getActionOnCopy() == Element.ONCOPY_DELETE) {
+ } else if (elements[i].getActionOnCopy() == Element.ONCOPY_DELETE) {
String key = elements[i].getName();
removeAllValues(key);
}
@@ -160,7 +159,7 @@
public long getLastModified() throws MetaDataException {
try {
- return getHandler().getMetaLastModified();
+ return getHandler().getLastModified();
} catch (RepositoryException e) {
throw new MetaDataException(e);
}
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeMetaDataHandler.java Thu Jan 4 07:05:19 2007
@@ -18,16 +18,12 @@
package org.apache.lenya.cms.repository;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.metadata.ElementSet;
import org.apache.lenya.cms.metadata.MetaData;
@@ -47,21 +43,17 @@
public class SourceNodeMetaDataHandler implements MetaDataOwner {
private ServiceManager manager;
- private String metaSourceUri;
+ private String sourceUri;
/**
* @param manager The service manager.
- * @param sourceUri The soure uri.
+ * @param sourceUri The soure URI.
*/
public SourceNodeMetaDataHandler(ServiceManager manager, String sourceUri) {
this.manager = manager;
- this.metaSourceUri = sourceUri;
+ this.sourceUri = sourceUri;
}
- protected String getMetaSourceUri() {
- return this.metaSourceUri;
- }
-
private Map namespace2metadata = new HashMap();
public MetaData getMetaData(String namespaceUri) throws MetaDataException {
@@ -89,7 +81,7 @@
return meta;
}
- private Map namespace2metamap = null;
+ protected Map namespace2metamap = null;
protected Map getMetaDataMap(String namespaceUri) throws MetaDataException {
if (this.namespace2metamap == null) {
@@ -119,8 +111,8 @@
try {
this.namespace2metamap = new HashMap();
- if (SourceUtil.exists(getMetaSourceUri(), this.manager)) {
- Document xml = SourceUtil.readDOM(getMetaSourceUri(), this.manager);
+ if (SourceUtil.exists(this.sourceUri, this.manager)) {
+ Document xml = SourceUtil.readDOM(this.sourceUri, this.manager);
if (!xml.getDocumentElement().getNamespaceURI().equals(META_DATA_NAMESPACE)) {
loadLegacyMetaData(xml);
} else {
@@ -211,45 +203,8 @@
}
- protected void saveMetaData() throws MetaDataException {
- try {
- NamespaceHelper helper = new NamespaceHelper(META_DATA_NAMESPACE, "", ELEMENT_METADATA);
- Collection namespaces = this.namespace2metamap.keySet();
- for (Iterator i = namespaces.iterator(); i.hasNext();) {
- String namespace = (String) i.next();
-
- Element setElement = helper.createElement(ELEMENT_SET);
- setElement.setAttribute(ATTRIBUTE_NAMESPACE, namespace);
- helper.getDocument().getDocumentElement().appendChild(setElement);
-
- Map map = getMetaDataMap(namespace);
- Collection keys = map.keySet();
- for (Iterator keyIterator = keys.iterator(); keyIterator.hasNext();) {
- String key = (String) keyIterator.next();
-
- Element elementElement = helper.createElement(ELEMENT_ELEMENT);
- elementElement.setAttribute(ATTRIBUTE_KEY, key);
-
- List values = (List) map.get(key);
- for (Iterator valueIterator = values.iterator(); valueIterator.hasNext();) {
- String value = (String) valueIterator.next();
- if (!value.equals("")) {
- Element valueElement = helper.createElement(ELEMENT_VALUE, value);
- elementElement.appendChild(valueElement);
- }
- }
- if (elementElement.hasChildNodes()) {
- setElement.appendChild(elementElement);
- }
- }
- }
- SourceUtil.writeDOM(helper.getDocument(), getMetaSourceUri(), this.manager);
- } catch (Exception e) {
- throw new MetaDataException(e);
- }
- }
-
- protected String[] getValues(String namespaceUri, String key, int revisionNumber) throws MetaDataException {
+ protected String[] getValues(String namespaceUri, String key, int revisionNumber)
+ throws MetaDataException {
List values = getValueList(namespaceUri, key);
return (String[]) values.toArray(new String[values.size()]);
}
@@ -270,15 +225,15 @@
}
protected void addValue(String namespaceUri, String key, String value) throws MetaDataException {
- List values = getValueList(namespaceUri, key);
- values.add(value);
- saveMetaData();
+ throw new IllegalStateException("Operation not supported");
}
protected void removeAllValues(String namespaceUri, String key) throws MetaDataException {
- List values = getValueList(namespaceUri, key);
- values.clear();
- saveMetaData();
+ throw new IllegalStateException("Operation not supported");
+ }
+
+ protected void setValue(String namespaceUri, String key, String value) throws MetaDataException {
+ throw new IllegalStateException("Operation not supported");
}
public String[] getMetaDataNamespaceUris() throws MetaDataException {
@@ -294,43 +249,12 @@
}
}
}
-
- private long lastModified;
- /**
- * @return the last modified date of the meta data
- * @throws RepositoryException if an error occurs.
- */
- public long getMetaLastModified() throws RepositoryException {
- SourceResolver resolver = null;
- Source source = null;
+ protected long getLastModified() throws RepositoryException {
try {
- resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
- source = resolver.resolveURI(getMetaSourceUri());
-
- long sourceLastModified;
-
- if (source.exists()) {
- sourceLastModified = source.getLastModified();
- if (sourceLastModified > this.lastModified) {
- this.lastModified = sourceLastModified;
- }
- } else if (this.lastModified == -1) {
- throw new RepositoryException("The source [" + getMetaSourceUri()
- + "] does not exist!");
- }
-
- return this.lastModified;
-
+ return SourceUtil.getLastModified(this.sourceUri, this.manager);
} catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (resolver != null) {
- if (source != null) {
- resolver.release(source);
- }
- this.manager.release(resolver);
- }
+ throw new RepositoryException(e);
}
}
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceNodeRCML.java Thu Jan 4 07:05:19 2007
@@ -51,7 +51,7 @@
public class SourceNodeRCML implements RCML {
private SourceNode node;
- private Document document = null;
+ private Document xml = null;
private boolean dirty = false;
private int maximalNumberOfEntries = 5;
@@ -98,13 +98,6 @@
checkOutIn(SourceNodeRCML.ci, RevisionController.systemUsername, lastModified, false);
write();
- } else {
- try {
- this.document = SourceUtil.readDOM(getRcmlSourceUri(), this.manager);
- } catch (Exception e) {
- throw new RevisionControlException("Could not read RC file [" + getRcmlSourceUri()
- + "]");
- }
}
}
@@ -119,7 +112,7 @@
* @throws ParserConfigurationException
*/
public void initDocument() throws ParserConfigurationException {
- this.document = DocumentHelper.createDocument(null, "XPSRevisionControl", null);
+ this.xml = DocumentHelper.createDocument(null, "XPSRevisionControl", null);
}
/**
@@ -140,11 +133,11 @@
* @throws Exception if an error occurs
*/
public void write() throws Exception {
- if (this.document == null) {
+ if (getDocument() == null) {
throw new IllegalStateException("The XML for RC source [" + getRcmlSourceUri()
+ "] is null!");
}
- SourceUtil.writeDOM(this.document, getRcmlSourceUri(), this.manager);
+ SourceUtil.writeDOM(getDocument(), getRcmlSourceUri(), this.manager);
clearDirty();
}
@@ -160,6 +153,8 @@
*/
public void checkOutIn(short type, String identity, long time, boolean backup)
throws IOException, Exception {
+
+ Document doc = getDocument();
if (identity == null) {
throw new IllegalArgumentException("The identity must not be null!");
@@ -170,13 +165,13 @@
+ ".checkOutIn(): No such type");
}
- Element identityElement = this.document.createElement("Identity");
- identityElement.appendChild(this.document.createTextNode(identity));
- Element timeElement = this.document.createElement("Time");
- timeElement.appendChild(this.document.createTextNode("" + time));
+ Element identityElement = doc.createElement("Identity");
+ identityElement.appendChild(doc.createTextNode(identity));
+ Element timeElement = doc.createElement("Time");
+ timeElement.appendChild(doc.createTextNode("" + time));
String elementName = (String) ELEMENTS.get(new Short(type));
- Element checkOutElement = this.document.createElement(elementName);
+ Element checkOutElement = doc.createElement(elementName);
checkOutElement.appendChild(identityElement);
checkOutElement.appendChild(timeElement);
@@ -188,17 +183,17 @@
version = latestEntry.getVersion();
}
version++;
- Element versionElement = this.document.createElement("Version");
- versionElement.appendChild(this.document.createTextNode("" + version));
+ Element versionElement = doc.createElement("Version");
+ versionElement.appendChild(doc.createTextNode("" + version));
checkOutElement.appendChild(versionElement);
}
if (backup) {
- Element backupElement = this.document.createElement(ELEMENT_BACKUP);
+ Element backupElement = doc.createElement(ELEMENT_BACKUP);
checkOutElement.appendChild(backupElement);
}
- Element root = this.document.getDocumentElement();
+ Element root = doc.getDocumentElement();
root.insertBefore(checkOutElement, root.getFirstChild());
setDirty();
@@ -222,6 +217,23 @@
write();
}
}
+
+ private long lastModified = 0;
+
+ protected Document getDocument() throws RevisionControlException {
+ try {
+ String uri = getRcmlSourceUri();
+ long sourceLastModified = SourceUtil.getLastModified(uri, manager);
+ if (this.xml == null || sourceLastModified > this.lastModified) {
+ this.xml = SourceUtil.readDOM(getRcmlSourceUri(), this.manager);
+ this.lastModified = sourceLastModified;
+ }
+ } catch (Exception e) {
+ throw new RevisionControlException("Could not read RC file [" + getRcmlSourceUri()
+ + "]");
+ }
+ return this.xml;
+ }
/**
* get the latest check out
@@ -229,7 +241,7 @@
* @throws Exception if an error occurs
*/
public CheckOutEntry getLatestCheckOutEntry() throws Exception {
- Element parent = this.document.getDocumentElement();
+ Element parent = getDocument().getDocumentElement();
Node identity = null;
Node time = null;
String rcIdentity = null;
@@ -254,7 +266,8 @@
* @throws Exception if an error occurs
*/
public CheckInEntry getLatestCheckInEntry() throws Exception {
- Element parent = this.document.getDocumentElement();
+ Document doc = getDocument();
+ Element parent = doc.getDocumentElement();
Node identity = XPathAPI.selectSingleNode(parent,
"/XPSRevisionControl/CheckIn[1]/Identity/text()");
@@ -304,7 +317,8 @@
* @throws Exception if an error occurs
*/
public Vector getEntries() throws Exception {
- Element parent = this.document.getDocumentElement();
+ Document doc = getDocument();
+ Element parent = doc.getDocumentElement();
NodeList entries = XPathAPI.selectNodeList(parent,
"/XPSRevisionControl/CheckOut|/XPSRevisionControl/CheckIn");
Vector RCMLEntries = new Vector();
@@ -338,7 +352,7 @@
* @throws Exception if an error occurs
*/
public Vector getBackupEntries() throws Exception {
- Element parent = this.document.getDocumentElement();
+ Element parent = getDocument().getDocumentElement();
NodeList entries = XPathAPI.selectNodeList(parent, "/XPSRevisionControl/CheckOut["
+ ELEMENT_BACKUP + "]|/XPSRevisionControl/CheckIn[" + ELEMENT_BACKUP + "]");
Vector RCMLEntries = new Vector();
@@ -409,7 +423,7 @@
* @throws Exception if an error occurs
*/
public void pruneEntries() throws Exception {
- Element parent = this.document.getDocumentElement();
+ Element parent = getDocument().getDocumentElement();
NodeList entries = XPathAPI.selectNodeList(parent,
"/XPSRevisionControl/CheckOut|/XPSRevisionControl/CheckIn");
@@ -443,7 +457,7 @@
Document documentClone = DocumentHelper.createDocument(null, "dummy", null);
documentClone.removeChild(documentClone.getDocumentElement());
documentClone.appendChild(documentClone
- .importNode(this.document.getDocumentElement(), true));
+ .importNode(getDocument().getDocumentElement(), true));
return documentClone;
}
@@ -475,7 +489,7 @@
* @throws Exception if an error occurs
*/
public void deleteFirstCheckIn() throws Exception {
- Node root = this.document.getDocumentElement();
+ Node root = getDocument().getDocumentElement();
Node firstCheckIn = XPathAPI.selectSingleNode(root, "/XPSRevisionControl/CheckIn[1]");
root.removeChild(firstCheckIn);
root.removeChild(root.getFirstChild()); // remove EOL (end of line)
@@ -487,7 +501,7 @@
* @throws Exception if an error occurs
*/
public void deleteFirstCheckOut() throws Exception {
- Node root = this.document.getDocumentElement();
+ Node root = getDocument().getDocumentElement();
Node firstCheckIn = XPathAPI.selectSingleNode(root, "/XPSRevisionControl/CheckOut[1]");
root.removeChild(firstCheckIn);
root.removeChild(root.getFirstChild()); // remove EOL (end of line)
@@ -500,7 +514,7 @@
* @throws Exception if an error occurs
*/
public String[] getBackupsTime() throws Exception {
- Node root = this.document.getDocumentElement();
+ Node root = getDocument().getDocumentElement();
NodeList entries = XPathAPI.selectNodeList(root, "/XPSRevisionControl/CheckIn");
ArrayList times = new ArrayList();
Modified: lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java (original)
+++ lenya/trunk/src/modules/sourcerepository/java/src/org/apache/lenya/cms/repository/SourceWrapper.java Thu Jan 4 07:05:19 2007
@@ -58,16 +58,16 @@
* @param logger
*/
public SourceWrapper(SourceNode node, String sourceUri, ServiceManager manager, Logger logger) {
-
+
Assert.notNull("node", node);
this.node = node;
-
+
Assert.notNull("source URI", sourceUri);
this.sourceUri = sourceUri;
-
+
Assert.notNull("service manager", manager);
this.manager = manager;
-
+
enableLogging(logger);
}
@@ -198,10 +198,6 @@
*/
protected synchronized void loadData() throws RepositoryException {
- if (this.data != null) {
- return;
- }
-
ByteArrayOutputStream out = null;
InputStream in = null;
SourceResolver resolver = null;
@@ -210,7 +206,8 @@
resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
source = (TraversableSource) resolver.resolveURI(getRealSourceUri());
- if (source.exists() && !source.isCollection()) {
+ if (source.exists() && !source.isCollection()
+ && source.getLastModified() > this.lastModified) {
byte[] buf = new byte[4096];
out = new ByteArrayOutputStream();
in = source.getInputStream();
@@ -222,6 +219,7 @@
}
this.data = out.toByteArray();
+ this.lastModified = source.getLastModified();
}
} catch (Exception e) {
throw new RepositoryException(e);
Modified: lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml?view=diff&rev=492591&r1=492590&r2=492591
==============================================================================
--- lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml (original)
+++ lenya/trunk/src/webapp/lenya/resources/i18n/cmsui_de.xml Thu Jan 4 07:05:19 2007
@@ -158,7 +158,7 @@
</message>
<message key="Edit with one Form">Bearbeiten mit Formulareditor</message>
<message key="Edit with Forms">Bearbeiten mit Formwizard</message>
- <message key="Edit Metadata">Metadata bearbeiten</message>
+ <message key="Edit Metadata">Metadaten bearbeiten</message>
<message key="Edit Navigation Title">Navigationstitel bearbeiten</message>
<message key="Visible in Navigation">Sichtbar in Navigation</message>
<message key="Rename URL">URL umbenennen</message>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org