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.rest; 014 015import static org.apache.juneau.internal.StringUtils.*; 016 017import java.net.*; 018import java.text.*; 019 020/** 021 * @deprecated Use {@link org.apache.juneau.rest.response.SeeOther} 022 */ 023@Deprecated 024public final class Redirect { 025 026 private final int httpResponseCode; 027 private final URI uri; 028 029 /** 030 * Redirect to the specified URL. 031 * 032 * <p> 033 * Relative paths are interpreted as relative to the servlet path. 034 * 035 * @param uri 036 * The URL to redirect to. 037 * <br>Can be any of the following: 038 * <ul> 039 * <li><code>URL</code> 040 * <li><code>URI</code> 041 * <li><code>CharSequence</code> 042 * </ul> 043 * @param args Optional {@link MessageFormat}-style arguments. 044 */ 045 public Redirect(Object uri, Object...args) { 046 this(0, uri, args); 047 } 048 049 /** 050 * Convenience method for redirecting to instance of {@link URL} and {@link URI}. 051 * 052 * <p> 053 * Same as calling <code>toString()</code> on the object and using the other constructor. 054 * 055 * @param uri 056 * The URL to redirect to. 057 * <br>Can be any of the following: 058 * <ul> 059 * <li><code>URL</code> 060 * <li><code>URI</code> 061 * <li><code>CharSequence</code> 062 * </ul> 063 */ 064 public Redirect(Object uri) { 065 this(0, uri, (Object[])null); 066 } 067 068 /** 069 * Redirect to the specified URL. 070 * 071 * <p> 072 * Relative paths are interpreted as relative to the servlet path. 073 * 074 * @param httpResponseCode The HTTP response code. 075 * @param url 076 * The URL to redirect to. 077 * <br>Can be any of the following: 078 * <ul> 079 * <li><code>URL</code> 080 * <li><code>URI</code> 081 * <li><code>CharSequence</code> 082 * </ul> 083 * @param args Optional {@link MessageFormat}-style arguments. 084 */ 085 public Redirect(int httpResponseCode, Object url, Object...args) { 086 this.httpResponseCode = httpResponseCode; 087 if (url == null) 088 url = ""; 089 this.uri = toURI(format(url.toString(), args)); 090 } 091 092 /** 093 * Shortcut for redirecting to the servlet root. 094 */ 095 public Redirect() { 096 this(0, null, (Object[])null); 097 } 098 099 /** 100 * Returns the response code passed in through the constructor. 101 * 102 * @return The response code passed in through the constructor, or <code>0</code> if response code wasn't specified. 103 */ 104 public int getHttpResponseCode() { 105 return httpResponseCode; 106 } 107 108 /** 109 * Returns the URI to redirect to. 110 * 111 * @return The URI to redirect to. 112 */ 113 public URI getURI() { 114 return uri; 115 } 116}