< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Sep 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *     http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  23 


 416                 }
 417             }
 418         }
 419         catch (TypeCheckError e) {
 420             reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
 421         }
 422     }
 423 
 424     /**
 425      * Parses a stylesheet and builds the internal abstract syntax tree
 426      * @param reader A SAX2 SAXReader (parser)
 427      * @param input A SAX2 InputSource can be passed to a SAX reader
 428      * @return The root of the abstract syntax tree
 429      */
 430     public SyntaxTreeNode parse(XMLReader reader, InputSource input) {
 431         try {
 432             // Parse the input document and build the abstract syntax tree
 433             reader.setContentHandler(this);
 434             reader.parse(input);
 435             // Find the start of the stylesheet within the tree
 436             return (SyntaxTreeNode)getStylesheet(_root);
 437         }
 438         catch (IOException e) {
 439             if (_xsltc.debug()) e.printStackTrace();
 440             reportError(ERROR,new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
 441         }
 442         catch (SAXException e) {
 443             Throwable ex = e.getException();
 444             if (_xsltc.debug()) {
 445                 e.printStackTrace();
 446                 if (ex != null) ex.printStackTrace();
 447             }
 448             reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
 449         }
 450         catch (CompilerException e) {
 451             if (_xsltc.debug()) e.printStackTrace();
 452             reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
 453         }
 454         catch (Exception e) {
 455             if (_xsltc.debug()) e.printStackTrace();
 456             reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));


 651                 if (node != null) return node;
 652             }
 653         }
 654         return null;
 655     }
 656 
 657     /**
 658      * For embedded stylesheets: Load an external file with stylesheet
 659      */
 660     private SyntaxTreeNode loadExternalStylesheet(String location)
 661         throws CompilerException {
 662 
 663         InputSource source;
 664 
 665         // Check if the location is URL or a local file
 666         if ((new File(location)).exists())
 667             source = new InputSource("file:"+location);
 668         else
 669             source = new InputSource(location);
 670 
 671         SyntaxTreeNode external = (SyntaxTreeNode)parse(source);
 672         return(external);
 673     }
 674 
 675     private void initAttrTable(String elementName, String[] attrs) {
 676         _instructionAttrs.put(getQName(XSLT_URI, XSL, elementName).getStringRep(),
 677                                 attrs);
 678     }
 679 
 680     private void initInstructionAttrs() {
 681         initAttrTable("template",
 682             new String[] {"match", "name", "priority", "mode"});
 683         initAttrTable("stylesheet",
 684             new String[] {"id", "version", "extension-element-prefixes",
 685                 "exclude-result-prefixes"});
 686         initAttrTable("transform",
 687             new String[] {"id", "version", "extension-element-prefixes",
 688                 "exclude-result-prefixes"});
 689         initAttrTable("text", new String[] {"disable-output-escaping"});
 690         initAttrTable("if", new String[] {"test"});
 691         initAttrTable("choose", new String[] {});


   1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Nov 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *     http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  23 


 416                 }
 417             }
 418         }
 419         catch (TypeCheckError e) {
 420             reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
 421         }
 422     }
 423 
 424     /**
 425      * Parses a stylesheet and builds the internal abstract syntax tree
 426      * @param reader A SAX2 SAXReader (parser)
 427      * @param input A SAX2 InputSource can be passed to a SAX reader
 428      * @return The root of the abstract syntax tree
 429      */
 430     public SyntaxTreeNode parse(XMLReader reader, InputSource input) {
 431         try {
 432             // Parse the input document and build the abstract syntax tree
 433             reader.setContentHandler(this);
 434             reader.parse(input);
 435             // Find the start of the stylesheet within the tree
 436             return getStylesheet(_root);
 437         }
 438         catch (IOException e) {
 439             if (_xsltc.debug()) e.printStackTrace();
 440             reportError(ERROR,new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
 441         }
 442         catch (SAXException e) {
 443             Throwable ex = e.getException();
 444             if (_xsltc.debug()) {
 445                 e.printStackTrace();
 446                 if (ex != null) ex.printStackTrace();
 447             }
 448             reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
 449         }
 450         catch (CompilerException e) {
 451             if (_xsltc.debug()) e.printStackTrace();
 452             reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));
 453         }
 454         catch (Exception e) {
 455             if (_xsltc.debug()) e.printStackTrace();
 456             reportError(ERROR, new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR, e));


 651                 if (node != null) return node;
 652             }
 653         }
 654         return null;
 655     }
 656 
 657     /**
 658      * For embedded stylesheets: Load an external file with stylesheet
 659      */
 660     private SyntaxTreeNode loadExternalStylesheet(String location)
 661         throws CompilerException {
 662 
 663         InputSource source;
 664 
 665         // Check if the location is URL or a local file
 666         if ((new File(location)).exists())
 667             source = new InputSource("file:"+location);
 668         else
 669             source = new InputSource(location);
 670 
 671         SyntaxTreeNode external = parse(source);
 672         return(external);
 673     }
 674 
 675     private void initAttrTable(String elementName, String[] attrs) {
 676         _instructionAttrs.put(getQName(XSLT_URI, XSL, elementName).getStringRep(),
 677                                 attrs);
 678     }
 679 
 680     private void initInstructionAttrs() {
 681         initAttrTable("template",
 682             new String[] {"match", "name", "priority", "mode"});
 683         initAttrTable("stylesheet",
 684             new String[] {"id", "version", "extension-element-prefixes",
 685                 "exclude-result-prefixes"});
 686         initAttrTable("transform",
 687             new String[] {"id", "version", "extension-element-prefixes",
 688                 "exclude-result-prefixes"});
 689         initAttrTable("text", new String[] {"disable-output-escaping"});
 690         initAttrTable("if", new String[] {"test"});
 691         initAttrTable("choose", new String[] {});


< prev index next >