Author: chatellier Date: 2009-03-02 13:53:14 +0000 (Mon, 02 Mar 2009) New Revision: 1898 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java isis-fish/trunk/src/main/resources/templates/prescript/factorprescript.ftl isis-fish/trunk/src/main/resources/templates/script/script.ftl Log: Remove java script content in java source, use only those from freemarker. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java 2009-03-02 11:00:13 UTC (rev 1897) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/ScriptStorage.java 2009-03-02 13:53:14 UTC (rev 1898) @@ -56,7 +56,7 @@ public static final String SCRIPT_PATH = "scripts"; /** Template freemarker pour les scripts. */ - public static final String FORMULE_TEMPLATE = "templates/script/script.ftl"; + public static final String SCRIPT_TEMPLATE = "templates/script/script.ftl"; @SuppressWarnings("unchecked") static private Map<String, ScriptStorage> scriptsCache = Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2009-03-02 11:00:13 UTC (rev 1897) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2009-03-02 13:53:14 UTC (rev 1898) @@ -30,7 +30,6 @@ import java.io.StringWriter; import java.io.Writer; import java.lang.reflect.Method; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -298,7 +297,6 @@ .getMessage()), e); } - String scriptContent = mapping.getDefaultContent(); String scriptTemplatePath = mapping.getTemplatePath(); if (scriptTemplatePath != null) { @@ -326,20 +324,9 @@ template.process(root, out); out.flush(); script.setContent(out.toString()); - } else if (scriptContent != null) { - // FIXME remove this part when ant script will be in FTL - - // add default script content - String content = MessageFormat.format(scriptContent, - category.isEmpty() ? "" : '.' + category.replaceAll( - "\\/", "."), realFilename, new Date(), - IsisFish.config.getUserName(), IsisFish.config - .getUserMail()); - script.setContent(content); - } else { throw new IsisFishRuntimeException( - "There is no content nor templatePath"); + "There is no templatePath"); } code = script; @@ -678,386 +665,35 @@ Script( ScriptStorage.getScriptDirectory(), - /** - * 0 = package name, - * 1 = class name, - * 2 = current date, - * 3 = author name, - * 4 = author email - */ - "package scripts{0};\n" - + "\n" - + "import org.apache.commons.logging.Log;\n" - + "import org.apache.commons.logging.LogFactory;\n" - + "\n" - + "import fr.ifremer.isisfish.util.Doc;\n" - + "\n" - + "import org.codelutin.math.matrix.*;\n" - + "\n" - + "import fr.ifremer.isisfish.entities.*;\n" - + "\n" - + "/**\n" - + " * {1}.java\n" - + " *\n" - + " * Created: {2,date, long}\n" - + " *\n" - + " * @author {3} <{4}>\n" - + - //" * @version $Revision: 1545 $\n" + - " *\n" - + - //" * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $\n" + - //" * by : $Author: sletellier $\n" + - " */\n" - + "public class {1} '{'\n" - + "\n" - + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" - + " static private Log log = LogFactory.getLog({1}.class);\n" - + "\n" + " // add your method here\n" + "'}'\n", - null), - + ScriptStorage.SCRIPT_TEMPLATE), Simulator( SimulatorStorage.getSimulatorDirectory(), - /** - * 0 = package name, - * 1 = class name, - * 2 = current date, - * 3 = author name, - * 4 = author email - */ - "package simulators{0};\n" - + "\n" - + "import org.apache.commons.logging.Log;\n" - + "import org.apache.commons.logging.LogFactory;\n" - + "\n" - + "import org.codelutin.math.matrix.*;\n" - + "\n" - + "import fr.ifremer.isisfish.util.Doc;\n" - + "import fr.ifremer.isisfish.entities.*;\n" - + "import fr.ifremer.isisfish.simulator.Simulator;\n" - + "import fr.ifremer.isisfish.simulator.SimulationContext;\n" - + "\n" - + "/**\n" - + " * {1}.java\n" - + " *\n" - + " * Created: {2,date, long}\n" - + " *\n" - + " * @author {3} <{4}>\n" - + - //" * @version $Revision: 1545 $\n" + - " *\n" - + - //" * Last update$\n" + - //" * by : $Author: sletellier $\n" + - " */\n" - + "public class {1} implements Simulator '{'\n" - + "\n" - + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" - + " static private Log log = LogFactory.getLog({1}.class);\n" - + "\n" - + " public void simulate(SimulationContext context) throws Exception '{'\n" - + " // put your code here\n" + " '}'\n" - + "\n" + "'}'\n", null), Export( + SimulatorStorage.SIMULATOR_TEMPLATE), + Export( ExportStorage.getExportDirectory(), - /** - * 0 = package name, - * 1 = class name, - * 2 = current date, - * 3 = author name, - * 4 = author email - */ - "package exports{0};\n" - + "\n" - + "import org.apache.commons.logging.Log;\n" - + "import org.apache.commons.logging.LogFactory;\n" - + "\n" - + "import java.io.Writer;\n" - + "\n" - + + ExportStorage.EXPORT_TEMPLATE), - "import static org.codelutin.i18n.I18n._;\n" - + "import org.codelutin.math.matrix.*;\n" - + "\n" - + "import fr.ifremer.isisfish.util.Doc;\n" - + "import fr.ifremer.isisfish.entities.*;\n" - + "import fr.ifremer.isisfish.export.Export;\n" - + "import fr.ifremer.isisfish.datastore.SimulationStorage;\n" - + "import fr.ifremer.isisfish.datastore.ResultStorage;\n" - + "\n" - + "/**\n" - + " * {1}.java\n" - + " *\n" - + " * Created: {2,date, long}\n" - + " *\n" - + " * @author {3} <{4}>\n" - + - //" * @version $Revision: 1545 $\n" + - " *\n" - + - //" * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $\n" + - //" * by : $Author: sletellier $\n" + - " */\n" - + "public class {1} implements Export '{'\n" - + "\n" - + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" - + " static private Log log = LogFactory.getLog({1}.class);\n" - + "\n" - + " public String [] necessaryResult = '{'\n" - + " // put here all necessary result for this rule\n" - + " // example: \n" - + " // ResultName.MATRIX_BIOMASS,\n" - + " // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,\n" - + " '}';\n" - + "\n" - + " public String[] getNecessaryResult() '{'\n" - + " return this.necessaryResult;\n" - + " '}'\n" - + "\n" - + " public String getExportFilename() '{'\n" - + " // remove _(...) if you don''t want translation on filename\n" - + " return _(\"{0}\");\n" - + " '}'\n" - + "\n" - + " public String getExtensionFilename() '{'\n" - + " return \".csv\";\n" - + " '}'\n" - + "\n" - + " public String getDescription() '{'\n" - + " return _(\"TODO export description\");\n" - + " '}'\n" - + "\n" - + " public void export(SimulationStorage simulation, Writer out) throws Exception '{'\n" - + " // put your code here, and write export with: out.write(\"...\")\n" - + " '}'\n" + "\n" + "'}'\n", null), - Rule( RuleStorage.getRuleDirectory(), - /** - * 0 = package name, - * 1 = class name, - * 2 = current date, - * 3 = author name, - * 4 = author email, - * 5 = region name - */ - "package rules{0};\n" - + "\n" - + "import static org.codelutin.i18n.I18n._;\n" - + "\n" - + "import org.apache.commons.logging.Log;\n" - + "import org.apache.commons.logging.LogFactory;\n" - + "\n" - + "import scripts.ResultName;\n" - + "\n" - + "import java.io.Writer;\n" - + "\n" - + "import org.codelutin.math.matrix.*;\n" - + "\n" - + "import fr.ifremer.isisfish.util.Doc;\n" - + "import fr.ifremer.isisfish.simulator.SimulationContext;\n" - + "import fr.ifremer.isisfish.types.Date;\n" - + "import fr.ifremer.isisfish.entities.*;\n" - + "import fr.ifremer.isisfish.rule.AbstractRule;\n" - + "import fr.ifremer.isisfish.datastore.SimulationStorage;\n" - + "import fr.ifremer.isisfish.datastore.ResultStorage;\n" - + "\n" - + "/**\n" - + " * {1}.java\n" - + " *\n" - + " * Created: {2,date, long}\n" - + " *\n" - + " * @author {3} <{4}>\n" - + - //" * @version $Revision: 1545 $\n" + - " *\n" - + - //" * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $\n" + - //" * by : $Author: sletellier $\n" + - " */\n" - + "public class {1} extends AbstractRule '{'\n" - + "\n" - + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" - + " static private Log log = LogFactory.getLog({1}.class);\n" - + "\n" - + " public String [] necessaryResult = '{'\n" - + " // put here all necessary result for this rule\n" - + " // example: \n" - + " // ResultName.MATRIX_BIOMASS,\n" - + " // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,\n" - + " '}';\n" - + "\n" - + " public String[] getNecessaryResult() '{'\n" - + " return this.necessaryResult;\n" - + " '}'\n" - + "\n" - + " /**\n" - + " * Permet d''afficher a l''utilisateur une aide sur la regle.\n" - + " * @return L''aide ou la description de la regle\n" - + " */\n" - + " public String getDescription() throws Exception '{'\n" - + " // TODO\n" - + " return _(\"TODO description rule\");\n" - + " '}'\n" - + " \n" - + " /**\n" - + " * Appelé au démarrage de la simulation, cette méthode permet d''initialiser\n" - + " * des valeurs\n" - + " * @param simulation La simulation pour lequel on utilise cette regle\n" - + " */\n" - + " public void init(SimulationContext context) throws Exception '{'\n" - + " // TODO\n" - + " '}'\n" - + " /**\n" - + " * La condition qui doit etre vrai pour faire les actions\n" - + " * @param simulation La simulation pour lequel on utilise cette regle\n" - + " * @return vrai si on souhaite que les actions soit faites\n" - + " */\n" - + " public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception '{'\n" - + " // TODO\n" - + " return false;\n" - + " '}'\n" - + " \n" - + " /**\n" - + " * Si la condition est vrai alors cette action est executée avant le pas\n" - + " * de temps de la simulation.\n" - + " * @param simulation La simulation pour lequel on utilise cette regle\n" - + " */\n" - + " public void preAction(SimulationContext context, Date date, Metier metier) throws Exception '{'\n" - + " // TODO\n" - + " '}'\n" - + " \n" - + " /**\n" - + " * Si la condition est vrai alors cette action est executée apres le pas\n" - + " * de temps de la simulation.\n" - + " * @param simulation La simulation pour lequel on utilise cette regle\n" - + " */\n" - + " public void postAction(SimulationContext context, Date date, Metier metier) throws Exception '{'\n" - + " // TODO\n" + " '}'\n" + "\n" + "'}'\n", - null), + RuleStorage.RULE_TEMPLATE), AnalysePlan( AnalysePlanStorage.getAnalysePlanDirectory(), - /** - * 0 = package name, - * 1 = class name, - * 2 = current date, - * 3 = author name, - * 4 = author email, - * 5 = region name - */ - "package analyseplans{0};\n" - + "\n" - + "import static org.codelutin.i18n.I18n._;\n" - + "\n" - + "import org.apache.commons.logging.Log;\n" - + "import org.apache.commons.logging.LogFactory;\n" - + "\n" - + "import scripts.ResultName;\n" - + "\n" - + "import java.io.Writer;\n" - + "\n" - + "import org.codelutin.math.matrix.*;\n" - + "import org.codelutin.util.*;\n" - + "import org.codelutin.topia.*;\n" - + "\n" - + "import fr.ifremer.isisfish.util.Doc;\n" - + "import fr.ifremer.isisfish.*;\n" - + "import fr.ifremer.isisfish.simulator.SimulationContext;\n" - + "import fr.ifremer.isisfish.types.Date;\n" - + "import fr.ifremer.isisfish.entities.*;\n" - + "import fr.ifremer.isisfish.simulator.AnalysePlan;\n" - + "import fr.ifremer.isisfish.simulator.AnalysePlanContext;\n" - + "import fr.ifremer.isisfish.simulator.SimulationParameter;\n" - + "import fr.ifremer.isisfish.datastore.SimulationStorage;\n" - + "import fr.ifremer.isisfish.datastore.ResultStorage;\n" - + "\n" - + "/**\n" - + " * {1}.java\n" - + " *\n" - + " * Created: {2,date, long}\n" - + " *\n" - + " * @author {3} <{4}>\n" - + - //" * @version $Revision: 1545 $\n" + - " *\n" - + - //" * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $\n" + - //" * by : $Author: sletellier $\n" + - " */\n" - + "public class {1} implements AnalysePlan '{'\n" - + "\n" - + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" - + " static private Log log = LogFactory.getLog({1}.class);\n" - + "\n" - + " public String [] necessaryResult = '{'\n" - + " // put here all necessary result for this rule\n" - + " // example: \n" - + " // ResultName.MATRIX_BIOMASS,\n" - + " // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,\n" - + " '}';\n" - + "\n" - + " public String[] getNecessaryResult() '{'\n" - + " return this.necessaryResult;\n" - + " '}'\n" - + "\n" - + " /**\n" - + " * Permet d''afficher a l''utilisateur une aide sur le plan.\n" - + " * @return L''aide ou la description du plan\n" - + " */\n" - + " public String getDescription() throws Exception '{'\n" - + " // TODO\n" - + " return _(\"TODO description plan\");\n" - + " '}'\n" - + " \n" - + " /**\n" - + " * Appelé au démarrage de la simulation, cette méthode permet d''initialiser\n" - + " * des valeurs\n" - + " * @param simulation La simulation pour lequel on utilise cette regle\n" - + " */\n" - + " public void init(AnalysePlanContext context) throws Exception '{'\n" - + " // TODO\n" - + " '}'\n" - + " \n" - + " /**\n" - + " * Call before each simulation\n" - + " * @param context plan context\n" - + " * @param nextSimulation storage used for next simulation\n" - + " * @return true if we must do next simulation, false to stop plan\n" - + " * @throws Exception\n" - + " */\n" - + " public boolean next(AnalysePlanContext context, SimulationStorage nextSimulation) throws Exception '{'\n" - + " return false; // TODO\n" + " '}'\n" - + "\n" + "'}'\n", null), + AnalysePlanStorage.ANALYSE_PLAN_TEMPLATE), - EquationModel(FormuleStorage.getFormuleDirectory(), - /** - * 0 = package name, - * 1 = class name, - * 2 = current date, - * 3 = author name, - * 4 = author email - */ - "/**\n" + " * {1}.java\n" + " *\n" + " * Created: {2,date, long}\n" - + " *\n" + " * @author {3} <{4}>\n" + - //" * @version $Revision: 1545 $\n" + - " *\n" + - //" * Last update: $7 $\n" + - //" * by : $Author: sletellier $\n" + - //" */\n" + - "\n" + "// put your code here\n" + "\n", null), + EquationModel( + FormuleStorage.getFormuleDirectory(), + FormuleStorage.FORMULE_TEMPLATE), - Sensitivity(SensitivityStorage.getSensitivityDirectory(), null, + Sensitivity( + SensitivityStorage.getSensitivityDirectory(), SensitivityStorage.SENSIVITY_TEMPLATE); protected File module; - /** @deprecated content, use #templatePath instead */ - protected String defaultContent; protected String templatePath; - private ScriptMapping(File module, String defaultContent, - String templatePath) { + private ScriptMapping(File module, String templatePath) { this.module = module; - this.defaultContent = defaultContent; this.templatePath = templatePath; } @@ -1065,14 +701,6 @@ return module; } - /** - * @deprecated use #getTemplatePath() instead - * @return - */ - public String getDefaultContent() { - return defaultContent; - } - public String getTemplatePath() { return templatePath; } Modified: isis-fish/trunk/src/main/resources/templates/prescript/factorprescript.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/prescript/factorprescript.ftl 2009-03-02 11:00:13 UTC (rev 1897) +++ isis-fish/trunk/src/main/resources/templates/prescript/factorprescript.ftl 2009-03-02 13:53:14 UTC (rev 1898) @@ -1,7 +1,32 @@ -//SimulationStorage simulation = context.getSimulationStorage(); -//SimulationParameter parameters = simulation.getParameter(); -//String presimulationScript = parameters.getPreScript(); +<#-- *##% + * Copyright (C) 2009 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + *##% +Freemarker template used to make simulation prescripts. + +Produce : + +Object value = beanUtils.convert("99.0", java.lang.Double.class); +TopiaEntity entity = db.findByTopiaId("fr.ifremer.isisfish.entities.PopulationGroup#1156461521076#0.6526656643346673"); +BeanUtils.setProperty(entity, "minLength", value); + +--> + import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.ConvertUtilsBean; import fr.ifremer.isisfish.util.ConverterUtil; Modified: isis-fish/trunk/src/main/resources/templates/script/script.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/script/script.ftl 2009-03-02 11:00:13 UTC (rev 1897) +++ isis-fish/trunk/src/main/resources/templates/script/script.ftl 2009-03-02 13:53:14 UTC (rev 1898) @@ -12,7 +12,7 @@ * * Created: ${date?date?string.long} * - * @author ${author} <$email}> + * @author ${author} <${email}> * @version $Revision: 0 $ * * Last update: $Date: ${date?date?string.long} $