jicarilla-sandbox/platform/components/http/impl/src/java/org/jicarilla/http ProtocolPolicyTransformerImpl.java,1.1,1.2

Leo Simons <[email protected]>
Newsgroups gmane.comp.java.jicarilla.cvs
Message-ID <[email protected]>
Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/impl/src/java/org/jicarilla/http
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9759/platform/components/http/impl/src/java/org/jicarilla/http

Modified Files:
	ProtocolPolicyTransformerImpl.java 
Log Message:
more early code to tackle the higher-level protocol issues

Index: ProtocolPolicyTransformerImpl.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/impl/src/java/org/jicarilla/http/ProtocolPolicyTransformerImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ProtocolPolicyTransformerImpl.java	9 Apr 2004 18:56:00 -0000	1.1
+++ ProtocolPolicyTransformerImpl.java	9 Apr 2004 20:29:49 -0000	1.2
@@ -25,8 +25,11 @@
 ==================================================================== */
 package org.jicarilla.http;
 
+import org.jicarilla.http.util.NioUtil;
 import org.jicarilla.http.util.RFC2119;
+import org.jicarilla.lang.Assert;
 
+import java.nio.ByteBuffer;
 import java.util.Date;
 
 /**
@@ -39,8 +42,11 @@
 {
     public void apply( ProtocolPolicy policy, Message response )
     {
+        Assert.assertNotNull( "policy argument may not be null", policy );
+        Assert.assertNotNull( "response argument may not be null", response );
+        
         applyPersistentConnectionRequirement(
-                policy.persistentConnectionRequirement(),
+                policy.getPersistentConnectionRequirement(),
                 response );
         applyLastModifiedDate( policy.getLastModifiedDate(), response );
         applyEntityTag( policy.getEntityTag(), response );
@@ -48,7 +54,7 @@
         applyCookies( policy.getCookies(), response );
         applyContentType( policy.getContentType(), response );
         applyChunkedTransferEncodingRequirement(
-                policy.chunkedTransferCodingRequirement(),
+                policy.getChunkedTransferCodingRequirement(),
                 response );
         applyContentLength( policy.getContentLength(), response );
         applyContentCoding( policy.getContentCoding(), response );
@@ -57,45 +63,112 @@
     protected void applyPersistentConnectionRequirement( RFC2119.Level level,
             Message response )
     {
-        if( level.compareTo( RFC2119.SHOULD_NOT ) <= 0 )
-            response.addHeader( Encoding.HEADER_CONNECTION_BUFFER,
-                    Encoding.HEADER_CONNECTION_CLOSE_BUFFER );
+        if( level.compareTo( RFC2119.SHOULD_NOT ) > 0 ) return;
+        
+        response.addHeader( Encoding.HEADER_CONNECTION_BUFFER,
+                Encoding.HEADER_CONNECTION_CLOSE_BUFFER );
     }
 
     protected void applyLastModifiedDate( Date lastModifiedDate,
             Message response )
     {
+        if( lastModifiedDate == null ) return;
+        
         response.addHeader( Encoding.HEADER_LAST_MODIFIED_BUFFER,
                 Encoding.dateToBuffer( lastModifiedDate ) );
     }
 
     protected void applyEntityTag( EntityTag entityTag, Message response )
     {
+        if( entityTag == null ) return;
+
+        String value = entityTag.getValue();
+        if( entityTag.isWeak() )
+            value = "W/" + value;
+        
+        response.addHeader( Encoding.HEADER_ETAG_BUFFER,
+                NioUtil.toByteBuffer( value ) );
     }
 
     protected void applyCachePolicy( CachePolicy cachePolicy, Message response )
     {
+        if( cachePolicy == null ) return;
+        
+        ByteBuffer value = cachePolicyToBuffer( cachePolicy );
+        
+        response.addHeader( Encoding.HEADER_CACHE_CONTROL_BUFFER,
+                value );
+        
+        applySharedCachePolicy( cachePolicy, response );
     }
 
     protected void applyCookies( Cookie[] cookies, Message response )
     {
+        if( cookies == null || cookies.length == 0 ) return;
+        
+        for( int i = 0; i < cookies.length; i++ )
+        {
+            Cookie cookie = cookies[i];
+            applyCookie( cookie, response );
+        }
     }
 
     protected void applyContentType( String contentType, Message response )
     {
+        //todo
     }
 
     protected void applyChunkedTransferEncodingRequirement( RFC2119.Level level,
             Message response )
     {
+        //todo
+        // header only, set transformation flag
     }
 
     protected void applyContentLength( int contentLength, Message response )
     {
+        //todo
+        // header only
     }
 
     protected void applyContentCoding( ContentCoding contentCoding,
             Message response )
     {
+        //todo
+        // header only, set transformation flag
+    }
+
+    protected ByteBuffer cachePolicyToBuffer( CachePolicy cachePolicy )
+    {
+        if( CachePolicy.MUST_REVALIDATE.equals( cachePolicy ) )
+            return Encoding.HEADER_CACHE_CONTROL_MUST_REVALIDATE_BUFFER;
+
+        if( CachePolicy.NO_CACHE.equals( cachePolicy ) )
+            return Encoding.HEADER_CACHE_CONTROL_NO_CACHE_BUFFER;
+
+        if( CachePolicy.NO_STORE.equals( cachePolicy ) )
+            return Encoding.HEADER_CACHE_CONTROL_NO_STORE_BUFFER;
+
+        return NioUtil.toByteBuffer( "max-age=" + cachePolicy.getMaxAge() );
     }
+
+    protected void applySharedCachePolicy( CachePolicy cachePolicy,
+            Message response )
+    {
+        int sharedMaxAge = cachePolicy.getSharedMaxAge();
+        if( sharedMaxAge > 0 )
+        {
+            ByteBuffer value = NioUtil.toByteBuffer( "s-maxage=" +
+                    sharedMaxAge );
+            
+            response.addHeader( Encoding.HEADER_CACHE_CONTROL_BUFFER,
+                    value );
+        }
+    }
+
+    protected void applyCookie( Cookie cookie, Message response )
+    {
+        //todo
+    }
+
 }



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.