001 package com.saelist.command;
002 import java.io.*;
003 import com.saelist.stx.parser.*;
004 import com.saelist.stx.xpath.*;
005 import java.util.*;
006 import org.jaxen.JaxenException;
007 import org.jaxen.XPathFunctionContext;
008 import org.apache.log4j.*;
009
010 /** Expects an xpath on the command line.
011 * Prints the found files to standard out.<p>
012 * See the schema file for exact format of the configuration.
013 */
014 public class FindFilesCommand extends AbstractCommand {
015
016 protected static Logger logger = Logger.getLogger("com.saelist.command.FindFilesCommand");
017
018 static {
019 ((XPathFunctionContext) XPathFunctionContext.getInstance()).registerFunction(
020 null, // namespace URI
021 "matches",
022 new MatchesFunction() );
023 }
024
025 public void execute() {
026
027 try {
028 String rootstr = config.eval("root");
029 if(rootstr.equals(""))
030 rootstr = ".";
031 String xpathstr = config.eval("xpath");
032
033 FileXPath xpath = new FileXPath(xpathstr);
034 File file = new File(rootstr);
035 List results = xpath.selectNodes(file);
036
037 for(Iterator it = results.iterator(); it.hasNext(); )
038 System.out.println(" '" + it.next() + "'");
039
040 } catch(JaxenException e) {
041 e.printStackTrace(System.out);
042 }
043
044 }
045
046 public void undo() { }
047
048 public boolean undoable() {
049 return false;
050 }
051
052
053
054 }