ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Suresh Avadhanula <avadhan...@gmail.com>
Subject XSL Extensions inside ant
Date Tue, 08 Aug 2006 07:15:37 GMT
Hi,

I have created a custom ant task that executes an XSL which has 
extensions. The XSL is attached below.  I placed the latest xalan ( 
xalan-j 2.7.0 ), xercesImpl, xml-api and serializer jars in 
ANT_HOME/lib. I am using JDK 1.5. It works fine using command line. But 
when I execute the task from ant, I get the following error. Any help is 
greatly appreciated.



generateModel:
 [modelGen] Generate Model
 [modelGen] hibernateFile is model.xml
 [modelGen] ************* Transformering  *************
 [modelGen] hibernateFile model.xml
 [modelGen] destFile ufs-hibernate-mapping.hbm.xml
 [modelGen] 
file:///C:/cygwin/home/suresh/dev/javatest/xsl/generateModel.xsl; Line 
#35; Column #35; javax.xml.transform.TransformerException: java.lan
g.ClassNotFoundException: com.gandeev.transformer.ModelExtensions
 [modelGen] 
file:///C:/cygwin/home/suresh/dev/javatest/xsl/generateModel.xsl; Line 
#47; Column #67; java.lang.NoSuchMethodException: For extension fun
ction, could not find method 
org.apache.xml.utils.NodeVector.getBaseClass([ExpressionContext,] ).
 [modelGen] 
file:///C:/cygwin/home/suresh/dev/javatest/xsl/generateModel.xsl; Line 
#47; Column #67; java.lang.NullPointerException
 [modelGen] ************* Result *************




<?xml version="1.0" encoding="UTF-8"?>


<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xalan="http://xml.apache.org/xalan"
        xmlns:gd="xalan://com.gandeev.transformer.ModelExtensions"
        exclude-result-prefixes="gd xalan"
        extension-element-prefixes="gd">
 

<!-- Set output -->

<xsl:output method="xml" indent="yes" />

<!-- Initialize params -->

  <xsl:template
    match="*|@*|comment()|processing-instruction()|text()">
    <xsl:copy>
      <xsl:apply-templates
       select="*|@*|comment()|processing-instruction()|text()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:param name="src.dir"/>

<!-- hibernate-mapping -->       

  <xsl:template match="hibernate-mapping">
    <gd:init srcDir="{$src.dir}"/>
    <hibernate-mapping>
      <xsl:apply-templates select="class" mode="base"/>
      <xsl:apply-templates select="class" mode="sub"/>
    </hibernate-mapping>
  </xsl:template>
<!-- end hibernate-mapping -->

<!-- Get base class -->

  <xsl:template match="class" mode="base" >
    <class>
      <xsl:variable name="fqcn" select="gd:getBaseClass(@name)" />
      <xsl:attribute name="name">
    <xsl:value-of select="$fqcn" />
      </xsl:attribute>
            <xsl:copy-of select="descendant::*" />
    </class>
  </xsl:template>
<!-- end get base class -->
  <xsl:template match="class" mode="sub" >
    <class>
    <xsl:variable name="fqcn" select="gd:getSubClass(@name)" />
      <xsl:attribute name="name">
    <xsl:value-of select="$fqcn" />
      </xsl:attribute>
    </class>
  </xsl:template>


</xsl:stylesheet>

---- The Ant Task file

public class ModelGen extends Task
{
  private final static String styleName = "generateModel.xsl";
  private String hibernateFile = null;
  private String destFile = null;
  private String srcDir = null;

  public ModelGen()
  {  }

  public void setHibernateFile(String hibernateFile)
  {
     this.hibernateFile = hibernateFile;
  }

  public String getHibernateFile()
  {
    return this.hibernateFile;
  }

  public void setDestFile(String destFile)
  {
    this.destFile = destFile;
   }

  public String getDestFile()
  {
    return this.destFile;
  }

  public void setSrcDir ( String srcDir)
  {
    this.srcDir = srcDir;
  }

  public String getSrcDir ()
  {
    return this.srcDir;
  }

public void execute() throws BuildException
  {
    if (hibernateFile == null)
      throw new BuildException(" Hibernate file not specified");

      if (destFile == null) throw new BuildException(" Dest Dir not 
specified");

      if (srcDir == null) throw new BuildException(" src Dir not 
specified");

    System.out.println("Generate Model");

    String filename = null;
    try{
  
       TransformerFactory tFactory = TransformerFactory.newInstance();
   
    Transformer transformer = tFactory.newTransformer(new 
StreamSource(styleName));
    transformer.setParameter("src.dir", 
"c:/cygwin/home/suresh/dev/gandeev/ufs");

    System.out.println("************* Transformering  *************");
    System.out.println ("hibernateFile "+ hibernateFile);
    System.out.println ("destFile "+ destFile);
    transformer.transform(new StreamSource(hibernateFile), new 
StreamResult(new FileOutputStream(destFile)));
   
    System.out.println("************* Result *************");
    }
    catch (Exception e)
      {
    e.printStackTrace();
      }
  }


  public static void main (String[] args)
  {
    try
      {
    ModelGen modelGen = new ModelGen();
    modelGen.setDestFile("main.xml");
    modelGen.setSrcDir("c:/cygwin/home/suresh/dev/gandeev/ufs");
    modelGen.setHibernateFile("model.xml");
    modelGen.execute();
      }
    catch (Exception e)
      {
    e.printStackTrace();
      }
  }

}

Thanks
Suresh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message