WebdavIfHeader (Apache Tomcat 10.1.55 API Documentation)
Description: declaration: package: org.apache.tomcat.util.http, class: WebdavIfHeader

# Class WebdavIfHeader

java.lang.Object
org.apache.tomcat.util.http.WebdavIfHeader

public class WebdavIfHeader extends Object
The `IfHeader` class represents the state lists defined through the HTTP If header, which is specified in RFC 2518 as follows :

       If = "If" ":" ( 1*No-tag-list | 1*Tagged-list)
       No-tag-list = List
       Tagged-list = Resource 1*List
       Resource = Coded-URL
       List = "(" 1*(["Not"](State-etag | "[" entity-tag "]")) ")"
       State-etag = Coded-URL
       Coded-URL = "<" absoluteURI ">"

Reformulating this specification into proper EBNF as specified by N. Wirth we get the following productions, which map to the parse METHODS of this class. Any whitespace is ignored except for white space surrounding and within words which is considered significant.

       If = "If:" ( Tagged | Untagged ).
       Tagged = { "<" Word ">" Untagged } .
       Untagged = { "(" IfList ")" } .
       IfList = { [ "Not" ] ( ("<" Word ">" ) | ( "[" Word "]" ) ) } .
       Word = characters .

An If header either contains untagged IfList entries or tagged IfList entries but not a mixture of both. An If header containing tagged entries is said to be of tagged type while an If header containing untagged entries is said to be of untagged type.

An IfList is a list of tokens - words enclosed in < > - and etags - words enclosed in [ ]. An IfList matches a (token, etag) tuple if all entries in the list match. If an entry in the list is prefixed with the word Not (parsed case insensitively) the entry must not match the concrete token or etag.

Example: The ifList `(<token> [etag])` only matches if the concrete token has the value `token` and the concrete etag has the value `etag`. On the other hand, the ifList `(Not <notoken>)` matches any token which is not `notoken` (in this case the concrete value of the etag is not taken into consideration).

This class was contributed by Apache Jackrabbit

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WebdavIfHeader(String[] tokens)`
  Create an Untagged `IfHeader` if the given lock tokens.
  `WebdavIfHeader(String uriPrefix, String ifHeaderValue)`
  Parses the If header and creates and internal representation which is easy to query.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Iterator<String>`
  `getAllNotTokens()`
  `Iterator<String>`
  `getAllTokens()`
  `String`
  `getHeaderName()`
  `String`
  `getHeaderValue()`
  Return the String representation of the If header present on the given request or `null`.
  `Iterator<String>`
  `getResources()`
  `boolean`
  `hasValue()`
  Returns true if an If header was present in the given request.
  `boolean`
  `matches(String tag, List<String> tokens, String etag)`
  Tries to match the contents of the If header with the given token and etag values with the restriction to only check for the tag.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### WebdavIfHeader

    public WebdavIfHeader(String[] tokens) throws IOException
    Create an Untagged `IfHeader` if the given lock tokens.
    Parameters:
      `tokens` - the tokens
    Throws:
      `IOException` - If the parsing of the `IfHeader` fails

  - ### WebdavIfHeader

    public WebdavIfHeader(String uriPrefix, String ifHeaderValue) throws IOException
    Parses the If header and creates and internal representation which is easy to query.
    Parameters:
      `uriPrefix` - The uri prefix to use for the absolute href
      `ifHeaderValue` - the if header
    Throws:
      `IOException` - If the parsing of the `IfHeader` fails

- ## Method Details

  - ### getHeaderName

    public String getHeaderName()
    Returns:
      If String.

  - ### getHeaderValue

    public String getHeaderValue()
    Return the String representation of the If header present on the given request or `null`.
    Returns:
      If header value as String or `null`.

  - ### hasValue

    public boolean hasValue()
    Returns true if an If header was present in the given request. False otherwise.
    Returns:
      true if an If header was present.

  - ### matches

    public boolean matches(String tag, List<String> tokens, String etag)
    Tries to match the contents of the If header with the given token and etag values with the restriction to only check for the tag.

    If the If header is of untagged type, the untagged IfList is matched against the token and etag given: A match of the token and etag is found if at least one of the IfList entries match the token and etag tuple.

    Parameters:
      `tag` - The tag to identify the IfList to match the token and etag against.
      `tokens` - The tokens to compare.
      `etag` - The ETag value to compare.
    Returns:
      If the If header is of untagged type the result is `true` if any of the IfList entries matches the token and etag values. For tagged type If header the result is `true` if either no entry for the given tag exists in the If header or if the IfList for the given tag matches the token and etag given.

  - ### getResources

    public Iterator<String> getResources()
    Returns:
      an iterator over all resources present in the if header.

  - ### getAllTokens

    public Iterator<String> getAllTokens()
    Returns:
      an iterator over all tokens present in the if header, that were not denied by a leading NOT statement.

  - ### getAllNotTokens

    public Iterator<String> getAllNotTokens()
    Returns:
      an iterator over all NOT tokens present in the if header, that were explicitly denied.