/* * Copyright (C) 2005 Alfresco, Inc. * * Licensed under the Mozilla Public License version 1.1 * with a permitted attribution clause. You may obtain a * copy of the License at * * http://www.alfresco.org/legal/license.txt * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific * language governing permissions and limitations under the * License. */ package org.alfresco.web.templating.extension; import org.alfresco.jndi.AVMFileDirContext; import org.w3c.dom.Document; import org.xml.sax.SAXException; import javax.servlet.ServletContext; import java.io.IOException; import java.util.Map; public class ServletContextExtensionFunctionsAdapter extends ExtensionFunctions { private final ServletContext servletContext; public ServletContextExtensionFunctionsAdapter(final ServletContext servletContext) { super(AVMFileDirContext.getAVMRemote()); this.servletContext = servletContext; } private String toAVMPath(String path) { // The real_path will look somethign like this: // /alfresco.avm/avm.alfresco.localhost/$-1$alfreco-guest-main:/appBase/avm_webapps/my_webapp path = this.servletContext.getRealPath(path); // The avm_path to the root of the context will look something like this: // alfreco-guest-main:/appBase/avm_webapps/my_webapp path = path.substring(path.indexOf('$', path.indexOf('$') + 1) + 1); path = path.replace('\\','/'); return path; } public Document getXMLDocument(final String path) throws IOException, SAXException { return super.getXMLDocument(this.toAVMPath(path)); } public Map getXMLDocuments(final String templateTypeName, final String path) throws IOException, SAXException { return super.getXMLDocuments(templateTypeName, this.toAVMPath(path)); } }