/*
* Time-stamp: <01/07/16 16:11:29 smulloni>
* $Id: IfHeader.java,v 1.1 2001/07/17 04:41:32 smulloni Exp $
*
* Copyright (c) 2001, Jacob Smullyan.
*
* This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
* for the latest version.
*
* SkunkDAV is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* SkunkDAV is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SkunkDAV; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
package org.skunk.dav.client;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* represents the RFC2518 If HTTP header.
* You need this if you want to perform operations
* on locked resources.
*/
public class IfHeader
{
private HashMap resourceTokenMap=null;
private ArrayList stateTokenList=null;
private boolean tagged;
public IfHeader(boolean tagged)
{
this.tagged=tagged;
}
public IfHeader(Map resourceTokenMap)
{
this(true);
this.resourceTokenMap=new HashMap();
this.resourceTokenMap.putAll(resourceTokenMap);
}
public IfHeader(String[] stateTokens)
{
this(false);
this.stateTokenList=new ArrayList();
for (int i=0;i<stateTokens.length;i++)
this.stateTokenList.add(stateTokens[i]);
}
public void addStateToken(String token)
{
if (this.tagged)
{
throw new UnsupportedOperationException("method not allowed with a tagged list If header");
}
if (stateTokenList==null)
stateTokenList=new ArrayList();
stateTokenList.add(token);
}
public void addStateToken(String resourceURL, String token)
{
if (!this.tagged)
{
throw new UnsupportedOperationException("method not allowed with non-tagged list If header");
}
if (resourceTokenMap==null)
resourceTokenMap=new HashMap();
if (! resourceTokenMap.containsKey(resourceURL))
resourceTokenMap.put(resourceURL, token);
else
{
Object val=resourceTokenMap.get(resourceURL);
if (val instanceof ArrayList)
((ArrayList)val).add(token);
else
{
ArrayList newVal=new ArrayList();
newVal.add(val);
newVal.add(token);
resourceTokenMap.put(resourceURL, newVal);
}
}
}
public boolean isTagged()
{
return this.tagged;
}
public boolean isEmpty()
{
if (this.tagged)
{
return this.resourceTokenMap==null ||
this.resourceTokenMap.isEmpty();
}
return this.stateTokenList==null || stateTokenList.size()==0;
}
public String toString()
{
if (this.isEmpty())
return "";
StringBuffer sb=new StringBuffer();
if (this.tagged)
{
for (Iterator it=this.resourceTokenMap.keySet().iterator();
it.hasNext();)
{
Object key=it.next();
Object val=resourceTokenMap.get(key);
sb.append('<');
sb.append(key);
sb.append("> ");
if (val instanceof ArrayList)
{
ArrayList vallist=(ArrayList) val;
for (Iterator it2=vallist.iterator();it2.hasNext();)
{
sb.append("(<");
sb.append(it2.next());
sb.append(">) ");
}
}
else
{
sb.append("(<");
sb.append(val);
sb.append(">) ");
}
}
}
else
{
for (Iterator it=this.stateTokenList.iterator();
it.hasNext();)
{
sb.append("(<");
sb.append(it.next());
sb.append(">) ");
}
}
return sb.toString();
}
}
/* $Log: IfHeader.java,v $
/* Revision 1.1 2001/07/17 04:41:32 smulloni
/* integrated IfHeader more closely into method package; added lock test.
/* */
|