You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ch...@apache.org on 2006/07/18 05:12:21 UTC

svn commit: r422950 - in /lenya/trunk/src: impl/java/org/apache/lenya/cms/publication/ java/org/apache/lenya/cms/cocoon/components/modules/input/ java/org/apache/lenya/cms/metadata/ java/org/apache/lenya/cms/publication/ modules/xhtml/config/cocoon-xco...

Author: chestnut
Date: Mon Jul 17 20:12:21 2006
New Revision: 422950

URL: http://svn.apache.org/viewvc?rev=422950&view=rev
Log:
Added ability to set an expires value by resource type and/or by document.  
Can be fetched by using the DocumentInfoModule or ResourceTypeModule in RFC 1123 date format

Modified:
    lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java
    lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java
    lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java
    lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java
    lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf
    lenya/trunk/src/pubs/default/sitemap.xmap

Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java?rev=422950&r1=422949&r2=422950&view=diff
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/ResourceTypeImpl.java Mon Jul 17 20:12:21 2006
@@ -48,12 +48,15 @@
     protected static final String ATTRIBUTE_URI = "uri";
     protected static final String ATTRIBUTE_NAME = "name";
     protected static final String ATTRIBUTE_LANGUAGE = "language";
+    protected static final String EXPIRES_ELEMENT = "expires";
+    protected static final String SECONDS_ATTRIBUTE = "seconds";
 
     private Schema schema = null;
     private String sampleUri = null;
     private String defaultSampleUri = null;
     private Map sampleUris = new HashMap();
     private String[] linkAttributeXPaths;
+    private long expires = 0;
 
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
@@ -96,11 +99,20 @@
                 String uri = formatConfigs[i].getAttribute(ATTRIBUTE_URI);
                 this.formats.put(name, new Format(uri));
             }
+            
+            Configuration expiresConf = config.getChild(EXPIRES_ELEMENT, false);
+            if (expiresConf != null) {
+                this.expires = expiresConf.getAttributeAsLong(SECONDS_ATTRIBUTE);
+            }
 
         } catch (Exception e) {
             throw new ConfigurationException("Configuring resource type failed: ", e);
         }
 
+    }
+    
+    public long getExpires() {
+        return this.expires;
     }
 
     public Schema getSchema() {

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java?rev=422950&r1=422949&r2=422950&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java Mon Jul 17 20:12:21 2006
@@ -20,6 +20,7 @@
 package org.apache.lenya.cms.cocoon.components.modules.input;
 
 import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Map;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -51,6 +52,8 @@
  * <li>resourceType</li>
  * <li>lastModified</li>
  * <li>mimeType</li>
+ * <li>expires</li>
+ * <li>visibleInNav</li>
  * </ul>
  */
 public class DocumentInfoModule extends AbstractInputModule implements Serviceable {
@@ -68,12 +71,14 @@
     protected final static String RESOURCE_TYPE = "resourceType";
     protected final static String LAST_MODIFIED = "lastModified";
     protected final static String MIME_TYPE = "mimeType";
+    protected final static String EXPIRES = "expires";
     protected final static String VISIBLE_IN_NAVIGATION = "visibleInNav";
 
     protected final static String[] PARAMS = { PARAM_PUBLICATION_ID, PARAM_AREA, PARAM_DOCUMENT_ID,
             PARAM_DOCUMENT_LANGUAGE, PARAM_PROPERTY, VISIBLE_IN_NAVIGATION };
 
     protected final static String META_RESOURCE_TYPE = "resourceType";
+    protected final static String META_EXPIRES = "expires";
 
     /**
      * Parse the parameters and return a document.
@@ -130,6 +135,10 @@
                 if (value == null)
                     throw new ConfigurationException("Attribute '" + attribute + "' not defined ["
                             + name + "]");
+            } else if (attribute.equals(EXPIRES)) {
+                
+                value = getExpires(document, params.getParameter(PARAM_AREA));
+                
             } else if (attribute.equals(VISIBLE_IN_NAVIGATION)) {
                 value = Boolean.toString(isVisibleInNavigation(document));
             } else {
@@ -153,6 +162,37 @@
 
     }
 
+    protected String getExpires(Document document, String area) throws ConfigurationException {
+        String expires = null;
+        long secs = 0;
+        if (area.equals("live")) {
+            try {
+                //use resource-types seconds to expire as default
+                secs = document.getResourceType().getExpires();
+            } catch (DocumentException e) {
+                throw new ConfigurationException("Error getting Resource Type of document.", e);
+            }
+        
+            MetaData metaData = null;
+            try {
+                metaData = document.getMetaDataManager().getLenyaMetaData();
+                String expiresMeta = metaData.getFirstValue(META_EXPIRES);
+                if (expiresMeta != null) {
+                    secs = Long.parseLong(metaData.getFirstValue(META_EXPIRES));
+                }
+            } catch (DocumentException e) {
+                throw new ConfigurationException("Obtaining custom meta data value for ["
+                        + document.getSourceURI() + "] failed: " + e.getMessage(), e);
+            }
+        }
+        Date date = new Date();
+        date.setTime(date.getTime() + secs * 1000l);
+        SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss zzz");
+        expires = sdf.format(date);
+
+        return expires;
+    }
+    
     protected String getResourceType(Document document) throws ConfigurationException {
         String resourceType = null;
         MetaData metaData = null;

Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java?rev=422950&r1=422949&r2=422950&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/ResourceTypeModule.java Mon Jul 17 20:12:21 2006
@@ -17,6 +17,8 @@
 package org.apache.lenya.cms.cocoon.components.modules.input;
 
 import java.util.Map;
+import java.util.Date;
+import java.text.SimpleDateFormat;
 
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -50,6 +52,7 @@
 
     protected static final String SCHEMA_URI = "schemaUri";
     protected static final String HTTP_SCHEMA_URI = "httpSchemaUri";
+    protected static final String EXPIRES = "expires";
 
     public Object getAttribute(String name, Configuration modeConf, Map objectModel)
             throws ConfigurationException {
@@ -95,6 +98,12 @@
                 String uri = resourceType.getSchema().getURI();
                 String prefix = request.getContextPath();
                 value = transformFallbackUriToHttp(pub.getId(), prefix, uri);
+            } else if (attribute.equals(EXPIRES)) {
+                Date date = new Date();
+                long secs = resourceType.getExpires();
+                date.setTime(date.getTime() + secs * 1000l);
+                SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss zzz");
+                value = sdf.format(date);
             } else {
                 throw new ConfigurationException("Attribute [" + name + "] not supported!");
             }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java?rev=422950&r1=422949&r2=422950&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/metadata/LenyaMetaData.java Mon Jul 17 20:12:21 2006
@@ -49,6 +49,11 @@
     public static final String ELEMENT_CONTENT_TYPE = "contentType";
     
     /**
+     * The number of seconds from the request that a document can be cached before it expires
+     */
+    public static final String ELEMENT_EXPIRES = "expires";
+    
+    /**
      * The extension to use for the document source.
      */
     public static final String ELEMENT_EXTENSION = "extension";
@@ -75,6 +80,7 @@
        ELEMENT_PLACEHOLDER,
        ELEMENTE_HEIGHT,
        ELEMENT_WIDTH,
+       ELEMENT_EXPIRES,
        ELEMENT_EXTENSION
     };
 

Modified: lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java?rev=422950&r1=422949&r2=422950&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/publication/ResourceType.java Mon Jul 17 20:12:21 2006
@@ -45,6 +45,12 @@
     String ROLE = ResourceType.class.getName();
     
     /**
+     * Returns the expires time in num of seconds
+     * @return A long value.
+     */
+    long getExpires();
+    
+    /**
      * Returns the name of this document type.
      * @return A string value.
      */

Modified: lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf?rev=422950&r1=422949&r2=422950&view=diff
==============================================================================
--- lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf (original)
+++ lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf Mon Jul 17 20:12:21 2006
@@ -25,6 +25,9 @@
     <schema language="http://relaxng.org/ns/structure/0.9"
       src="fallback://lenya/modules/xhtml/resources/schemas/xhtml.rng"/>
     
+    <!-- Default time in seconds until the resource-type has expired -->  
+    <expires seconds="3600" />
+    
     <sample-name>fallback://lenya/modules/xhtml/samples/xhtml.xml</sample-name>
     <!-- <sample-name name="Two Column Layout">fallback://lenya/modules/xhtml/samples/xhtml-2col.xml</sample-name> -->
     

Modified: lenya/trunk/src/pubs/default/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/sitemap.xmap?rev=422950&r1=422949&r2=422950&view=diff
==============================================================================
--- lenya/trunk/src/pubs/default/sitemap.xmap (original)
+++ lenya/trunk/src/pubs/default/sitemap.xmap Mon Jul 17 20:12:21 2006
@@ -246,6 +246,9 @@
                           <map:parameter name="serializer" value="xhtml"/>
                         </map:transform>
                         <map:transform src="fallback://lenya/xslt/authoring/edit/removeSourceTags.xsl"/>
+                        <map:act type="set-header">
+                          <map:parameter name="Expires" value="{doc-info:{page-envelope:publication-id}:{page-envelope:area}:{page-envelope:document-id}:{page-envelope:document-language}:expires}"/>
+                        </map:act>
                       </map:when>
                       <!-- Turn off caching in authoring area -->
                       <map:otherwise>



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


Re: Resource Type / Document expires [was: svn commit: r422950 - in /lenya/trunk/src: ]

Posted by Andreas Hartmann <an...@apache.org>.
Andreas Hartmann wrote:

[...]

> Shouldn't we move this functionality to the Document interface?
> 
>   Document.expires()

I just noticed that this should rather read

   getExpires()


> The code below would be moved to the DocumentImpl class.
> IMO the approach below is that it is not really object oriented:
> The document and resource type objects serve only as "data providers",
> but the logic is executed by the input module. I'd prefer to
> encapsulate the logic and the data in the Document object.

Another note on this issue: I see the DocumentInfoModule rather
as a facade to the Document object, not as a service which
contains specific knowledge. Otherwise, we'll always have to
use the DocumentInfoModule to get particular information about
the document. IMO input modules are just adapters to make
information available to Cocoon pipelines in a convenient way.

-- Andreas



-- 
Andreas Hartmann
Wyona Inc.  -   Open Source Content Management   -   Apache Lenya
http://www.wyona.com                      http://lenya.apache.org
andreas.hartmann@wyona.com                     andreas@apache.org


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


Re: Resource Type / Document expires [was: svn commit: r422950 - in /lenya/trunk/src: ]

Posted by Doug Chestnut <dh...@virginia.edu>.
Opps, I meant tab.meta usecase.  It's not dublin core metadata (didn't 
see any dc elements that fit the need).  The expires value is stored in 
the lenya:expires element.

--Doug

Doug Chestnut wrote:
> Ok, now that those issues have been addressed.
> How should we make the experation of a document editable?  via the 
> tab.overview usecase?
> 
> --Doug
> 
> Andreas Hartmann wrote:
> 
>> Doug Chestnut wrote:
>>
>>>
>>>
>>> Andreas Hartmann wrote:
>>
>>
>>
>> [...]
>>
>>>> IMO the Document.getExpires() and ResourceType().getExpires() shouldn't
>>>> return a formatted string, but rather either an integer (number of
>>>> seconds) or a Date object. The date format is specific to the 
>>>> particular
>>>> usage scenario (HTTP headers), which might be seen as closely 
>>>> related to
>>>> the  input module functionality - so IMO the date formatting could be
>>>> done by the input module.
>>>>
>>>> WDY (and the others) T?
>>
>>
>>
>>> I agree, I prefer the Date object over the number of seconds,
>>
>>
>>
>> OK, I think this is the better solution (no javadocs needed to
>> understand the method)
>>
>>> thanks for the review!
>>
>>
>>
>> Thanks for the quick response! :)
>>
>> -- Andreas
>>
>>
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lenya.apache.org
> For additional commands, e-mail: dev-help@lenya.apache.org
> 

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


Re: Resource Type / Document expires [was: svn commit: r422950 - in /lenya/trunk/src: ]

Posted by Doug Chestnut <dh...@virginia.edu>.
Ok, now that those issues have been addressed.
How should we make the experation of a document editable?  via the 
tab.overview usecase?

--Doug

Andreas Hartmann wrote:
> Doug Chestnut wrote:
> 
>>
>>
>> Andreas Hartmann wrote:
> 
> 
> [...]
> 
>>> IMO the Document.getExpires() and ResourceType().getExpires() shouldn't
>>> return a formatted string, but rather either an integer (number of
>>> seconds) or a Date object. The date format is specific to the particular
>>> usage scenario (HTTP headers), which might be seen as closely related to
>>> the  input module functionality - so IMO the date formatting could be
>>> done by the input module.
>>>
>>> WDY (and the others) T?
> 
> 
>> I agree, I prefer the Date object over the number of seconds,
> 
> 
> OK, I think this is the better solution (no javadocs needed to
> understand the method)
> 
>> thanks for the review!
> 
> 
> Thanks for the quick response! :)
> 
> -- Andreas
> 
> 
> 
> 

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


Re: Resource Type / Document expires [was: svn commit: r422950 - in /lenya/trunk/src: ]

Posted by Andreas Hartmann <an...@apache.org>.
Doug Chestnut wrote:
> 
> 
> Andreas Hartmann wrote:

[...]

>> IMO the Document.getExpires() and ResourceType().getExpires() shouldn't
>> return a formatted string, but rather either an integer (number of
>> seconds) or a Date object. The date format is specific to the particular
>> usage scenario (HTTP headers), which might be seen as closely related to
>> the  input module functionality - so IMO the date formatting could be
>> done by the input module.
>>
>> WDY (and the others) T?

> I agree, I prefer the Date object over the number of seconds,

OK, I think this is the better solution (no javadocs needed to
understand the method)

> thanks for the review!

Thanks for the quick response! :)

-- Andreas




-- 
Andreas Hartmann
Wyona Inc.  -   Open Source Content Management   -   Apache Lenya
http://www.wyona.com                      http://lenya.apache.org
andreas.hartmann@wyona.com                     andreas@apache.org


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


Re: Resource Type / Document expires [was: svn commit: r422950 - in /lenya/trunk/src: ]

Posted by Doug Chestnut <dh...@virginia.edu>.

Andreas Hartmann wrote:
> Doug Chestnut wrote:
> 
> [...]
> 
>>> The code below would be moved to the DocumentImpl class.
>>> IMO the approach below is that it is not really object oriented:
>>> The document and resource type objects serve only as "data providers",
>>> but the logic is executed by the input module. I'd prefer to
>>> encapsulate the logic and the data in the Document object.
> 
> 
>> Totally agree, any better now?  I moved the conversion from seconds to 
>> a date string to the document and resourcetype.
> 
> 
> That looks great, thanks a lot! :)
> 
> Just one more issue:
> 
> IMO the Document.getExpires() and ResourceType().getExpires() shouldn't
> return a formatted string, but rather either an integer (number of
> seconds) or a Date object. The date format is specific to the particular
> usage scenario (HTTP headers), which might be seen as closely related to
> the  input module functionality - so IMO the date formatting could be
> done by the input module.
> 
> WDY (and the others) T?
I agree, I prefer the Date object over the number of seconds, thanks for 
the review!

--Doug
> 
> -- Andreas
> 
> 

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


Re: Resource Type / Document expires [was: svn commit: r422950 - in /lenya/trunk/src: ]

Posted by Andreas Hartmann <an...@apache.org>.
Doug Chestnut wrote:

[...]

>> The code below would be moved to the DocumentImpl class.
>> IMO the approach below is that it is not really object oriented:
>> The document and resource type objects serve only as "data providers",
>> but the logic is executed by the input module. I'd prefer to
>> encapsulate the logic and the data in the Document object.

> Totally agree, any better now?  I moved the conversion from seconds to a 
> date string to the document and resourcetype.

That looks great, thanks a lot! :)

Just one more issue:

IMO the Document.getExpires() and ResourceType().getExpires() shouldn't
return a formatted string, but rather either an integer (number of
seconds) or a Date object. The date format is specific to the particular
usage scenario (HTTP headers), which might be seen as closely related to
the  input module functionality - so IMO the date formatting could be
done by the input module.

WDY (and the others) T?

-- Andreas


-- 
Andreas Hartmann
Wyona Inc.  -   Open Source Content Management   -   Apache Lenya
http://www.wyona.com                      http://lenya.apache.org
andreas.hartmann@wyona.com                     andreas@apache.org


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


Re: Resource Type / Document expires [was: svn commit: r422950 - in /lenya/trunk/src: ]

Posted by Doug Chestnut <dh...@virginia.edu>.
Hi Andreas

Andreas Hartmann wrote:
> Hi Doug,
> 
> thanks a lot for this functionality!
> I have just some little questions:
> 
> chestnut@apache.org wrote:
> [...]
> 
>> Modified: 
>> lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java 
>>
> 
> 
> [...]
> 
>> +    protected String getExpires(Document document, String area) 
>> throws ConfigurationException {
> 
> 
> Shouldn't we move this functionality to the Document interface?
> 
>   Document.expires()
> 
> The code below would be moved to the DocumentImpl class.
> IMO the approach below is that it is not really object oriented:
> The document and resource type objects serve only as "data providers",
> but the logic is executed by the input module. I'd prefer to
> encapsulate the logic and the data in the Document object.
Totally agree, any better now?  I moved the conversion from seconds to a 
date string to the document and resourcetype.
> 
> 
>> +        String expires = null;
>> +        long secs = 0;
>> +        if (area.equals("live")) {
> 
> 
> Why is this necessary? IMO we should avoid to hard-code areas.
> I know that we have several of these hard-coded values (which
> is IMO very regrettable), but in this case - isn't this a concern
> of the sitemap which calls the input module? (for instance, enclose
> the header action in an area-related matcher)
Opps, forgot to get rid to that last night.  This is handled in the 
default pubs sitemap so it was redundant. removed.
> 
> 
>> +            try {
>> +                //use resource-types seconds to expire as default
>> +                secs = document.getResourceType().getExpires();
>> +            } catch (DocumentException e) {
>> +                throw new ConfigurationException("Error getting 
>> Resource Type of document.", e);
>> +            }
>> +        +            MetaData metaData = null;
>> +            try {
>> +                metaData = 
>> document.getMetaDataManager().getLenyaMetaData();
>> +                String expiresMeta = 
>> metaData.getFirstValue(META_EXPIRES);
>> +                if (expiresMeta != null) {
>> +                    secs = 
>> Long.parseLong(metaData.getFirstValue(META_EXPIRES));
>> +                }
>> +            } catch (DocumentException e) {
>> +                throw new ConfigurationException("Obtaining custom 
>> meta data value for ["
>> +                        + document.getSourceURI() + "] failed: " + 
>> e.getMessage(), e);
>> +            }
> 
> 
> Sorry for nitpicking, but maybe it would be a little faster the other way
> round (try meta data first, and if the value is not set, use the resource
> type as a default). Usually these little things probably don't matter, but
> this particular code is likely to be executed for a lot live requests,
> isn't it?
Yes, this has the potential to get requested allot.  I just switched it 
around.
> 
> WDYT?
Your suggestions are invaluable as always :).

Thanks,
--Doug

> 
> -- Andreas
> 
> 

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


Resource Type / Document expires [was: svn commit: r422950 - in /lenya/trunk/src: ]

Posted by Andreas Hartmann <an...@apache.org>.
Hi Doug,

thanks a lot for this functionality!
I have just some little questions:

chestnut@apache.org wrote:
[...]

> Modified: lenya/trunk/src/java/org/apache/lenya/cms/cocoon/components/modules/input/DocumentInfoModule.java

[...]

> +    protected String getExpires(Document document, String area) throws ConfigurationException {

Shouldn't we move this functionality to the Document interface?

   Document.expires()

The code below would be moved to the DocumentImpl class.
IMO the approach below is that it is not really object oriented:
The document and resource type objects serve only as "data providers",
but the logic is executed by the input module. I'd prefer to
encapsulate the logic and the data in the Document object.


> +        String expires = null;
> +        long secs = 0;
> +        if (area.equals("live")) {

Why is this necessary? IMO we should avoid to hard-code areas.
I know that we have several of these hard-coded values (which
is IMO very regrettable), but in this case - isn't this a concern
of the sitemap which calls the input module? (for instance, enclose
the header action in an area-related matcher)


> +            try {
> +                //use resource-types seconds to expire as default
> +                secs = document.getResourceType().getExpires();
> +            } catch (DocumentException e) {
> +                throw new ConfigurationException("Error getting Resource Type of document.", e);
> +            }
> +        
> +            MetaData metaData = null;
> +            try {
> +                metaData = document.getMetaDataManager().getLenyaMetaData();
> +                String expiresMeta = metaData.getFirstValue(META_EXPIRES);
> +                if (expiresMeta != null) {
> +                    secs = Long.parseLong(metaData.getFirstValue(META_EXPIRES));
> +                }
> +            } catch (DocumentException e) {
> +                throw new ConfigurationException("Obtaining custom meta data value for ["
> +                        + document.getSourceURI() + "] failed: " + e.getMessage(), e);
> +            }

Sorry for nitpicking, but maybe it would be a little faster the other way
round (try meta data first, and if the value is not set, use the resource
type as a default). Usually these little things probably don't matter, but
this particular code is likely to be executed for a lot live requests,
isn't it?

WDYT?

-- Andreas


-- 
Andreas Hartmann
Wyona Inc.  -   Open Source Content Management   -   Apache Lenya
http://www.wyona.com                      http://lenya.apache.org
andreas.hartmann@wyona.com                     andreas@apache.org


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