/* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.id.auth.frontend.builder; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.URI; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import at.gv.egiz.eaaf.core.api.gui.IVelocityGUIBuilderConfiguration; import at.gv.egiz.eaaf.core.exceptions.GUIBuildException; import at.gv.egiz.eaaf.core.impl.gui.AbstractVelocityGUIFormBuilderImpl; import at.gv.egovernment.moa.id.commons.api.AuthConfiguration; import at.gv.egovernment.moa.logging.Logger; /** * @author tlenz * */ @Service("guiFormBuilder") public class GUIFormBuilderImpl extends AbstractVelocityGUIFormBuilderImpl { private static final String CONFIG_HTMLTEMPLATES_DIR = "htmlTemplates/"; private static final String CLASSPATH_HTMLTEMPLATES_DIR = "templates/"; @Autowired private AuthConfiguration authConfig; public GUIFormBuilderImpl() throws GUIBuildException { super(); } @Override protected InputStream getInternalTemplate(IVelocityGUIBuilderConfiguration config) throws GUIBuildException { String viewName = config.getViewName(); //load specific template InputStream is = config.getTemplate(viewName); if (is == null) { //load template from default resources try { Logger.trace("Loading GUI template:" + viewName + " from default resources ... "); String pathLocation = null; try { //load template from config directory String rootconfigdir = authConfig.getRootConfigFileDir(); pathLocation = rootconfigdir + CONFIG_HTMLTEMPLATES_DIR + viewName; File file = new File(new URI(pathLocation)); is = new FileInputStream(file); } catch (Exception e) { //load template from classpath as backup Logger.debug("GUI template:" + viewName + " is not found in configuration directory. " + " Load template from project library ... "); try { pathLocation = super.getInternalClasspathTemplateDir(config, CLASSPATH_HTMLTEMPLATES_DIR) + viewName; is = Thread.currentThread() .getContextClassLoader() .getResourceAsStream(pathLocation); } catch (Exception e1) { Logger.error("GUI template:" + pathLocation + " is NOT loadable!", e); throw new GUIBuildException("GUI template:" + pathLocation + " is NOT loadable!", e); } } } catch (GUIBuildException e) { throw e; } catch (Exception e) { Logger.error("GUI builder has an internal error during template load operation", e); throw new GUIBuildException("GUI builder has an internal error during template load operation", e); } } return is; } }