You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by gr...@apache.org on 2004/12/28 19:25:43 UTC

svn commit: r123528 - in lenya/trunk/src: java/org/apache/lenya/cms/ant java/org/apache/lenya/cms/metadata/dublincore java/org/apache/lenya/cms/publication java/org/apache/lenya/cms/publication/task java/org/apache/lenya/cms/site webapp/WEB-INF webapp/lenya/content/info webapp/lenya/usecases/site

Author: gregor
Date: Tue Dec 28 10:25:41 2004
New Revision: 123528

URL: http://svn.apache.org/viewcvs?view=rev&rev=123528
Log:
Refactored ResourcesManager, added addResource method.
Based ResourcesManager on DublinCore. 
Added getResourcesManager() to Document interface.
Added Assets usecase.
Improved the assets JX view.
Changed all callers of ResourceManager to use getResourcesManager()
Added:
   lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java   (contents, props changed)
   lenya/trunk/src/java/org/apache/lenya/cms/site/Assets.java   (contents, props changed)
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/metadata/dublincore/DublinCoreImpl.java
   lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java
   lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.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/webapp/WEB-INF/cocoon-xconf.xsl
   lenya/trunk/src/webapp/lenya/content/info/assets.xsp
   lenya/trunk/src/webapp/lenya/usecases/site/assets.jx

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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java&r2=123528
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java	(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/CopyResourcesTask.java	Tue Dec 28 10:25:41 2004
@@ -68,7 +68,7 @@
         } catch (DocumentBuildException e) {
             throw new BuildException(e);
         }
-        ResourcesManager resourcesMgr = new ResourcesManager(srcDoc);
+        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()]);
@@ -84,8 +84,7 @@
         } catch (DocumentBuildException e) {
             throw new BuildException(e);
         }
-        resourcesMgr = new ResourcesManager(destDoc);
-
+        resourcesMgr = destDoc.getResourcesManager();
         for (int i = 0; i < srcFiles.length; i++) {
 
             try {

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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java&r2=123528
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java	(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/DeactivateResourcesTask.java	Tue Dec 28 10:25:41 2004
@@ -76,7 +76,7 @@
                 } catch (DocumentBuildException e) {
                     throw new BuildException(e);
                 }
-                ResourcesManager resourcesMgr = new ResourcesManager(doc);
+                ResourcesManager resourcesMgr = doc.getResourcesManager();
                 File[] resources = resourcesMgr.getResources();
                 for (int i = 0; i < resources.length; i++) {
                     resources[i].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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java&r2=123528
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java	(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/DeleteResourcesTask.java	Tue Dec 28 10:25:41 2004
@@ -63,7 +63,7 @@
                 throw new BuildException(e);
             }
 
-            ResourcesManager resourcesMgr = new ResourcesManager(srcDoc);
+            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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java&r2=123528
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java	(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ant/ResourcePublisher.java	Tue Dec 28 10:25:41 2004
@@ -44,10 +44,10 @@
 
         try {
             Document authoringDocument = getIdentityMap().getFactory().get(Publication.AUTHORING_AREA, documentId);
-            ResourcesManager authoringManager = new ResourcesManager(authoringDocument);
+            ResourcesManager authoringManager = authoringDocument.getResourcesManager();
 
             Document liveDocument = getIdentityMap().getFactory().get(Publication.LIVE_AREA, documentId);
-            ResourcesManager liveManager = new ResourcesManager(liveDocument);
+            ResourcesManager liveManager = liveDocument.getResourcesManager();
             
             // find all resource files and their associated meta files
             List resourcesList =

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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/metadata/dublincore/DublinCoreImpl.java&r2=123528
==============================================================================
--- 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	Tue Dec 28 10:25:41 2004
@@ -102,6 +102,20 @@
     }
 
     /**
+     * Creates a new instance of Dublin Core 
+     * 
+     * @param file the File for which the Dublin Core instance is created.
+     * TODO This is a hack until resources are treated as documents, and .meta files
+     * can be accessed through the Document interface.
+     * 
+     * @throws DocumentException if an error occurs
+     */
+    public DublinCoreImpl(File file) throws DocumentException {
+        infofile = file;
+        loadValues();
+    }
+
+    /**
      * Loads the dublin core values from the XML file.
      * @throws DocumentException when something went wrong.
      */

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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java&r2=123528
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java	(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultDocument.java	Tue Dec 28 10:25:41 2004
@@ -38,7 +38,7 @@
     private String id;
     private DublinCore dublincore;
     private DocumentIdentityMap identityMap;
-
+    private ResourcesManager resourcesManager;
     /**
      * Creates a new instance of DefaultDocument.
      * @param map The identity map the document belongs to.
@@ -57,6 +57,7 @@
 
         this.identityMap = map;
         this.dublincore = new DublinCoreProxy(this);
+        this.resourcesManager = new DefaultResourcesManager(this);
     }
 
     /**
@@ -106,6 +107,7 @@
         setArea(area);
 
         this.dublincore = new DublinCoreProxy(this);
+        this.resourcesManager = new DefaultResourcesManager(this);
 
     }
 
@@ -375,6 +377,13 @@
      */
     public DocumentIdentityMap getIdentityMap() {
         return this.identityMap;
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.Document#getResourcesManager()
+     */
+    public ResourcesManager getResourcesManager() {
+        return this.resourcesManager;
     }
 
     /**

Added: 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=auto&rev=123528
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/DefaultResourcesManager.java	Tue Dec 28 10:25:41 2004
@@ -0,0 +1,320 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ *
+ */
+
+/* $Id$  */
+
+package org.apache.lenya.cms.publication;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+
+import org.apache.avalon.excalibur.io.FileUtil;
+
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.cocoon.servlet.multipart.PartInMemory;
+import org.apache.cocoon.servlet.multipart.PartOnDisk;
+import org.apache.lenya.xml.DocumentHelper;
+import org.apache.lenya.xml.NamespaceHelper;
+import org.apache.lenya.cms.metadata.dublincore.DublinCoreImpl;
+
+import org.w3c.dom.Element;
+
+/**
+ * Manager for resources of a CMS document.
+ */
+public class DefaultResourcesManager extends AbstractLogEnabled 
+	implements ResourcesManager {
+
+	private Document document = null;
+	private DublinCoreImpl dc = null;
+
+    /**
+     * Create a new instance of Resources.
+     * 
+     * @param document the document for which the resources are managed
+     */
+    public DefaultResourcesManager(Document document) {
+        this.document = document;
+    }
+
+
+    /**
+     * 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 Exception if an error occurs
+     */
+    public void addResource(Part part, Map metadata) throws Exception {
+
+        File resourceFile;
+
+        String fileName = part.getFileName();
+        if (!fileName.matches(FILE_NAME_REGEXP)) {
+            // the file name contains characters which mean trouble
+            // and are therefore not allowed.
+            getLogger().warn("The filename [" + fileName + "]�is not valid for an asset.");
+        }
+        // convert spaces in the file name to underscores
+        fileName = fileName.replace(' ', '_');
+        String mimeType = part.getMimeType();
+        int fileSize = part.getSize();
+
+        metadata.put("format", mimeType);
+        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);
+
+/*        }
+        // must be a content upload then
+        else {
+            resourceFile = new File(document.getFile().getParent(), fileName);
+            getLogger().debug("resourceFile: " + resourceFile);
+        }
+*/
+        saveResource(resourceFile, part);
+    }
+
+    /**
+     * Saves the resource to a file.
+     * 
+     * @param resourceFile The resource file.
+     * @param part The part of the multipart request.
+     * @throws Exception if an error occurs.
+     */
+    protected void saveResource(File resourceFile, Part part) throws Exception {
+        if (!resourceFile.exists()) {
+            boolean created = resourceFile.createNewFile();
+            if (!created) {
+                throw new RuntimeException("The file [" + resourceFile + "]�could not be created.");
+            }
+        }
+
+        byte[] buf = new byte[4096];
+        FileOutputStream out = new FileOutputStream(resourceFile);
+        try {
+            InputStream in = part.getInputStream();
+            int read = in.read(buf);
+
+            while (read > 0) {
+                out.write(buf, 0, read);
+                read = in.read(buf);
+            }
+        } finally {
+            out.close();
+        }
+    }
+
+    /**
+     * Create the meta data file given the dublin core parameters.
+     * 
+     * @param metaDataFile the file where the meta data file is to be created
+     * @param metadata a <code>Map</code> containing the dublin core values
+     * @throws TransformerConfigurationException if an error occurs.
+     * @throws TransformerException if an error occurs.
+     * @throws IOException if an error occurs
+     * @throws ParserConfigurationException if an error occurs.
+     */
+    protected void createMetaData(File metaDataFile, Map metadata)
+            throws TransformerConfigurationException, TransformerException, IOException,
+            ParserConfigurationException {
+
+        assert (metaDataFile.getParentFile().exists());
+        try {
+	        dc = new DublinCoreImpl(metaDataFile);
+	        Iterator iter = metadata.keySet().iterator();
+	
+	        while (iter.hasNext()) {
+	            String key = (String) iter.next();
+	            String value = (String) metadata.get(key);
+	            dc.setValue(key, value);
+	        }
+	        dc.save();
+        } catch(Exception e) {
+            getLogger().error("Saving of [" + metaDataFile + "]�failed.");
+        }
+    }
+
+    /**
+     * Get the path to the resources.
+     * 
+     * @return the path to the resources
+     */
+    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.
+     * @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() {
+
+        // filter the meta files out. We only want to see the "real" resources.
+        FileFilter filter = new FileFilter() {
+
+            public boolean accept(File file) {
+                return file.isFile() && !file.getName().endsWith(RESOURCES_META_SUFFIX);
+            }
+        };
+
+        return getFiles(filter);
+    }
+
+    /**
+     * Return all resources which are images.
+     * @return All image resources.
+     */
+    public File[] getImageResources() {
+        return getFiles( new FileFilter() {
+                public boolean accept(File file) {
+                    for(int i=0; i<IMAGE_FILE_EXTENSIONS.length; i++)
+                        if (file.getName().toLowerCase().endsWith(IMAGE_FILE_EXTENSIONS[i]))
+                            return true;
+                    return false;
+                }
+            });
+    }
+    
+    /**
+     * Returns the resources that are matched by a certain file filter.
+     * @param filter A file filter.
+     * @return A file array.
+     */
+    protected File[] getFiles(FileFilter filter) {
+        File[] files = new File[0];
+        if (getPath().isDirectory()) {
+            files = getPath().listFiles(filter);
+        }
+
+        return files;
+    }
+
+    /**
+     * 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 FileFilter() {
+
+            public boolean accept(File file) {
+                return file.isFile() && file.getName().endsWith(RESOURCES_META_SUFFIX);
+            }
+        };
+        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.
+     */
+    public File getMetaFile(final File resource) throws IllegalArgumentException {
+        if(resource.getName().endsWith(RESOURCES_META_SUFFIX))
+            throw new IllegalArgumentException("File is itself a meta file.");
+        
+        final FileFilter filter = new FileFilter() {
+            public boolean accept(File file) {
+                return file.isFile() && 
+                    file.getName().equals(resource.getName().concat(RESOURCES_META_SUFFIX));
+            }
+        };
+        
+        final File[] metaFiles = getFiles(filter);
+        assert(metaFiles.length == 0);
+        return metaFiles[0];
+    }
+    
+    /**
+     * Deletes all resources.
+     */
+    public void deleteResources() {
+
+        File stopDirectory = new File(getDocument().getPublication().getDirectory(), RESOURCES_PREFIX);
+
+        File[] resources = getResources();
+        for (int i = 0; i < resources.length; i++) {
+            resources[i].delete();
+           //TODO replace with excalibur FileUtil.deleteParentDirs(resources[i], stopDirectory);
+        }
+
+        File[] metas = getMetaFiles();
+        for (int i = 0; i < metas.length; i++) {
+            metas[i].delete();
+            //TODO replace with excalibur FileUtil.deleteParentDirs(metas[i], stopDirectory);
+        }
+    }
+
+    public Document getDocument() {
+        return document;
+    }
+}
\ No newline at end of file

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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java&r2=123528
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java	(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java	Tue Dec 28 10:25:41 2004
@@ -199,6 +199,12 @@
     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.
      */

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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java&r2=123528
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java	(original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourcesManager.java	Tue Dec 28 10:25:41 2004
@@ -20,127 +20,73 @@
 package org.apache.lenya.cms.publication;
 
 import java.io.File;
-import java.io.FileFilter;
+import java.util.Map;
 
-import org.apache.lenya.util.FileUtil;
+import org.apache.cocoon.servlet.multipart.Part;
 
 /**
  * Manager for resources of a CMS document.
  */
-public class ResourcesManager {
-
-    private Document document;
+public interface ResourcesManager {
 
+    public static final String CONTENT_PREFIX = "content";
     public static final String RESOURCES_PREFIX = "resources";
-
     public static final String RESOURCES_META_SUFFIX = ".meta";
 
-    /**
-     * Create a new instance of Resources.
-     * 
-     * @param document the document for which the resources are managed
-     */
-    public ResourcesManager(Document document) {
-        this.document = document;
-    }
+    public static final String UPLOADASSET_PARAM_NAME = "properties.asset.data";
+    public static final String UPLOADASSET_PARAM_PREFIX = "properties.asset.";
+
+    public static final String UPLOADASSET_RETURN_FILESIZE = "file-size";
+    public static final String UPLOADASSET_RETURN_MIMETYPE = "mime-type";
+
+    public static final String FILE_NAME_REGEXP = "[-a-zA-Z0-9_.]+";
+    public static final String[] IMAGE_FILE_EXTENSIONS = {".jpg", ".png", ".bmp", ".gif", ".svg"};
+
+    // optional parameters for meta data according to dublin core
+    public static final String[] DUBLIN_CORE_PARAMETERS = { "title", "creator", "subject",
+            "description", "publisher", "contributor", "date", "type", "format", "identifier",
+            "source", "language", "relation", "coverage", "rights" };
 
     /**
-     * Get the path to the resources.
-     * 
-     * @return the path to the resources
+     * Add a resource to the document.
+     * @param part the part that contains the uploaded file
+     * @param metadata the metadata for the resource
      */
-    public String getPathFromPublication() {
-        return RESOURCES_PREFIX + "/" + getDocument().getArea() + getDocument().getId();
-    }
+    public void addResource(Part part, Map metadata) throws Exception;
 
     /**
      * Get the path to the resources.
      * 
      * @return the path to the resources
+     * @deprecated the resource manager should not expose storage details.
      */
-    public File getPath() {
-        File publicationPath = getDocument().getPublication().getDirectory();
-        File resourcesPath = new File(publicationPath, getPathFromPublication().replace('/',
-                File.separatorChar));
-        return resourcesPath;
-    }
+    public File getPath();
 
     /**
      * Returns the path of a resource relative to the context prefix.
      * @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();   
-    }
+    public String getResourceUrl(File resource);
     
     /**
      * Get all resources for the associated document.
      * 
      * @return all resources of the associated document
      */
-    public File[] getResources() {
-
-        // filter the meta files out. We only want to see the "real" resources.
-        FileFilter filter = new FileFilter() {
-
-            public boolean accept(File file) {
-                return file.isFile() && !file.getName().endsWith(RESOURCES_META_SUFFIX);
-            }
-        };
-
-        return getFiles(filter);
-    }
+    public File[] getResources();
 
     /**
      * Return all resources which are images.
      * @return All image resources.
      */
-    public File[] getImageResources() {
-        final String[] IMAGE_FILE_EXTENSIONS = {".jpg", ".png", ".bmp", ".gif", ".svg"};
-        return getFiles( new FileFilter() {
-                public boolean accept(File file) {
-                    for(int i=0; i<IMAGE_FILE_EXTENSIONS.length; i++)
-                        if (file.getName().toLowerCase().endsWith(IMAGE_FILE_EXTENSIONS[i]))
-                            return true;
-                    return false;
-                }
-            });
-    }
+    public File[] getImageResources();
     
     /**
-     * Returns the resources that are matched by a certain file filter.
-     * @param filter A file filter.
-     * @return A file array.
-     */
-    protected File[] getFiles(FileFilter filter) {
-        File[] files = new File[0];
-        if (getPath().isDirectory()) {
-            files = getPath().listFiles(filter);
-        }
-
-        return files;
-    }
-
-    /**
      * 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 FileFilter() {
-
-            public boolean accept(File file) {
-                return file.isFile() && file.getName().endsWith(RESOURCES_META_SUFFIX);
-            }
-        };
-        return getFiles(filter);
-    }
+    public File[] getMetaFiles();
 
     /**
      * Returns a meta file for a given resource.
@@ -149,43 +95,15 @@
      * Returns null if no meta file was found.
      * @throws IllegalArgumentException If resource is a meta file itself.
      */
-    public File getMetaFile(final File resource) throws IllegalArgumentException {
-        if(resource.getName().endsWith(RESOURCES_META_SUFFIX))
-            throw new IllegalArgumentException("File is itself a meta file.");
-        
-        final FileFilter filter = new FileFilter() {
-            public boolean accept(File file) {
-                return file.isFile() && 
-                    file.getName().equals(resource.getName().concat(RESOURCES_META_SUFFIX));
-            }
-        };
-        
-        final File[] metaFiles = getFiles(filter);
-        assert(metaFiles.length == 0);
-        return metaFiles[0];
-    }
+    public File getMetaFile(final File resource) throws IllegalArgumentException;
     
     /**
      * Deletes all resources.
      */
-    public void deleteResources() {
-
-        File stopDirectory = new File(getDocument().getPublication().getDirectory(), RESOURCES_PREFIX);
+    public void deleteResources();
 
-        File[] resources = getResources();
-        for (int i = 0; i < resources.length; i++) {
-            resources[i].delete();
-            FileUtil.deleteParentDirs(resources[i], stopDirectory);
-        }
-
-        File[] metas = getMetaFiles();
-        for (int i = 0; i < metas.length; i++) {
-            metas[i].delete();
-            FileUtil.deleteParentDirs(metas[i], stopDirectory);
-        }
-    }
-
-    public Document getDocument() {
-        return document;
-    }
+    /**
+     * Gets the document this resource manager belongs to.
+     */
+    public Document getDocument();
 }

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&rev=123528&p1=lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java&r1=123527&p2=lenya/trunk/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java&r2=123528
==============================================================================
--- 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	Tue Dec 28 10:25:41 2004
@@ -97,8 +97,8 @@
             log.debug("Copying resources");
         }
 
-        ResourcesManager sourceManager = new ResourcesManager(sourceDocument);
-        ResourcesManager destinationManager = new ResourcesManager(destinationDocument);
+        ResourcesManager sourceManager = sourceDocument.getResourcesManager();
+        ResourcesManager destinationManager = destinationDocument.getResourcesManager();
 
         List resourcesList = new ArrayList(Arrays.asList(sourceManager.getResources()));
         resourcesList.addAll(Arrays.asList(sourceManager.getMetaFiles()));

Added: lenya/trunk/src/java/org/apache/lenya/cms/site/Assets.java
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/Assets.java?view=auto&rev=123528
==============================================================================
--- (empty file)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/Assets.java	Tue Dec 28 10:25:41 2004
@@ -0,0 +1,101 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.site;
+
+import java.util.Map;
+import org.apache.cocoon.servlet.multipart.Part;
+
+import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.ResourcesManager;
+import org.apache.lenya.cms.publication.DocumentBuildException;
+import org.apache.lenya.cms.site.SiteUsecase;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+/**
+ * Usecase to Assets a resource.
+ * 
+ * @version $Id$
+ */
+public class Assets extends SiteUsecase {
+	
+	private ResourcesManager resourcesManager = null;
+
+	/**
+     * Ctor.
+     */
+    public Assets() {
+        super();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doInitialize()
+     */
+    protected void doInitialize() throws Exception {
+        super.doInitialize();
+        resourcesManager = getSourceDocument().getResourcesManager();
+    }
+            
+     /**
+     * Validates the request parameters.
+     * @throws UsecaseException if an error occurs.
+     */
+    void validate() throws UsecaseException {
+        String title = getParameterAsString("title");
+        String creator = getParameterAsString("creator");
+        String rights = getParameterAsString("rights");
+
+        if (title.length() == 0) {
+            addErrorMessage("Please enter a title.");
+        }
+
+   }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
+     */
+    protected void doCheckExecutionConditions() throws Exception {
+        validate();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+     */
+    protected void doExecute() throws Exception {
+        super.doExecute();
+        String title = getParameterAsString("title");
+        String creator = getParameterAsString("creator");
+        String rights = getParameterAsString("rights");
+        Part file = (Part)getParameter("file");
+
+        Map metadata = null;
+        metadata.put("title",title);
+        metadata.put("cretor",creator);
+        metadata.put("rights",rights);
+        try {
+        	resourcesManager.addResource(file, metadata);
+        } catch (Exception e) {
+            addErrorMessage("The resource could not be added.");
+        }
+    }
+
+    /**
+     * @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);
+    }
+}
\ No newline at end of file

Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?view=diff&rev=123528&p1=lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl&r1=123527&p2=lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl&r2=123528
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl	(original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl	Tue Dec 28 10:25:41 2004
@@ -243,6 +243,7 @@
     <component-instance name="ac.login" logger="lenya.ac" class="org.apache.lenya.cms.ac.Login"/>
     <component-instance name="ac.logout" logger="lenya.ac" class="org.apache.lenya.cms.ac.Logout"/>
     <component-instance name="site.meta" logger="lenya.site" class="org.apache.lenya.cms.metadata.Metadata"/>
+    <component-instance name="site.assets" logger="lenya.site" class="org.apache.lenya.cms.site.Assets"/>
     <component-instance name="authoring.create" logger="lenya.authoring" class="org.apache.lenya.cms.authoring.Create"/>
   </usecases>
       

Modified: lenya/trunk/src/webapp/lenya/content/info/assets.xsp
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/content/info/assets.xsp?view=diff&rev=123528&p1=lenya/trunk/src/webapp/lenya/content/info/assets.xsp&r1=123527&p2=lenya/trunk/src/webapp/lenya/content/info/assets.xsp&r2=123528
==============================================================================
--- lenya/trunk/src/webapp/lenya/content/info/assets.xsp	(original)
+++ lenya/trunk/src/webapp/lenya/content/info/assets.xsp	Tue Dec 28 10:25:41 2004
@@ -40,7 +40,7 @@
   <lenya-info:info>
     <xsp:logic>
       Document doc = (Document) <input:get-attribute module="page-envelope" as="object" name="document"/>;
-      ResourcesManager resourceMgr = new ResourcesManager(doc);
+      ResourcesManager resourceMgr = doc.getResourcesManager();
       File[] resources = resourceMgr.getResources();
       
       String documentId = (String) <request:get-parameter name="document-id"/>;

Modified: lenya/trunk/src/webapp/lenya/usecases/site/assets.jx
Url: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/site/assets.jx?view=diff&rev=123528&p1=lenya/trunk/src/webapp/lenya/usecases/site/assets.jx&r1=123527&p2=lenya/trunk/src/webapp/lenya/usecases/site/assets.jx&r2=123528
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/site/assets.jx	(original)
+++ lenya/trunk/src/webapp/lenya/usecases/site/assets.jx	Tue Dec 28 10:25:41 2004
@@ -17,10 +17,12 @@
 
 <!-- $Id$ -->
 
-<page:page xmlns:jx="http://apache.org/cocoon/templates/jx/1.0" 
+<html xmlns:jx="http://apache.org/cocoon/templates/jx/1.0" 
            xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" 
            xmlns="http://www.w3.org/1999/xhtml" 
            xmlns:i18n="http://apache.org/cocoon/i18n/2.1" >
+           <head/>
+            <body>
   <div>
     <table border="0" cellpadding="0" cellspacing="0">
       <tr>
@@ -105,7 +107,7 @@
               <jx:if test="${item.format.equals('image/jpeg') or item.format.equals('image/gif') or item.format.equals('image/png')}">
                   <img src="../authoring/${usecase.getParameter('documentnodeid')}/${item.source}" style="height: 32px; vertical-align: middle;"/>&#160;
               </jx:if>
-             </td>
+            </td>
             <td><jx:out value="${item.title}"/></td>
             <td align="right"><jx:out value="${item.extent}"/> kB</td>
             <td align="right"><jx:out value="${item.date}"/></td>
@@ -120,16 +122,55 @@
               </form>
             </td>
           </tr> 
-        </jx:forEeach>
+        </jx:forEach>
       </table>
-      <form>
+<!--     <jx:if test="${usecase.getParameter('area').equals('authoring')}">
+-->      <form>
         <input type="hidden" name="lenya.usecase" value="site.asset"/>
-        <input type="hidden" name="insert" value="false"/>
-        <jx:choose>
-           <jx:when test="${usecase.getParameter('area').equals('authoring')}"><input i18n:attr="value" type="submit" value="New Asset"/></jx:when>
-           <jx:otherwise><input i18n:attr="value" type="submit" disabled="disabled" value="New Asset"/></jx:otherwise>
-         </jx:choose>              
-      </form>
-    </div>
+        <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+        <table class="lenya-table-noborder">
+          <tr>
+            <td colspan="2">
+              <ul>
+              <jx:forEach var="message" items="${usecase.getErrorMessages()}">
+                <li>
+                  <i18n:text><jx:out value="${message}"/></i18n:text>
+                </li>
+              </jx:forEach>
+              <jx:forEach var="message" items="${usecase.getInfoMessages()}">
+                <li>
+                  <i18n:text><jx:out value="${message}"/></i18n:text>
+                </li>
+              </jx:forEach>
+              </ul>
+            </td>
+          </tr>
+          <tr>
+            <td class="lenya-entry-caption"><i18n:text>File</i18n:text> *</td>
+            <td><input type="file" name="file" class="lenya-form-entry"/></td>
+          </tr>
+          <tr>
+            <td class="lenya-entry-caption"><i18n:text>Title</i18n:text> *</td>
+            <td><input type="text" name="title" class="lenya-form-entry" value="${usecase.getParameter('title')}"/></td>
+          </tr>
+          <tr>
+            <td class="lenya-entry-caption"><i18n:text>Creator</i18n:text> *</td>
+            <td><input type="text" name="creator" class="lenya-form-entry" value="${usecase.getParameter('creator')}"/></td>
+          </tr>
+          <tr>
+            <td class="lenya-entry-caption"><i18n:text>Rights</i18n:text> *</td>
+            <td><input type="text" name="rights" class="lenya-form-entry" value="${usecase.getParameter('rights')}"/></td>
+          </tr>
+          <tr>
+            <td/>
+            <td>
+              <input i18n:attr="value" type="submit" value="New Asset"/>
+            </td>
+          </tr>
+        </table>
+       </form>
+<!--      </jx:if>
+-->    </div>
   </div>
-</page:page>
\ No newline at end of file
+  </body>
+</html>
\ No newline at end of file

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