001// Copyright 2005 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// 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 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry.engine; 016 017import org.apache.tapestry.web.WebRequest; 018 019/** 020 * Utilities needed by engine services and etc. 021 * 022 * @author Howard M. Lewis Ship 023 * @since 4.0 024 */ 025public class EngineUtils 026{ 027 028 /** 029 * Invoked by {@link #getURL(String, String, int, String, boolean)} to see if an absolute URL is 030 * needed (because a specific scheme, server or port was indicated that does not match the 031 * incoming request). 032 * 033 * @param scheme 034 * the desired URL scheme, or null 035 * @param server 036 * the desired URL server name, or null 037 * @param port 038 * the desired URL port, or 0 039 * @param request 040 * the request to check against 041 * @return true if absolute URL is needed, false otherwise 042 */ 043 public static boolean needAbsoluteURL(String scheme, String server, int port, WebRequest request) 044 { 045 if (scheme != null && !scheme.equals(request.getScheme())) 046 return true; 047 048 if (server != null && !server.equals(request.getServerName())) 049 return true; 050 051 if (port != 0 && port != request.getServerPort()) 052 return true; 053 054 return false; 055 } 056 057}