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 2006/07/23 23:28:29 UTC

svn commit: r424827 - in /lenya/trunk/src: impl/java/org/apache/lenya/cms/publication/DocumentImpl.java java/org/apache/lenya/cms/publication/Document.java

Author: andreas
Date: Sun Jul 23 14:28:29 2006
New Revision: 424827

URL: http://svn.apache.org/viewvc?rev=424827&view=rev
Log:
Added mimeType and contentLength methods to Document interface

Modified:
    lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java

Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java?rev=424827&r1=424826&r2=424827&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java Sun Jul 23 14:28:29 2006
@@ -27,6 +27,8 @@
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.lenya.cms.cocoon.source.RepositorySource;
 import org.apache.lenya.cms.cocoon.source.SourceUtil;
@@ -52,12 +54,17 @@
     public static final String METADATA_NAMESPACE = "http://apache.org/lenya/metadata/document/1.0";
 
     /**
-     * The name of the resource type attribute. An XML resource has a resource type; this
-     * information can be used e.g. for different rendering of different types.
+     * The name of the resource type attribute. A resource has a resource type; this information can
+     * be used e.g. for different rendering of different types.
      */
     public static final String METADATA_RESOURCE_TYPE = "resourceType";
 
     /**
+     * The name of the mime type attribute.
+     */
+    public static final String METADATA_MIME_TYPE = "mimeType";
+
+    /**
      * The name of the content type attribute. Any content managed by Lenya has a type; this
      * information can be used e.g. to provide an appropriate management interface.
      */
@@ -547,8 +554,7 @@
             String value = meta.getFirstValue(METADATA_PLACEHOLDER);
             if (value == null) {
                 return false;
-            }
-            else {
+            } else {
                 return Boolean.valueOf(value).booleanValue();
             }
         } catch (Exception e) {
@@ -565,4 +571,47 @@
         }
     }
 
+    public String getMimeType() throws DocumentException {
+        try {
+            String mimeType = getMetaData(METADATA_NAMESPACE).getFirstValue(METADATA_MIME_TYPE);
+            if (mimeType == null) {
+                mimeType = "";
+            }
+            return mimeType;
+        } catch (MetaDataException e) {
+            throw new DocumentException(e);
+        }
+    }
+
+    public long getContentLength() throws DocumentException {
+        SourceResolver resolver = null;
+        Source source = null;
+        try {
+            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+            source = resolver.resolveURI(getSourceURI());
+            if (source.exists()) {
+                return source.getContentLength();
+            } else {
+                throw new SourceNotFoundException("The source [" + getSourceURI()
+                        + "] does not exist!");
+            }
+        } catch (Exception e) {
+            throw new DocumentException(e);
+        } finally {
+            if (resolver != null) {
+                if (source != null) {
+                    resolver.release(source);
+                }
+                this.manager.release(resolver);
+            }
+        }
+    }
+
+    public void setMimeType(String mimeType) throws DocumentException {
+        try {
+            getMetaData(METADATA_NAMESPACE).setValue(METADATA_MIME_TYPE, mimeType);
+        } catch (MetaDataException e) {
+            throw new DocumentException(e);
+        }
+    }
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java?rev=424827&r1=424826&r2=424827&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/Document.java Sun Jul 23 14:28:29 2006
@@ -219,4 +219,23 @@
      *  Set if this is placeholder document (in trash / archive areas).
      */
     void setPlaceholder();
+    
+    /**
+     * Sets the mime type of this document.
+     * @param mimeType The mime type.
+     * @throws DocumentException if an error occurs.
+     */
+    void setMimeType(String mimeType) throws DocumentException;
+    
+    /**
+     * @return The mime type of this document.
+     * @throws DocumentException if an error occurs.
+     */
+    String getMimeType() throws DocumentException;
+    
+    /**
+     * @return The content length of the document.
+     * @throws DocumentException if an error occurs.
+     */
+    long getContentLength() throws DocumentException;
 }



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