001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * Contributors: 016 * Nuxeo - initial API and implementation 017 */ 018 019package org.nuxeo.ecm.user.invite; 020 021import java.io.File; 022import java.net.URL; 023 024import freemarker.template.Configuration; 025import org.nuxeo.ecm.platform.rendering.api.ResourceLocator; 026import org.nuxeo.ecm.platform.rendering.fm.FreemarkerEngine; 027 028 029public class RenderingHelper { 030 031 protected volatile FreemarkerEngine engine; 032 033 protected class CLResourceLocator implements ResourceLocator { 034 @Override 035 public File getResourceFile(String key) { 036 return null; 037 } 038 039 @Override 040 public URL getResourceURL(String key) { 041 return this.getClass().getClassLoader().getResource(key); 042 } 043 } 044 045 public FreemarkerEngine getRenderingEngine() { 046 if (engine == null) { 047 synchronized (this) { 048 if (engine == null) { 049 FreemarkerEngine fme = new FreemarkerEngine(); 050 fme.setResourceLocator(new CLResourceLocator()); 051 engine = fme; 052 } 053 } 054 } 055 return engine; 056 } 057 058 public Configuration getEngineConfiguration() { 059 return getRenderingEngine().getConfiguration(); 060 } 061 062}