@@ -7,25 +7,27 @@
*/
package org.apache.myrmidon.components.builder;
import java.net.URL;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.SAXConfigurationHandler;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
* Default implementation to construct project from a build file.
@@ -36,14 +38,8 @@ public class ATIProjectBuilder
extends DefaultProjectBuilder
implements Parameterizable
{
private final static String PARAM_EXCEPTION =
"Malformed PI: expected <?xsl-param name=\"foo\" value=\"bar\"?>";
private final static String PARAMS_EXCEPTION =
"Malformed PI: expected <?xsl-params location=\"myparams.properties\"?>";
private final static String STYLE_EXCEPTION =
"Malformed PI: expected <?xsl-params href=\"mystylesheet.xsl\"?>";
private static final Resources REZ =
ResourceManager.getPackageResources( ATIProjectBuilder.class );
private Parameters m_parameters;
private URL m_systemID;
@@ -82,12 +78,12 @@ public class ATIProjectBuilder
if( target.equals( "xsl-param" ) ) handleParameter( data );
else if( target.equals( "xsl-params" ) ) handleParameters( data, sourceID );
else if( target.equals( "xsl-stylesheet" ) )
else if( target.equals( "xsl-stylesheet" ) )
{
if( null != transformer )
{
throw new SAXException( "Build file can not contain " +
"two xsl-stylesheet PIs" );
final String message = REZ.getString( "ati.two.stylesheet.pis" );
throw new SAXException( message );
}
final TransformerFactory factory = TransformerFactory.newInstance();
@@ -113,9 +109,9 @@ public class ATIProjectBuilder
final SAXResult result = new SAXResult( handler );
transformer.transform( new StreamSource( sourceID.toString() ), result );
//transformer.transform( new StreamSource( sourceID.toString() ),
//transformer.transform( new StreamSource( sourceID.toString() ),
//new StreamResult( System.out ) );
}
}
}
private void handleParameter( final String data )
@@ -124,22 +120,25 @@ public class ATIProjectBuilder
int index = data.indexOf( '\"' );
if( -1 == index )
{
throw new SAXException( PARAM_EXCEPTION );
final String message = REZ.getString( "ati.param.error" );
throw new SAXException( message );
}
index = data.indexOf( '\"', index + 1 );
if( -1 == index )
{
throw new SAXException( PARAM_EXCEPTION );
final String message = REZ.getString( "ati.param.error" );
throw new SAXException( message );
}
//split between two "attributes" occurs on index
final String[] name = parseAttribute( data.substring( 0, index + 1 ) );
final String[] value = parseAttribute( data.substring( index + 1 ).trim() );
if( !name[ 0 ].equals( "name" ) || !value[ 0 ].equals( "value" ) )
{
throw new SAXException( PARAM_EXCEPTION );
final String message = REZ.getString( "ati.param.error" );
throw new SAXException( message );
}
m_parameters.setParameter( name[ 1 ], value[ 1 ] );
@@ -151,7 +150,8 @@ public class ATIProjectBuilder
final String[] params = parseAttribute( data );
if( !params[ 0 ].equals( "location" ) )
{
throw new SAXException( PARAMS_EXCEPTION );
final String message = REZ.getString( "ati.params.error" );
throw new SAXException( message );
}
try
@@ -165,7 +165,8 @@ public class ATIProjectBuilder
}
catch( final Exception e )
{
throw new SAXException( "Error loading parameters: " + e );
final String message = REZ.getString( "ati.loading-params.error", params[ 1 ], e );
throw new SAXException( message );
}
}
@@ -175,14 +176,16 @@ public class ATIProjectBuilder
final String[] stylesheet = parseAttribute( data );
if( !stylesheet[ 0 ].equals( "href" ) )
{
throw new SAXException( STYLE_EXCEPTION );
final String message = REZ.getString( "ati.style.error" );
throw new SAXException( message );
}
try { return new URL( baseSource, stylesheet[ 1 ] ).toString(); }
catch( final Exception e )
{
throw new SAXException( "Error locating stylesheet '" + stylesheet[ 1 ] +
"' due to " + e );
final String message =
REZ.getString( "ati.loading-style.error", stylesheet[ 1 ], e );
throw new SAXException( message );
}
}
@@ -193,20 +196,20 @@ public class ATIProjectBuilder
int index = data.indexOf( '=' );
if( -1 == index )
{
throw new SAXException( "Expecting an attribute but received '" +
data + "'" );
final String message = REZ.getString( "ati.attribue-expected.error", data );
throw new SAXException( message );
}
final int size = data.length();
if( '\"' != data.charAt( index + 1 ) ||
if( '\"' != data.charAt( index + 1 ) ||
'\"' != data.charAt( size - 1 ) ||
size - 1 == index )
{
throw new SAXException( "Expecting the value of attribute " +
data.substring( 0, index ) +
" to be enclosed in quotes" );
final String message =
REZ.getString( "ati.attribue-unquoted.error", data.substring( 0, index ) );
throw new SAXException( message );
}
final String[] result = new String[ 2 ];
result[ 0 ] = data.substring( 0, index );
result[ 1 ] = data.substring( index + 2, size - 1 );