jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http CachePolicy.java,NONE,1.1 ContentCoding.java,NONE,1.1 Cookie.java,NONE,1.1 EntityTag.java,NONE,1.1 ProtocolPolicy.java,NONE,1.1 Encoding.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/api/src/java/org/jicarilla/http
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22610/platform/components/http/api/src/java/org/jicarilla/http

Modified Files:
	Encoding.java 
Added Files:
	CachePolicy.java ContentCoding.java Cookie.java EntityTag.java 
	ProtocolPolicy.java 
Log Message:
start some early code to tackle the higher-level protocol issues

--- NEW FILE: ProtocolPolicy.java ---
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.http;

import org.jicarilla.http.util.RFC2119;

import java.util.Date;

/**
 * Next level from up from raw message handling is the handling of
 * encoding and connection management.
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: ProtocolPolicy.java,v 1.1 2004/04/09 18:56:00 lsimons Exp $
 */
public interface ProtocolPolicy
{
    public RFC2119.Level persistentConnectionRequirement();
    
    public Date getLastModifiedDate();
    
    public EntityTag getEntityTag();
    
    public CachePolicy getCachePolicy();
    
    public Cookie[] getCookies();
    
    public String getContentType();
    
    public RFC2119.Level chunkedTransferCodingRequirement();
    
    public int getContentLength();
    
    public ContentCoding getContentCoding();
}

--- NEW FILE: ContentCoding.java ---
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.http;

import org.jicarilla.lang.Assert;

/**
 * 
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: ContentCoding.java,v 1.1 2004/04/09 18:56:00 lsimons Exp $
 */
public class ContentCoding
{
    public final static ContentCoding GZIP =
            new ContentCoding();
    public final static ContentCoding COMPRESS =
            new ContentCoding();
    public final static ContentCoding DEFLATE =
            new ContentCoding();
    public final static ContentCoding IDENTITY =
            new ContentCoding();
    
    protected String m_coding = null;

    protected ContentCoding() {}

    public ContentCoding( String coding )
    {
        Assert.assertNotNull( "coding argument may not be null", coding );
        m_coding = coding;
    }
}

Index: Encoding.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http/Encoding.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Encoding.java	9 Apr 2004 15:52:08 -0000	1.1
+++ Encoding.java	9 Apr 2004 18:56:00 -0000	1.2
@@ -26,11 +26,17 @@
 package org.jicarilla.http;
 
 import org.jicarilla.http.util.Iso646;
+import org.jicarilla.http.util.NioUtil;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.nio.ByteBuffer;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.Arrays;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -596,13 +602,28 @@
     public static final String HEADER_CONTENT_LENGTH = "content-length";
     public static final String HEADER_TRANSFER_ENCODING = "transfer-encoding";
     public static final String HEADER_TRAILER = "trailer";
+    public static final String HEADER_CONNECTION = "connection";
+    public static final String HEADER_CONNECTION_CLOSE = " close";
+    public static final String HEADER_LAST_MODIFIED = "last-modified";
 
     public static final ByteBuffer HEADER_CONTENT_LENGTH_BUFFER;
+    public static final ByteBuffer HEADER_CONNECTION_BUFFER;
+    public static final ByteBuffer HEADER_CONNECTION_CLOSE_BUFFER;
+    public static final ByteBuffer HEADER_LAST_MODIFIED_BUFFER;
 
     static
     {
-        final byte[] arr = HEADER_CONTENT_LENGTH.getBytes();
+        byte[] arr = HEADER_CONTENT_LENGTH.getBytes();
         HEADER_CONTENT_LENGTH_BUFFER = ByteBuffer.wrap( arr );
+
+        arr = HEADER_CONNECTION.getBytes();
+        HEADER_CONNECTION_BUFFER = ByteBuffer.wrap( arr );
+
+        arr = HEADER_CONNECTION_CLOSE.getBytes();
+        HEADER_CONNECTION_CLOSE_BUFFER = ByteBuffer.wrap( arr );
+
+        arr = HEADER_LAST_MODIFIED.getBytes();
+        HEADER_LAST_MODIFIED_BUFFER = ByteBuffer.wrap( arr );
     }
 
 
@@ -846,4 +867,22 @@
 
         return token;
     }
+    
+    protected final static TimeZone GMT = TimeZone.getTimeZone("GMT"); 
+    public final static DateFormat dateFormat = 
+            new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US );
+    static
+    {
+        dateFormat.setTimeZone( GMT );
+    }
+        
+    public final static String dateToString( Date date )
+    {
+        return dateFormat.format( date );
+    }
+
+    public final static ByteBuffer dateToBuffer( Date date )
+    {
+        return NioUtil.toByteBuffer( dateToString( date ) );
+    }
 }

--- NEW FILE: EntityTag.java ---
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.http;

import org.jicarilla.lang.Assert;

/**
 * Simple javabean for modelling entity tags.
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: EntityTag.java,v 1.1 2004/04/09 18:56:00 lsimons Exp $
 */
public class EntityTag
{
    protected String m_value;
    protected boolean m_weak;

    public EntityTag( String value, boolean weak )
    {
        Assert.assertNotNull( "value argument may not be null", value );
        m_value = value;
        m_weak = weak;
    }

    public String getValue()
    {
        return m_value;
    }

    public void setValue( String value )
    {
        m_value = value;
    }

    public boolean isWeak()
    {
        return m_weak;
    }

    public void setWeak( boolean weak )
    {
        m_weak = weak;
    }
}

--- NEW FILE: CachePolicy.java ---
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.http;

import org.jicarilla.lang.Assert;

/**
 * Simple javabean modelling the value of the Cache-Control header
 * that is used by servers.
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: CachePolicy.java,v 1.1 2004/04/09 18:56:00 lsimons Exp $
 */
public class CachePolicy
{
    public final static CachePolicy NO_STORE = 
            new CachePolicy();
    public final static CachePolicy MUST_REVALIDATE = 
            new CachePolicy();
    public final static CachePolicy NO_CACHE = 
            new CachePolicy();
    public final static CachePolicy ONE_HOUR = 
            new CachePolicy( 3600 );
    public final static CachePolicy ONE_DAY = 
            new CachePolicy( 3600*24 );
    public final static CachePolicy ONE_WEEK = 
            new CachePolicy( 3600*24*7 );

    protected int m_maxAge = -1;
    protected int m_sharedMaxAge = -1;

    public CachePolicy( int maxAge )
    {
        Assert.assertTrue( maxAge > 0 );
        m_maxAge = maxAge;
    }
    
    public CachePolicy( int maxAge, int sharedMaxAge )
    {
        Assert.assertTrue( maxAge > 0 );
        Assert.assertTrue( sharedMaxAge > 0 );
        m_maxAge = maxAge;
        m_sharedMaxAge = maxAge;
    }
    
    protected CachePolicy() {}

    public int getMaxAge()
    {
        return m_maxAge;
    }

    public int getSharedMaxAge()
    {
        return m_sharedMaxAge;
    }
}

--- NEW FILE: Cookie.java ---
/* ====================================================================
The Jicarilla Software License

Copyright (c) 2003 Leo Simons.
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================== */
package org.jicarilla.http;

import org.jicarilla.lang.Assert;

import java.util.Date;

/**
 * Version 0 cookie. 
 *
 * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 * @version $Id: Cookie.java,v 1.1 2004/04/09 18:56:00 lsimons Exp $
 */
public class Cookie
{
    protected String m_name = null;
    protected Date m_expires = null;
    protected String m_domain = null;
    protected String m_path = null;
    protected boolean m_secure = false;

    public Cookie( String name )
    {
        Assert.assertNotNull( "name argument may not be null", name );
        m_name = name;
    }

    public Cookie( String name, Date expires )
    {
        this( name );
        m_expires = expires;
    }

    public Cookie( String name, Date expires, String domain )
    {
        this( name, expires );
        m_domain = domain;
    }

    public Cookie( String name, Date expires, String domain, String path )
    {
        this( name, expires, domain );
        m_path = path;
    }

    public Cookie( String name, Date expires, String domain, String path,
            boolean secure )
    {
        m_name = name;
        m_expires = expires;
        m_domain = domain;
        m_path = path;
        m_secure = secure;
    }

    public Cookie( String name, String domain, String path )
    {
        this( name );
        m_domain = domain;
        m_path = path;
    }

    public Cookie( String name, String domain, String path, boolean secure )
    {
        this( name, domain, path );
        m_secure = secure;
    }

    public String getName()
    {
        return m_name;
    }

    public Date getExpires()
    {
        return m_expires;
    }

    public String getDomain()
    {
        return m_domain;
    }

    public String getPath()
    {
        return m_path;
    }

    public boolean isSecure()
    {
        return m_secure;
    }
    
    public String toString()
    {
        StringBuffer buf = new StringBuffer();
        buf.append( "name="+m_name );
        if( m_expires != null )
        {
            buf.append( "; expires=" );
            buf.append(  Encoding.dateToString( m_expires ) );
        }
        if( m_path != null )
        {
            buf.append( "; path="+m_path );
        }
        if( m_secure )
        {
            buf.append( "; secure" );
        }
            
        return buf.toString();
    }
}



-------------------------------------------------------
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.