You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by tm...@apache.org on 2001/06/11 16:09:09 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler XSLTC.java Parser.java
tmiller 01/06/11 07:09:09
Modified: java/src/org/apache/xalan/xsltc/compiler XSLTC.java
Parser.java
Log:
support for java.io.InputStream StreamSources
Revision Changes Path
1.8 +57 -2 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java
Index: XSLTC.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/XSLTC.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XSLTC.java 2001/06/11 12:03:36 1.7
+++ XSLTC.java 2001/06/11 14:09:00 1.8
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: XSLTC.java,v 1.7 2001/06/11 12:03:36 morten Exp $
+ * @(#)$Id: XSLTC.java,v 1.8 2001/06/11 14:09:00 tmiller Exp $
*
* The Apache Software License, Version 1.1
*
@@ -169,7 +169,62 @@
public void setMultiDocument(boolean flag) {
_multiDocument = flag;
}
+
+ // GTM: TBD this is a prototype to handle input stream input..
+ public boolean compile(InputStream input, String transletName) {
+ return compile(input, transletName, null);
+ }
+ // GTM: TBD this is a prototype, copied and modified fr compile(URL..)
+ public boolean compile(InputStream input, String transletName,
+ ErrorListener elistener)
+ {
+ if (elistener != null) {
+ _parser.setErrorListener(elistener);
+ }
+ try {
+ reset();
+ final String name = transletName;
+ setClassName(transletName);
+
+ // Get the root node of the abstract syntax tree
+ final SyntaxTreeNode element = _parser.parse(input);
+ // Process any error and/or warning messages
+ _parser.printWarnings();
+ if (_parser.errorsFound()) {
+ _parser.printErrors();
+ return false;
+ }
+
+ if ((!_parser.errorsFound()) && (element != null)) {
+ _stylesheet = _parser.makeStylesheet(element);
+ //_stylesheet.setURL(url);
+ // This is the top level stylesheet - it has no parent
+ _stylesheet.setParentStylesheet(null);
+ _parser.setCurrentStylesheet(_stylesheet);
+ _parser.createAST(_stylesheet);
+ if (_stylesheet != null && _parser.errorsFound() == false) {
+ _stylesheet.setMultiDocument(_multiDocument);
+ _stylesheet.translate();
+ }
+ else {
+ _parser.printErrors();
+ }
+ }
+ else {
+ _parser.printErrors();
+ }
+ _parser.printWarnings();
+ return !_parser.errorsFound();
+ }
+ catch (CompilerException e) {
+ e.printStackTrace();
+ _parser.reportError(Constants.FATAL, new ErrorMsg(e.getMessage()));
+ _parser.printErrors();
+ return false;
+ }
+ }
+
/**
* Compiles the stylesheet into Java bytecode. Returns 'true' if the
* compilation was successful - 'false' otherwise.
@@ -177,7 +232,7 @@
public boolean compile(URL stylesheet) {
return compile(stylesheet, null);
}
-
+
/**
* Compile stylesheet into Java bytecode. Returns 'true' if compilation
* is successful. - 'false' otherwise. ErrorListener arg (may be null)
1.11 +44 -1 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Parser.java 2001/06/08 12:57:52 1.10
+++ Parser.java 2001/06/11 14:09:02 1.11
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Parser.java,v 1.10 2001/06/08 12:57:52 morten Exp $
+ * @(#)$Id: Parser.java,v 1.11 2001/06/11 14:09:02 tmiller Exp $
*
* The Apache Software License, Version 1.1
*
@@ -357,6 +357,49 @@
catch (TypeCheckError e) {
reportError(Constants.ERROR, new ErrorMsg(e.toString()));
}
+ }
+
+ // GTM prototype:
+ public SyntaxTreeNode parse(InputStream input){
+ try {
+ // Create a SAX parser and get the XMLReader object it uses
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+ try {
+ factory.setFeature(Constants.NAMESPACE_FEATURE,true);
+ }
+ catch (Exception e) {
+ factory.setNamespaceAware(true);
+ }
+ final SAXParser parser = factory.newSAXParser();
+ final XMLReader reader = parser.getXMLReader();
+
+ // Parse the input document and build the abstract syntax tree
+ reader.setContentHandler(this);
+ InputSource is = new InputSource(input);
+ reader.parse(new InputSource(input));
+
+ // Find the start of the stylesheet within the tree
+ return (SyntaxTreeNode)getStylesheet(_root);
+ }
+ catch (ParserConfigurationException e) {
+ reportError(Constants.ERROR,
+ new ErrorMsg("JAXP parser not configured correctly"));
+ }
+ catch (IOException e) {
+ reportError(Constants.ERROR,
+ new ErrorMsg(e.getMessage()));
+ }
+ catch (SAXParseException e){
+ reportError(Constants.ERROR,
+ new ErrorMsg(e.getMessage(),e.getLineNumber()));
+ }
+ catch (SAXException e) {
+ reportError(Constants.ERROR, new ErrorMsg(e.getMessage()));
+ }
+ catch (CompilerException e) {
+ reportError(Constants.ERROR, new ErrorMsg(e.getMessage()));
+ }
+ return null;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org