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 2005/04/14 15:53:34 UTC
svn commit: r161284 - in lenya/trunk/src/java/org/apache/lenya: ./ cms/ant/
cms/cocoon/acting/ cms/cocoon/components/modules/input/
cms/metadata/dublincore/ cms/metadata/usecases/ cms/publication/
cms/publication/task/ cms/site/usecases/
Author: andreas
Date: Thu Apr 14 06:53:29 2005
New Revision: 161284
URL: http://svn.apache.org/viewcvs?view=rev&rev=161284
Log:
generalized DublinCore to MetaDataManager, using lenya:// sources for asset management
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/SetIdentifier.java
lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java
lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreProxy.java
lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java
lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java
lenya/trunk/src/java/org/apache/lenya/lenya.roles
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java Thu Apr 14 06:53:29 2005
@@ -19,23 +19,15 @@
package org.apache.lenya.cms.ant;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.cms.site.Label;
import org.apache.lenya.cms.site.tree.SiteTreeNode;
import org.apache.tools.ant.BuildException;
/**
- * Ant task, which implements the SiteTreeNodeVisitor for the operation copy the
- * resources. (Visitor pattern)
+ * Ant task, which implements the SiteTreeNodeVisitor for the operation copy the resources. (Visitor
+ * pattern)
*/
public class CopyResourcesTask extends TwoDocumentsOperationTask {
@@ -47,8 +39,7 @@
}
/**
- * Copy the resources files belongs to the documents corresponding to this
- * node
+ * Copy the resources files belongs to the documents corresponding to this node
* @see org.apache.lenya.cms.site.tree.SiteTreeNodeVisitor#visitSiteTreeNode(org.apache.lenya.cms.site.tree.SiteTreeNode)
*/
public void visitSiteTreeNode(SiteTreeNode node) {
@@ -63,43 +54,20 @@
String language = labels[0].getLanguage();
Document srcDoc;
+ ResourcesManager resourcesManager = null;
try {
- srcDoc = getIdentityMap().get(getPublication(),
- getFirstarea(),
- srcDocumentid,
- language);
- } catch (DocumentBuildException e) {
- throw new BuildException(e);
- }
- ResourcesManager resourcesMgr = srcDoc.getResourcesManager();
- List resources = new ArrayList(Arrays.asList(resourcesMgr.getResources()));
- resources.addAll(Arrays.asList(resourcesMgr.getMetaFiles()));
- File[] srcFiles = (File[]) resources.toArray(new File[resources.size()]);
-
- if (srcFiles == null) {
- log("There are no resources for the document " + getFirstdocumentid());
- return;
- }
+ srcDoc = getIdentityMap()
+ .get(getPublication(), getFirstarea(), srcDocumentid, language);
- Document destDoc;
- try {
- destDoc = getIdentityMap().get(getPublication(),
+ resourcesManager = (ResourcesManager) getServiceManager().lookup(ResourcesManager.ROLE);
+
+ Document destDoc = getIdentityMap().get(getPublication(),
getSecarea(),
destDocumentid,
language);
- } catch (DocumentBuildException e) {
+ resourcesManager.copyResources(srcDoc, destDoc);
+ } catch (Exception e) {
throw new BuildException(e);
- }
- resourcesMgr = destDoc.getResourcesManager();
- for (int i = 0; i < srcFiles.length; i++) {
-
- try {
- log("copy file " + srcFiles[i].getAbsolutePath() + "to file "
- + resourcesMgr.getPath().getCanonicalPath());
- FileUtil.copyFileToDirectory(srcFiles[i], resourcesMgr.getPath());
- } catch (IOException e) {
- throw new BuildException(e);
- }
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java Thu Apr 14 06:53:29 2005
@@ -19,10 +19,7 @@
package org.apache.lenya.cms.ant;
-import java.io.File;
-
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.cms.site.Label;
import org.apache.lenya.cms.site.tree.SiteTree;
@@ -64,19 +61,19 @@
}
if (node == null || (labels != null && labels.length < 1)) {
- Document doc;
+ ResourcesManager resMgr = null;
try {
- doc = getIdentityMap().get(getPublication(), _area, _documentid, _language);
- } catch (DocumentBuildException e) {
+ Document doc = getIdentityMap()
+ .get(getPublication(), _area, _documentid, _language);
+ resMgr = (ResourcesManager) getServiceManager().lookup(ResourcesManager.ROLE);
+ resMgr.deleteResources(doc);
+ } catch (Exception e) {
throw new BuildException(e);
+ } finally {
+ if (resMgr != null) {
+ getServiceManager().release(resMgr);
+ }
}
- ResourcesManager resourcesMgr = doc.getResourcesManager();
- File[] resources = resourcesMgr.getResources();
- for (int i = 0; i < resources.length; i++) {
- resources[i].delete();
- }
- File directory = resourcesMgr.getPath();
- directory.delete();
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java Thu Apr 14 06:53:29 2005
@@ -20,7 +20,6 @@
package org.apache.lenya.cms.ant;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.cms.site.Label;
import org.apache.lenya.cms.site.tree.SiteTree;
@@ -54,18 +53,23 @@
Label[] labels = node.getLabels();
for (int i = 0; i < labels.length; i++) {
String language = labels[i].getLanguage();
- Document srcDoc;
+ ResourcesManager resMgr = null;
try {
- srcDoc = getIdentityMap().get(getPublication(),
+ Document srcDoc = getIdentityMap().get(getPublication(),
getFirstarea(),
srcDocumentid,
language);
- } catch (DocumentBuildException e) {
+ resMgr = (ResourcesManager) getServiceManager().lookup(ResourcesManager.ROLE);
+ resMgr.deleteResources(srcDoc);
+ } catch (Exception e) {
throw new BuildException(e);
}
+ finally {
+ if (resMgr != null) {
+ getServiceManager().release(resMgr);
+ }
+ }
- ResourcesManager resourcesMgr = srcDoc.getResourcesManager();
- resourcesMgr.deleteResources();
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java Thu Apr 14 06:53:29 2005
@@ -17,12 +17,6 @@
package org.apache.lenya.cms.ant;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.ResourcesManager;
@@ -42,33 +36,24 @@
*/
public void execute() throws BuildException {
+ ResourcesManager resMgr = null;
try {
+ resMgr = (ResourcesManager) getServiceManager().lookup(ResourcesManager.ROLE);
Document authoringDocument = getIdentityMap().get(getPublication(),
Publication.AUTHORING_AREA,
this.documentId);
- ResourcesManager authoringManager = authoringDocument.getResourcesManager();
-
Document liveDocument = getIdentityMap().get(getPublication(),
Publication.LIVE_AREA,
this.documentId);
- ResourcesManager liveManager = liveDocument.getResourcesManager();
-
- // find all resource files and their associated meta files
- List resourcesList = new ArrayList(Arrays.asList(authoringManager.getResources()));
- resourcesList.addAll(Arrays.asList(authoringManager.getMetaFiles()));
- File[] resources = (File[]) resourcesList.toArray(new File[resourcesList.size()]);
- File liveDirectory = liveManager.getPath();
-
- for (int i = 0; i < resources.length; i++) {
- File liveResource = new File(liveDirectory, resources[i].getName());
- String destPath = liveResource.getAbsolutePath();
-
- log("Copy file [" + resources[i].getAbsolutePath() + "] to [" + destPath + "]");
- FileUtil.copyFile(resources[i], liveResource);
- }
+ resMgr.copyResources(authoringDocument, liveDocument);
} catch (Exception e) {
throw new BuildException(e);
+ }
+ finally {
+ if (resMgr != null) {
+ getServiceManager().release(resMgr);
+ }
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/SetIdentifier.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/SetIdentifier.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/SetIdentifier.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/SetIdentifier.java Thu Apr 14 06:53:29 2005
@@ -80,8 +80,10 @@
* DublinCore.
*/
public void writeDCIdentifier(Document document) throws DocumentException {
+ /*
DublinCore dublincore = document.getDublinCore();
dublincore.setValue("identifier", this.documentid);
+ */
}
/**
Modified: lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/WriteDCParametersTask.java Thu Apr 14 06:53:29 2005
@@ -234,7 +234,7 @@
Document doc = getIdentityMap()
.get(getPublication(), _area, _documentId, lang);
- DublinCore dc = doc.getDublinCore();
+ DublinCore dc = (DublinCore) doc.getMetaData();
dc.setValue(DublinCore.ELEMENT_CREATOR, _creator);
dc.setValue(DublinCore.ELEMENT_TITLE, _title);
dc.setValue(DublinCore.ELEMENT_DESCRIPTION, _description);
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/acting/UploadAction.java Thu Apr 14 06:53:29 2005
@@ -109,10 +109,12 @@
*
* @exception Exception if an error occurs
*/
+
public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source,
Parameters parameters) throws Exception {
Map results = new HashMap();
+ /*
Request request = ObjectModelHelper.getRequest(objectModel);
DocumentIdentityMap map = new DocumentIdentityMap(this.manager, getLogger());
this.pageEnvelope = PageEnvelopeFactory.getInstance().getPageEnvelope(map, objectModel);
@@ -174,6 +176,7 @@
}
saveAsset(assetFile, part);
+ */
return Collections.unmodifiableMap(results);
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DublinCoreModule.java Thu Apr 14 06:53:29 2005
@@ -27,9 +27,9 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.metadata.dublincore.DublinCoreImpl;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentException;
/**
* Input module to access the dublin core values.
@@ -38,7 +38,8 @@
/**
* @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ * org.apache.avalon.framework.configuration.Configuration,
+ * java.util.Map)
*/
public Object getAttribute(String name, Configuration modeConf, Map objectModel)
throws ConfigurationException {
@@ -54,8 +55,9 @@
}
Object value;
try {
- value = document.getDublinCore().getFirstValue(name);
- } catch (DocumentException e) {
+ DublinCore dc = (DublinCore) document.getMetaData();
+ value = dc.getFirstValue(name);
+ } catch (Exception e) {
throw new ConfigurationException("Obtaining dublin core value for [" + name
+ "] failed: ", e);
}
@@ -78,7 +80,8 @@
/**
* @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String,
- * org.apache.avalon.framework.configuration.Configuration, java.util.Map)
+ * org.apache.avalon.framework.configuration.Configuration,
+ * java.util.Map)
*/
public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
throws ConfigurationException {
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCore.java Thu Apr 14 06:53:29 2005
@@ -17,7 +17,7 @@
package org.apache.lenya.cms.metadata.dublincore;
-import org.apache.lenya.cms.publication.DocumentException;
+import org.apache.lenya.cms.metadata.MetaDataManager;
/**
* <p>
@@ -29,7 +29,7 @@
*
* @version $Id$
*/
-public interface DublinCore {
+public interface DublinCore extends MetaDataManager {
/**
* A name given to the resource. Typically, Title will be a name by which the resource is
@@ -345,68 +345,5 @@
* Date (often a range) of validity of a resource.
*/
static final String TERM_VALID = "valid";
-
- /**
- * Returns the values for a certain key.
- * @param key The key.
- * @return An array of strings.
- * @throws DocumentException when something went wrong.
- */
- String[] getValues(String key) throws DocumentException;
-
- /**
- * Returns the first value for a certain key.
- * @param key The key.
- * @return A string or <code>null</code> if no value is set for this key.
- * @throws DocumentException if an error occurs.
- */
- String getFirstValue(String key) throws DocumentException;
-
- /**
- * Sets the value for a certain key. All existing values will be removed.
- * @param key The key.
- * @param value The value to set.
- * @throws DocumentException when something went wrong.
- */
- void setValue(String key, String value) throws DocumentException;
-
- /**
- * Adds a value for a certain key.
- * @param key The key.
- * @param value The value to add.
- * @throws DocumentException when something went wrong.
- */
- void addValue(String key, String value) throws DocumentException;
-
- /**
- * Add all values for a certain key.
- *
- * @param key The key
- * @param values The value to add
- * @throws DocumentException if something went wrong
- */
- void addValues(String key, String[] values) throws DocumentException;
-
- /**
- * Removes a specific value for a certain key.
- * @param key The key.
- * @param value The value to remove.
- * @throws DocumentException when something went wrong.
- */
- void removeValue(String key, String value) throws DocumentException;
-
- /**
- * Removes all values for a certain key.
- * @param key The key.
- * @throws DocumentException when something went wrong.
- */
- void removeAllValues(String key) throws DocumentException;
-
- /**
- * Replace the contents of the current dublin core by the contents of other.
- * @param other The other dublin core object.
- * @throws DocumentException if an error occurs.
- */
- void replaceBy(DublinCore other) throws DocumentException;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreHelper.java Thu Apr 14 06:53:29 2005
@@ -19,8 +19,9 @@
package org.apache.lenya.cms.metadata.dublincore;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.publication.Document;
-import org.apache.lenya.cms.publication.DocumentBuildException;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.DocumentIdentityMap;
import org.apache.lenya.cms.publication.Publication;
@@ -42,6 +43,7 @@
/**
* Get the value of the DCIdentifier corresponding to a document id.
+ * @param manager The service manager.
* @param map The identity map.
* @param publication The publication the document(s) belongs to.
* @param area The area the document(s) belongs to.
@@ -49,11 +51,13 @@
* @return a String. The value of the DCIdentifier.
* @throws DocumentException when something with the document went wrong.
*/
- public static String getDCIdentifier(DocumentIdentityMap map, Publication publication,
- String area, String documentId) throws DocumentException {
+ public static String getDCIdentifier(ServiceManager manager, DocumentIdentityMap map,
+ Publication publication, String area, String documentId) throws DocumentException {
String identifier = null;
+ SourceResolver resolver = null;
try {
+ resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
identifier = null;
Document baseDocument = map.get(publication, area, documentId);
@@ -64,7 +68,7 @@
while (identifier == null && i < languages.length) {
Document document = map.get(publication, area, documentId, languages[i]);
log.debug("document file : " + document.getFile().getAbsolutePath());
- DublinCore dublincore = document.getDublinCore();
+ DublinCore dublincore = (DublinCore) document.getMetaData();
log.debug("dublincore title : "
+ dublincore.getFirstValue(DublinCore.ELEMENT_TITLE));
identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
@@ -72,15 +76,18 @@
}
}
if (languages.length < 1 || identifier == null) {
- DublinCore dublincore = baseDocument.getDublinCore();
+ DublinCore dublincore = (DublinCore) baseDocument.getMetaData();
identifier = dublincore.getFirstValue(DublinCore.ELEMENT_IDENTIFIER);
}
- } catch (final DocumentBuildException e) {
- log.error("" + e.toString());
- throw new DocumentException(e);
} catch (final DocumentException e) {
- log.error("" + e.toString());
+ throw e;
+ } catch (final Exception e) {
throw new DocumentException(e);
+ }
+ finally {
+ if (resolver != null) {
+ manager.release(resolver);
+ }
}
return identifier;
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java Thu Apr 14 06:53:29 2005
@@ -19,21 +19,26 @@
package org.apache.lenya.cms.metadata.dublincore;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
-import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentException;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
-import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
/**
* Access dublin core meta data in documents. This class uses the dublin core specification from
@@ -85,18 +90,6 @@
/**
* Creates a new instance of Dublin Core
- * @param aDocument the document for which the Dublin Core instance is created.
- * @param manager The service manager.
- * @throws DocumentException if an error occurs
- */
- protected DublinCoreImpl(Document aDocument, ServiceManager manager) throws DocumentException {
- this.manager = manager;
- this.sourceUri = aDocument.getSourceURI();
- loadValues();
- }
-
- /**
- * Creates a new instance of Dublin Core
* @param sourceUri The source URI.
* @param manager The service manager.
* @throws DocumentException if an error occurs
@@ -114,7 +107,7 @@
protected void loadValues() throws DocumentException {
try {
- org.w3c.dom.Document doc = SourceUtil.readDOM(this.sourceUri, this.manager);
+ Document doc = getDocument();
if (doc != null) {
// FIXME: what if "lenya:meta" element doesn't exist yet?
@@ -153,11 +146,8 @@
protected void save() throws DocumentException {
try {
-
- org.w3c.dom.Document doc = SourceUtil.readDOM(this.sourceUri, this.manager);
-
+ Document doc = getDocument();
Element metaElement = getMetaElement(doc);
-
String[] namespaces = { DC_NAMESPACE, DCTERMS_NAMESPACE };
String[] prefixes = { DC_PREFIX, DCTERMS_PREFIX };
String[][] arrays = { ELEMENTS, TERMS };
@@ -179,25 +169,25 @@
}
}
}
- SourceUtil.writeDOM(doc, this.sourceUri, this.manager);
- } catch (Exception e) {
+ SourceUtil.writeDOM(doc, this.sourceUri, this.manager);
+ } catch (final Exception e) {
throw new DocumentException(e);
}
}
/**
* Returns the Lenya meta data element.
- * @param doc The XML document.
+ * @param document The XML document.
* @return A DOM element.
* @throws DocumentException if an error occurs.
*/
- protected Element getMetaElement(org.w3c.dom.Document doc) throws DocumentException {
+ protected Element getMetaElement(Document document) throws DocumentException {
Element metaElement;
try {
NamespaceHelper namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
- PageEnvelope.DEFAULT_PREFIX, doc);
- Element documentElement = doc.getDocumentElement();
+ PageEnvelope.DEFAULT_PREFIX, document);
+ Element documentElement = namespaceHelper.getDocument().getDocumentElement();
metaElement = namespaceHelper.getFirstChild(documentElement, META);
if (metaElement == null) {
@@ -209,11 +199,24 @@
documentElement.insertBefore(metaElement, children[0]);
}
}
- } catch (final DOMException e) {
+ } catch (final Exception e) {
throw new DocumentException(e);
}
return metaElement;
+ }
+ protected Document getDocument() throws ServiceException, SourceNotFoundException,
+ ParserConfigurationException, SAXException, IOException {
+ org.w3c.dom.Document doc = SourceUtil.readDOM(this.sourceUri, this.manager);
+ NamespaceHelper namespaceHelper;
+ if (doc == null) {
+ namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
+ PageEnvelope.DEFAULT_PREFIX, "document");
+ } else {
+ namespaceHelper = new NamespaceHelper(PageEnvelope.NAMESPACE,
+ PageEnvelope.DEFAULT_PREFIX, doc);
+ }
+ return namespaceHelper.getDocument();
}
/**
@@ -432,6 +435,16 @@
*/
public static boolean isValidElement(String key) {
return Arrays.asList(DublinCoreImpl.ELEMENTS).contains(key);
+ }
+
+ /**
+ * @return All possible keys.
+ */
+ public String[] getPossibleKeys() {
+ List keys = new ArrayList();
+ keys.addAll(Arrays.asList(DublinCoreImpl.ELEMENTS));
+ keys.addAll(Arrays.asList(DublinCoreImpl.TERMS));
+ return (String[]) keys.toArray(new String[keys.size()]);
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreProxy.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreProxy.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreProxy.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreProxy.java Thu Apr 14 06:53:29 2005
@@ -20,7 +20,7 @@
package org.apache.lenya.cms.metadata.dublincore;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.metadata.MetaDataManager;
import org.apache.lenya.cms.publication.DocumentException;
/**
@@ -30,17 +30,16 @@
public class DublinCoreProxy implements DublinCore {
private DublinCoreImpl dcCore;
- private Document cmsDocument;
+ private String sourceUri;
private ServiceManager manager;
- /**
- * Creates a new instance of Dublin Core
- *
- * @param aDocument the document for which the Dublin Core instance is created.
+ /**
+ * Ctor.
+ * @param sourceUri The source URI.
* @param manager The service manager.
*/
- public DublinCoreProxy(Document aDocument, ServiceManager manager) {
- this.cmsDocument = aDocument;
+ public DublinCoreProxy(String sourceUri, ServiceManager manager) {
+ this.sourceUri = sourceUri;
this.manager = manager;
}
@@ -52,7 +51,7 @@
*/
protected DublinCoreImpl instance() throws DocumentException {
if (this.dcCore == null) {
- this.dcCore = new DublinCoreImpl(this.cmsDocument, this.manager);
+ this.dcCore = new DublinCoreImpl(this.sourceUri, this.manager);
}
return this.dcCore;
}
@@ -101,10 +100,10 @@
}
/**
- * @see org.apache.lenya.cms.metadata.dublincore.DublinCore#replaceBy(org.apache.lenya.cms.metadata.dublincore.DublinCore)
+ * @see org.apache.lenya.cms.metadata.MetaDataManager#replaceBy(org.apache.lenya.cms.metadata.MetaDataManager)
*/
- public void replaceBy(DublinCore other) throws DocumentException {
- instance().replaceBy(other);
+ public void replaceBy(MetaDataManager other) throws DocumentException {
+ instance().replaceBy((DublinCore) other);
}
@@ -121,6 +120,17 @@
*/
public void setValue(String key, String value) throws DocumentException {
instance().setValue(key, value);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.metadata.MetaDataManager#getPossibleKeys()
+ */
+ public String[] getPossibleKeys() {
+ try {
+ return instance().getPossibleKeys();
+ } catch (DocumentException e) {
+ throw new RuntimeException(e);
+ }
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/usecases/Metadata.java Thu Apr 14 06:53:29 2005
@@ -16,7 +16,7 @@
*/
package org.apache.lenya.cms.metadata.usecases;
-import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.metadata.MetaDataManager;
import org.apache.lenya.cms.site.usecases.SiteUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
import org.apache.lenya.transaction.Transactionable;
@@ -28,8 +28,6 @@
*/
public class Metadata extends SiteUsecase {
- private DublinCore dc;
-
/**
* Ctor.
*/
@@ -51,30 +49,16 @@
super.initParameters();
try {
- this.dc = getSourceDocument().getDublinCore();
- setParameter(DublinCore.ELEMENT_CREATOR, this.dc
- .getFirstValue(DublinCore.ELEMENT_CREATOR));
- setParameter(DublinCore.ELEMENT_TITLE, this.dc.getFirstValue(DublinCore.ELEMENT_TITLE));
- setParameter(DublinCore.ELEMENT_DESCRIPTION, this.dc
- .getFirstValue(DublinCore.ELEMENT_CREATOR));
- setParameter(DublinCore.ELEMENT_SUBJECT, this.dc
- .getFirstValue(DublinCore.ELEMENT_SUBJECT));
- setParameter(DublinCore.ELEMENT_PUBLISHER, this.dc
- .getFirstValue(DublinCore.ELEMENT_PUBLISHER));
- setParameter(DublinCore.ELEMENT_RIGHTS, this.dc
- .getFirstValue(DublinCore.ELEMENT_RIGHTS));
- setParameter(DublinCore.ELEMENT_TYPE, this.dc.getFirstValue(DublinCore.ELEMENT_TYPE));
- setParameter(DublinCore.ELEMENT_DATE, this.dc.getFirstValue(DublinCore.ELEMENT_DATE));
- setParameter(DublinCore.ELEMENT_FORMAT, this.dc
- .getFirstValue(DublinCore.ELEMENT_FORMAT));
- setParameter(DublinCore.ELEMENT_SOURCE, this.dc
- .getFirstValue(DublinCore.ELEMENT_SOURCE));
- setParameter(DublinCore.ELEMENT_LANGUAGE, this.dc
- .getFirstValue(DublinCore.ELEMENT_LANGUAGE));
- setParameter(DublinCore.ELEMENT_RELATION, this.dc
- .getFirstValue(DublinCore.ELEMENT_RELATION));
- setParameter(DublinCore.ELEMENT_COVERAGE, this.dc
- .getFirstValue(DublinCore.ELEMENT_COVERAGE));
+ MetaDataManager meta = getSourceDocument().getMetaData();
+
+ String[] keys = meta.getPossibleKeys();
+ for (int i = 0; i < keys.length; i++) {
+ String value = meta.getFirstValue(keys[i]);
+ if (value != null) {
+ setParameter(keys[i], value);
+ }
+ }
+
} catch (Exception e) {
getLogger().error("Unable to load Dublin Core metadata.", e);
addErrorMessage("Unable to load Dublin Core metadata.");
@@ -102,27 +86,17 @@
protected void doExecute() throws Exception {
super.doExecute();
- String creator = getParameterAsString(DublinCore.ELEMENT_CREATOR);
- String title = getParameterAsString(DublinCore.ELEMENT_TITLE);
- String description = getParameterAsString(DublinCore.ELEMENT_DESCRIPTION);
- String subject = getParameterAsString(DublinCore.ELEMENT_SUBJECT);
- String publisher = getParameterAsString(DublinCore.ELEMENT_PUBLISHER);
- String rights = getParameterAsString(DublinCore.ELEMENT_RIGHTS);
-
- this.dc.setValue(DublinCore.ELEMENT_CREATOR, creator);
- this.dc.setValue(DublinCore.ELEMENT_TITLE, title);
- this.dc.setValue(DublinCore.ELEMENT_DESCRIPTION, description);
- this.dc.setValue(DublinCore.ELEMENT_SUBJECT, subject);
- this.dc.setValue(DublinCore.ELEMENT_PUBLISHER, publisher);
- this.dc.setValue(DublinCore.ELEMENT_RIGHTS, rights);
- //TODO set workflow situation to edit here.
- }
+ MetaDataManager meta = getSourceDocument().getMetaData();
- /**
- * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String, java.lang.Object)
- */
- public void setParameter(String name, Object value) {
- super.setParameter(name, value);
+ String[] keys = meta.getPossibleKeys();
+ for (int i = 0; i < keys.length; i++) {
+ String value = getParameterAsString(keys[i]);
+ if (value != null) {
+ meta.setValue(keys[i], value);
+ }
+ }
+ //TODO set workflow situation to edit here.
}
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java Thu Apr 14 06:53:29 2005
@@ -32,7 +32,7 @@
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.RepositorySource;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
-import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.metadata.MetaDataManager;
import org.apache.lenya.cms.metadata.dublincore.DublinCoreProxy;
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.repository.Node;
@@ -50,9 +50,7 @@
public class DefaultDocument extends AbstractLogEnabled implements Document {
private String id;
- private DublinCore dublincore;
private DocumentIdentityMap identityMap;
- private ResourcesManager resourcesManager;
protected ServiceManager manager;
/**
@@ -101,8 +99,6 @@
this.identityMap = map;
this.language = _language;
setArea(_area);
-
- this.dublincore = new DublinCoreProxy(this, this.manager);
}
/**
@@ -139,13 +135,6 @@
}
/**
- * @see org.apache.lenya.cms.publication.Document#getDublinCore()
- */
- public DublinCore getDublinCore() {
- return this.dublincore;
- }
-
- /**
* Returns the file for this document.
* @return A file object.
*/
@@ -372,17 +361,6 @@
}
/**
- * @see org.apache.lenya.cms.publication.Document#getResourcesManager()
- */
- public ResourcesManager getResourcesManager() {
- if (this.resourcesManager == null) {
- this.resourcesManager = new DefaultResourcesManager(this, this.manager);
- ContainerUtil.enableLogging(this.resourcesManager, getLogger());
- }
- return this.resourcesManager;
- }
-
- /**
* @see org.apache.lenya.cms.publication.Document#getCanonicalWebappURL()
*/
public String getCanonicalWebappURL() {
@@ -401,6 +379,13 @@
*/
public void accept(DocumentVisitor visitor) throws PublicationException {
visitor.visitDocument(this);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.metadata.MetaDataOwner#getMetaData()
+ */
+ public MetaDataManager getMetaData() {
+ return new DublinCoreProxy(getSourceURI(), this.manager);
}
private History history;
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java Thu Apr 14 06:53:29 2005
@@ -22,30 +22,31 @@
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.io.OutputStream;
import java.util.Iterator;
-import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-
-import org.apache.avalon.excalibur.io.FileUtil;
+import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.servlet.multipart.Part;
-import org.apache.lenya.cms.metadata.dublincore.DublinCoreImpl;
-import org.apache.lenya.xml.DocumentHelper;
-import org.apache.lenya.xml.NamespaceHelper;
+import org.apache.excalibur.source.ModifiableSource;
+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.MetaDataManager;
+import org.apache.lenya.transaction.Transactionable;
/**
* Manager for resources of a CMS document.
*/
-public class DefaultResourcesManager extends AbstractLogEnabled implements ResourcesManager {
+public class DefaultResourcesManager extends AbstractLogEnabled implements ResourcesManager,
+ Serviceable {
private static final class MetaSuffixFileFilter implements FileFilter {
/**
@@ -94,30 +95,19 @@
}
}
- private Document document = null;
- private ServiceManager manager;
-
protected static final String NAMESPACE_META = "http://lenya.apache.org/meta/1.0";
/**
* Create a new instance of Resources.
- * @param _document the document for which the resources are managed
- * @param manager The service manager.
*/
- public DefaultResourcesManager(Document _document, ServiceManager manager) {
- this.document = _document;
- this.manager = manager;
+ public DefaultResourcesManager() {
}
/**
- * Add the file in the Part either as a resource or content
- * @param part The Part
- * @param metadata Holds the metadata for the resource
- * @exception IOException if an error occurs
+ * @see org.apache.lenya.cms.publication.ResourcesManager#addResource(org.apache.lenya.cms.publication.Document,
+ * org.apache.cocoon.servlet.multipart.Part, java.util.Map)
*/
- public void addResource(Part part, Map metadata) throws IOException {
-
- File resourceFile;
+ public void addResource(Document document, Part part, Map metadata) throws Exception {
try {
String fileName = part.getFileName();
@@ -128,6 +118,13 @@
}
// convert spaces in the file name to underscores
fileName = fileName.replace(' ', '_');
+
+ Resource resource = new Resource(document, fileName, this.manager);
+ Transactionable[] nodes = resource.getRepositoryNodes();
+ for (int i = 0; i < nodes.length; i++) {
+ nodes[i].lock();
+ }
+
String mimeType = part.getMimeType();
int fileSize = part.getSize();
@@ -135,23 +132,17 @@
metadata.put("extent", Integer.toString(fileSize));
/* if (type.equals("resource")) { */
- resourceFile = new File(this.getPath(), fileName);
-
- if (!this.getPath().exists()) {
- this.getPath().mkdirs();
- }
// create an extra file containing the meta description for
// the resource.
- File metaDataFile = new File(this.getPath(), fileName + RESOURCES_META_SUFFIX);
- createMetaData(metaDataFile, metadata);
+ createMetaData(resource, metadata);
/*
* } // must be a content upload then else { resourceFile = new
* File(document.getFile().getParent(), fileName); getLogger().debug("resourceFile: " +
* resourceFile); }
*/
- saveResource(resourceFile, part);
+ saveResource(resource, part);
} catch (final DocumentException e) {
getLogger().error("Document exception " + e.toString());
throw new RuntimeException(e);
@@ -163,24 +154,23 @@
/**
* Saves the resource to a file.
- * @param resourceFile The resource file.
+ * @param resource The resource.
* @param part The part of the multipart request.
* @throws IOException if an error occurs.
*/
- protected void saveResource(File resourceFile, Part part) throws IOException {
- FileOutputStream out = null;
+ protected void saveResource(Resource resource, Part part) throws IOException {
+ OutputStream out = null;
InputStream in = null;
- if (!resourceFile.exists()) {
- boolean created = resourceFile.createNewFile();
- if (!created) {
- throw new IOException("The file [" + resourceFile + "]�could not be created.");
- }
- }
+ SourceResolver resolver = null;
+ ModifiableSource source = null;
try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = (ModifiableSource) resolver.resolveURI(resource.getSourceURI());
+
byte[] buf = new byte[4096];
- out = new FileOutputStream(resourceFile);
+ out = source.getOutputStream();
in = part.getInputStream();
int read = in.read(buf);
@@ -198,198 +188,207 @@
getLogger().error("Exception" + e.toString());
throw new IOException(e.toString());
} finally {
- if (in != null)
+ if (in != null) {
in.close();
- if (out != null)
+ }
+ if (out != null) {
+ out.flush();
out.close();
+ }
+
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
}
}
/**
* Create the meta data file given the dublin core parameters.
- * @param metaDataFile the file where the meta data file is to be created
+ * @param resource the resource
* @param metadata a <code>Map</code> containing the dublin core values
* @throws DocumentException if an error occurs
*/
- protected void createMetaData(File metaDataFile, Map metadata) throws DocumentException {
+ protected void createMetaData(Resource resource, Map metadata) throws DocumentException {
- assert (metaDataFile.getParentFile().exists());
+ SourceResolver resolver = null;
try {
-
- if (!metaDataFile.exists()) {
- metaDataFile.createNewFile();
- NamespaceHelper helper = new NamespaceHelper(NAMESPACE_META, "", "meta");
- DocumentHelper.writeDocument(helper.getDocument(), metaDataFile);
- }
- String key;
- String value;
- Map.Entry entry;
- String sourceUrl = "file:/" + metaDataFile.getAbsolutePath();
- DublinCoreImpl dc = new DublinCoreImpl(sourceUrl, this.manager);
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ MetaDataManager meta = resource.getMetaData();
Iterator iter = metadata.entrySet().iterator();
while (iter.hasNext()) {
- entry = (Map.Entry) iter.next();
- key = (String) entry.getKey();
- value = (String) entry.getValue();
- dc.setValue(key, value);
+ Map.Entry entry = (Map.Entry) iter.next();
+ meta.setValue((String) entry.getKey(), (String) entry.getValue());
}
} catch (final Exception e) {
- getLogger().error("Saving of [" + metaDataFile + "] �failed.");
+ getLogger().error("Saving of [" + resource.getSourceURI() + "]� failed.");
throw new DocumentException(e);
+ } finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
+ }
}
}
/**
- * Get the path to the resources.
- * @return the path to the resources
+ * @see org.apache.lenya.cms.publication.ResourcesManager#getResources(org.apache.lenya.cms.publication.Document)
*/
- private String getPathFromPublication() {
- return RESOURCES_PREFIX + "/" + getDocument().getArea() + getDocument().getId();
- }
-
- /**
- * Get the path to the resources.
- * @return the path to the resources
- */
- public File getPath() {
- File publicationPath = getDocument().getPublication().getDirectory();
- File resourcesPath = new File(publicationPath, getPathFromPublication().replace('/',
- File.separatorChar));
- return resourcesPath;
- }
-
- /**
- * Returns the path of a resource relative to the context prefix.
- * @param resource The resource
- * @return The path of a resource relative to the context prefix.
- */
- public String getResourceUrl(File resource) {
- return getDocument().getPublication().getId() + "/" + getDocument().getArea()
- + getDocument().getId() + "/" + resource.getName();
- }
-
- /**
- * Get all resources for the associated document.
- * @return all resources of the associated document
- */
- public File[] getResources() {
+ public Resource[] getResources(Document document) {
// filter the meta files out. We only want to see the "real" resources.
FileFilter filter = new NotMetaSuffixFileFilter();
- return getFiles(filter);
+ return getResources(document, filter);
}
/**
- * Return all resources which are images.
- * @return All image resources.
+ * @see org.apache.lenya.cms.publication.ResourcesManager#getImageResources(org.apache.lenya.cms.publication.Document)
*/
- public File[] getImageResources() {
- return getFiles(new ImageExtensionsFileFilter());
+ public Resource[] getImageResources(Document document) {
+ return getResources(document, new ImageExtensionsFileFilter());
}
/**
* Returns the resources that are matched by a certain file filter.
+ * @param document The document.
* @param filter A file filter.
- * @return A file array.
+ * @return A resource array.
*/
- protected File[] getFiles(FileFilter filter) {
+ protected Resource[] getResources(Document document, FileFilter filter) {
File[] files = new File[0];
- if (getPath().isDirectory()) {
- files = getPath().listFiles(filter);
- }
+ Resource tempResource = new Resource(document, "temp", this.manager);
- return files;
- }
+ SourceResolver resolver = null;
+ Source source = null;
+ try {
+ Resource[] resources;
+
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ source = resolver.resolveURI(tempResource.getBaseURI());
+ if (source.exists()) {
+ File directory = org.apache.excalibur.source.SourceUtil.getFile(source);
+ if (directory.isDirectory()) {
+ files = directory.listFiles(filter);
+ }
+ resources = new Resource[files.length];
+ for (int i = 0; i < files.length; i++) {
+ resources[i] = new Resource(document, files[i].getName(), this.manager);
+ }
+ }
+ else {
+ resources = new Resource[0];
+ }
+ return resources;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resolver != null) {
+ if (source != null) {
+ resolver.release(source);
+ }
+ this.manager.release(resolver);
+ }
+ }
- /**
- * Get the meta data for all resources for the associated document.
- * @return all meta data files for the resources for the associated document.
- */
- public File[] getMetaFiles() {
- FileFilter filter = new MetaSuffixFileFilter();
- return getFiles(filter);
}
/**
- * Returns a meta file for a given resource.
- * @param resource A resource the meta file should be returned for.
- * @return A file containing meta information about a resource. Returns null if no meta file was
- * found.
- * @throws IllegalArgumentException If resource is a meta file itself.
+ * @see org.apache.lenya.cms.publication.ResourcesManager#deleteResources(org.apache.lenya.cms.publication.Document)
*/
- public File getMetaFile(final File resource) throws IllegalArgumentException {
- if (resource.getName().endsWith(RESOURCES_META_SUFFIX))
- throw new IllegalArgumentException("File is itself a meta file.");
+ public void deleteResources(Document document) {
- final FileFilter filter = new ResourceMetaFileFilter(resource);
+ try {
+ Resource[] resources = getResources(document);
+ for (int i = 0; i < resources.length; i++) {
+ SourceUtil.delete(resources[i].getSourceURI(), this.manager);
+ SourceUtil.delete(resources[i].getMetaSourceURI(), this.manager);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
- final File[] metaFiles = getFiles(filter);
- assert (metaFiles.length == 0);
- return metaFiles[0];
}
/**
- * Deletes all resources.
+ * @see org.apache.lenya.cms.publication.ResourcesManager#copyResources(org.apache.lenya.cms.publication.Document,
+ * org.apache.lenya.cms.publication.Document)
*/
- public void deleteResources() {
+ public void copyResources(Document sourceDocument, Document destinationDocument)
+ throws Exception {
- File[] resources = getResources();
- for (int i = 0; i < resources.length; i++) {
- resources[i].delete();
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Copying resources from [" + sourceDocument + "] to ["
+ + destinationDocument + "]");
}
- File[] metas = getMetaFiles();
- for (int i = 0; i < metas.length; i++) {
- metas[i].delete();
+ SourceResolver resolver = null;
+ try {
+ Resource[] resources = getResources(sourceDocument);
+ for (int i = 0; i < resources.length; i++) {
+ Resource sourceResource = resources[i];
+ Resource destinationResource = new Resource(destinationDocument, sourceResource
+ .getName(), this.manager);
+
+ Source sourceSource = null;
+ Source sourceMetaSource = null;
+ ModifiableSource destSource = null;
+ ModifiableSource destMetaSource = null;
+
+ try {
+
+ sourceSource = resolver.resolveURI(sourceResource.getSourceURI());
+ sourceMetaSource = resolver.resolveURI(sourceResource.getMetaSourceURI());
+ destSource = (ModifiableSource) resolver.resolveURI(destinationResource
+ .getSourceURI());
+ destMetaSource = (ModifiableSource) resolver.resolveURI(destinationResource
+ .getMetaSourceURI());
+
+ SourceUtil.copy(sourceSource, destSource, true);
+ SourceUtil.copy(sourceMetaSource, destMetaSource, true);
+ } finally {
+ if (sourceSource != null) {
+ resolver.release(sourceSource);
+ }
+ if (sourceMetaSource != null) {
+ resolver.release(sourceMetaSource);
+ }
+ if (destSource != null) {
+ resolver.release(destSource);
+ }
+ if (destMetaSource != null) {
+ resolver.release(destMetaSource);
+ }
+ }
+ }
+ } finally {
+ if (resolver != null) {
+ this.manager.release(resolver);
+ }
}
}
- /**
- * @see org.apache.lenya.cms.publication.ResourcesManager#getDocument()
- */
- public Document getDocument() {
- return this.document;
- }
+ protected ServiceManager manager;
/**
- * @see org.apache.lenya.cms.publication.ResourcesManager#copyResourcesTo(org.apache.lenya.cms.publication.Document)
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
- public void copyResourcesTo(Document destinationDocument) throws Exception {
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Copying resources of document [" + getDocument() + "]");
- }
-
- ResourcesManager _destinationManager = destinationDocument.getResourcesManager();
-
- List resourcesList = new ArrayList(Arrays.asList(getResources()));
- resourcesList.addAll(Arrays.asList(getMetaFiles()));
- File[] resources = (File[]) resourcesList.toArray(new File[resourcesList.size()]);
- File destinationDirectory = _destinationManager.getPath();
-
- for (int i = 0; i < resources.length; i++) {
- File destinationResource = new File(destinationDirectory, resources[i].getName());
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Copy file [" + resources[i].getAbsolutePath() + "] to ["
- + destinationResource.getAbsolutePath() + "]");
- }
- FileUtil.copyFile(resources[i], destinationResource);
- }
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
}
/**
- * @see org.apache.lenya.cms.publication.ResourcesManager#deleteResource(java.lang.String)
+ * @see org.apache.lenya.cms.publication.ResourcesManager#deleteResource(org.apache.lenya.cms.publication.Document,
+ * java.lang.String)
*/
- public void deleteResource(String name) throws Exception {
- File[] resources = getResources();
+ public void deleteResource(Document document, String name) throws Exception {
+ Resource[] resources = getResources(document);
for (int i = 0; i < resources.length; i++) {
if (resources[i].getName().equals(name)) {
- File metaFile = getMetaFile(resources[i]);
- metaFile.delete();
- resources[i].delete();
+ SourceUtil.delete(resources[i].getMetaSourceURI(), this.manager);
+ SourceUtil.delete(resources[i].getSourceURI(), this.manager);
}
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java Thu Apr 14 06:53:29 2005
@@ -22,6 +22,7 @@
import java.io.File;
import java.util.Date;
+import org.apache.lenya.cms.metadata.MetaDataOwner;
import org.apache.lenya.cms.metadata.dublincore.DublinCore;
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.repository.Node;
@@ -31,7 +32,7 @@
/**
* A CMS document.
*/
-public interface Document extends Workflowable, Identifiable {
+public interface Document extends MetaDataOwner, Workflowable, Identifiable {
/**
* The document namespace URI.
@@ -85,12 +86,6 @@
*/
String getCanonicalDocumentURL();
- /**
- * Returns the dublin core class for this document.
- * @return A DublinCore object.
- */
- DublinCore getDublinCore();
-
/**
* Returns the language of this document.
* Each document has one language associated to it.
@@ -172,12 +167,6 @@
DocumentIdentityMap getIdentityMap();
/**
- * Returns the resources manager for this document.
- * @return A resources manager.
- */
- ResourcesManager getResourcesManager();
-
- /**
* Returns the URI to resolve the document's source.
* @return A string.
*/
@@ -200,4 +189,5 @@
* @return The repository nodes that represent this document.
*/
Node[] getRepositoryNodes();
+
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java Thu Apr 14 06:53:29 2005
@@ -33,6 +33,7 @@
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.MetaDataManager;
import org.apache.lenya.cms.publication.util.DocumentSet;
import org.apache.lenya.cms.publication.util.DocumentVisitor;
import org.apache.lenya.cms.site.SiteManager;
@@ -88,17 +89,17 @@
Publication publication = sourceDocument.getPublication();
copyDocumentSource(sourceDocument, destinationDocument);
- ResourcesManager resourcesManager = sourceDocument.getResourcesManager();
+ ResourcesManager resourcesManager = null;
WorkflowManager workflowManager = null;
SiteManager siteManager = null;
ServiceSelector selector = null;
try {
+ resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
+ resourcesManager.copyResources(sourceDocument, destinationDocument);
selector = (ServiceSelector) this.manager.lookup(SiteManager.ROLE + "Selector");
siteManager = (SiteManager) selector.select(publication.getSiteManagerHint());
siteManager.copy(sourceDocument, destinationDocument);
- resourcesManager.copyResourcesTo(destinationDocument);
-
workflowManager = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
workflowManager.copyHistory(sourceDocument, destinationDocument);
} catch (Exception e) {
@@ -107,6 +108,9 @@
if (workflowManager != null) {
this.manager.release(workflowManager);
}
+ if (resourcesManager != null) {
+ this.manager.release(resourcesManager);
+ }
if (selector != null) {
if (siteManager != null) {
selector.release(siteManager);
@@ -124,13 +128,13 @@
throw new PublicationException("Document [" + document + "] does not exist!");
}
- ResourcesManager resourcesManager = document.getResourcesManager();
- resourcesManager.deleteResources();
-
SiteManager siteManager = null;
ServiceSelector selector = null;
WorkflowManager workflowManager = null;
+ ResourcesManager resourcesManager = null;
try {
+ resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
+ resourcesManager.deleteResources(document);
workflowManager = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
workflowManager.deleteHistory(document);
@@ -146,6 +150,9 @@
if (workflowManager != null) {
this.manager.release(workflowManager);
}
+ if (resourcesManager != null) {
+ this.manager.release(resourcesManager);
+ }
if (selector != null) {
if (siteManager != null) {
selector.release(siteManager);
@@ -163,11 +170,12 @@
throws PublicationException {
copy(sourceDocument, destinationDocument);
- ResourcesManager resourcesManager = sourceDocument.getResourcesManager();
+ ResourcesManager resourcesManager = null;
WorkflowManager workflowManager = null;
try {
- resourcesManager.copyResourcesTo(destinationDocument);
- resourcesManager.deleteResources();
+ resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
+ resourcesManager.copyResources(sourceDocument, destinationDocument);
+ resourcesManager.deleteResources(sourceDocument);
workflowManager = (WorkflowManager) this.manager.lookup(WorkflowManager.ROLE);
workflowManager.moveHistory(sourceDocument, destinationDocument);
@@ -177,6 +185,9 @@
if (workflowManager != null) {
this.manager.release(workflowManager);
}
+ if (resourcesManager != null) {
+ this.manager.release(resourcesManager);
+ }
}
delete(sourceDocument);
@@ -352,7 +363,10 @@
source = sourceResolver.resolveURI(sourceDocument.getSourceURI());
destination = sourceResolver.resolveURI(destinationDocument.getSourceURI());
SourceUtil.copy(source, (ModifiableSource) destination, true);
- destinationDocument.getDublinCore().replaceBy(sourceDocument.getDublinCore());
+
+ MetaDataManager sourceCore = sourceDocument.getMetaData();
+ MetaDataManager destCore = destinationDocument.getMetaData();
+ destCore.replaceBy(sourceCore);
} catch (Exception e) {
throw new PublicationException(e);
} finally {
@@ -596,4 +610,4 @@
copy(sortedSourceDocs[i], (Document) source2target.get(sortedSourceDocs[i]));
}
}
-}
\ No newline at end of file
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java Thu Apr 14 06:53:29 2005
@@ -69,6 +69,7 @@
* @see org.apache.lenya.cms.publication.DocumentTypeResolver#resolve(org.apache.lenya.cms.publication.Document)
*/
public DocumentType resolve(Document document) {
+
DocumentType documentType;
URIParameterizer parameterizer = null;
Map map = null;
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java Thu Apr 14 06:53:29 2005
@@ -19,7 +19,6 @@
package org.apache.lenya.cms.publication;
-import java.io.File;
import java.util.Map;
import org.apache.cocoon.servlet.multipart.Part;
@@ -28,6 +27,11 @@
* Manager for resources of a CMS document.
*/
public interface ResourcesManager {
+
+ /**
+ * The Avalon role.
+ */
+ String ROLE = ResourcesManager.class.getName();
/**
* <code>CONTENT_PREFIX</code> The content prefix
@@ -75,77 +79,48 @@
/**
* Add a resource to the document.
+ * @param document The document.
* @param part the part that contains the uploaded file
* @param metadata the metadata for the resource
* @throws Exception if an error occurs
*/
- void addResource(Part part, Map metadata) throws Exception;
+ void addResource(Document document, Part part, Map metadata) throws Exception;
/**
* Delete a resource from the document.
+ * @param document The document.
* @param name The filename of the resource.
* @throws Exception if an error occurs
*/
- void deleteResource(String name) throws Exception;
-
- /**
- * Get the path to the resources.
- * @return the path to the resources
- * @deprecated the resource manager should not expose storage details.
- */
- File getPath();
-
- /**
- * Returns the path of a resource relative to the context prefix.
- * @param resource The resource
- * @return The path of a resource relative to the context prefix.
- */
- String getResourceUrl(File resource);
+ void deleteResource(Document document, String name) throws Exception;
/**
* Get all resources for the associated document.
+ * @param document The document.
* @return all resources of the associated document
*/
- File[] getResources();
+ Resource[] getResources(Document document);
/**
- * Return all resources which are images.
- * @return All image resources.
- */
- File[] getImageResources();
-
- /**
- * Get the meta data for all resources for the associated document.
+ * Get the image resources for the associated document.
+ * @param document The document.
* @return all meta data files for the resources for the associated
* document.
*/
- File[] getMetaFiles();
-
- /**
- * Returns a meta file for a given resource.
- * @param resource A resource the meta file should be returned for.
- * @return A file containing meta information about a resource. Returns null
- * if no meta file was found.
- * @throws IllegalArgumentException If resource is a meta file itself.
- */
- File getMetaFile(final File resource) throws IllegalArgumentException;
+ Resource[] getImageResources(Document document);
/**
* Deletes all resources.
+ * @param document The document.
*/
- void deleteResources();
-
- /**
- * Gets the document this resource manager belongs to.
- * @return The document
- */
- Document getDocument();
+ void deleteResources(Document document);
/**
* Copies the resources of a document to another document.
+ * @param sourceDocument The source document.
* @param destinationDocument The destination document.
* @throws Exception when something went wrong.
*/
- void copyResourcesTo(Document destinationDocument) throws Exception;
+ void copyResources(Document sourceDocument, Document destinationDocument) throws Exception;
-}
\ No newline at end of file
+}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java Thu Apr 14 06:53:29 2005
@@ -91,7 +91,6 @@
* @param sourceDocument The source document.
* @param destinationDocument The destination document.
* @throws ExecutionException when something went wrong.
- */
protected void copyResources(Document sourceDocument, Document destinationDocument)
throws ExecutionException {
@@ -121,6 +120,7 @@
}
}
}
+ */
/**
* <code>PARAMETER_WORKFLOW_EVENT</code> The workflow event parameter
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Assets.java Thu Apr 14 06:53:29 2005
@@ -16,13 +16,17 @@
*/
package org.apache.lenya.cms.site.usecases;
-import java.io.File;
import java.text.DateFormat;
+import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.metadata.dublincore.DublinCore;
+import org.apache.lenya.cms.publication.Resource;
import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.cms.site.usecases.SiteUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
@@ -45,7 +49,6 @@
if (title.length() == 0) {
addErrorMessage("Please enter a title.");
}
-
}
/**
@@ -62,36 +65,46 @@
*/
protected void initParameters() {
super.initParameters();
- ResourcesManager resourcesManager = getSourceDocument().getResourcesManager();
- File[] resources = resourcesManager.getResources();
- if (resources != null) {
- Map[] assets = new Map[resources.length];
+ ResourcesManager resourcesManager = null;
+ SourceResolver resolver = null;
+
+ try {
+ resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
+
+ Resource[] resources = resourcesManager.getResources(getSourceDocument());
+ setParameter("assets", Arrays.asList(resources));
- for (int i = 0; i < resources.length; i++) {
- Map asset = new HashMap();
- String title = "";
- String format = "";
- org.w3c.dom.Document metaDoc;
- try {
- metaDoc = DocumentHelper.readDocument(resourcesManager
- .getMetaFile(resources[i]));
- title = metaDoc.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",
- "title").item(0).getChildNodes().item(0).getNodeValue();
- format = metaDoc.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",
- "format").item(0).getChildNodes().item(0).getNodeValue();
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
- asset.put("source", resources[i].getName());
- asset.put("title", title);
- asset.put("date", DateFormat.getDateInstance().format(new Date(resources[i]
- .lastModified())));
- asset.put("format", format);
- asset.put("extent", new Long(resources[i].length() / 1024));
- assets[i] = asset;
+ /*
+ * Map[] assets = new Map[resources.length];
+ *
+ * for (int i = 0; i < resources.length; i++) { Map asset = new HashMap(); String title =
+ * ""; String format = ""; org.w3c.dom.Document metaDoc; Source assetSource = null;
+ * Source metaSource = null; try { DublinCore core = (DublinCore)
+ * resources[i].getMetaData(); metaDoc =
+ * DocumentHelper.readDocument(metaSource.getInputStream()); title =
+ * metaDoc.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",
+ * "title").item(0).getChildNodes().item(0).getNodeValue(); format =
+ * metaDoc.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",
+ * "format").item(0).getChildNodes().item(0).getNodeValue();
+ *
+ * assetSource = resolver.resolveURI(resources[i].getSourceURI()); asset.put("source",
+ * resources[i].getName()); asset.put("title", title); Date lastModified = new
+ * Date(assetSource.getLastModified()); asset.put("date",
+ * DateFormat.getDateInstance().format(lastModified)); asset.put("format", format);
+ * asset.put("extent", new Long(assetSource.getContentLength() / 1024)); assets[i] =
+ * asset;
+ * } finally { if (metaSource != null) { resolver.release(metaSource); } if
+ * (assetSource != null) { resolver.release(assetSource); } } } setParameter("assets",
+ * assets);
+ */
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (resourcesManager != null) {
+ this.manager.release(resourcesManager);
}
- setParameter("assets", assets);
}
}
@@ -114,7 +127,18 @@
*/
protected void deleteAsset() throws Exception {
String assetName = getParameterAsString("delete");
- getSourceDocument().getResourcesManager().deleteResource(assetName);
+ ResourcesManager resourcesManager = null;
+ try {
+ resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
+ resourcesManager.deleteResource(getSourceDocument(), assetName);
+ } catch (final Exception e) {
+ getLogger().error("The resource could not be added: ", e);
+ addErrorMessage("The resource could not be added (see log files for details).");
+ } finally {
+ if (resourcesManager != null) {
+ this.manager.release(resourcesManager);
+ }
+ }
}
/**
@@ -130,11 +154,17 @@
metadata.put("title", title);
metadata.put("creator", creator);
metadata.put("rights", rights);
+ ResourcesManager resourcesManager = null;
try {
- getSourceDocument().getResourcesManager().addResource(file, metadata);
+ resourcesManager = (ResourcesManager) this.manager.lookup(ResourcesManager.ROLE);
+ resourcesManager.addResource(getSourceDocument(), file, metadata);
} catch (final Exception e) {
getLogger().error("The resource could not be added: ", e);
addErrorMessage("The resource could not be added (see log files for details).");
+ } finally {
+ if (resourcesManager != null) {
+ this.manager.release(resourcesManager);
+ }
}
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java Thu Apr 14 06:53:29 2005
@@ -148,7 +148,7 @@
* @throws DocumentException if an error occurs.
*/
protected void setMetaData(Document document) throws DocumentException {
- DublinCore dublinCore = document.getDublinCore();
+ DublinCore dublinCore = (DublinCore) document.getMetaData();
dublinCore.setValue(DublinCore.ELEMENT_TITLE,
getParameterAsString(DublinCore.ELEMENT_TITLE));
dublinCore.setValue(DublinCore.ELEMENT_CREATOR,
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/CreateLanguage.java Thu Apr 14 06:53:29 2005
@@ -94,21 +94,12 @@
Document source = getSourceDocument();
if (source != null) {
- DocumentTypeResolver resolver = null;
-
try {
- resolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
- DocumentType type = resolver.resolve(source);
- this.documentTypeName = type.getName();
-
List nonExistingLanguages = getNonExistingLanguages();
setParameter(LANGUAGES, nonExistingLanguages
.toArray(new String[nonExistingLanguages.size()]));
-
} catch (Exception e) {
throw new RuntimeException(e);
- } finally {
- this.manager.release(resolver);
}
}
}
@@ -169,6 +160,24 @@
* @see org.apache.lenya.cms.site.usecases.Create#getDocumentTypeName()
*/
protected String getDocumentTypeName() {
+ if (this.documentTypeName == null) {
+ Document source = getSourceDocument();
+ DocumentTypeResolver resolver = null;
+ try {
+ resolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
+ DocumentType type = resolver.resolve(source);
+ this.documentTypeName = type.getName();
+
+ List nonExistingLanguages = getNonExistingLanguages();
+ setParameter(LANGUAGES, nonExistingLanguages.toArray(new String[nonExistingLanguages
+ .size()]));
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ this.manager.release(resolver);
+ }
+ }
return this.documentTypeName;
}
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Overview.java Thu Apr 14 06:53:29 2005
@@ -28,9 +28,8 @@
* @version $Id: Overview.java 123984 2005-01-03 15:02:18Z andreas $
*/
public class Overview extends SiteUsecase {
- private DublinCore dc;
- /**
+ /**
* Ctor.
*/
public Overview() {
@@ -42,36 +41,36 @@
*/
protected void initParameters() {
super.initParameters();
- this.dc = getSourceDocument().getDublinCore();
-
+
DocumentTypeResolver doctypeResolver = null;
try {
+ DublinCore dc = (DublinCore) getSourceDocument().getMetaData();
+ setParameter("languages", getSourceDocument().getLanguages());
+ setParameter("title", dc.getFirstValue(DublinCore.ELEMENT_TITLE));
+
doctypeResolver = (DocumentTypeResolver) this.manager.lookup(DocumentTypeResolver.ROLE);
DocumentType doctype = doctypeResolver.resolve(getSourceDocument());
- setParameter("languages", getSourceDocument().getLanguages());
- setParameter("title", this.dc.getFirstValue(DublinCore.ELEMENT_TITLE));
- setParameter("description", this.dc.getFirstValue(DublinCore.ELEMENT_DESCRIPTION));
- setParameter("lastmodified", getSourceDocument().getLastModified());
- setParameter("resourcetype", doctype.getName());
- setParameter("live", "");
- } catch (Exception e) {
- addErrorMessage("Could not read a value. See log files for details.");
- getLogger().error("Could not read value for Overview usecase. ", e);
- }
- finally {
+ setParameter("languages", getSourceDocument().getLanguages());
+ setParameter("lastmodified", getSourceDocument().getLastModified());
+ setParameter("resourcetype", doctype.getName());
+ setParameter("live", "");
+ } catch (final Exception e) {
+ addErrorMessage("Could not read a value. See log files for details.");
+ getLogger().error("Could not read value for Overview usecase. ", e);
+ } finally {
if (doctypeResolver != null) {
this.manager.release(doctypeResolver);
}
}
}
-
- /**
+
+ /**
* Validates the request parameters.
* @throws UsecaseException if an error occurs.
*/
void validate() throws UsecaseException {
- // do nothing
- }
+ // do nothing
+ }
/**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
Modified: lenya/trunk/src/java/org/apache/lenya/lenya.roles
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/lenya.roles?view=diff&r1=161283&r2=161284
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/lenya.roles (original)
+++ lenya/trunk/src/java/org/apache/lenya/lenya.roles Thu Apr 14 06:53:29 2005
@@ -114,6 +114,10 @@
shorthand="document-manager"
default-class="org.apache.lenya.cms.publication.DocumentManagerImpl"/>
+ <role name="org.apache.lenya.cms.publication.ResourcesManager"
+ shorthand="resources-manager"
+ default-class="org.apache.lenya.cms.publication.DefaultResourcesManager"/>
+
<role name="org.apache.lenya.cms.site.SiteManagerSelector"
shorthand="site-managers"
default-class="org.apache.cocoon.components.ExtendedComponentSelector"/>
@@ -130,4 +134,4 @@
shorthand="usecase-scheduler"
default-class="org.apache.lenya.cms.usecase.scheduling.UsecaseSchedulerImpl"/>
-</role-list>
\ No newline at end of file
+</role-list>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org
Re: [trunk] creating document fails (Was Re: svn commit: r161284
- in lenya/trunk/src/java/org/apache/lenya: ./ cms/ant/ cms/cocoon/acting/
cms/cocoon/components/modules/input/ cms/metadata/dublincore/ cms/metadata/usecases/
cms/publication/ cms/publication/task/ cms/site/usecases/)
Posted by Andreas Hartmann <an...@apache.org>.
J. Wolfgang Kaltz wrote:
> I'm trying to figure out the error regarding document creation in trunk
> I mentioned earlier today.
>
> In DefaultSiteTree::addNode() the error occurs at
> parentNode.appendChild(), namely
> WRONG_DOCUMENT_ERR: A node is used in a different document than the
> one that created it. (This is a Java DOM Api error)
>
> IIUC in that method,
> - "parentNode" is created with "getNodeInternal(parentid)". This
> ultimately calls load() to create a Document instance;
> - "document" is a document instance created with "Document document =
> load()"
> - "child" is a new node, created from "document" (via the NamespaceHelper)
> - the document instance created for "parentNode" is not the same as
> "document", which is used for "child"
> -> so parentNode.appendChild(child) raises an error
>
> What I don't understand is precisely which code change is causing this
> error, since this was working recently (wednesday IIRC). Maybe a
> side-effect of something else ? I'm a bit lost, frankly - any ideas ?
The reason is that SourceNode doesn't store the document but a byte array
since my last commit. I'm fixing the sitetree, I hope I can check it in
on Sunday. Sorry for the inconvenience.
> P.S. BTW maybe the interface o.a.l.cms.repository.Node should be called
> something else; it is too easy to confuse with org.w3c.dom.Node (I don't think
> the different package name is sufficient distinction)
Why could it be confused?
o.a.l.cms.publication.Document and o.w3c.dom.Document would have the same
problem, and o.a.l.c.p.Document is a lot more commonly used in the codebase
than o.a.l.cms.repository.Node.
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lenya.apache.org
For additional commands, e-mail: dev-help@lenya.apache.org
[trunk] creating document fails (Was Re: svn commit: r161284 - in
lenya/trunk/src/java/org/apache/lenya: ./ cms/ant/ cms/cocoon/acting/ cms/cocoon/components/modules/input/
cms/metadata/dublincore/ cms/metadata/usecases/ cms/publication/ cms/publication/task/
cms/site/usecases/)
Posted by "J. Wolfgang Kaltz" <jw...@apache.org>.
I'm trying to figure out the error regarding document creation in trunk
I mentioned earlier today.
In DefaultSiteTree::addNode() the error occurs at
parentNode.appendChild(), namely
WRONG_DOCUMENT_ERR: A node is used in a different document than the
one that created it. (This is a Java DOM Api error)
IIUC in that method,
- "parentNode" is created with "getNodeInternal(parentid)". This
ultimately calls load() to create a Document instance;
- "document" is a document instance created with "Document document =
load()"
- "child" is a new node, created from "document" (via the NamespaceHelper)
- the document instance created for "parentNode" is not the same as
"document", which is used for "child"
-> so parentNode.appendChild(child) raises an error
What I don't understand is precisely which code change is causing this
error, since this was working recently (wednesday IIRC). Maybe a
side-effect of something else ? I'm a bit lost, frankly - any ideas ?
--
Wolfgang
P.S. BTW maybe the interface o.a.l.cms.repository.Node should be called
something else; it is too easy to confuse with org.w3c.dom.Node (I don't
think the different package name is sufficient distinction)
Re: svn commit: r161284 - in lenya/trunk/src/java/org/apache/lenya:
./ cms/ant/ cms/cocoon/acting/ cms/cocoon/components/modules/input/ cms/metadata/dublincore/
cms/metadata/usecases/ cms/publication/ cms/publication/task/ cms/site/usecases/
Posted by "J. Wolfgang Kaltz" <ka...@interactivesystems.info>.
andreas@apache.org schrieb:
> Author: andreas
> Date: Thu Apr 14 06:53:29 2005
> New Revision: 161284
>
> URL: http://svn.apache.org/viewcvs?view=rev&rev=161284
> Log:
> generalized DublinCore to MetaDataManager, using lenya:// sources for asset management
>
> Modified:
> (...)
> lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
> lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java
> lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
> lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
> lenya/trunk/src/java/org/apache/lenya/cms/publication/DocumentTypeResolverImpl.java
> lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java
> (...)
I can not create a new document, I'm wondering if it's related to the
above changes ?
(I tried on fresh checkout as well)
Stacktrace:
org.apache.avalon.framework.CascadingRuntimeException:
"file:/home/ds9kaltz/src/lenya-trunk-test/build/lenya/webapp/lenya/usecases/usecases.js",
line 179: uncaught JavaScript exception:
at executeUsecase
(file:/home/ds9kaltz/src/lenya-trunk-test/build/lenya/webapp/lenya/usecases/usecases.js,
Line 179):
org.apache.lenya.cms.usecase.UsecaseException: org.w3c.dom.DOMException:
WRONG_DOCUMENT_ERR: A node is used in a different document than the one
that created it.
...
Caused by: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used
in a different document than the one that created it.
at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknown Source)
at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
at
org.apache.lenya.cms.site.tree.DefaultSiteTree.addNode(DefaultSiteTree.java:285)
at
org.apache.lenya.cms.site.tree.DefaultSiteTree.addNode(DefaultSiteTree.java:199)
at
org.apache.lenya.cms.site.tree.DefaultSiteTree.addNode(DefaultSiteTree.java:208)
at
org.apache.lenya.cms.site.tree.TreeSiteManager.add(TreeSiteManager.java:364)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.apache.avalon.excalibur.component.ComponentProxyGenerator$ComponentInvocationHandler.invoke(ComponentProxyGenerator.java:143)
at $Proxy13.add(Unknown Source)
at
org.apache.lenya.cms.publication.DocumentManagerImpl.add(DocumentManagerImpl.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.apache.avalon.excalibur.component.ComponentProxyGenerator$ComponentInvocationHandler.invoke(ComponentProxyGenerator.java:143)
at $Proxy18.add(Unknown Source)
at org.apache.lenya.cms.site.usecases.Create.doExecute(Create.java:111)
Re: svn commit: r161284 - in lenya/trunk/src/java/org/apache/lenya:
./ cms/ant/ cms/cocoon/acting/ cms/cocoon/components/modules/input/ cms/metadata/dublincore/
cms/metadata/usecases/ cms/publication/ cms/publication/task/ cms/site/usecases/
Posted by Andreas Hartmann <an...@apache.org>.
J. Wolfgang Kaltz wrote:
[...]
> On a (somewhat) related note, I just experimented with changing the
> DocumentTypeBuilder to an Avalon service as well. It works; I haven't
> however yet touched on the usage of java.io.File in there.
>
> Should I check that state in ?
+1, I don't see any problems.
> Or is some other work going on in parallel on that code ?
At least not in my sandbox.
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lenya.apache.org
For additional commands, e-mail: dev-help@lenya.apache.org
Re: svn commit: r161284 - in lenya/trunk/src/java/org/apache/lenya:
./ cms/ant/ cms/cocoon/acting/ cms/cocoon/components/modules/input/ cms/metadata/dublincore/
cms/metadata/usecases/ cms/publication/ cms/publication/task/ cms/site/usecases/
Posted by "J. Wolfgang Kaltz" <ka...@interactivesystems.info>.
> (...)
> Modified: lenya/trunk/src/java/org/apache/lenya/lenya.roles
> URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/lenya.roles?view=diff&r1=161283&r2=161284
> ==============================================================================
> --- lenya/trunk/src/java/org/apache/lenya/lenya.roles (original)
> +++ lenya/trunk/src/java/org/apache/lenya/lenya.roles Thu Apr 14 06:53:29 2005
> @@ -114,6 +114,10 @@
> shorthand="document-manager"
> default-class="org.apache.lenya.cms.publication.DocumentManagerImpl"/>
>
> + <role name="org.apache.lenya.cms.publication.ResourcesManager"
> + shorthand="resources-manager"
> + default-class="org.apache.lenya.cms.publication.DefaultResourcesManager"/>
> +
> <role name="org.apache.lenya.cms.site.SiteManagerSelector"
On a (somewhat) related note, I just experimented with changing the
DocumentTypeBuilder to an Avalon service as well. It works; I haven't
however yet touched on the usage of java.io.File in there.
Should I check that state in ? Or is some other work going on in
parallel on that code ?
Wolfgang
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lenya.apache.org
For additional commands, e-mail: dev-help@lenya.apache.org