001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.http; 014 015import org.apache.juneau.http.annotation.*; 016import org.apache.juneau.internal.*; 017 018/** 019 * Category of headers that consist of a comma-delimited list of string values. 020 * 021 * <p> 022 * <h5 class='figure'>Example</h5> 023 * <p class='bcode w800'> 024 * Allow: GET, PUT 025 * </p> 026 * 027 * <h5 class='section'>See Also:</h5> 028 * <ul class='doctree'> 029 * <li class='extlink'>{@doc RFC2616} 030 * </ul> 031 */ 032@Header(type="array",collectionFormat="csv",items=@Items(type="string")) 033public class HeaderStringArray { 034 035 private final String[] value; 036 037 /** 038 * Constructor. 039 * 040 * @param value The raw header value. 041 */ 042 protected HeaderStringArray(String[] value) { 043 this.value = value; 044 } 045 046 /** 047 * Constructor. 048 * 049 * @param value The raw header value. 050 */ 051 protected HeaderStringArray(String value) { 052 this.value = StringUtils.split(value); 053 } 054 055 /** 056 * Returns this header as a simple string value. 057 * 058 * <p> 059 * Functionally equivalent to calling {@link #toString()}. 060 * 061 * @return This header as a simple string. 062 */ 063 public String asString() { 064 return StringUtils.joine(value, ','); 065 } 066 067 /** 068 * Returns <jk>true</jk> if this header contains the specified value. 069 * 070 * @param val The value to check for. 071 * @return <jk>true</jk> if this header contains the specified value. 072 */ 073 public boolean contains(String val) { 074 if (val != null) 075 for (String v : value) 076 if (val.equals(v)) 077 return true; 078 return false; 079 } 080 081 /** 082 * Returns <jk>true</jk> if this header contains the specified value using {@link String#equalsIgnoreCase(String)}. 083 * 084 * @param val The value to check for. 085 * @return <jk>true</jk> if this header contains the specified value. 086 */ 087 public boolean containsIC(String val) { 088 if (val != null) 089 for (String v : value) 090 if (val.equalsIgnoreCase(v)) 091 return true; 092 return false; 093 } 094 095 @Override /* Object */ 096 public String toString() { 097 return asString(); 098 } 099}