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 2011/09/27 16:53:24 UTC

svn commit: r1176413 - in /lenya/contributions/2_0_X/modules/atom: config/module.xml java/src/org/apache/lenya/modules/atom/Assets.java

Author: andreas
Date: Tue Sep 27 14:53:24 2011
New Revision: 1176413

URL: http://svn.apache.org/viewvc?rev=1176413&view=rev
Log:
Use ResourceWrapper for asset upload in atom module, sets media meta data correctly.

Modified:
    lenya/contributions/2_0_X/modules/atom/config/module.xml
    lenya/contributions/2_0_X/modules/atom/java/src/org/apache/lenya/modules/atom/Assets.java

Modified: lenya/contributions/2_0_X/modules/atom/config/module.xml
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/atom/config/module.xml?rev=1176413&r1=1176412&r2=1176413&view=diff
==============================================================================
--- lenya/contributions/2_0_X/modules/atom/config/module.xml (original)
+++ lenya/contributions/2_0_X/modules/atom/config/module.xml Tue Sep 27 14:53:24 2011
@@ -18,6 +18,7 @@
 <module xmlns="http://apache.org/lenya/module/1.0">
   <id>org.apache.lenya.modules.atom</id>
   <depends module="org.apache.lenya.modules.rest"/>
+  <depends module="org.apache.lenya.modules.resource"/>
   <package>org.apache.lenya.modules</package>
   <version>1.0-alpha1</version>
   <name>Atom Syndication Format and Publishing Protocol</name>

Modified: lenya/contributions/2_0_X/modules/atom/java/src/org/apache/lenya/modules/atom/Assets.java
URL: http://svn.apache.org/viewvc/lenya/contributions/2_0_X/modules/atom/java/src/org/apache/lenya/modules/atom/Assets.java?rev=1176413&r1=1176412&r2=1176413&view=diff
==============================================================================
--- lenya/contributions/2_0_X/modules/atom/java/src/org/apache/lenya/modules/atom/Assets.java (original)
+++ lenya/contributions/2_0_X/modules/atom/java/src/org/apache/lenya/modules/atom/Assets.java Tue Sep 27 14:53:24 2011
@@ -17,15 +17,12 @@
  */
 package org.apache.lenya.modules.atom;
 
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.StringTokenizer;
 
 import org.apache.avalon.framework.service.ServiceSelector;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Response;
 import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.io.IOUtils;
 import org.apache.lenya.cms.metadata.MetaData;
 import org.apache.lenya.cms.metadata.dublincore.DublinCore;
 import org.apache.lenya.cms.publication.Document;
@@ -36,6 +33,7 @@ import org.apache.lenya.cms.publication.
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.cms.publication.ResourceType;
 import org.apache.lenya.cms.publication.ResourceType.Sample;
+import org.apache.lenya.cms.publication.ResourceWrapper;
 import org.apache.lenya.cms.site.SiteUtil;
 import org.apache.lenya.modules.rest.RestView;
 import org.apache.lenya.util.Assert;
@@ -97,26 +95,13 @@ public class Assets extends AtomHandler 
             Sample sample = resourceType.getSample(resourceType.getSampleNames()[0]);
             Document document = documentManager.add(factory, resourceType, sample.getUri(), pub,
                     parent.getArea(), path, language, extension, title, visibleInNav);
-
-            InputStream in = getInputStream();
-            OutputStream out = document.getOutputStream();
-            try {
-                IOUtils.copy(in, out);
-            } finally {
-                if (in != null) {
-                    in.close();
-                }
-                if (out != null) {
-                    out.flush();
-                    out.close();
-                }
-            }
-
-            document.setMimeType(mimeType);
+            
+            final ResourceWrapper wrapper = new ResourceWrapper(document, this.manager, getLogger());
+            wrapper.write(getInputStream(), mimeType, slug, getRequest().getContentLength());
 
             MetaData dublinCore = document.getMetaData(DublinCore.DC_NAMESPACE);
             dublinCore.setValue(DublinCore.ELEMENT_TITLE, title);
-
+            
             document.getSession().commit();
             setLocationHeader(document);
             return new EntryView(document, HttpStatus.SC_CREATED);
@@ -164,10 +149,10 @@ public class Assets extends AtomHandler 
 
     protected String getAvailablePath(String name, String language) throws Exception {
         Document doc = getDocumentWrapper().getDocument();
-        DocumentLocator requestedLocator = doc.getLocator().getChild(name).getLanguageVersion(
-                language);
-        DocumentLocator availableLocator = SiteUtil.getAvailableLocator(this.manager, doc
-                .getFactory(), requestedLocator);
+        DocumentLocator requestedLocator = doc.getLocator().getChild(name)
+                .getLanguageVersion(language);
+        DocumentLocator availableLocator = SiteUtil.getAvailableLocator(this.manager,
+                doc.getFactory(), requestedLocator);
         return availableLocator.getPath();
     }
 



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