All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tentackle.maven.wizard.AbstractGenerator Maven / Gradle / Ivy

There is a newer version: 21.16.1.0
Show newest version
/*
 * Tentackle - http://www.tentackle.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.tentackle.maven.wizard;

import freemarker.template.Configuration;
import freemarker.template.TemplateExceptionHandler;

import org.tentackle.validate.ScopeConfigurator;
import org.tentackle.validate.Validateable;
import org.tentackle.validate.ValidationResult;
import org.tentackle.validate.ValidationScope;
import org.tentackle.validate.ValidationUtilities;
import org.tentackle.validate.scope.ChangeableScope;
import org.tentackle.validate.scope.MandatoryScope;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * Base class for generators.
* Holds common methods for {@link PdoGenerator} and {@link OperationGenerator}. */ public class AbstractGenerator implements ScopeConfigurator, Validateable { private File templateDirectory; /** * Sets the freemarker template directory. * * @param templateDirectory the template directory */ public void setTemplateDirectory(File templateDirectory) { this.templateDirectory = templateDirectory; } /** * Creates the freemarker configuration. * * @return the config * @throws IOException if there's some trouble with the template directory */ public Configuration createFreemarkerConfiguration() throws IOException { Configuration cfg = new Configuration(Configuration.VERSION_2_3_28); cfg.setDirectoryForTemplateLoading(templateDirectory); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(false); cfg.setWrapUncheckedExceptions(true); return cfg; } @Override @SuppressWarnings("unchecked") public Class[] getDefaultScopes() { return new Class[] { MandatoryScope.class, ChangeableScope.class}; } @Override public List validate(String validationPath, ValidationScope scope) { return ValidationUtilities.getInstance().validate(this, validationPath, scope); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy