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 015 package org.apache.tapestry.engine; 016 017 import 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 */ 025 public final class EngineUtils 026 { 027 028 /* defeat instantiation */ 029 private EngineUtils() { } 030 031 /** 032 * Invoked by to see if an absolute URL is needed (because a specific scheme, server or port 033 * was indicated that does not match the incoming request). 034 * 035 * @param scheme 036 * the desired URL scheme, or null 037 * @param server 038 * the desired URL server name, or null 039 * @param port 040 * the desired URL port, or 0 041 * @param request 042 * the request to check against 043 * @return true if absolute URL is needed, false otherwise 044 */ 045 public static boolean needAbsoluteURL(String scheme, String server, int port, WebRequest request) 046 { 047 if (scheme != null && !scheme.equals(request.getScheme())) return true; 048 049 if (server != null && !server.equals(request.getServerName())) 050 return true; 051 052 if (port != 0 && port != request.getServerPort()) return true; 053 054 return false; 055 } 056 057 }