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 java.net.*; 016 017import org.apache.juneau.internal.*; 018 019/** 020 * Category of headers that consist of a single URL value. 021 * 022 * <p> 023 * <h5 class='figure'>Example</h5> 024 * <p class='bcode'> 025 * Location: http://www.w3.org/pub/WWW/People.html 026 * </p> 027 * 028 * <h5 class='section'>See Also:</h5> 029 * <ul class='doctree'> 030 * <li class='extlink'><a class='doclink' href='https://www.w3.org/Protocols/rfc2616/rfc2616.html'>Hypertext Transfer Protocol -- HTTP/1.1</a> 031 * </ul> 032 */ 033public class HeaderUri{ 034 035 final String value; 036 037 /** 038 * Constructor. 039 * 040 * @param value The raw header value. 041 */ 042 protected HeaderUri(String value) { 043 this.value = StringUtils.trim(value); 044 } 045 046 /** 047 * Returns this header as a {@link URI}. 048 * 049 * @return This header as a {@link URI}. 050 */ 051 public URI asURI() { 052 return URI.create(toString()); 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 value; 065 } 066 067 @Override /* Object */ 068 public String toString() { 069 return value == null ? "" : value; 070 } 071}