DslCompiler: Use s9api instead of JAXP
The difference is described here: http://www.saxonica.com/html/documentation/using-xsl/embedding/ And s9api here: http://www.saxonica.com/html/documentation/using-xsl/embedding/s9api-transformation.html * Makefile.am (DSLC_CLASSPATH): Export for submakes. * configure.ac (DSLC_CLASSPATH): Prefix with SAXON_CP. * rater/rater.xsd (classNameType): Increase length 50=>75 (generated identifiers can now exceed that, it seems). * src/current/rater.xsd: Likewise. These files need to be combined. * src/current/src/Makefile (CLASSPATH): Set to DSLC_CLASSPATH. * src/current/src/com/lovullo/dslc/DslCompiler.java: Update imports. (DslCompiler)[_DslCompiler]: New members _processor and _xsltCompiler. Convert to s9api.master
parent
044498f03f
commit
c7e84f2e29
|
@ -29,6 +29,7 @@ apply_dest := $(apply_src:%.xsl=%.xsl.apply)
|
|||
|
||||
# needed by test runner
|
||||
export SAXON_CP
|
||||
export DSLC_CLASSPATH
|
||||
|
||||
|
||||
.DELETE_ON_ERROR:
|
||||
|
|
|
@ -54,7 +54,7 @@ AS_IF(test ! -d "$HOXSL",
|
|||
AC_MSG_RESULT(found)
|
||||
|
||||
# BC with RATER_CLASSPATH
|
||||
DSLC_CLASSPATH="${DSLC_CLASSPATH:-$RATER_CLASSPATH}"
|
||||
DSLC_CLASSPATH="$SAXON_CP:${DSLC_CLASSPATH:-$RATER_CLASSPATH}"
|
||||
AC_SUBST(DSLC_CLASSPATH, [$DSLC_CLASSPATH])
|
||||
|
||||
AC_SUBST([AUTOGENERATED],
|
||||
|
|
|
@ -1350,7 +1350,7 @@
|
|||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[a-z-][a-z0-9-]+|@[a-z][a-zA-Z0-9_]*@" />
|
||||
<xs:minLength value="2" />
|
||||
<xs:maxLength value="50" />
|
||||
<xs:maxLength value="75" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
|
|
|
@ -1327,7 +1327,7 @@
|
|||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[a-z-][a-z0-9-]+|@[a-z][a-zA-Z0-9_]*@" />
|
||||
<xs:minLength value="2" />
|
||||
<xs:maxLength value="50" />
|
||||
<xs:maxLength value="75" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ dslc_bin := $(dslc_src:.java=.class)
|
|||
|
||||
.PHONY: all all-nodoc dslc clean check info pdf html
|
||||
|
||||
export CLASSPATH=$(DSLC_CLASSPATH)
|
||||
|
||||
all: dslc
|
||||
dslc: dslc.jar
|
||||
|
||||
|
|
|
@ -31,17 +31,15 @@ package com.lovullo.dslc;
|
|||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import javax.xml.XMLConstants;
|
||||
import java.util.Map;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.validation.*;
|
||||
import javax.xml.transform.sax.SAXTransformerFactory;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotRecognizedException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.Validator;
|
||||
import javax.xml.XMLConstants;
|
||||
import net.sf.saxon.s9api.*;
|
||||
|
||||
|
||||
// TODO: Decouple from rater/ path assumptions
|
||||
|
@ -50,8 +48,10 @@ public class DslCompiler
|
|||
private static class _DslCompiler
|
||||
{
|
||||
private Validator _xsd;
|
||||
private HashMap<String,Transformer> _xsl;
|
||||
private HashMap<String,XsltTransformer> _xsl;
|
||||
private Path _pathRoot;
|
||||
private Processor _processor;
|
||||
private XsltCompiler _xsltCompiler;
|
||||
|
||||
|
||||
public _DslCompiler( String path_root )
|
||||
|
@ -59,7 +59,10 @@ public class DslCompiler
|
|||
{
|
||||
_pathRoot = Paths.get( path_root ).toRealPath();
|
||||
_xsd = _createXsd();
|
||||
_xsl = new HashMap<String,Transformer>();
|
||||
_xsl = new HashMap<String,XsltTransformer>();
|
||||
|
||||
_processor = new Processor( false );
|
||||
_xsltCompiler = _processor.newXsltCompiler();
|
||||
}
|
||||
|
||||
|
||||
|
@ -96,7 +99,7 @@ public class DslCompiler
|
|||
src,
|
||||
doc,
|
||||
cmd,
|
||||
new StreamResult( new File( dest ) ),
|
||||
_processor.newSerializer( new File( dest ) ),
|
||||
params
|
||||
);
|
||||
|
||||
|
@ -122,7 +125,7 @@ public class DslCompiler
|
|||
String src,
|
||||
Source doc,
|
||||
String cmd,
|
||||
StreamResult dest,
|
||||
Destination dest,
|
||||
HashMap<String,String> params
|
||||
) throws Exception
|
||||
{
|
||||
|
@ -142,26 +145,45 @@ public class DslCompiler
|
|||
Integer dircount = srcpkg.replaceAll( "[^/]", "" ).length();
|
||||
String relroot = new String( new char[ dircount ] ).replace( "\0", "../" );
|
||||
|
||||
Transformer t = _xsl.get( cmd );
|
||||
t.setParameter( "__path-root", _pathRoot.toString() + "/tame" );
|
||||
t.setParameter( "__srcpkg", srcpkg );
|
||||
t.setParameter( "__relroot", relroot );
|
||||
t.setParameter( "__rseed", (int)( Math.random() * 10e6 ) );
|
||||
XsltTransformer t = _xsl.get( cmd );
|
||||
|
||||
t.setParameter(
|
||||
new QName( "__path-root" ),
|
||||
XdmValue.makeValue( _pathRoot.toString() + "/tame" )
|
||||
);
|
||||
t.setParameter(
|
||||
new QName( "__srcpkg" ),
|
||||
XdmValue.makeValue( srcpkg )
|
||||
);
|
||||
t.setParameter(
|
||||
new QName( "__relroot" ),
|
||||
XdmValue.makeValue( relroot )
|
||||
);
|
||||
t.setParameter(
|
||||
new QName( "__rseed" ),
|
||||
XdmValue.makeValue( (int)( Math.random() * 10e6 ) )
|
||||
);
|
||||
|
||||
_setTemplateParams( t, params );
|
||||
|
||||
t.transform( doc, dest );
|
||||
t.setSource( doc );
|
||||
t.setDestination( dest );
|
||||
|
||||
t.transform();
|
||||
}
|
||||
|
||||
|
||||
private void _setTemplateParams(
|
||||
Transformer t,
|
||||
XsltTransformer t,
|
||||
HashMap<String,String> params
|
||||
) throws Exception
|
||||
{
|
||||
for ( Map.Entry<String, String> param : params.entrySet() )
|
||||
{
|
||||
t.setParameter( param.getKey(), param.getValue() );
|
||||
t.setParameter(
|
||||
new QName( param.getKey() ),
|
||||
XdmValue.makeValue( param.getValue() )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,7 +222,7 @@ public class DslCompiler
|
|||
|
||||
return schema.newValidator();
|
||||
}
|
||||
catch ( SAXException e )
|
||||
catch ( Exception e )
|
||||
{
|
||||
System.err.printf(
|
||||
"fatal: %s\n",
|
||||
|
@ -214,19 +236,15 @@ public class DslCompiler
|
|||
}
|
||||
|
||||
|
||||
private Transformer _createXslt( String src )
|
||||
private XsltTransformer _createXslt( String src )
|
||||
{
|
||||
try
|
||||
{
|
||||
final TransformerFactory factory = TransformerFactory.newInstance(
|
||||
"net.sf.saxon.TransformerFactoryImpl", null
|
||||
);
|
||||
|
||||
final Source xsl = new StreamSource(
|
||||
_pathRoot.toString() + "/" + src + ".xsl"
|
||||
);
|
||||
|
||||
return factory.newTransformer( xsl );
|
||||
return _xsltCompiler.compile( xsl ).load();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue