Index: lutinprocessor/src/java/org/codelutin/processor/filters/DefaultFilter.java diff -u lutinprocessor/src/java/org/codelutin/processor/filters/DefaultFilter.java:1.3 lutinprocessor/src/java/org/codelutin/processor/filters/DefaultFilter.java:1.4 --- lutinprocessor/src/java/org/codelutin/processor/filters/DefaultFilter.java:1.3 Wed Jun 23 10:48:28 2004 +++ lutinprocessor/src/java/org/codelutin/processor/filters/DefaultFilter.java Mon Aug 16 20:47:12 2004 @@ -1,131 +1,133 @@ /* *##%% -* Copyright (C) 2002, 2003 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. -*##%%**/ - -/* * -* DefaultFilter.java -* -* Created: Wed Sep 4 2002 -* -* @author -* Copyright Code Lutin -* @version $Revision: 1.3 $ -* -* Mise a jour: $Date: 2004/06/23 10:48:28 $ -* par : $Author: bpoussin $ -*/ + * Copyright (C) 2002, 2003 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. + *##%%**/ + +/******************************************************************************* + * DefaultFilter.java + * + * Created: Wed Sep 4 2002 + * + * @author Copyright Code Lutin + * + * @version $Revision: 1.4 $ + * + * Mise a jour: $Date: 2004/08/16 20:47:12 $ par : $Author: pineau $ + */ package org.codelutin.processor.filters; public abstract class DefaultFilter implements Filter { // DefaultFilter - protected StringBuffer cache = new StringBuffer(); + protected StringBuffer cache = new StringBuffer(); - public DefaultFilter() { + public DefaultFilter() { - } + } - /** Type of states */ - protected static class State{ - /** Looking-for-header state */ - public final static State SEARCH_HEADER = new State(); - /** Looking-for-footer state */ - public final static State SEARCH_FOOTER = new State(); - } - - protected State currentState = State.SEARCH_HEADER; - - public String parse (String input) { - int index; - if (currentState.equals(State.SEARCH_HEADER)) { - // Looking for a header - index = input.indexOf(getHeader()); - if (index != -1) { - // Header found, store last part of input, return first part of it. - currentState = State.SEARCH_FOOTER; - cache.append(input.substring(0,index)); - String ch = cache.toString(); - cache.setLength(0); - return performOutFilter(ch) + - parse(input.substring(index+getHeader().length())); - } else { - // No header, cache the string - cache.append(input); - return EMPTY_STRING; - } - } - - if (currentState.equals(State.SEARCH_FOOTER)) { - // Looking for a footer - index = input.indexOf(getFooter()); - if (index != -1) { - // Footer found, add first part of input to the cache, - cache.append(input.substring(0,index)); - String ch = cache.toString(); - // then return parsing of last part of input. - currentState = State.SEARCH_HEADER; - cache.setLength(0); - return performInFilter(ch) + - parse(input.substring(index+getFooter().length())); - } else { - // No footer, add the input to cache - cache.append(input); - return EMPTY_STRING; - } - } - - return "INVALID STATE in DefaultFilter !"; - } - - public boolean hasCachedData() { - return (cache.length() > 0); - } - - public String flush () { - String line = cache.toString(); - // Empty the cache, - cache.setLength(0); - // and returns its content - if (currentState.equals(State.SEARCH_HEADER)) - return performOutFilter(line); - else - return performInFilter(line); - } - - /** - * methode appele lorsqu'on a la chaine entiere entre le header - * et le footer. - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - abstract protected String performInFilter(String ch); - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - abstract protected String performOutFilter(String ch); + /** Type of states */ + protected static class State { + /** Looking-for-header state */ + public final static State SEARCH_HEADER = new State(); + + /** Looking-for-footer state */ + public final static State SEARCH_FOOTER = new State(); + } + + protected State currentState = State.SEARCH_HEADER; + + public String parse(String input) { + int index; + if (currentState.equals(State.SEARCH_HEADER)) { + // Looking for a header + index = input.indexOf(getHeader()); + if (index != -1) { + // Header found, store last part of input, return first part of + // it. + currentState = State.SEARCH_FOOTER; + cache.append(input.substring(0, index)); + String ch = cache.toString(); + cache.setLength(0); + return performOutFilter(ch) + + parse(input.substring(index + getHeader().length())); + } + // No header, cache the string + cache.append(input); + return EMPTY_STRING; + } + + if (currentState.equals(State.SEARCH_FOOTER)) { + // Looking for a footer + index = input.indexOf(getFooter()); + if (index != -1) { + // Footer found, add first part of input to the cache, + cache.append(input.substring(0, index)); + String ch = cache.toString(); + // then return parsing of last part of input. + currentState = State.SEARCH_HEADER; + cache.setLength(0); + return performInFilter(ch) + + parse(input.substring(index + getFooter().length())); + } + // No footer, add the input to cache + cache.append(input); + return EMPTY_STRING; + } + + return "INVALID STATE in DefaultFilter !"; + } + + public boolean hasCachedData() { + return (cache.length() > 0); + } + + public String flush() { + String line = cache.toString(); + // Empty the cache, + cache.setLength(0); + // and returns its content + if (currentState.equals(State.SEARCH_HEADER)) + return performOutFilter(line); + return performInFilter(line); + } + + /** + * methode appele lorsqu'on a la chaine entiere entre le header et le + * footer. + * + * @param ch + * la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + abstract protected String performInFilter(String ch); + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * + * @param ch + * la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + abstract protected String performOutFilter(String ch); - /** la chaine du header */ - abstract protected String getHeader(); + /** la chaine du header */ + abstract protected String getHeader(); - /** la chaine du footer */ - abstract protected String getFooter(); + /** la chaine du footer */ + abstract protected String getFooter(); } // DefaultFilter Index: lutinprocessor/src/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java diff -u lutinprocessor/src/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java:1.11 lutinprocessor/src/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java:1.12 --- lutinprocessor/src/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java:1.11 Wed Jun 23 10:48:28 2004 +++ lutinprocessor/src/java/org/codelutin/processor/filters/GeneratorTemplatesFilterIn.java Mon Aug 16 20:47:12 2004 @@ -1,94 +1,96 @@ /* *##% -* Copyright (C) 2002, 2003 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. -*##%*/ + * Copyright (C) 2002, 2003 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. + *##%*/ /* * -* GeneratorTemplatesFilterIn.java -* -* Created: 14 janv. 2004 -* -* @author Benjamin Poussin -* Copyright Code Lutin -* @version $Revision: 1.11 $ -* -* Mise a jour: $Date: 2004/06/23 10:48:28 $ -* par : $Author: bpoussin $ -*/ + * GeneratorTemplatesFilterIn.java + * + * Created: 14 janv. 2004 + * + * @author Benjamin Poussin + * Copyright Code Lutin + * @version $Revision: 1.12 $ + * + * Mise a jour: $Date: 2004/08/16 20:47:12 $ + * par : $Author: pineau $ + */ package org.codelutin.processor.filters; /** - * Le tag *) n'est substitué que s'il est a l'extérieur du tag <%=...%> ou <%...%> + * Le tag *) n'est substitué que s'il est a l'extérieur du tag <%=...%>ou + * <%...%> */ public class GeneratorTemplatesFilterIn extends DefaultFilter { // GeneratorTemplatesFilterIn - GeneratorTemplatesFilter parent = null; + GeneratorTemplatesFilter parent = null; - public GeneratorTemplatesFilterIn(GeneratorTemplatesFilter parent){ - this.parent = parent; - } - - /** - * méthode appelée lorsqu'on a la chaîne entière entre le header - * et le footer. - * @param ch la chaîne trouvé - * @return ce qu'il faut écrire dans le fichier de sortie - */ - protected String performInFilter(String ch){ - if(ch.startsWith("=")){ - return "\"+" + ch.substring(1) + "+\""; - }else{ - return "\");"+ ch + parent.getWriteString() + "(\""; - } - } - - /** - * Converti les fin de commentaire *) en fin normal de commentraire - */ - protected String convertEndComment(String ch){ - String result = ch.replaceAll("\\*\\)", "*/"); - return result; - } - - /** - * methode appele lorsqu'on a la chaine entiere a l'exterieur du - * header/footer - * @param ch la chaine trouve - * @return ce qu'il faut ecrire dans le fichier de sortie - */ - protected String performOutFilter(String ch) { - String result = convertEndComment(ch) - .replaceAll("\"", "\\\\\"") - .replaceAll("(\r\n|\n|\r)", "\\\\n\");\n" + parent.getWriteString() + "(\""); - // it's important that \r\n is first in regexp. - - return result; - } - - - /** la chaine du header */ - protected String getHeader() { - return "<%"; - } - - /** la chaine du footer */ - protected String getFooter() { - return "%>"; - } + public GeneratorTemplatesFilterIn(GeneratorTemplatesFilter parent) { + this.parent = parent; + } + + /** + * méthode appelée lorsqu'on a la chaîne entière entre le header et le + * footer. + * + * @param ch + * la chaîne trouvé + * @return ce qu'il faut écrire dans le fichier de sortie + */ + protected String performInFilter(String ch) { + if (ch.startsWith("=")) + return "\"+" + ch.substring(1) + "+\""; + return "\");" + ch + parent.getWriteString() + "(\""; + } + + /** + * Converti les fin de commentaire *) en fin normal de commentraire + */ + protected String convertEndComment(String ch) { + String result = ch.replaceAll("\\*\\)", "*/"); + return result; + } + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * + * @param ch + * la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performOutFilter(String ch) { + String result = convertEndComment(ch).replaceAll("\"", "\\\\\"") + .replaceAll("(\r\n|\n|\r)", + "\\\\n\");\n" + parent.getWriteString() + "(\""); + // it's important that \r\n is first in regexp. + + return result; + } + + /** la chaine du header */ + protected String getHeader() { + return "<%"; + } + + /** la chaine du footer */ + protected String getFooter() { + return "%>"; + } } // GeneratorTemplatesFilterIn Index: lutinprocessor/src/java/org/codelutin/processor/filters/I18nFilter.java diff -u /dev/null lutinprocessor/src/java/org/codelutin/processor/filters/I18nFilter.java:1.1 --- /dev/null Mon Aug 16 20:47:17 2004 +++ lutinprocessor/src/java/org/codelutin/processor/filters/I18nFilter.java Mon Aug 16 20:47:12 2004 @@ -0,0 +1,66 @@ +/* *##%% +* Copyright (C) 2002, 2003 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. +*##%%**/ + +/* * +* I18nFilter.java +* +* Created: Sun Sep 1 2002 +* +* @author +* Copyright Code Lutin +* @version $Revision: 1.1 $ +* +* Mise a jour: $Date: 2004/08/16 20:47:12 $ +* par : $Author: pineau $ +*/ + +package org.codelutin.processor.filters; + +public class I18nFilter extends DefaultFilter { // I18nFilter + + private String header = "_(\""; + private String footer = "\")"; + + protected String getHeader(){ + return header; + } + protected String getFooter(){ + return footer; + } + + /** + * methode appele lorsqu'on a la chaine entiere entre le header + * et le footer. + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performInFilter(String ch){ + return ch+"="; + } + + /** + * methode appele lorsqu'on a la chaine entiere a l'exterieur du + * header/footer + * @param ch la chaine trouve + * @return ce qu'il faut ecrire dans le fichier de sortie + */ + protected String performOutFilter(String ch){ + return EMPTY_STRING; + } + +} // I18nFilter