ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional XalanLiaison.java XslpLiaison.java
Date Tue, 02 Jan 2001 14:08:30 GMT
conor       01/01/02 06:08:30

  Modified:    src/main/org/apache/tools/ant/taskdefs XSLTLiaison.java
                        XSLTProcess.java
               src/main/org/apache/tools/ant/taskdefs/optional
                        XalanLiaison.java XslpLiaison.java
  Log:
  Add nested param element to the style task.
  Also allow an input and output file to be specified.
  
  Submitted by:	Jeff Martin <jmartin@silacom.com>
  
  Revision  Changes    Path
  1.2       +3 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java
  
  Index: XSLTLiaison.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XSLTLiaison.java	2000/06/23 16:47:04	1.1
  +++ XSLTLiaison.java	2001/01/02 14:08:30	1.2
  @@ -59,11 +59,13 @@
   /**
    *
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
  - * @version $Revision: 1.1 $ $Date: 2000/06/23 16:47:04 $
  + * @version $Revision: 1.2 $ $Date: 2001/01/02 14:08:30 $
    */
   public interface XSLTLiaison {
   
       public void setStylesheet(String fileName) throws Exception;
  +
  +    public void addParam(String name, String expression) throws Exception;
   
       public void transform(String infile, String outfile) throws Exception;
   
  
  
  
  1.10      +90 -74    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  
  Index: XSLTProcess.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XSLTProcess.java	2000/11/25 02:38:37	1.9
  +++ XSLTProcess.java	2001/01/02 14:08:30	1.10
  @@ -84,7 +84,7 @@
    * @author <a href="mailto:kvisco@exoffice.com">Keith Visco</a>
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
    * @author <a href="mailto:russgold@acm.org">Russell Gold</a>
  - * @version $Revision: 1.9 $ $Date: 2000/11/25 02:38:37 $
  + * @version $Revision: 1.10 $ $Date: 2001/01/02 14:08:30 $
    */
   public class XSLTProcess extends MatchingTask {
   
  @@ -95,6 +95,11 @@
       private File xslFile = null;
   
       private String targetExtension = ".html";
  +    private Vector params = new Vector();
  + 
  +    private File inFile = null;
  + 
  +    private File outFile = null;
   
       private XSLTLiaison liaison;
   
  @@ -113,8 +118,10 @@
           String[]         list;
           String[]         dirs;
   
  -        if (baseDir == null)
  +        if (baseDir == null) {
               baseDir = project.resolveFile(".");
  +        }
  +        
           //-- make sure Source directory exists...
           if (destDir == null ) {
               String msg = "destdir attributes must be set!";
  @@ -147,12 +154,22 @@
                   styleSheetLastModified = file.lastModified();
                   log( "Loading stylesheet " + file, Project.MSG_INFO);
                   liaison.setStylesheet( file.toString() );
  +                for(Enumeration e = params.elements();e.hasMoreElements();) {
  +                    Param p = (Param)e.nextElement();
  +                    liaison.addParam( p.getName(), p.getExpression() );
  +                }
               } catch (Exception ex) {
                   log("Failed to read stylesheet " + xslFile, Project.MSG_INFO);
                   throw new BuildException(ex);
               }
           }
   
  +        // if we have an in file and out then process them
  +        if (inFile != null && outFile != null) {
  +            process(inFile, outFile, styleSheetLastModified);
  +            return;
  +        }
  +
           // Process all the files marked for styling
           list = scanner.getIncludedFiles();
           for (int i = 0;i < list.length; ++i) {
  @@ -217,75 +234,20 @@
           }
   
       }
  +
  +    /**
  +     * Sets an out file
  +     */
  +    public void setOut(File outFile){
  +        this.outFile = outFile;
  +    }
   
  -    /*
  -      private void process(File sourceDir, File destDir)
  -      throws BuildException
  -      {
  -
  -        
  -      if (!sourceDir.isDirectory()) {
  -      throw new BuildException(sourceDir.getName() +
  -      " is not a directory!");
  -      }
  -      else if (!destDir.isDirectory()) {
  -      throw new BuildException(destDir.getName() +
  -      " is not a directory!");
  -      }
  -
  -      String[] list = sourceDir.list(new DesirableFilter());
  -
  -      if (list == null) {
  -      return;  //-- nothing to do
  -      }
  -
  -      for (int i = 0; i < list.length; i++) {
  -
  -      String filename = list[i];
  -
  -      File inFile  = new File(sourceDir, filename);
  -
  -      //-- if inFile is a directory, recursively process it
  -      if (inFile.isDirectory()) {
  -      if (!excluded(filename)) {
  -      new File(destDir, filename).mkdir();
  -      process(inFile, new File(destDir, filename));
  -      }
  -      }
  -      //-- process XML files
  -      else if (hasXMLFileExtension(filename) && ! excluded(filename)) {
  -
  -      //-- replace extension with the target extension
  -      int idx = filename.lastIndexOf('.');
  -
  -      File outFile = new File(destDir,
  -      filename.substring(0,idx) + targetExt);
  -
  -      if ((inFile.lastModified() > outFile.lastModified()) ||
  -      (xslFile != null && xslFile.lastModified() > outFile.lastModified()))
  -      {
  -      processXML(inFile, outFile);
  -      }
  -      }
  -      else {
  -      File outFile = new File(destDir, filename);
  -      if (inFile.lastModified() > outFile.lastModified()) {
  -      try {
  -      copyFile(inFile, outFile);
  -      }
  -      catch(java.io.IOException ex) {
  -      String err = "error copying file: ";
  -      err += inFile.getAbsolutePath();
  -      err += "; " + ex.getMessage();
  -      throw new BuildException(err, ex);
  -      }
  -      //filecopyList.put(srcFile.getAbsolutePath(),
  -      //destFile.getAbsolutePath());
  -      }
  -      }
  -      } //-- </for>
  -      } //-- process(File, File)
  -    */
  +    /**
  +     * Sets an input xml file to be styled
  +     */
  +    public void setIn(File inFile){
  +        this.inFile = inFile;
  +    }
   
       /**
        * Processes the given input XML file and stores the result
  @@ -301,12 +263,16 @@
   
           try {
               inFile = new File(baseDir,xmlFile);
  -            outFile = new File(destDir,xmlFile.substring(0,xmlFile.lastIndexOf('.'))+fileExt);
  +            int dotPos = xmlFile.lastIndexOf('.');
  +            if(dotPos>0){
  +                outFile = new File(destDir,xmlFile.substring(0,xmlFile.lastIndexOf('.'))+fileExt);
  +            }else{
  +                outFile = new File(destDir,xmlFile+fileExt);
  +            }
               if (inFile.lastModified() > outFile.lastModified() ||
                   styleSheetLastModified > outFile.lastModified()) {
                   ensureDirectoryFor( outFile );
  -                //-- command line status
  -                log("Processing " + xmlFile + " to " + outFile, Project.MSG_VERBOSE);
  +                log("Transforming into "+destDir);
   
                   liaison.transform(inFile.toString(), outFile.toString());
               }
  @@ -315,12 +281,33 @@
               // If failed to process document, must delete target document,
               // or it will not attempt to process it the second time
               log("Failed to process " + inFile, Project.MSG_INFO);
  -            outFile.delete();
  +            if (outFile != null) {
  +                outFile.delete();
  +            }
  +        
               throw new BuildException(ex);
           }
   
       } //-- processXML
   
  +    private void process(File inFile, File outFile, long styleSheetLastModified) throws
BuildException {
  +        try{
  +            log("In file "+inFile+" time: " + inFile.lastModified() , Project.MSG_DEBUG);
  +            log("Out file "+outFile+" time: " + outFile.lastModified() , Project.MSG_DEBUG);
  +            log("Style file "+xslFile+" time: " + styleSheetLastModified , Project.MSG_DEBUG);
  +            if (inFile.lastModified() > outFile.lastModified() ||
  +                styleSheetLastModified > outFile.lastModified()) {
  +                ensureDirectoryFor( outFile );
  +                log("Processing " + inFile + " to " + outFile, Project.MSG_INFO);
  +                liaison.transform(inFile.toString(), outFile.toString());
  +            }
  +        }catch (Exception ex) {
  +            log("Failed to process " + inFile, Project.MSG_INFO);
  +            if(outFile!=null)outFile.delete();
  +            throw new BuildException(ex);
  +        }
  +    }
  +
       private void ensureDirectoryFor( File targetFile ) throws BuildException {
           File directory = new File( targetFile.getParent() );
           if (!directory.exists()) {
  @@ -328,6 +315,35 @@
                   throw new BuildException("Unable to create directory: " 
                                            + directory.getAbsolutePath() );
               }
  +        }
  +    }
  +    
  +    public Param createParam() {
  +        Param p = new Param();
  +        params.addElement(p);
  +        return p;
  +    }
  +
  +    public class Param {
  +        private String name=null;
  +        private String expression=null;
  +        
  +        public void setName(String name){
  +            this.name = name;
  +        }
  +        
  +        public void setExpression(String expression){
  +            this.expression = expression;
  +        }
  +        
  +        public String getName() throws BuildException{
  +            if(name==null)throw new BuildException("Name attribute is missing.");
  +            return name;
  +        }
  +        
  +        public String getExpression() throws BuildException{
  +            if(expression==null)throw new BuildException("Expression attribute is missing.");
  +            return expression;
           }
       }
   } //-- XSLTProcess
  
  
  
  1.4       +5 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java
  
  Index: XalanLiaison.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XalanLiaison.java	2000/08/03 09:34:05	1.3
  +++ XalanLiaison.java	2001/01/02 14:08:30	1.4
  @@ -64,7 +64,7 @@
   /**
    *
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
  - * @version $Revision: 1.3 $ $Date: 2000/08/03 09:34:05 $
  + * @version $Revision: 1.4 $ $Date: 2001/01/02 14:08:30 $
    */
   public class XalanLiaison implements XSLTLiaison {
   
  @@ -91,5 +91,9 @@
               return FILEURL + fileName;
           }
           return fileName;
  +    }
  +    
  +    public void addParam(String name, String value){
  +        processor.setStylesheetParam(name, value);
       }
   } //-- XalanLiaison
  
  
  
  1.3       +5 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java
  
  Index: XslpLiaison.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XslpLiaison.java	2000/06/23 21:18:07	1.2
  +++ XslpLiaison.java	2001/01/02 14:08:30	1.3
  @@ -65,7 +65,7 @@
   /**
    *
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
  - * @version $Revision: 1.2 $ $Date: 2000/06/23 21:18:07 $
  + * @version $Revision: 1.3 $ $Date: 2001/01/02 14:08:30 $
    */
   public class XslpLiaison implements XSLTLiaison {
   
  @@ -83,6 +83,10 @@
   
       public void transform(String infile, String outfile) throws Exception {
         processor.process(infile, xslSheet, new FileWriter(outfile));
  +    }
  +
  +    public void addParam(String name, String expression){
  +      processor.setProperty(name, expression);
       }
   
   } //-- XSLPLiaison
  
  
  

Mime
View raw message