adammurdoch 2002/07/06 00:51:54
Modified: site build.xml
Added: site/src/java/org/apache/myrmidon/build/xdoc XdocTask.java
site/src/xdocs/stylesheets xdoc2html.xsl
Removed: site/src/xdocs/stylesheets docs.vsl
Log:
- Generate xdocs using xsl, rather than anakia. Added a task to drive the process.
- Added <classname> element to xdocs schema. Gets transformed into a link to the
javadoc.
Revision Changes Path
1.1 jakarta-ant-myrmidon/site/src/java/org/apache/myrmidon/build/xdoc/XdocTask.java
Index: XdocTask.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.myrmidon.build.xdoc;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.avalon.excalibur.io.FileUtil;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
/**
* A task that transforms docs in XDoc XML format into HTML.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision: 1.1 $ $Date: 2002/07/06 07:51:54 $
*/
public class XdocTask
extends Task
{
private final ArrayList m_filesets = new ArrayList();
private File m_destDir;
private File m_projectFile;
public void setDestDir( final File destDir )
{
m_destDir = destDir;
}
public void setProjectFile( final File projectFile )
{
m_projectFile = projectFile;
}
public void addFileset( final FileSet fileset )
{
m_filesets.add( fileset );
}
public void execute()
{
// Validate
if( m_destDir == null )
{
throw new BuildException( "No destination directory specified." );
}
if( m_destDir.exists() && !m_destDir.isDirectory() )
{
throw new BuildException( "Destination directory " + m_destDir + " exists and
is not a directory." );
}
if( !( m_destDir.exists() || m_destDir.mkdirs() ) )
{
throw new BuildException( "Could not create destination directory " + m_destDir
);
}
if( m_projectFile == null )
{
throw new BuildException( "No project file specified." );
}
if( !m_projectFile.isFile() )
{
throw new BuildException( "Project file " + m_projectFile + " does not exist
or is not a file." );
}
// Locate the stylesheet
final URL url = getClass().getResource( "/xdoc2html.xsl" );
if( url == null )
{
throw new BuildException( "Could not find stylesheet." );
}
final long styleLastMod = new File( url.getFile() ).lastModified();
final long baseLastMod = Math.max( styleLastMod, m_projectFile.lastModified() );
// Create a transformer
final Transformer transformer;
try
{
final TransformerFactory factory = TransformerFactory.newInstance();
final InputStream inputStream = url.openStream();
final Source source;
try
{
source = new StreamSource( inputStream, url.toExternalForm() );
transformer = factory.newTransformer( source );
}
finally
{
inputStream.close();
}
}
catch( final Exception e )
{
throw new BuildException( "Could not load stylesheet " + url, e );
}
// Transform each of the source files that is out-of-date
for( int i = 0; i < m_filesets.size(); i++ )
{
final FileSet fileSet = (FileSet)m_filesets.get( i );
final File dir = fileSet.getDir( getProject() );
final DirectoryScanner scanner = fileSet.getDirectoryScanner( getProject() );
final String[] files = scanner.getIncludedFiles();
for( int j = 0; j < files.length; j++ )
{
final String file = files[ j ];
final File srcFile = new File( dir, file );
final File destFile = getDestFile( file );
destFile.getParentFile().mkdirs();
// Check if up to date
final long lastMod = Math.max( baseLastMod, srcFile.lastModified() );
if( destFile.exists() && destFile.lastModified() > lastMod )
{
log( "Skipping " + destFile, Project.MSG_VERBOSE );
continue;
}
log( "Transforming " + srcFile + " to " + destFile, Project.MSG_INFO );
final Source source = new StreamSource( srcFile );
final Result result = new StreamResult( destFile );
try
{
transformer.setParameter( "relativePath", getRelPath( file ) );
transformer.setParameter( "projectFile", m_projectFile.toURL().toExternalForm()
);
transformer.transform( source, result );
}
catch( final Exception e )
{
throw new BuildException( "Could not transform " + srcFile, e );
}
}
}
}
/**
* Builds a relative path from given file to base directory.
*/
private Object getRelPath( final String file )
{
int depth = 0;
for( int i = file.indexOf( File.separatorChar ); i != -1; )
{
i = file.indexOf( File.separatorChar, i + 1 );
depth++;
}
if( depth == 0 )
{
return ".";
}
final StringBuffer p = new StringBuffer( ".." );
for( int i = 1; i < depth; i++ )
{
p.append( "/.." );
}
return p.toString();
}
/**
* Builds the name of the destination file that corresponds to the given
* source file.
*/
private File getDestFile( final String relName )
{
final String destFile = FileUtil.removeExtension( relName ) + ".html";
return new File( m_destDir, destFile );
}
}
1.3 +18 -13 jakarta-ant-myrmidon/site/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant-myrmidon/site/build.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- build.xml 6 Jun 2002 12:54:28 -0000 1.2
+++ build.xml 6 Jul 2002 07:51:54 -0000 1.3
@@ -10,30 +10,35 @@
<property file="../ant.properties"/>
<property file="${user.home}/.ant.properties"/>
+ <property name="build.dir" value="build/classes"/>
<property name="docs.dir" value="docs"/>
<property name="xdocs.dir" value="src/xdocs"/>
+ <path id="classpath">
+ <fileset dir="../tools/xalan" includes="*.jar"/>
+ <path location="../lib/excalibur-io-1.1.jar"/>
+ </path>
<!-- Main target -->
<target name="main" depends="docs" description="Builds the distribution"/>
<target name="docs" description="Generate documentation and website">
- <taskdef name="anakia"
- classname="org.apache.velocity.anakia.AnakiaTask">
+ <mkdir dir="${build.dir}"/>
+ <javac destdir="${build.dir}" srcdir="src/java">
+ <classpath refid="classpath"/>
+ </javac>
+ <copy file="${xdocs.dir}/stylesheets/xdoc2html.xsl" todir="${build.dir}"/>
+
+ <taskdef name="xdoc" classname="org.apache.myrmidon.build.xdoc.XdocTask">
<classpath>
- <fileset dir="${jakarta-site.dir}/lib">
- <include name="*.jar"/>
- </fileset>
+ <path location="${build.dir}"/>
+ <path refid="classpath"/>
</classpath>
</taskdef>
- <anakia basedir="${xdocs.dir}"
- destdir="${docs.dir}"
- style="docs.vsl"
- projectfile="stylesheets/project.xml"
- includes="**/*.xml"
- excludes="stylesheets/**"
- velocitypropertiesfile="${xdocs.dir}/velocity.properties"
- />
+ <xdoc destdir="${docs.dir}"
+ projectfile="${xdocs.dir}/stylesheets/project.xml">
+ <fileset dir="${xdocs.dir}" includes="**/*.xml" excludes="stylesheets/**"
/>
+ </xdoc>
<copy todir="${docs.dir}">
<fileset dir="src" includes="css/**, images/**"/>
1.1 jakarta-ant-myrmidon/site/src/xdocs/stylesheets/xdoc2html.xsl
Index: xdoc2html.xsl
===================================================================
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:param name="relativePath"/>
<xsl:param name="projectFile"/>
<xsl:variable name="project" select="document($projectFile)/project"/>
<xsl:template match="/document">
<html>
<head>
<style type="text/css">
@import url("<xsl:value-of select="$relativePath"/>/css/tigris.css");
@import url("<xsl:value-of select="$relativePath"/>/css/site.css");
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<xsl:for-each select="properties/author">
<meta name="author" value="{.}"/>
<meta name="email" value="{@email}"/>
</xsl:for-each>
<title>
<xsl:value-of select="$project/title"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="properties/title"/>
</title>
</head>
<body marginwidth="0" marginheight="0" class="composite">
<!-- BANNER -->
<div id="banner">
<table border="0" cellspacing="0" cellpadding="8" width="100%">
<tr>
<td colspan="2">
<a href="http://jakarta.apache.org">
<img src="http://jakarta.apache.org/images/jakarta-logo.gif"
align="left" border="0"/>
</a>
</td>
<td>
<div align="right" valign="bottom">
<b>
<font size="+3">
<xsl:value-of select="$project/title"/>
</font>
</b>
</div>
</td>
</tr>
</table>
</div>
<table border="0" cellspacing="0" cellpadding="8" width="100%" id="main">
<tr valign="top">
<!-- LEFT SIDE NAVIGATION -->
<td id="leftcol" width="20%">
<div id="navcolumn">
<xsl:apply-templates select="$project/body/menu"/>
</div>
</td>
<td>
<div id="bodycol">
<!-- CONTENT -->
<div class="app">
<xsl:apply-templates select="body/section"/>
</div>
<!-- AUTHORS -->
<xsl:if test="properties/author">
<div align="right" id="authors">
<xsl:text>by </xsl:text>
<xsl:for-each select="properties/author">
<xsl:if test="position() > 1">, </xsl:if>
<a href="{@email}"><xsl:value-of select="."/></a>
</xsl:for-each>
</div>
</xsl:if>
</div>
</td>
</tr>
</table>
<!-- FOOTER -->
<div id="footer">
<table border="0" cellspacing="0" cellpadding="4">
<tr>
<td>Copyright © 2000-2002, Apache Software Foundation</td>
</tr>
</table>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="menu">
<div>
<strong><xsl:value-of select="@name"/></strong>
<xsl:for-each select="item">
<div>
<small>
<xsl:call-template name="anchor">
<xsl:with-param name="href" select="@href"/>
<xsl:with-param name="content" select="string(@name)"/>
</xsl:call-template>
</small>
</div>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template name="anchor">
<xsl:param name="href"/>
<xsl:param name="content"/>
<a>
<xsl:attribute name="href">
<xsl:choose>
<xsl:when test="starts-with($href, 'http://')">
<xsl:value-of select="$href"/>
</xsl:when>
<xsl:when test="starts-with($href, '/site')">
<xsl:text>http://jakarta.apache.org</xsl:text>
<xsl:value-of select="$href"/>
</xsl:when>
<xsl:when test="starts-with($href, '/')">
<xsl:value-of select="$relativePath"/>
<xsl:value-of select="$href"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$href"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:copy-of select="$content"/>
</a>
</xsl:template>
<xsl:template match="section">
<div class="h3">
<h3>
<a>
<xsl:attribute name="name">
<xsl:choose>
<xsl:when test="@anchor">
<xsl:value-of select="@anchor"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="@name"/>
</a>
</h3>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="subsection">
<div class="h4">
<h4>
<a>
<xsl:attribute name="name">
<xsl:choose>
<xsl:when test="@anchor">
<xsl:value-of select="@anchor"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="@name"/>
</a>
</h4>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="a">
<xsl:call-template name="anchor">
<xsl:with-param name="href" select="@href"/>
<xsl:with-param name="content" select="*|text()"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="source">
<div id="source">
<pre>
<br/>
<xsl:apply-templates/>
<br/>
</pre>
</div>
</xsl:template>
<xsl:template match="table">
<table cellpadding="3" cellspacing="2" border="1" width="100%">
<xsl:for-each select="tr">
<tr>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="position() mod 2 > 0">a</xsl:when>
<xsl:otherwise>b</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="th|td"/>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="th|td">
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:choose>
<xsl:when test="*|text()">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>
<xsl:template match="classname">
<a href="{$relativePath}/api/{translate(., '.', '/' )}.html"
title="{normalize-space(.)}" >
<code>
<xsl:call-template name="get-last">
<xsl:with-param name="value" select="normalize-space(.)"/>
</xsl:call-template>
</code>
</a>
</xsl:template>
<!-- There has to be a better way to do this .. -->
<xsl:template name="get-last">
<xsl:param name="value"/>
<xsl:variable name="newvalue" select="substring-after( $value, '.' )"/>
<xsl:choose>
<xsl:when test="string-length( $newvalue )">
<xsl:call-template name="get-last">
<xsl:with-param name="value" select="$newvalue"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="escaped">
<xsl:value-of disable-output-escaping="yes" select="."/>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
--
To unsubscribe, e-mail: <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>
|