package com.ettrema.json;

import com.bradmcevoy.http.GetableResource;
import com.bradmcevoy.http.PropFindableResource;
import com.bradmcevoy.http.Range;
import com.bradmcevoy.http.Request;
import com.bradmcevoy.http.Request.Method;
import com.bradmcevoy.http.exceptions.NotAuthorizedException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

public class PropFindJsonResource extends JsonResource implements GetableResource {
    
    private final PropFindableResource wrappedResource;
    private final JsonPropFindHandler jsonPropFindHandler;
    private final String encodedUrl;

    public PropFindJsonResource( PropFindableResource wrappedResource, JsonPropFindHandler jsonPropFindHandler, String encodedUrl, Long maxAgeSecs ) {
        super(wrappedResource, Request.Method.PROPFIND.code, maxAgeSecs);
        this.wrappedResource = wrappedResource;
        this.encodedUrl = encodedUrl;
        this.jsonPropFindHandler = jsonPropFindHandler;
    }

    public void sendContent( OutputStream out, Range range, Map<String, String> params, String contentType ) throws IOException, NotAuthorizedException {
        //jsonPropFindHandler.sendContent( wrappedResource, encodedUrl, out, range, params, contentType );
        jsonPropFindHandler.sendContent( wrappedResource, encodedUrl, out, range, params, contentType );
    }

    @Override
    public Method applicableMethod() {
        return Method.PROPFIND;
    }


}

@@ -47,31 +47,104 @@
 oy.http.
-GetableResource
+Auth;%0Aimport com.bradmcevoy.http.GetableResource;%0Aimport com.bradmcevoy.http.HttpManager
 ;%0Aimport
@@ -439,16 +439,73 @@
 til.Map;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Apublic
@@ -582,20 +582,110 @@
 ource %7B%0A
+%0A
     
+private static final Logger log = LoggerFactory.getLogger( PropFindJsonResource.class );%0A
 %0A    pri
@@ -862,17 +862,16 @@
 esource(
- 
 PropFind
@@ -975,17 +975,16 @@
 xAgeSecs
- 
 ) %7B%0A    
@@ -1230,17 +1230,16 @@
 Content(
- 
 OutputSt
@@ -1307,17 +1307,16 @@
 tentType
- 
 ) throws
@@ -1493,33 +1493,32 @@
 ler.sendContent(
- 
 wrappedResource,
@@ -1557,25 +1557,24 @@
  contentType
- 
 );%0A    %7D%0A%0A  
@@ -1663,11 +1663,944 @@
 %0A    %7D%0A%0A
+    /**%0A     * Overridden to allow clients to specifiy the max age as a request parameter%0A     *%0A     * This is to allow efficient browser caching of results in cases that need it,%0A     * while also permitting non-cached access%0A     *%0A     * @param auth%0A     * @return%0A     */%0A    @Override%0A    public Long getMaxAgeSeconds(Auth auth) %7B%0A        Request req = HttpManager.request();%0A        if (req != null) %7B%0A            String sMaxAge = req.getParams().get(%22maxAgeSecs%22);%0A            if (sMaxAge != null && sMaxAge.length() %3E 0) %7B%0A                try %7B%0A                    log.trace(%22using max age from parameter%22);%0A                    Long maxAge = Long.parseLong(sMaxAge);%0A                    return maxAge;%0A                %7D catch (NumberFormatException e) %7B%0A                    log.debug(%22Couldnt parse max age parameter: %22 + sMaxAge);%0A                %7D%0A            %7D%0A        %7D%0A        return super.getMaxAgeSeconds(auth);%0A    %7D
 %0A%7D%0A

allow maxAge to be determined from the web browser through a request parameter.