net.disy.commons.servlet.util.ServletUrlProvider Maven / Gradle / Ivy
/**
* Legato is a configurable, lightweight web mapping client that can be
* easily embedded into web pages and portals, CMS and individual web
* applications. Legato is implemented in JavaScript and based on the
* popular open source library OpenLayers.
*
* Copyright (C) 2010 disy Informationssysteme GmbH, http://www.disy.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package net.disy.commons.servlet.util;
import javax.servlet.http.HttpServletRequest;
public class ServletUrlProvider implements UrlProvider {
private final HttpServletRequest request;
public ServletUrlProvider(HttpServletRequest request) {
this.request = request;
}
@Override
public String getUrl(String queryString) {
return createAbsoluteContextUrl(
request.getScheme(),
request.getServerName(),
request.getServerPort(),
request.getContextPath() + queryString);
}
private String createAbsoluteContextUrl(String protocol, String host, int port, String context) {
StringBuffer sb = new StringBuffer();
sb.append(protocol).append("://").append(host);
if ((protocol.equals("http") && (port != 80)) || (protocol.equals("https") && (port != 443))) {
sb.append(":").append(port);
}
sb.append(context);
return sb.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy