/** * Get the error listener. If no ErrorListener * has been set locally, the ErrorListener in the Controller is returned; this in turn defaults * to the ErrorListener set in the Configuration. * * @return the ErrorListener in use. Note that this is not necessarily the ErrorListener that was supplied * to the {@link #setErrorListener(ErrorListener)} method; if that was not an {@link UnfailingErrorListener}, * it will have been wrapped in a {@link DelegatingErrorListener}, and it is the DelegatingErrorListener * that this method returns. * @since 9.6 */ public UnfailingErrorListener getErrorListener() { return errorListener == null ? controller.getErrorListener() : errorListener; }
/** * Get the error listener. If no ErrorListener * has been set locally, the ErrorListener in the Controller is returned; this in turn defaults * to the ErrorListener set in the Configuration. * * @return the ErrorListener in use. Note that this is not necessarily the ErrorListener that was supplied * to the {@link #setErrorListener(ErrorListener)} method; if that was not an {@link UnfailingErrorListener}, * it will have been wrapped in a {@link DelegatingErrorListener}, and it is the DelegatingErrorListener * that this method returns. * @since 9.6 */ public UnfailingErrorListener getErrorListener() { return errorListener == null ? controller.getErrorListener() : errorListener; }
/** * Report a run-time warning * * @param message the warning message * @param errorCode the local part of the error code (in the ERR namespace). May be null. * @param locator the location in the source code. May be null. */ public void warning(String message, String errorCode, Location locator) { getErrorListener().warning(new XPathException(message, errorCode, locator)); }
/** * Report a run-time warning * * @param message the warning message * @param errorCode the local part of the error code (in the ERR namespace). May be null. * @param locator the location in the source code. May be null. */ public void warning(String message, String errorCode, Location locator) { getErrorListener().warning(new XPathException(message, errorCode, locator)); }
public static Evaluator getEvaluator (XPathContext context) { // TODO: check thread safety of controller's error listener TransformErrorListener listener = (TransformErrorListener) context.getController().getErrorListener(); return (Evaluator) listener.getUserData(); }
private Properties validateOutputProperties(Controller controller, Properties outputProperties) throws XPathException { // Validate the serialization properties requested Properties baseProperties = controller.getOutputProperties(); if (outputProperties != null) { Enumeration iter = outputProperties.propertyNames(); while (iter.hasMoreElements()) { String key = (String)iter.nextElement(); String value = outputProperties.getProperty(key); try { SaxonOutputKeys.checkOutputProperty(key, value, controller.getConfiguration().getNameChecker()); baseProperties.setProperty(key, value); } catch (XPathException dynamicError) { try { outputProperties.remove(key); controller.getErrorListener().warning(dynamicError); } catch (TransformerException err2) { throw XPathException.makeXPathException(err2); } } } } if (baseProperties.getProperty("method") == null) { // XQuery forces the default method to XML, unlike XSLT where it depends on the contents of the result tree baseProperties.setProperty("method", "xml"); } return baseProperties; }
/** * Report a fatal error * @param err the error to be reported */ public void reportFatalError(XPathException err) { if (!err.hasBeenReported()) { try { getErrorListener().fatalError(err); } catch (TransformerException e) { // } err.setHasBeenReported(); } }
/** * Report a fatal error * @param err the error to be reported */ public void reportFatalError(XPathException err) { if (!err.hasBeenReported()) { try { getErrorListener().fatalError(err); } catch (TransformerException e) { // } err.setHasBeenReported(); } }
/** * Validate the serialization properties requested; any problems result in warnings being output * @param controller The query controller * @param outputProperties the requested serialization properties (may be null) * @return the properties after validation and normalization */ protected Properties validateOutputProperties(Controller controller, /*@Nullable*/ Properties outputProperties) { // Validate the serialization properties requested Properties baseProperties = controller.getExecutable().getPrimarySerializationProperties().getProperties(); SerializerFactory sf = controller.getConfiguration().getSerializerFactory(); if (outputProperties != null) { Enumeration iter = outputProperties.propertyNames(); while (iter.hasMoreElements()) { String key = (String) iter.nextElement(); String value = outputProperties.getProperty(key); try { value = sf.checkOutputProperty(key, value); baseProperties.setProperty(key, value); } catch (XPathException dynamicError) { outputProperties.remove(key); controller.getErrorListener().warning(dynamicError); } } } if (baseProperties.getProperty("method") == null) { // XQuery forces the default method to XML, unlike XSLT where it depends on the contents of the result tree baseProperties.setProperty("method", "xml"); } return baseProperties; }
public void outputWarning(Item item, XPathContext context) { String id = item instanceof NodeInfo ? "the node " + Navigator.getPath((NodeInfo) item) : "the atomic value " + item.getStringValue(); XPathException warning = new XPathException("No user-defined template rule matches " + id, "XTDE0555"); context.getController().getErrorListener().warning(warning); }
public void outputWarning(Item item, XPathContext context) { String id = item instanceof NodeInfo ? "the node " + Navigator.getPath((NodeInfo) item) : "the atomic value " + item.getStringValue(); XPathException warning = new XPathException("No user-defined template rule matches " + id, "XTDE0555"); context.getController().getErrorListener().warning(warning); }
/** * Determine at run-time whether a particular instruction is available. Returns true * only in the case of XSLT instructions and Saxon extension instructions; returns false * for user-defined extension instructions * @param uri the namespace URI of the element * @param localname the local part of the element name * @param context the XPath evaluation context * @return true if the instruction is available, in the sense of the XSLT element-available() function */ private boolean isElementAvailable(String uri, String localname, XPathContext context) { // This is horribly inefficient. But hopefully it's hardly ever executed, because there // is very little point calling element-available() with a dynamically-constructed argument. // And the inefficiency is only incurred once, on the first call. // Note: this requires the compile-time classes to be available at run-time; it will need // changing if we ever want to build a run-time JAR file. try { if (styleNodeFactory==null) { Configuration config = context.getConfiguration(); styleNodeFactory = new StyleNodeFactory(config, context.getController().getErrorListener()); } return styleNodeFactory.isElementAvailable(uri, localname); } catch (Exception err) { //err.printStackTrace(); return false; } }
/** * Determine at run-time whether a particular instruction is available. Returns true * only in the case of XSLT instructions and Saxon extension instructions; returns false * for user-defined extension instructions * @param uri the namespace URI of the element * @param localname the local part of the element name * @param context the XPath evaluation context * @return true if the instruction is available, in the sense of the XSLT element-available() function */ private boolean isElementAvailable(String uri, String localname, XPathContext context) { // This is horribly inefficient. But hopefully it's hardly ever executed, because there // is very little point calling element-available() with a dynamically-constructed argument. // And the inefficiency is only incurred once, on the first call. // Note: this requires the compile-time classes to be available at run-time; it will need // changing if we ever want to build a run-time JAR file. try { if (styleNodeFactory==null) { Configuration config = context.getConfiguration(); styleNodeFactory = new StyleNodeFactory(config, context.getController().getErrorListener()); } return styleNodeFactory.isElementAvailable(uri, localname); } catch (Exception err) { //err.printStackTrace(); return false; } }
/** * Determine at run-time whether a particular instruction is available. Returns true * only in the case of XSLT instructions and Saxon extension instructions; returns false * for user-defined extension instructions * @param uri the namespace URI of the element * @param localname the local part of the element name * @param context the XPath evaluation context * @return true if the instruction is available, in the sense of the XSLT element-available() function */ private boolean isElementAvailable(String uri, String localname, XPathContext context) { // This is horribly inefficient. But hopefully it's hardly ever executed, because there // is very little point calling element-available() with a dynamically-constructed argument. // And the inefficiency is only incurred once, on the first call. // Note: this requires the compile-time classes to be available at run-time; it will need // changing if we ever want to build a run-time JAR file. try { if (styleNodeFactory==null) { Configuration config = context.getConfiguration(); styleNodeFactory = new StyleNodeFactory(config, context.getController().getErrorListener()); } return styleNodeFactory.isElementAvailable(uri, localname); } catch (Exception err) { //err.printStackTrace(); return false; } }
/** * Initialize the controller ready for a new transformation. This method should not normally be called by * users (it is done automatically when transform() is invoked). However, it is available as a low-level API * especially for use with XQuery. * * @param params the values of stylesheet parameters. Changed in 9.9.1.1 so this no longer includes * static parameters (which are already available in the {@link PreparedStylesheet}). * @throws XPathException if an error occurs, for example if a required parameter is not supplied. */ public void initializeController(GlobalParameterSet params) throws XPathException { // get a new bindery, to clear out any variables from previous runs binderies = new HashMap<>(); // if parameters were supplied, set them up try { executable.checkSuppliedParameters(params); } catch (XPathException e) { if (!e.hasBeenReported()) { getErrorListener().fatalError(e); throw e; } } globalParameters = params; // Check the global context item globalContextItem = executable.checkInitialContextItem(globalContextItem, newXPathContext()); if (traceListener != null) { traceListener.open(this); preEvaluateGlobals(newXPathContext()); } }
/** * Report a fatal error * * @param err the error to be reported */ public void reportFatalError(XPathException err) { if (!err.hasBeenReported()) { if (err.getHostLanguage() == null) { if (executable.getHostLanguage() == Configuration.XSLT) { err.setHostLanguage("XSLT"); } else if (executable.getHostLanguage() == Configuration.XQUERY) { err.setHostLanguage("XQuery"); } } getErrorListener().fatalError(err); err.setHasBeenReported(true); } }
/** * Evaluate the expression * @param context * @return the result of evaluating the expression (a BooleanValue) * @throws net.sf.saxon.trans.XPathException */ public Item evaluateItem(XPathContext context) throws XPathException { AtomicValue hrefVal = (AtomicValue)argument[0].evaluateItem(context); if (hrefVal==null) { return BooleanValue.FALSE; } String href = hrefVal.getStringValue(); // suppress all error messages while attempting to fetch the document Controller controller = context.getController(); ErrorListener old = controller.getErrorListener(); controller.setErrorListener(new ErrorListener() { public void warning(TransformerException exception) {} public void error(TransformerException exception) {} public void fatalError(TransformerException exception) {} }); boolean b = docAvailable(href, context); controller.setErrorListener(old); return BooleanValue.get(b); }
/** * Report a fatal error * * @param err the error to be reported */ public void reportFatalError(XPathException err) { if (!err.hasBeenReported()) { if (err.getHostLanguage() == null) { if (executable.getHostLanguage() == Configuration.XSLT) { err.setHostLanguage("XSLT"); } else if (executable.getHostLanguage() == Configuration.XQUERY) { err.setHostLanguage("XQuery"); } } getErrorListener().fatalError(err); err.setHasBeenReported(true); } }
/** * Make a PipelineConfiguration based on the properties of this Controller. * <p> * This interface is intended primarily for internal use, although it may be necessary * for applications to call it directly if they construct pull or push pipelines * @return a newly constructed PipelineConfiguration holding a reference to this * Controller as well as other configuration information. */ public PipelineConfiguration makePipelineConfiguration() { PipelineConfiguration pipe = new PipelineConfiguration(); pipe.setConfiguration(getConfiguration()); pipe.setErrorListener(getErrorListener()); pipe.setURIResolver(userURIResolver==null ? standardURIResolver : userURIResolver); pipe.setSchemaURIResolver(schemaURIResolver); pipe.setExpandAttributeDefaults(getConfiguration().isExpandAttributeDefaults()); pipe.setUseXsiSchemaLocation(((Boolean)getConfiguration().getConfigurationProperty( FeatureKeys.USE_XSI_SCHEMA_LOCATION)).booleanValue()); pipe.setController(this); final Executable executable = getExecutable(); if (executable != null) { // can be null for an IdentityTransformer pipe.setLocationProvider(executable.getLocationMap()); pipe.setHostLanguage(executable.getHostLanguage()); } return pipe; }
/** * Make a PipelineConfiguration based on the properties of this Controller. * <p> * This interface is intended primarily for internal use, although it may be necessary * for applications to call it directly if they construct pull or push pipelines * @return a newly constructed PipelineConfiguration holding a reference to this * Controller as well as other configuration information. */ public PipelineConfiguration makePipelineConfiguration() { PipelineConfiguration pipe = new PipelineConfiguration(); pipe.setConfiguration(getConfiguration()); pipe.setErrorListener(getErrorListener()); pipe.setURIResolver(userURIResolver==null ? standardURIResolver : userURIResolver); pipe.setSchemaURIResolver(schemaURIResolver); pipe.setExpandAttributeDefaults(getConfiguration().isExpandAttributeDefaults()); pipe.setController(this); final Executable executable = getExecutable(); if (executable != null) { // can be null for an IdentityTransformer pipe.setLocationProvider(executable.getLocationMap()); pipe.setHostLanguage(executable.getHostLanguage()); } return pipe; }