Thread: [CJ-dev] commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/generics/multifile DirTuning
Brought to you by:
johnqueso
From: <joh...@co...> - 2004-03-12 20:14:44
|
Update of /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/generics/multifile In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2746/src/java/org/commonjava/opl/generics/multifile Modified Files: DirTuningParser.java ImportFileParser.java ImportDirParser.java DirTuningParent.java ExcludeParser.java IncludeParser.java Log Message: updated to 0.2, made method call parameter generation more robust. Index: DirTuningParser.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/generics/multifile/DirTuningParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- DirTuningParser.java 16 Jan 2004 01:37:33 -0000 1.3 +++ DirTuningParser.java 12 Mar 2004 19:46:54 -0000 1.4 @@ -6,14 +6,13 @@ import org.commonjava.opl.OPLContext; import org.commonjava.opl.ParseException; + /** * @author jdcasey */ public abstract class DirTuningParser extends NodeParser { - private static final String PATTERN = "pattern"; - private String pattern; /** @@ -24,7 +23,7 @@ super(context); addRequiredAttribute(PATTERN); } - + /** * @param context * @param parent @@ -34,22 +33,24 @@ super(context, parent); addRequiredAttribute(PATTERN); } - - protected String getPattern() { + + protected String getPattern() + { return pattern; } - + /* (non-Javadoc) * @see org.commonjava.opl.NodeParser#doBeforeChildren(org.commonjava.opl.ElementInfo) */ - protected final void doBeforeChildren(ElementInfo element) throws ParseException + protected final void doBeforeChildren(ElementInfo element) + throws ParseException { this.pattern = getAttribute(PATTERN, element, true); } - + /* (non-Javadoc) * @see org.commonjava.opl.NodeParser#doAfterChildren(org.commonjava.opl.ElementInfo, java.lang.String) */ - protected abstract void doAfterChildren(ElementInfo element, String bodyText) - throws ParseException; + protected abstract void doAfterChildren(ElementInfo element, String bodyText) + throws ParseException; } Index: ImportFileParser.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/generics/multifile/ImportFileParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ImportFileParser.java 16 Jan 2004 01:37:33 -0000 1.3 +++ ImportFileParser.java 12 Mar 2004 19:46:54 -0000 1.4 @@ -8,13 +8,14 @@ import org.commonjava.opl.OPLEngine; import org.commonjava.opl.ParseException; + /** * @author jdcasey */ public class ImportFileParser extends NodeParser { private static final String FILENAME = "file"; - + /** * @param context */ @@ -23,7 +24,7 @@ super(context); addRequiredAttribute(FILENAME); } - + /** * @param context * @param parent @@ -33,16 +34,16 @@ super(context, parent); addRequiredAttribute(FILENAME); } - + /* (non-Javadoc) * @see org.commonjava.opl.NodeParser#doBeforeChildren(org.commonjava.opl.ElementInfo) */ - protected void doBeforeChildren(ElementInfo element) throws ParseException + protected void doBeforeChildren(ElementInfo element) + throws ParseException { String filename = getAttribute(FILENAME, element); - + DocumentDriver driver = new DocumentDriver(getParent()); OPLEngine.getInstance(driver).parse(filename); } - } Index: ImportDirParser.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/generics/multifile/ImportDirParser.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- ImportDirParser.java 20 Feb 2004 21:16:04 -0000 1.6 +++ ImportDirParser.java 12 Mar 2004 19:46:54 -0000 1.7 @@ -1,35 +1,37 @@ /* Created on Jan 2, 2004 */ package org.commonjava.opl.generics.multifile; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.commonjava.opl.DocumentDriver; import org.commonjava.opl.ElementInfo; import org.commonjava.opl.NodeParser; import org.commonjava.opl.OPLContext; import org.commonjava.opl.OPLEngine; import org.commonjava.opl.ParseException; + import org.commonjava.util.AndLogicFilenameFilter; import org.commonjava.util.FileFinder; import org.commonjava.util.OrLogicFilenameFilter; import org.commonjava.util.RegexFilenameFilter; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + + /** * @author jdcasey */ public class ImportDirParser extends NodeParser implements DirTuningParent { private static final Log LOG = LogFactory.getLog(ImportDirParser.class); - private static final String DIRECTORY = "dir"; - private Set inclusions = new HashSet(); private Set exclusions = new HashSet(); @@ -41,7 +43,7 @@ super(context); addRequiredAttribute(DIRECTORY); } - + /** * @param context * @param parent @@ -51,70 +53,83 @@ super(context, parent); addRequiredAttribute(DIRECTORY); } - + /* (non-Javadoc) * @see org.commonjava.opl.NodeParser#doAfterChildren(org.commonjava.opl.ElementInfo, java.lang.String) */ - protected void doAfterChildren(ElementInfo element, String bodyText) throws ParseException + protected void doAfterChildren(ElementInfo element, String bodyText) + throws ParseException { String dir = getAttribute(DIRECTORY, element, true); String[] files = getFiles(dir); - try{ + + try { runImports(files); } - catch (FileNotFoundException e){ + catch(FileNotFoundException e) { throw new ParseException("File from file scanner could not be located for reading.", e); } } - - private String[] getFiles(String dir) { - if (LOG.isDebugEnabled()) { + + private String[] getFiles(String dir) + { + if(LOG.isDebugEnabled()) { LOG.debug("Looking for files to import in directory: " + dir); } - + OrLogicFilenameFilter includeFilter = new OrLogicFilenameFilter(); - for (Iterator it = inclusions.iterator(); it.hasNext(); ) - { + + for(Iterator it = inclusions.iterator(); it.hasNext();) { String pattern = (String)it.next(); includeFilter.addFilter(new RegexFilenameFilter(pattern, false)); } - + OrLogicFilenameFilter excludeFilter = new OrLogicFilenameFilter(); - for (Iterator it = exclusions.iterator(); it.hasNext(); ) - { + + for(Iterator it = exclusions.iterator(); it.hasNext();) { String pattern = (String)it.next(); excludeFilter.addFilter(new RegexFilenameFilter(pattern, false, true)); } - + AndLogicFilenameFilter allFilter = new AndLogicFilenameFilter(); allFilter.addFilter(includeFilter); allFilter.addFilter(excludeFilter); - + String[] files = FileFinder.getFileNames(dir, allFilter, true); - - - if (LOG.isDebugEnabled()) { + + if(LOG.isDebugEnabled()) { StringBuffer buffer = new StringBuffer("Found files to import:"); - for (int i = 0; i < files.length; i++) { + + for(int i = 0; i < files.length; i++) { buffer.append("\n").append(files[i]); } + LOG.debug(buffer.toString()); } - + return files; } - - private void runImports(String[] files) throws FileNotFoundException, ParseException { - for (int i = 0; i < files.length; i++) - { + + private void runImports(String[] files) throws FileNotFoundException, ParseException + { + for(int i = 0; i < files.length; i++) { String file = files[i]; - if (LOG.isDebugEnabled()) {LOG.debug("Parsing/importing file: " + file + " under element: " + getContext().getLastElement());} - + + if(LOG.isDebugEnabled()) { + LOG.debug( + "Parsing/importing file: " + file + " under element: " + getContext().getLastElement() + ); + } + DocumentDriver driver = new DocumentDriver(getParent()); BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); OPLEngine.getInstance(driver).parse(in); - - if (LOG.isDebugEnabled()) {LOG.debug("Parsed/imported file: " + file + " under element: " + getContext().getLastElement());} + + if(LOG.isDebugEnabled()) { + LOG.debug( + "Parsed/imported file: " + file + " under element: " + getContext().getLastElement() + ); + } } } @@ -133,5 +148,4 @@ { exclusions.add(pattern); } - } Index: DirTuningParent.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/generics/multifile/DirTuningParent.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- DirTuningParent.java 5 Jan 2004 03:25:16 -0000 1.1 +++ DirTuningParent.java 12 Mar 2004 19:46:54 -0000 1.2 @@ -1,13 +1,13 @@ /* Created on Jan 2, 2004 */ package org.commonjava.opl.generics.multifile; + /** * @author jdcasey */ public interface DirTuningParent { - public void addInclude(String pattern); + public void addExclude(String pattern); - } Index: ExcludeParser.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/generics/multifile/ExcludeParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ExcludeParser.java 5 Jan 2004 03:25:16 -0000 1.1 +++ ExcludeParser.java 12 Mar 2004 19:46:54 -0000 1.2 @@ -6,12 +6,12 @@ import org.commonjava.opl.OPLContext; import org.commonjava.opl.ParseException; + /** * @author jdcasey */ public class ExcludeParser extends DirTuningParser { - /** * @param context */ @@ -32,12 +32,10 @@ /* (non-Javadoc) * @see org.commonjava.opl.NodeParser#doAfterChildren(org.commonjava.opl.ElementInfo, java.lang.String) */ - protected void doAfterChildren(ElementInfo element, String bodyText) throws ParseException + protected void doAfterChildren(ElementInfo element, String bodyText) + throws ParseException { - DirTuningParent parent = (DirTuningParent)findAncestorOfType( - DirTuningParent.class, true - ); + DirTuningParent parent = (DirTuningParent)findAncestorOfType(DirTuningParent.class, true); parent.addExclude(getPattern()); } - } Index: IncludeParser.java =================================================================== RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-opl/src/java/org/commonjava/opl/generics/multifile/IncludeParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- IncludeParser.java 5 Jan 2004 03:25:16 -0000 1.1 +++ IncludeParser.java 12 Mar 2004 19:46:54 -0000 1.2 @@ -6,12 +6,12 @@ import org.commonjava.opl.OPLContext; import org.commonjava.opl.ParseException; + /** * @author jdcasey */ public class IncludeParser extends DirTuningParser { - /** * @param context */ @@ -32,12 +32,10 @@ /* (non-Javadoc) * @see org.commonjava.opl.NodeParser#doAfterChildren(org.commonjava.opl.ElementInfo, java.lang.String) */ - protected void doAfterChildren(ElementInfo element, String bodyText) throws ParseException + protected void doAfterChildren(ElementInfo element, String bodyText) + throws ParseException { - DirTuningParent parent = (DirTuningParent)findAncestorOfType( - DirTuningParent.class, true - ); + DirTuningParent parent = (DirTuningParent)findAncestorOfType(DirTuningParent.class, true); parent.addInclude(getPattern()); } - } |