blob: 19596bb2b3a9b58933305f250574c52d66db4502 [file] [log] [blame]
/*
* Copyright (C) 2010-2011 The University of Manchester
*
* See the file "LICENSE" for license terms.
*/
package org.taverna.server.master.utils;
import javax.servlet.ServletContext;
import org.springframework.web.context.ServletContextAware;
import org.taverna.server.master.common.version.Version;
/**
* Convert a string (URL, etc) to a version that is contextualized to the
* web-application.
*
* @author Donal Fellows
*/
public class Contextualizer implements ServletContextAware {
static final String ROOT_PLACEHOLDER = "%{WEBAPPROOT}";
static final String VERSION_PLACEHOLDER = "%{VERSION}";
/**
* Apply the contextualization operation. This consists of replacing the
* string <tt>{@value #ROOT_PLACEHOLDER}</tt> with the real root of the webapp.
*
* @param input
* the string to contextualize
* @return the contextualized string
*/
public String contextualize(String input) {
// Hack to work around bizarre CXF bug
String path = context.getRealPath("/").replace("%2D", "-");
return input.replace(ROOT_PLACEHOLDER, path).replace(
VERSION_PLACEHOLDER, Version.JAVA);
}
private ServletContext context;
@Override
public void setServletContext(ServletContext servletContext) {
context = servletContext;
}
}