001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.request.handler.resource;
018
019import org.apache.wicket.core.util.resource.WebExternalResourceStream;
020import org.apache.wicket.request.IRequestCycle;
021import org.apache.wicket.request.resource.ContentDisposition;
022
023
024/**
025 * Request target that is not a Wicket resource. For example, such a resource could denote an image
026 * in the web application directory (not mapped to a Wicket servlet). NOTE: this target can only be
027 * used in a servlet environment with {@link org.apache.wicket.request.cycle.RequestCycle}s.
028 * 
029 * <p>
030 * <b>NOTE:</b> this class is a wrapper around
031 * {@link ResourceStreamRequestHandler#ResourceStreamRequestHandler(org.apache.wicket.util.resource.IResourceStream)}
032 * , and kept for compatibility purposes.
033 * </p>
034 * 
035 * @author Eelco Hillenius
036 */
037public class WebExternalResourceRequestHandler extends ResourceStreamRequestHandler
038{
039        /** the relative url of the external resource. */
040        private final String uri;
041
042        /**
043         * Construct.
044         * 
045         * @param uri
046         *            the relative url of the external resource
047         */
048        public WebExternalResourceRequestHandler(String uri)
049        {
050                super(new WebExternalResourceStream(uri));
051                this.uri = uri;
052                setContentDisposition(ContentDisposition.INLINE);
053        }
054
055        /**
056         * Gets the url to the external resource.
057         * 
058         * @return the url to the external resource
059         */
060        public final String getUrl()
061        {
062                return uri;
063        }
064
065        @Override
066        public boolean equals(Object obj)
067        {
068                if (obj instanceof WebExternalResourceRequestHandler)
069                {
070                        WebExternalResourceRequestHandler that = (WebExternalResourceRequestHandler)obj;
071                        return uri.equals(that.uri);
072                }
073                return false;
074        }
075
076        @Override
077        public int hashCode()
078        {
079                int result = "WebExternalResourceRequestTarget".hashCode();
080                result += uri.hashCode();
081                return 17 * result;
082        }
083
084        @Override
085        public String toString()
086        {
087                return "[WebExternalResourceRequestTarget@" + hashCode() + " " + uri + "]";
088        }
089}