1 /* |
1 /* |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
3 */ |
3 */ |
4 /* |
4 /* |
5 * Licensed to the Apache Software Foundation (ASF) under one or more |
5 * Licensed to the Apache Software Foundation (ASF) under one or more |
6 * contributor license agreements. See the NOTICE file distributed with |
6 * contributor license agreements. See the NOTICE file distributed with |
7 * this work for additional information regarding copyright ownership. |
7 * this work for additional information regarding copyright ownership. |
35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; |
36 import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver; |
36 import com.sun.org.apache.xml.internal.serializer.utils.SystemIDResolver; |
37 import java.io.File; |
37 import java.io.File; |
38 import java.io.IOException; |
38 import java.io.IOException; |
39 import java.io.StringReader; |
39 import java.io.StringReader; |
|
40 import java.util.ArrayList; |
40 import java.util.HashMap; |
41 import java.util.HashMap; |
41 import java.util.Iterator; |
42 import java.util.Iterator; |
42 import java.util.List; |
43 import java.util.List; |
43 import java.util.Map; |
44 import java.util.Map; |
44 import java.util.Properties; |
45 import java.util.Properties; |
45 import java.util.Stack; |
46 import java.util.Stack; |
46 import java.util.StringTokenizer; |
47 import java.util.StringTokenizer; |
47 import java.util.Vector; |
|
48 import javax.xml.XMLConstants; |
48 import javax.xml.XMLConstants; |
|
49 import javax.xml.catalog.CatalogFeatures; |
49 import javax.xml.parsers.ParserConfigurationException; |
50 import javax.xml.parsers.ParserConfigurationException; |
50 import javax.xml.parsers.SAXParser; |
51 import javax.xml.parsers.SAXParser; |
51 import javax.xml.parsers.SAXParserFactory; |
52 import javax.xml.parsers.SAXParserFactory; |
|
53 import jdk.xml.internal.JdkXmlFeatures; |
|
54 import jdk.xml.internal.JdkXmlUtils; |
52 import org.xml.sax.Attributes; |
55 import org.xml.sax.Attributes; |
53 import org.xml.sax.ContentHandler; |
56 import org.xml.sax.ContentHandler; |
54 import org.xml.sax.InputSource; |
57 import org.xml.sax.InputSource; |
55 import org.xml.sax.Locator; |
58 import org.xml.sax.Locator; |
56 import org.xml.sax.SAXException; |
59 import org.xml.sax.SAXException; |
57 import org.xml.sax.SAXNotRecognizedException; |
60 import org.xml.sax.SAXNotRecognizedException; |
|
61 import org.xml.sax.SAXNotSupportedException; |
58 import org.xml.sax.SAXParseException; |
62 import org.xml.sax.SAXParseException; |
59 import org.xml.sax.XMLReader; |
63 import org.xml.sax.XMLReader; |
60 import org.xml.sax.helpers.AttributesImpl; |
64 import org.xml.sax.helpers.AttributesImpl; |
61 |
65 |
62 /** |
66 /** |
73 |
77 |
74 private Locator _locator = null; |
78 private Locator _locator = null; |
75 |
79 |
76 private XSLTC _xsltc; // Reference to the compiler object. |
80 private XSLTC _xsltc; // Reference to the compiler object. |
77 private XPathParser _xpathParser; // Reference to the XPath parser. |
81 private XPathParser _xpathParser; // Reference to the XPath parser. |
78 private Vector _errors; // Contains all compilation errors |
82 private ArrayList<ErrorMsg> _errors; // Contains all compilation errors |
79 private Vector _warnings; // Contains all compilation errors |
83 private ArrayList<ErrorMsg> _warnings; // Contains all compilation errors |
80 |
84 |
81 private Map<String, String> _instructionClasses; // Maps instructions to classes |
85 private Map<String, String> _instructionClasses; // Maps instructions to classes |
82 private Map<String, String[]> _instructionAttrs; // reqd and opt attrs |
86 private Map<String, String[]> _instructionAttrs; // reqd and opt attrs |
83 private Map<String, QName> _qNames; |
87 private Map<String, QName> _qNames; |
84 private Map<String, Map> _namespaces; |
88 private Map<String, Map> _namespaces; |
111 _namespaces = new HashMap<>(); |
115 _namespaces = new HashMap<>(); |
112 _instructionClasses = new HashMap<>(); |
116 _instructionClasses = new HashMap<>(); |
113 _instructionAttrs = new HashMap<>(); |
117 _instructionAttrs = new HashMap<>(); |
114 _variableScope = new HashMap<>(); |
118 _variableScope = new HashMap<>(); |
115 _template = null; |
119 _template = null; |
116 _errors = new Vector(); |
120 _errors = new ArrayList<>(); |
117 _warnings = new Vector(); |
121 _warnings = new ArrayList<>(); |
118 _symbolTable = new SymbolTable(); |
122 _symbolTable = new SymbolTable(); |
119 _xpathParser = new XPathParser(this); |
123 _xpathParser = new XPathParser(this); |
120 _currentStylesheet = null; |
124 _currentStylesheet = null; |
121 _output = null; |
125 _output = null; |
122 _root = null; |
126 _root = null; |
473 } |
477 } |
474 |
478 |
475 try { |
479 try { |
476 factory.setFeature(Constants.NAMESPACE_FEATURE,true); |
480 factory.setFeature(Constants.NAMESPACE_FEATURE,true); |
477 } |
481 } |
478 catch (Exception e) { |
482 catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) { |
479 factory.setNamespaceAware(true); |
483 factory.setNamespaceAware(true); |
480 } |
484 } |
|
485 |
481 final SAXParser parser = factory.newSAXParser(); |
486 final SAXParser parser = factory.newSAXParser(); |
482 try { |
487 try { |
483 parser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, |
488 parser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, |
484 _xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD)); |
489 _xsltc.getProperty(XMLConstants.ACCESS_EXTERNAL_DTD)); |
485 } catch (SAXNotRecognizedException e) { |
490 } catch (SAXNotRecognizedException e) { |
486 ErrorMsg err = new ErrorMsg(ErrorMsg.WARNING_MSG, |
491 ErrorMsg err = new ErrorMsg(ErrorMsg.WARNING_MSG, |
487 parser.getClass().getName() + ": " + e.getMessage()); |
492 parser.getClass().getName() + ": " + e.getMessage()); |
488 reportError(WARNING, err); |
493 reportError(WARNING, err); |
|
494 } |
|
495 |
|
496 boolean supportCatalog = true; |
|
497 boolean useCatalog = _xsltc.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG); |
|
498 try { |
|
499 factory.setFeature(JdkXmlUtils.USE_CATALOG,useCatalog); |
|
500 } |
|
501 catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) { |
|
502 supportCatalog = false; |
|
503 } |
|
504 |
|
505 if (supportCatalog && useCatalog) { |
|
506 try { |
|
507 CatalogFeatures cf = (CatalogFeatures)_xsltc.getProperty(JdkXmlFeatures.CATALOG_FEATURES); |
|
508 if (cf != null) { |
|
509 for (CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { |
|
510 parser.setProperty(f.getPropertyName(), cf.get(f)); |
|
511 } |
|
512 } |
|
513 } catch (SAXNotRecognizedException e) { |
|
514 //shall not happen for internal settings |
|
515 } |
489 } |
516 } |
490 |
517 |
491 final XMLReader reader = parser.getXMLReader(); |
518 final XMLReader reader = parser.getXMLReader(); |
492 String lastProperty = ""; |
519 String lastProperty = ""; |
493 try { |
520 try { |
1215 public void reportError(final int category, final ErrorMsg error) { |
1242 public void reportError(final int category, final ErrorMsg error) { |
1216 switch (category) { |
1243 switch (category) { |
1217 case Constants.INTERNAL: |
1244 case Constants.INTERNAL: |
1218 // Unexpected internal errors, such as null-ptr exceptions, etc. |
1245 // Unexpected internal errors, such as null-ptr exceptions, etc. |
1219 // Immediately terminates compilation, no translet produced |
1246 // Immediately terminates compilation, no translet produced |
1220 _errors.addElement(error); |
1247 _errors.add(error); |
1221 break; |
1248 break; |
1222 case Constants.UNSUPPORTED: |
1249 case Constants.UNSUPPORTED: |
1223 // XSLT elements that are not implemented and unsupported ext. |
1250 // XSLT elements that are not implemented and unsupported ext. |
1224 // Immediately terminates compilation, no translet produced |
1251 // Immediately terminates compilation, no translet produced |
1225 _errors.addElement(error); |
1252 _errors.add(error); |
1226 break; |
1253 break; |
1227 case Constants.FATAL: |
1254 case Constants.FATAL: |
1228 // Fatal error in the stylesheet input (parsing or content) |
1255 // Fatal error in the stylesheet input (parsing or content) |
1229 // Immediately terminates compilation, no translet produced |
1256 // Immediately terminates compilation, no translet produced |
1230 _errors.addElement(error); |
1257 _errors.add(error); |
1231 break; |
1258 break; |
1232 case Constants.ERROR: |
1259 case Constants.ERROR: |
1233 // Other error in the stylesheet input (parsing or content) |
1260 // Other error in the stylesheet input (parsing or content) |
1234 // Does not terminate compilation, no translet produced |
1261 // Does not terminate compilation, no translet produced |
1235 _errors.addElement(error); |
1262 _errors.add(error); |
1236 break; |
1263 break; |
1237 case Constants.WARNING: |
1264 case Constants.WARNING: |
1238 // Other error in the stylesheet input (content errors only) |
1265 // Other error in the stylesheet input (content errors only) |
1239 // Does not terminate compilation, a translet is produced |
1266 // Does not terminate compilation, a translet is produced |
1240 _warnings.addElement(error); |
1267 _warnings.add(error); |
1241 break; |
1268 break; |
1242 } |
1269 } |
1243 } |
1270 } |
1244 |
1271 |
1245 public Vector getErrors() { |
1272 public ArrayList<ErrorMsg> getErrors() { |
1246 return _errors; |
1273 return _errors; |
1247 } |
1274 } |
1248 |
1275 |
1249 public Vector getWarnings() { |
1276 public ArrayList<ErrorMsg> getWarnings() { |
1250 return _warnings; |
1277 return _warnings; |
1251 } |
1278 } |
1252 |
1279 |
1253 /************************ SAX2 ContentHandler INTERFACE *****************/ |
1280 /************************ SAX2 ContentHandler INTERFACE *****************/ |
1254 |
1281 |