From c37863b7fc331c614115a3934310d1a95a8811df Mon Sep 17 00:00:00 2001 From: Norman Walsh Date: Sat, 15 Apr 2023 15:33:43 +0100 Subject: [PATCH] Initial port to Saxon 12 --- .../xmlcalabash/core/XProcConfiguration.java | 48 ++-- .../com/xmlcalabash/core/XProcConstants.java | 224 ++++++++++-------- .../com/xmlcalabash/core/XProcException.java | 4 +- .../com/xmlcalabash/core/XProcRuntime.java | 9 +- .../com/xmlcalabash/drivers/CalabashTask.java | 3 +- .../java/com/xmlcalabash/drivers/Main.java | 4 +- .../xmlcalabash/drivers/RunTestReport.java | 13 +- .../xmlcalabash/extensions/CssFormatter.java | 5 +- .../java/com/xmlcalabash/extensions/Eval.java | 12 +- .../xmlcalabash/extensions/GetCookies.java | 6 +- .../xmlcalabash/extensions/HashDocument.java | 27 ++- .../extensions/JavaProperties.java | 4 +- .../extensions/NamespaceDelete.java | 3 +- .../xmlcalabash/extensions/ReportErrors.java | 2 +- .../xmlcalabash/extensions/SetCookies.java | 8 +- .../com/xmlcalabash/extensions/Unzip.java | 6 +- .../com/xmlcalabash/extensions/UriInfo.java | 4 +- .../java/com/xmlcalabash/extensions/Zip.java | 44 ++-- .../extensions/fileutils/Head.java | 2 +- .../extensions/fileutils/Info.java | 12 +- .../extensions/fileutils/Tail.java | 2 +- .../xmlcalabash/extensions/osutils/Cwd.java | 2 +- .../xmlcalabash/extensions/osutils/Env.java | 2 +- .../java/com/xmlcalabash/io/PipeLogger.java | 4 +- .../java/com/xmlcalabash/io/ReadableData.java | 6 +- .../com/xmlcalabash/io/ReadableInline.java | 3 +- .../com/xmlcalabash/library/AddAttribute.java | 16 +- .../java/com/xmlcalabash/library/Compare.java | 2 +- .../java/com/xmlcalabash/library/Count.java | 2 +- .../com/xmlcalabash/library/DefaultStep.java | 17 +- .../xmlcalabash/library/DirectoryList.java | 6 +- .../java/com/xmlcalabash/library/Error.java | 15 +- .../java/com/xmlcalabash/library/Exec.java | 6 +- .../java/com/xmlcalabash/library/Hash.java | 6 +- .../com/xmlcalabash/library/HttpRequest.java | 51 +++- .../xmlcalabash/library/LabelElements.java | 6 +- .../java/com/xmlcalabash/library/Load.java | 2 +- .../xmlcalabash/library/NamespaceRename.java | 41 ++-- .../com/xmlcalabash/library/Parameters.java | 13 +- .../java/com/xmlcalabash/library/Rename.java | 17 +- .../java/com/xmlcalabash/library/Store.java | 19 +- .../xmlcalabash/library/StringReplace.java | 5 +- .../com/xmlcalabash/library/Template.java | 9 +- .../xmlcalabash/library/UnescapeMarkup.java | 7 +- .../xmlcalabash/library/ValidateWithSCH.java | 8 +- .../xmlcalabash/library/ValidateWithXSD.java | 9 +- .../xmlcalabash/library/WWWFormURLDecode.java | 6 +- .../java/com/xmlcalabash/library/Wrap.java | 2 +- .../com/xmlcalabash/library/XInclude.java | 39 ++- .../java/com/xmlcalabash/library/XQuery.java | 4 +- .../com/xmlcalabash/library/XSLFormatter.java | 7 +- .../java/com/xmlcalabash/library/XSLT.java | 4 +- .../java/com/xmlcalabash/model/Choose.java | 3 +- .../com/xmlcalabash/model/DeclareStep.java | 7 +- .../java/com/xmlcalabash/model/ForEach.java | 3 +- .../java/com/xmlcalabash/model/Group.java | 3 +- .../com/xmlcalabash/model/InlineBinding.java | 13 +- .../xmlcalabash/model/NamespaceBinding.java | 13 +- .../java/com/xmlcalabash/model/Otherwise.java | 3 +- .../java/com/xmlcalabash/model/Parser.java | 67 +++--- .../com/xmlcalabash/model/RuntimeValue.java | 15 +- src/main/java/com/xmlcalabash/model/Step.java | 10 +- src/main/java/com/xmlcalabash/model/Try.java | 3 +- .../java/com/xmlcalabash/model/Viewport.java | 3 +- src/main/java/com/xmlcalabash/model/When.java | 3 +- .../com/xmlcalabash/piperack/BaseStatus.java | 2 +- .../com/xmlcalabash/piperack/Pipeline.java | 4 +- .../com/xmlcalabash/runtime/XAtomicStep.java | 57 ++--- .../com/xmlcalabash/runtime/XPipeline.java | 8 +- .../java/com/xmlcalabash/runtime/XSelect.java | 2 +- .../java/com/xmlcalabash/runtime/XStep.java | 10 +- .../java/com/xmlcalabash/runtime/XTry.java | 18 +- .../java/com/xmlcalabash/util/AxisNodes.java | 14 +- .../util/DefaultXMLCalabashConfigurer.java | 2 +- .../util/DefaultXProcMessageListener.java | 2 +- .../java/com/xmlcalabash/util/JSONtoXML.java | 43 ++-- .../com/xmlcalabash/util/NodeToBytes.java | 23 +- .../java/com/xmlcalabash/util/ParseArgs.java | 3 +- .../com/xmlcalabash/util/ProcessMatch.java | 11 +- .../java/com/xmlcalabash/util/S9apiUtils.java | 21 +- .../xmlcalabash/util/StepErrorListener.java | 16 +- .../java/com/xmlcalabash/util/TreeWriter.java | 17 +- .../java/com/xmlcalabash/util/TypeUtils.java | 6 +- .../java/com/xmlcalabash/util/UserArgs.java | 22 +- .../java/com/xmlcalabash/util/XMLtoJSON.java | 13 +- .../java/com/xmlcalabash/util/XPointer.java | 7 +- .../com/xmlcalabash/util/XPointerScheme.java | 3 +- .../util/XProcSystemPropertySet.java | 7 +- 88 files changed, 643 insertions(+), 592 deletions(-) diff --git a/src/main/java/com/xmlcalabash/core/XProcConfiguration.java b/src/main/java/com/xmlcalabash/core/XProcConfiguration.java index b24c3d6a..057f507e 100644 --- a/src/main/java/com/xmlcalabash/core/XProcConfiguration.java +++ b/src/main/java/com/xmlcalabash/core/XProcConfiguration.java @@ -15,6 +15,7 @@ import com.xmlcalabash.util.URIUtils; import net.sf.saxon.Version; import net.sf.saxon.lib.Feature; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.om.NoElementsSpaceStrippingRule; import net.sf.saxon.s9api.Axis; import net.sf.saxon.s9api.DocumentBuilder; @@ -159,7 +160,7 @@ public class XProcConfiguration { bFeatureMap.put("http://saxon.sf.net/feature/linenumbering", Feature.LINE_NUMBERING); bFeatureMap.put("http://saxon.sf.net/feature/markDefaultedAttributes", Feature.MARK_DEFAULTED_ATTRIBUTES); iFeatureMap.put("http://saxon.sf.net/feature/maxCompiledClasses", Feature.MAX_COMPILED_CLASSES); - sFeatureMap.put("http://saxon.sf.net/feature/messageEmitterClass", Feature.MESSAGE_EMITTER_CLASS); + //sFeatureMap.put("http://saxon.sf.net/feature/messageEmitterClass", Feature.MESSAGE_EMITTER_CLASS); sFeatureMap.put("http://saxon.sf.net/feature/moduleURIResolverClass", Feature.MODULE_URI_RESOLVER_CLASS); bFeatureMap.put("http://saxon.sf.net/feature/monitorHotSpotByteCode", Feature.MONITOR_HOT_SPOT_BYTE_CODE); bFeatureMap.put("http://saxon.sf.net/feature/multipleSchemaImports", Feature.MULTIPLE_SCHEMA_IMPORTS); @@ -383,7 +384,7 @@ private void createSaxonProcessor(String proctype, boolean schemaAware, Input sa cfgProcessor = new Processor(licensed); } - cfgProcessor.getUnderlyingConfiguration().getParseOptions().setSpaceStrippingRule(NoElementsSpaceStrippingRule.getInstance()); + cfgProcessor.getUnderlyingConfiguration().getParseOptions().withSpaceStrippingRule(NoElementsSpaceStrippingRule.getInstance()); String actualtype = Version.softwareEdition; if ((proctype != null) && !"he".equals(proctype) && (!actualtype.toLowerCase().equals(proctype))) { @@ -697,11 +698,11 @@ public void parse(XdmNode doc) { } for (XdmNode node : new AxisNodes(null, doc, Axis.CHILD, AxisNodes.PIPELINE)) { - String uri = node.getNodeName().getNamespaceURI(); + NamespaceUri uri = node.getNodeName().getNamespaceUri(); String localName = node.getNodeName().getLocalName(); - if (XProcConstants.NS_CALABASH_CONFIG.equals(uri) - || XProcConstants.NS_EXPROC_CONFIG.equals(uri)) { + if (XProcConstants.NS_CALABASH_CONFIG == uri + || XProcConstants.NS_EXPROC_CONFIG == uri) { if ("implementation".equals(localName)) { parseImplementation(node); } else if ("saxon-processor".equals(localName)) { @@ -786,8 +787,7 @@ public boolean isStepAvailable(QName type) { Class klass = implementations.get(type); try { Method method = klass.getMethod("isAvailable"); - Boolean available = (Boolean) method.invoke(null); - return available.booleanValue(); + return (Boolean) method.invoke(null); } catch (NoSuchMethodException e) { return true; // Failure to implement the method... } catch (InvocationTargetException e) { @@ -1154,7 +1154,7 @@ private void parseInput(XdmNode node) { documents.add(new ConfigDocument(href, node.getBaseURI().toASCIIString())); } else { - HashSet excludeURIs = S9apiUtils.excludeInlinePrefixes(node, node.getAttributeValue(_exclude_inline_prefixes)); + HashSet excludeURIs = S9apiUtils.excludeInlinePrefixes(node, node.getAttributeValue(_exclude_inline_prefixes)); documents.add(new ConfigDocument(docnodes, excludeURIs)); } } @@ -1180,7 +1180,7 @@ private void parsePipeline(XdmNode node) { } pipeline = new ConfigDocument(href, node.getBaseURI().toASCIIString()); } else { - HashSet excludeURIs = S9apiUtils.excludeInlinePrefixes(node, node.getAttributeValue(_exclude_inline_prefixes)); + HashSet excludeURIs = S9apiUtils.excludeInlinePrefixes(node, node.getAttributeValue(_exclude_inline_prefixes)); pipeline = new ConfigDocument(docnodes, excludeURIs); } } @@ -1258,18 +1258,15 @@ private void parseSafeMode(XdmNode node) { private void parseStepName(XdmNode node) { - String value = node.getStringValue().trim(); - stepName = value; + stepName = node.getStringValue().trim(); } private void parseURIResolver(XdmNode node) { - String value = node.getAttributeValue(_class_name); - uriResolver = value; + uriResolver = node.getAttributeValue(_class_name); } private void parseErrorListener(XdmNode node) { - String value = node.getAttributeValue(_class_name); - errorListener = value; + errorListener = node.getAttributeValue(_class_name); } private void parseImplementation(XdmNode node) { @@ -1340,21 +1337,18 @@ private void parseSerialization(XdmNode node) { } } - private HashSet checkAttributes(XdmNode node, String[] attrs, boolean optionShortcutsOk) { - HashSet hash = null; + private void checkAttributes(XdmNode node, String[] attrs, boolean optionShortcutsOk) { + HashSet hash = new HashSet<> (); if (attrs != null) { - hash = new HashSet (); - for (String attr : attrs) { - hash.add(attr); - } + Collections.addAll(hash, attrs); } HashSet options = null; for (XdmNode attr : new AxisNodes(node, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); - if ("".equals(aname.getNamespaceURI())) { + if (NamespaceUri.NULL == aname.getNamespaceUri()) { if (hash.contains(aname.getLocalName())) { - // ok + // ok } else if (optionShortcutsOk) { if (options == null) { options = new HashSet (); @@ -1363,13 +1357,11 @@ private HashSet checkAttributes(XdmNode node, String[] attrs, boolean op } else { throw new XProcException(node, "Configuration error: attribute \"" + aname + "\" not allowed on " + node.getNodeName()); } - } else if (XProcConstants.NS_XPROC.equals(aname.getNamespaceURI())) { + } else if (XProcConstants.NS_XPROC == aname.getNamespaceUri()) { throw new XProcException(node, "Configuration error: attribute \"" + aname + "\" not allowed on " + node.getNodeName()); } // Everything else is ok } - - return options; } private void checkBoolean(XdmNode node, String name, String value) { @@ -1384,14 +1376,14 @@ private class ConfigDocument implements ReadablePipe { private Vector nodes = null; private boolean read = false; private XdmNode doc = null; - private HashSet excludeUris = null; + private HashSet excludeUris = null; public ConfigDocument(String href, String base) { this.href = href; this.base = base; } - public ConfigDocument(Vector nodes, HashSet excludeUris) { + public ConfigDocument(Vector nodes, HashSet excludeUris) { this.nodes = nodes; this.excludeUris = excludeUris; } diff --git a/src/main/java/com/xmlcalabash/core/XProcConstants.java b/src/main/java/com/xmlcalabash/core/XProcConstants.java index 7430572b..87022154 100644 --- a/src/main/java/com/xmlcalabash/core/XProcConstants.java +++ b/src/main/java/com/xmlcalabash/core/XProcConstants.java @@ -20,6 +20,8 @@ package com.xmlcalabash.core; import javax.xml.XMLConstants; + +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import java.io.IOException; @@ -32,100 +34,102 @@ */ public class XProcConstants { public static final String XPROC_VERSION = initializeVersion(); - public static final String NS_XML = "http://www.w3.org/XML/1998/namespace"; - public static final String NS_XPROC = "http://www.w3.org/ns/xproc"; - public static final String NS_XPROC_ERROR = "http://www.w3.org/ns/xproc-error"; - public static final String NS_XPROC_ERROR_EX = "http://xproc.org/ns/errors"; - public static final String NS_XPROC_STEP = "http://www.w3.org/ns/xproc-step"; - public static final String NS_CALABASH_EX = "http://xmlcalabash.com/ns/extensions"; - public static final String NS_XMLSCHEMA = "http://www.w3.org/2001/XMLSchema"; - public static final String NS_CALABASH_CONFIG = "http://xmlcalabash.com/ns/configuration"; - public static final String NS_EXPROC_CONFIG = "http://exproc.org/ns/configuration"; - public static final String NS_EXPROC_FUNCTIONS = "http://exproc.org/standard/functions"; - - public static final String CALABASH_EXTENSION_LIBRARY_1_0 = "http://xmlcalabash.com/extension/steps/library-1.0.xpl"; - - public static final QName p_pipeline = new QName(NS_XPROC,"pipeline"); - public static final QName p_library = new QName(NS_XPROC,"library"); - public static final QName p_declare_step = new QName(NS_XPROC,"declare-step"); - public static final QName p_for_each = new QName(NS_XPROC,"for-each"); - public static final QName p_viewport = new QName(NS_XPROC,"viewport"); - public static final QName p_viewport_source = new QName(NS_XPROC,"viewport-source"); - public static final QName p_choose = new QName(NS_XPROC,"choose"); - public static final QName p_otherwise = new QName(NS_XPROC,"otherwise"); - public static final QName p_xpath_context = new QName(NS_XPROC,"xpath-context"); - public static final QName p_when = new QName(NS_XPROC,"when"); - public static final QName p_group = new QName(NS_XPROC,"group"); - public static final QName p_try = new QName(NS_XPROC,"try"); - public static final QName p_catch = new QName(NS_XPROC,"catch"); - public static final QName p_iteration_source = new QName(NS_XPROC,"iteration-source"); - public static final QName p_import = new QName(NS_XPROC,"import"); - public static final QName p_log = new QName(NS_XPROC,"log"); - public static final QName p_input = new QName(NS_XPROC,"input"); - public static final QName p_pipe = new QName(NS_XPROC,"pipe"); - public static final QName p_document = new QName(NS_XPROC,"document"); - public static final QName p_data = new QName(NS_XPROC,"data"); - public static final QName p_inline = new QName(NS_XPROC,"inline"); - public static final QName p_empty = new QName(NS_XPROC,"empty"); - public static final QName p_output = new QName(NS_XPROC,"output"); - public static final QName p_option = new QName(NS_XPROC,"option"); - public static final QName p_with_option = new QName(NS_XPROC,"with-option"); - public static final QName p_parameter = new QName(NS_XPROC,"parameter"); - public static final QName p_with_param = new QName(NS_XPROC,"with-param"); - public static final QName p_variable = new QName(NS_XPROC,"variable"); - public static final QName p_namespaces = new QName(NS_XPROC,"namespaces"); - public static final QName p_serialization = new QName(NS_XPROC,"serialization"); - public static final QName p_documentation = new QName(NS_XPROC, "documentation"); - public static final QName p_pipeinfo = new QName(NS_XPROC, "pipeinfo"); - public static final QName p_in_scope_names = new QName(NS_XPROC, "in-scope-names"); - public static final QName p_template = new QName(NS_XPROC, "template"); - public static final QName p_document_template = new QName(NS_XPROC, "document-template"); // DEPRECATED - - public static final QName cx_until_unchanged = new QName(NS_CALABASH_EX, "until-unchanged"); - - public static final QName p_iteration_position = new QName(XProcConstants.NS_XPROC, "iteration-position"); - - public static final QName p_episode = new QName(XProcConstants.NS_XPROC, "episode"); - public static final QName p_language = new QName(XProcConstants.NS_XPROC, "language"); - public static final QName p_product_name = new QName(XProcConstants.NS_XPROC, "product-name"); - public static final QName p_product_version = new QName(XProcConstants.NS_XPROC, "product-version"); - public static final QName p_vendor = new QName(XProcConstants.NS_XPROC, "vendor"); - public static final QName p_vendor_uri = new QName(XProcConstants.NS_XPROC, "vendor-uri"); - public static final QName p_version = new QName(XProcConstants.NS_XPROC, "version"); - public static final QName p_xpath_version = new QName(XProcConstants.NS_XPROC, "xpath-version"); - public static final QName p_psvi_supported = new QName(XProcConstants.NS_XPROC, "psvi-supported"); - - public static final QName c_body = new QName("c",XProcConstants.NS_XPROC_STEP, "body"); - public static final QName c_multipart = new QName("c",XProcConstants.NS_XPROC_STEP, "multipart"); - public static final QName c_header = new QName("c",XProcConstants.NS_XPROC_STEP, "header"); - public static final QName c_data = new QName("c",XProcConstants.NS_XPROC_STEP, "data"); - public static final QName c_content_type = new QName("c",XProcConstants.NS_XPROC_STEP, "content-type"); - public static final QName c_result = new QName("c",XProcConstants.NS_XPROC_STEP, "result"); - public static final QName c_request = new QName("c",XProcConstants.NS_XPROC_STEP, "request"); - public static final QName c_response = new QName("c",XProcConstants.NS_XPROC_STEP, "response"); - public static final QName c_param = new QName("c",NS_XPROC_STEP, "param"); - public static final QName c_param_set = new QName("c",NS_XPROC_STEP, "param-set"); - public static final QName c_errors = new QName("c",NS_XPROC_STEP, "errors"); - public static final QName c_error = new QName("c",NS_XPROC_STEP, "error"); - - public static final QName xml_base = new QName("xml", XMLConstants.XML_NS_URI, "base"); - public static final QName xml_lang = new QName("xml", XMLConstants.XML_NS_URI, "lang"); - public static final QName xml_id = new QName("xml", XMLConstants.XML_NS_URI, "id"); - - public static final QName cx_depends_on = new QName("cx",NS_CALABASH_EX,"depends-on"); - public static final QName cx_cache = new QName("cx",NS_CALABASH_EX,"cache"); - public static final QName cx_type = new QName("cx",NS_CALABASH_EX,"type"); - - public static final QName xs_QName = new QName("xs", NS_XMLSCHEMA, "QName"); - public static final QName xs_untypedAtomic = new QName("xs", NS_XMLSCHEMA, "untypedAtomic"); - public static final QName xs_string = new QName("xs", NS_XMLSCHEMA, "string"); - public static final QName xs_anyURI = new QName("xs", NS_XMLSCHEMA, "anyURI"); - public static final QName xs_NCName = new QName("xs", NS_XMLSCHEMA, "NCName"); - public static final QName xs_boolean = new QName("xs", NS_XMLSCHEMA, "boolean"); - public static final QName xs_decimal = new QName("xs", NS_XMLSCHEMA, "decimal"); - public static final QName xs_double = new QName("xs", NS_XMLSCHEMA, "double"); - public static final QName xs_integer = new QName("xs", NS_XMLSCHEMA, "integer"); - public static final QName xs_float = new QName("xs", NS_XMLSCHEMA, "float"); + + public static final NamespaceUri NS_XML = NamespaceUri.of("http://www.w3.org/XML/1998/namespace"); + public static final NamespaceUri NS_XML_ATTR = NamespaceUri.of("http://www.w3.org/2000/xmlns/"); + public static final NamespaceUri NS_XPROC = NamespaceUri.of("http://www.w3.org/ns/xproc"); + public static final NamespaceUri NS_XQT_ERRORS = NamespaceUri.of("http://www.w3.org/2005/xqt-errors"); + public static final NamespaceUri NS_XPROC_ERROR = NamespaceUri.of("http://www.w3.org/ns/xproc-error"); + public static final NamespaceUri NS_XPROC_ERROR_EX = NamespaceUri.of("http://xproc.org/ns/errors"); + public static final NamespaceUri NS_XPROC_STEP = NamespaceUri.of("http://www.w3.org/ns/xproc-step"); + public static final NamespaceUri NS_CALABASH_EX = NamespaceUri.of("http://xmlcalabash.com/ns/extensions"); + public static final NamespaceUri NS_XMLSCHEMA = NamespaceUri.of("http://www.w3.org/2001/XMLSchema"); + public static final NamespaceUri NS_CALABASH_CONFIG = NamespaceUri.of("http://xmlcalabash.com/ns/configuration"); + public static final NamespaceUri NS_EXPROC_CONFIG = NamespaceUri.of("http://exproc.org/ns/configuration"); + public static final NamespaceUri NS_EXPROC_FUNCTIONS = NamespaceUri.of("http://exproc.org/standard/functions"); + + public static final NamespaceUri CALABASH_EXTENSION_LIBRARY_1_0 = NamespaceUri.of("http://xmlcalabash.com/extension/steps/library-1.0.xpl"); + public static final QName p_pipeline = XProcConstants.qNameFor(NS_XPROC,"pipeline"); + public static final QName p_library = XProcConstants.qNameFor(NS_XPROC,"library"); + public static final QName p_declare_step = XProcConstants.qNameFor(NS_XPROC,"declare-step"); + public static final QName p_for_each = XProcConstants.qNameFor(NS_XPROC,"for-each"); + public static final QName p_viewport = XProcConstants.qNameFor(NS_XPROC,"viewport"); + public static final QName p_viewport_source = XProcConstants.qNameFor(NS_XPROC,"viewport-source"); + public static final QName p_choose = XProcConstants.qNameFor(NS_XPROC,"choose"); + public static final QName p_otherwise = XProcConstants.qNameFor(NS_XPROC,"otherwise"); + public static final QName p_xpath_context = XProcConstants.qNameFor(NS_XPROC,"xpath-context"); + public static final QName p_when = XProcConstants.qNameFor(NS_XPROC,"when"); + public static final QName p_group = XProcConstants.qNameFor(NS_XPROC,"group"); + public static final QName p_try = XProcConstants.qNameFor(NS_XPROC,"try"); + public static final QName p_catch = XProcConstants.qNameFor(NS_XPROC,"catch"); + public static final QName p_iteration_source = XProcConstants.qNameFor(NS_XPROC,"iteration-source"); + public static final QName p_import = XProcConstants.qNameFor(NS_XPROC,"import"); + public static final QName p_log = XProcConstants.qNameFor(NS_XPROC,"log"); + public static final QName p_input = XProcConstants.qNameFor(NS_XPROC,"input"); + public static final QName p_pipe = XProcConstants.qNameFor(NS_XPROC,"pipe"); + public static final QName p_document = XProcConstants.qNameFor(NS_XPROC,"document"); + public static final QName p_data = XProcConstants.qNameFor(NS_XPROC,"data"); + public static final QName p_inline = XProcConstants.qNameFor(NS_XPROC,"inline"); + public static final QName p_empty = XProcConstants.qNameFor(NS_XPROC,"empty"); + public static final QName p_output = XProcConstants.qNameFor(NS_XPROC,"output"); + public static final QName p_option = XProcConstants.qNameFor(NS_XPROC,"option"); + public static final QName p_with_option = XProcConstants.qNameFor(NS_XPROC,"with-option"); + public static final QName p_parameter = XProcConstants.qNameFor(NS_XPROC,"parameter"); + public static final QName p_with_param = XProcConstants.qNameFor(NS_XPROC,"with-param"); + public static final QName p_variable = XProcConstants.qNameFor(NS_XPROC,"variable"); + public static final QName p_namespaces = XProcConstants.qNameFor(NS_XPROC,"namespaces"); + public static final QName p_serialization = XProcConstants.qNameFor(NS_XPROC,"serialization"); + public static final QName p_documentation = XProcConstants.qNameFor(NS_XPROC, "documentation"); + public static final QName p_pipeinfo = XProcConstants.qNameFor(NS_XPROC, "pipeinfo"); + public static final QName p_in_scope_names = XProcConstants.qNameFor(NS_XPROC, "in-scope-names"); + public static final QName p_template = XProcConstants.qNameFor(NS_XPROC, "template"); + public static final QName p_document_template = XProcConstants.qNameFor(NS_XPROC, "document-template"); // DEPRECATED + + public static final QName cx_until_unchanged = XProcConstants.qNameFor(NS_CALABASH_EX, "until-unchanged"); + + public static final QName p_iteration_position = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "iteration-position"); + + public static final QName p_episode = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "episode"); + public static final QName p_language = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "language"); + public static final QName p_product_name = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "product-name"); + public static final QName p_product_version = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "product-version"); + public static final QName p_vendor = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "vendor"); + public static final QName p_vendor_uri = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "vendor-uri"); + public static final QName p_version = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "version"); + public static final QName p_xpath_version = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "xpath-version"); + public static final QName p_psvi_supported = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "psvi-supported"); + + public static final QName c_body = XProcConstants.qNameFor("c",XProcConstants.NS_XPROC_STEP, "body"); + public static final QName c_multipart = XProcConstants.qNameFor("c",XProcConstants.NS_XPROC_STEP, "multipart"); + public static final QName c_header = XProcConstants.qNameFor("c",XProcConstants.NS_XPROC_STEP, "header"); + public static final QName c_data = XProcConstants.qNameFor("c",XProcConstants.NS_XPROC_STEP, "data"); + public static final QName c_content_type = XProcConstants.qNameFor("c",XProcConstants.NS_XPROC_STEP, "content-type"); + public static final QName c_result = XProcConstants.qNameFor("c",XProcConstants.NS_XPROC_STEP, "result"); + public static final QName c_request = XProcConstants.qNameFor("c",XProcConstants.NS_XPROC_STEP, "request"); + public static final QName c_response = XProcConstants.qNameFor("c",XProcConstants.NS_XPROC_STEP, "response"); + public static final QName c_param = XProcConstants.qNameFor("c",NS_XPROC_STEP, "param"); + public static final QName c_param_set = XProcConstants.qNameFor("c",NS_XPROC_STEP, "param-set"); + public static final QName c_errors = XProcConstants.qNameFor("c",NS_XPROC_STEP, "errors"); + public static final QName c_error = XProcConstants.qNameFor("c",NS_XPROC_STEP, "error"); + + public static final QName xml_base = XProcConstants.qNameFor("xml", NamespaceUri.of(XMLConstants.XML_NS_URI), "base"); + public static final QName xml_lang = XProcConstants.qNameFor("xml", NamespaceUri.of(XMLConstants.XML_NS_URI), "lang"); + public static final QName xml_id = XProcConstants.qNameFor("xml", NamespaceUri.of(XMLConstants.XML_NS_URI), "id"); + + public static final QName cx_depends_on = XProcConstants.qNameFor("cx",NS_CALABASH_EX,"depends-on"); + public static final QName cx_cache = XProcConstants.qNameFor("cx",NS_CALABASH_EX,"cache"); + public static final QName cx_type = XProcConstants.qNameFor("cx",NS_CALABASH_EX,"type"); + + public static final QName xs_QName = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "QName"); + public static final QName xs_untypedAtomic = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "untypedAtomic"); + public static final QName xs_string = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "string"); + public static final QName xs_anyURI = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "anyURI"); + public static final QName xs_NCName = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "NCName"); + public static final QName xs_boolean = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "boolean"); + public static final QName xs_decimal = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "decimal"); + public static final QName xs_double = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "double"); + public static final QName xs_integer = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "integer"); + public static final QName xs_float = XProcConstants.qNameFor("xs", NS_XMLSCHEMA, "float"); /** Creates a new instance of XProcConstants */ @@ -151,19 +155,45 @@ private static String initializeVersion() { } } + public static QName qNameFor(NamespaceUri uri, String localName) { + if (uri == NS_XML) { + return XProcConstants.qNameFor("xml", uri, localName); + } + if (uri == NS_XPROC) { + return XProcConstants.qNameFor("p", uri, localName); + } + if (uri == NS_XMLSCHEMA) { + return XProcConstants.qNameFor("xs", uri, localName); + } + if (uri == NS_XPROC_STEP) { + return XProcConstants.qNameFor("c", uri, localName); + } + if (uri == NS_CALABASH_EX) { + return XProcConstants.qNameFor("cx", uri, localName); + } + return new QName(uri.toString(), localName); + } + + public static QName qNameFor(String prefix, NamespaceUri uri, String localName) { + if (prefix == null || "".equals(prefix)) { + return new QName(uri.toString(), localName); + } + return new QName(prefix, uri.toString(), localName); + } + public static QName staticError(int errno) { String localName = String.format("XS%04d", errno); - return new QName("err", NS_XPROC_ERROR, localName); + return XProcConstants.qNameFor("err", NS_XPROC_ERROR, localName); } public static QName dynamicError(int errno) { String localName = String.format("XD%04d", errno); - return new QName("err", NS_XPROC_ERROR, localName); + return XProcConstants.qNameFor("err", NS_XPROC_ERROR, localName); } public static QName stepError(int errno) { String localName = String.format("XC%04d", errno); - return new QName("err", NS_XPROC_ERROR, localName); + return XProcConstants.qNameFor("err", NS_XPROC_ERROR, localName); } } diff --git a/src/main/java/com/xmlcalabash/core/XProcException.java b/src/main/java/com/xmlcalabash/core/XProcException.java index 7960d643..5a3ea879 100644 --- a/src/main/java/com/xmlcalabash/core/XProcException.java +++ b/src/main/java/com/xmlcalabash/core/XProcException.java @@ -32,8 +32,8 @@ * @author ndw */ public class XProcException extends RuntimeException { - public static final QName err_E0001 = new QName(XProcConstants.NS_XPROC_ERROR_EX, "XE0001"); // invalid pipeline - public static final QName err_E0002 = new QName(XProcConstants.NS_XPROC_ERROR_EX, "XE0002"); // invalid configuration + public static final QName err_E0001 = XProcConstants.qNameFor(XProcConstants.NS_XPROC_ERROR_EX, "XE0001"); // invalid pipeline + public static final QName err_E0002 = XProcConstants.qNameFor(XProcConstants.NS_XPROC_ERROR_EX, "XE0002"); // invalid configuration private QName error = null; private Step step = null; diff --git a/src/main/java/com/xmlcalabash/core/XProcRuntime.java b/src/main/java/com/xmlcalabash/core/XProcRuntime.java index 9e8aff1a..065d921b 100644 --- a/src/main/java/com/xmlcalabash/core/XProcRuntime.java +++ b/src/main/java/com/xmlcalabash/core/XProcRuntime.java @@ -65,6 +65,7 @@ import net.sf.saxon.lib.FeatureKeys; import net.sf.saxon.om.AttributeMap; import net.sf.saxon.om.EmptyAttributeMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.ExtensionFunction; import net.sf.saxon.s9api.Processor; import net.sf.saxon.s9api.QName; @@ -675,7 +676,7 @@ public XPathCompiler newXPathCompiler(URI baseURI) { return newXPathCompiler(baseURI, null); } - public XPathCompiler newXPathCompiler(URI baseURI, HashMap nsbindings) { + public XPathCompiler newXPathCompiler(URI baseURI, HashMap nsbindings) { XPathCompiler compiler = processor.newXPathCompiler(); compiler.setSchemaAware(processor.isSchemaAware()); if (baseURI != null) { @@ -687,7 +688,7 @@ public XPathCompiler newXPathCompiler(URI baseURI, HashMap nsbind } if (nsbindings != null) { for (String prefix : nsbindings.keySet()) { - compiler.declareNamespace(prefix, nsbindings.get(prefix)); + compiler.declareNamespace(prefix, nsbindings.get(prefix).toString()); } } return compiler; @@ -931,6 +932,10 @@ public XdmNode parse(String uri, String base) { return parse(uri, base, false); } + public XdmNode parse(NamespaceUri uri, String base, boolean validate) { + return uriResolver.parse(uri.toString(), base, validate); + } + public XdmNode parse(String uri, String base, boolean validate) { return uriResolver.parse(uri, base, validate); } diff --git a/src/main/java/com/xmlcalabash/drivers/CalabashTask.java b/src/main/java/com/xmlcalabash/drivers/CalabashTask.java index 7fa5ebca..65ba8525 100644 --- a/src/main/java/com/xmlcalabash/drivers/CalabashTask.java +++ b/src/main/java/com/xmlcalabash/drivers/CalabashTask.java @@ -32,6 +32,7 @@ import com.xmlcalabash.util.Input.Type; import com.xmlcalabash.util.UserArgs; +import net.sf.saxon.om.NamespaceUri; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; @@ -548,7 +549,7 @@ public void addConfiguredNamespace(Namespace namespace) { } try { - userArgs.addBinding(namespace.getPrefix(), namespace.getURI()); + userArgs.addBinding(namespace.getPrefix(), NamespaceUri.of(namespace.getURI())); } catch (Exception e) { handleError(e); } diff --git a/src/main/java/com/xmlcalabash/drivers/Main.java b/src/main/java/com/xmlcalabash/drivers/Main.java index 8601ad55..7df40f57 100644 --- a/src/main/java/com/xmlcalabash/drivers/Main.java +++ b/src/main/java/com/xmlcalabash/drivers/Main.java @@ -530,9 +530,9 @@ private String errorMessage(QName code) { InputStream instream = getClass().getResourceAsStream("/etc/error-list.xml"); if (instream != null) { XdmNode doc = runtime.parse(new InputSource(instream)); - XdmSequenceIterator iter = doc.axisIterator(Axis.DESCENDANT, new QName(XProcConstants.NS_XPROC_ERROR,"error")); + XdmSequenceIterator iter = doc.axisIterator(Axis.DESCENDANT, XProcConstants.qNameFor(XProcConstants.NS_XPROC_ERROR,"error")); while (iter.hasNext()) { - XdmNode error = (XdmNode) iter.next(); + XdmNode error = iter.next(); if (code.getLocalName().equals(error.getAttributeValue(_code))) { return error.getStringValue(); } diff --git a/src/main/java/com/xmlcalabash/drivers/RunTestReport.java b/src/main/java/com/xmlcalabash/drivers/RunTestReport.java index 7e3ab66d..51cf334f 100644 --- a/src/main/java/com/xmlcalabash/drivers/RunTestReport.java +++ b/src/main/java/com/xmlcalabash/drivers/RunTestReport.java @@ -27,6 +27,7 @@ import com.xmlcalabash.model.RuntimeValue; import com.xmlcalabash.runtime.XPipeline; import com.xmlcalabash.util.*; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -837,20 +838,20 @@ public void setTitle(XdmNode title) { public void setDescription(XdmNode desc) { if (desc != null) { - XdmSequenceIterator iter = desc.axisIterator(Axis.CHILD); + XdmSequenceIterator iter = desc.axisIterator(Axis.CHILD); description = new Vector (); while (iter.hasNext()) { - XdmNode node = (XdmNode) iter.next(); - HashSet prefixes = new HashSet (); - XdmSequenceIterator nsiter = node.axisIterator(Axis.NAMESPACE); + XdmNode node = iter.next(); + HashSet prefixes = new HashSet<> (); + XdmSequenceIterator nsiter = node.axisIterator(Axis.NAMESPACE); while (nsiter.hasNext()){ - XdmNode nsnode = (XdmNode) nsiter.next(); + XdmNode nsnode = nsiter.next(); if (nsnode.getNodeName() != null) { String prefix = nsnode.getNodeName().getLocalName(); String uri = nsnode.getStringValue(); if (!"http://www.w3.org/1999/xhtml".equals(uri) && !"xml".equals(prefix)) { - prefixes.add(uri); + prefixes.add(NamespaceUri.of(uri)); } } } diff --git a/src/main/java/com/xmlcalabash/extensions/CssFormatter.java b/src/main/java/com/xmlcalabash/extensions/CssFormatter.java index 05b67d3d..3a8f85d0 100644 --- a/src/main/java/com/xmlcalabash/extensions/CssFormatter.java +++ b/src/main/java/com/xmlcalabash/extensions/CssFormatter.java @@ -6,6 +6,7 @@ import java.util.Properties; import com.xmlcalabash.core.XMLCalabash; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmNode; @@ -64,8 +65,8 @@ public void setOutput(String port, WritablePipe pipe) { } public void setParameter(QName name, RuntimeValue value) { - if (!"".equals(name.getNamespaceURI())) { - throw new XProcException(step.getNode(), "The cx:css-formatter parameters are in no namespace: " + name + " (" + name.getNamespaceURI() + ")"); + if (NamespaceUri.NULL != name.getNamespaceUri()) { + throw new XProcException(step.getNode(), "The cx:css-formatter parameters are in no namespace: " + name + " (" + name.getNamespaceUri().toString() + ")"); } options.setProperty(name.getLocalName(), value.getString()); } diff --git a/src/main/java/com/xmlcalabash/extensions/Eval.java b/src/main/java/com/xmlcalabash/extensions/Eval.java index 1f514281..fe4383dd 100644 --- a/src/main/java/com/xmlcalabash/extensions/Eval.java +++ b/src/main/java/com/xmlcalabash/extensions/Eval.java @@ -46,19 +46,19 @@ type = "{http://xmlcalabash.com/ns/extensions}eval") public class Eval extends DefaultStep { - protected final static QName cx_document = new QName("cx", XProcConstants.NS_CALABASH_EX, "document"); - protected final static QName cx_options = new QName("cx", XProcConstants.NS_CALABASH_EX, "options"); - protected final static QName cx_option = new QName("cx", XProcConstants.NS_CALABASH_EX, "option"); + protected final static QName cx_document = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "document"); + protected final static QName cx_options = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "options"); + protected final static QName cx_option = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "option"); private static final QName _port = new QName("port"); private static final QName _detailed = new QName("detailed"); private static final QName _step = new QName("step"); private static final QName _name = new QName("name"); private static final QName _value = new QName("value"); - private Vector sources = new Vector (); + private final Vector sources = new Vector (); private ReadablePipe pipeline = null; - private HashMap params = new HashMap (); - private Vector options = new Vector (); + private final HashMap params = new HashMap (); + private final Vector options = new Vector (); private WritablePipe result = null; /* diff --git a/src/main/java/com/xmlcalabash/extensions/GetCookies.java b/src/main/java/com/xmlcalabash/extensions/GetCookies.java index 9033dd06..10182546 100644 --- a/src/main/java/com/xmlcalabash/extensions/GetCookies.java +++ b/src/main/java/com/xmlcalabash/extensions/GetCookies.java @@ -41,9 +41,9 @@ public class GetCookies extends DefaultStep { private static final QName _expires = new QName("","expires"); private static final QName _version = new QName("", "version"); private static final QName _secure = new QName("","secure"); - private static final QName c_cookies = new QName("c", XProcConstants.NS_XPROC_STEP, "cookies"); - private static final QName c_cookie = new QName("c", XProcConstants.NS_XPROC_STEP, "cookie"); - private static DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + private static final QName c_cookies = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "cookies"); + private static final QName c_cookie = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "cookie"); + private static final DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); private WritablePipe result = null; /* diff --git a/src/main/java/com/xmlcalabash/extensions/HashDocument.java b/src/main/java/com/xmlcalabash/extensions/HashDocument.java index e9fa9e6b..e8e7ec11 100644 --- a/src/main/java/com/xmlcalabash/extensions/HashDocument.java +++ b/src/main/java/com/xmlcalabash/extensions/HashDocument.java @@ -32,6 +32,7 @@ import com.xmlcalabash.model.RuntimeValue; import com.xmlcalabash.runtime.XAtomicStep; import com.xmlcalabash.util.*; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.Serializer; @@ -50,18 +51,18 @@ public class HashDocument extends DefaultStep { private static final QName _content_type = new QName("content-type"); - private static final QName c_encoding = new QName("c", XProcConstants.NS_XPROC_STEP, "encoding"); - private static final QName c_body = new QName("c", XProcConstants.NS_XPROC_STEP, "body"); - private static final QName c_json = new QName("c", XProcConstants.NS_XPROC_STEP, "json"); - private static final QName cx_decode = new QName("cx", XProcConstants.NS_CALABASH_EX, "decode"); + private static final QName c_encoding =XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "encoding"); + private static final QName c_body = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "body"); + private static final QName c_json = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "json"); + private static final QName cx_decode = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "decode"); private static final QName _algorithm = new QName("", "algorithm"); private static final QName _hash_version = new QName("", "hash-version"); private static final QName _crc = new QName("", "crc"); private static final QName _md = new QName("", "md"); private static final QName _sha = new QName("", "sha"); - private static final QName _hmac = new QName("cx", XProcConstants.NS_CALABASH_EX, "hmac"); - private static final QName _accessKey = new QName("cx", XProcConstants.NS_CALABASH_EX, "accessKey"); - private HashMap params = new HashMap (); + private static final QName _hmac = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "hmac"); + private static final QName _accessKey = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "accessKey"); + private final HashMap params = new HashMap (); private ReadablePipe source = null; @@ -116,10 +117,10 @@ public void run() throws SaxonApiException { String contentType = root.getAttributeValue(_content_type); byte[] bytes = null; if (("true".equals(decode) || "1".equals(decode)) - && ((XProcConstants.NS_XPROC_STEP.equals(root.getNodeName().getNamespaceURI()) + && ((XProcConstants.NS_XPROC_STEP == root.getNodeName().getNamespaceUri()) && "base64".equals(root.getAttributeValue(_encoding))) - || ("".equals(root.getNodeName().getNamespaceURI()) - && "base64".equals(root.getAttributeValue(c_encoding))))) { + || (NamespaceUri.NULL == root.getNodeName().getNamespaceUri() + && "base64".equals(root.getAttributeValue(c_encoding)))) { bytes = binaryContent(doc); } else if (("true".equals(decode) || "1".equals(decode)) && XProcConstants.c_result.equals(root.getNodeName()) @@ -131,9 +132,9 @@ public void run() throws SaxonApiException { && ("application/json".equals(contentType) || "text/json".equals(contentType))) || c_json.equals(root.getNodeName())) - || JSONtoXML.JSONX_NS.equals(root.getNodeName().getNamespaceURI()) - || JSONtoXML.JXML_NS.equals(root.getNodeName().getNamespaceURI()) - || JSONtoXML.MLJS_NS.equals(root.getNodeName().getNamespaceURI()))) { + || JSONtoXML.JSONX_NS == root.getNodeName().getNamespaceUri() + || JSONtoXML.JXML_NS == root.getNodeName().getNamespaceUri() + || JSONtoXML.MLJS_NS == root.getNodeName().getNamespaceUri())) { bytes = jsonContent(doc); } else { bytes = XmlContent(doc); diff --git a/src/main/java/com/xmlcalabash/extensions/JavaProperties.java b/src/main/java/com/xmlcalabash/extensions/JavaProperties.java index 6fd7f643..8d292140 100644 --- a/src/main/java/com/xmlcalabash/extensions/JavaProperties.java +++ b/src/main/java/com/xmlcalabash/extensions/JavaProperties.java @@ -38,8 +38,8 @@ public class JavaProperties extends DefaultStep { private static final String ACCEPT_TEXT = "text/plain, text/*, */*"; - private static final QName c_param_set = new QName("c", XProcConstants.NS_XPROC_STEP, "param-set"); - private static final QName c_param = new QName("c", XProcConstants.NS_XPROC_STEP, "param"); + private static final QName c_param_set = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "param-set"); + private static final QName c_param = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "param"); private static final QName _href = new QName("","href"); private static final QName _name = new QName("name"); private static final QName _namespace = new QName("namespace"); diff --git a/src/main/java/com/xmlcalabash/extensions/NamespaceDelete.java b/src/main/java/com/xmlcalabash/extensions/NamespaceDelete.java index 08309657..85064f9f 100644 --- a/src/main/java/com/xmlcalabash/extensions/NamespaceDelete.java +++ b/src/main/java/com/xmlcalabash/extensions/NamespaceDelete.java @@ -8,6 +8,7 @@ import com.xmlcalabash.runtime.XAtomicStep; import com.xmlcalabash.util.MessageFormatter; import com.xmlcalabash.util.S9apiUtils; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmNode; @@ -56,7 +57,7 @@ public void reset() { public void run() throws SaxonApiException { super.run(); - HashSet excludeUris = S9apiUtils.excludeInlinePrefixes(step.getNode(), getOption(_prefixes).getString()); + HashSet excludeUris = S9apiUtils.excludeInlinePrefixes(step.getNode(), getOption(_prefixes).getString()); while (source.moreDocuments()) { XdmNode doc = source.read(); diff --git a/src/main/java/com/xmlcalabash/extensions/ReportErrors.java b/src/main/java/com/xmlcalabash/extensions/ReportErrors.java index 72e06cac..35bb4b73 100644 --- a/src/main/java/com/xmlcalabash/extensions/ReportErrors.java +++ b/src/main/java/com/xmlcalabash/extensions/ReportErrors.java @@ -29,7 +29,7 @@ type = "{http://xmlcalabash.com/ns/extensions}report-errors") public class ReportErrors extends DefaultStep { - private static final QName c_error = new QName(XProcConstants.NS_XPROC_STEP, "error"); + private static final QName c_error = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "error"); private static final QName _code = new QName("code"); private static final QName _code_prefix = new QName("code-prefix"); private static final QName _code_namespace = new QName("code-namespace"); diff --git a/src/main/java/com/xmlcalabash/extensions/SetCookies.java b/src/main/java/com/xmlcalabash/extensions/SetCookies.java index 91c97987..b4f9bc1c 100644 --- a/src/main/java/com/xmlcalabash/extensions/SetCookies.java +++ b/src/main/java/com/xmlcalabash/extensions/SetCookies.java @@ -45,10 +45,10 @@ public class SetCookies extends DefaultStep { private static final QName _expires = new QName("","expires"); private static final QName _version = new QName("", "version"); private static final QName _secure = new QName("","secure"); - private static final QName c_cookies = new QName("c", XProcConstants.NS_XPROC_STEP, "cookies"); - private static final QName c_cookie = new QName("c", XProcConstants.NS_XPROC_STEP, "cookie"); - private static DateFormat iso8601tz = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); - private static DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + private static final QName c_cookies = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "cookies"); + private static final QName c_cookie =XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "cookie"); + private static final DateFormat iso8601tz = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + private static final DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); private ReadablePipe source = null; /* diff --git a/src/main/java/com/xmlcalabash/extensions/Unzip.java b/src/main/java/com/xmlcalabash/extensions/Unzip.java index 2466edd4..2e90c4e1 100644 --- a/src/main/java/com/xmlcalabash/extensions/Unzip.java +++ b/src/main/java/com/xmlcalabash/extensions/Unzip.java @@ -51,12 +51,12 @@ public class Unzip extends DefaultStep { private static final String ACCEPT_ZIP = "application/zip, */*"; protected final static QName _href = new QName("", "href"); protected final static QName _content_type = new QName("", "content-type"); - protected final static QName c_zipfile = new QName("c", XProcConstants.NS_XPROC_STEP, "zipfile"); - protected final static QName c_file = new QName("c", XProcConstants.NS_XPROC_STEP, "file"); + protected final static QName c_zipfile = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "zipfile"); + protected final static QName c_file = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "file"); protected final static QName _file = new QName("", "file"); protected final static QName _charset = new QName("", "charset"); protected final static QName _name = new QName("", "name"); - protected final static QName c_directory = new QName("c", XProcConstants.NS_XPROC_STEP, "directory"); + protected final static QName c_directory = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "directory"); protected final static QName _compressed_size = new QName("", "compressed-size"); protected final static QName _comment = new QName("", "comment"); protected final static QName _size = new QName("", "size"); diff --git a/src/main/java/com/xmlcalabash/extensions/UriInfo.java b/src/main/java/com/xmlcalabash/extensions/UriInfo.java index 0d5ba147..b3ed3557 100644 --- a/src/main/java/com/xmlcalabash/extensions/UriInfo.java +++ b/src/main/java/com/xmlcalabash/extensions/UriInfo.java @@ -48,7 +48,7 @@ public class UriInfo extends DefaultStep { private static final QName _password = new QName("password"); private static final QName _auth_method = new QName("auth_method"); private static final QName _send_authorization = new QName("send_authorization"); - protected final static QName c_uriinfo = new QName("c", XProcConstants.NS_XPROC_STEP, "uri-info"); + protected final static QName c_uriinfo = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "uri-info"); private static final QName _uri = new QName("uri"); private static final QName _readable = new QName("readable"); @@ -109,7 +109,7 @@ public void run() throws SaxonApiException { if (f.exists()) { attr = attr.put(TypeUtils.attributeInfo(_writable, f.canWrite() ? "true" : "false")); - attr = attr.put(TypeUtils.attributeInfo(_size, "" + f.length())); + attr = attr.put(TypeUtils.attributeInfo(_size, String.valueOf(f.length()))); attr = attr.put(TypeUtils.attributeInfo(_absolute, f.isAbsolute() ? "true" : "false")); attr = attr.put(TypeUtils.attributeInfo(_directory, f.isDirectory() ? "true" : "false")); attr = attr.put(TypeUtils.attributeInfo(_hidden, f.isHidden() ? "true" : "false")); diff --git a/src/main/java/com/xmlcalabash/extensions/Zip.java b/src/main/java/com/xmlcalabash/extensions/Zip.java index 2a8203d9..ef219798 100644 --- a/src/main/java/com/xmlcalabash/extensions/Zip.java +++ b/src/main/java/com/xmlcalabash/extensions/Zip.java @@ -21,6 +21,7 @@ import com.xmlcalabash.util.XMLtoJSON; import net.sf.saxon.om.AttributeMap; import net.sf.saxon.om.EmptyAttributeMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.om.SingletonAttributeMap; import net.sf.saxon.s9api.Axis; import net.sf.saxon.s9api.QName; @@ -74,11 +75,11 @@ public class Zip extends DefaultStep { protected final static QName _command = new QName("", "command"); protected final static QName _compression_method = new QName("", "compression-method"); protected final static QName _compression_level = new QName("", "compression-level"); - protected final static QName c_zip_manifest = new QName("c", XProcConstants.NS_XPROC_STEP, "zip-manifest"); - protected final static QName c_zipfile = new QName("c", XProcConstants.NS_XPROC_STEP, "zipfile"); - protected final static QName c_entry = new QName("c", XProcConstants.NS_XPROC_STEP, "entry"); - protected final static QName c_file = new QName("c", XProcConstants.NS_XPROC_STEP, "file"); - protected final static QName c_directory = new QName("c", XProcConstants.NS_XPROC_STEP, "directory"); + protected final static QName c_zip_manifest = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "zip-manifest"); + protected final static QName c_zipfile = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "zipfile"); + protected final static QName c_entry = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "entry"); + protected final static QName c_file = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "file"); + protected final static QName c_directory = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "directory"); protected final static QName _compressed_size = new QName("", "compressed-size"); protected final static QName _comment = new QName("", "comment"); protected final static QName _size = new QName("", "size"); @@ -87,13 +88,13 @@ public class Zip extends DefaultStep { private static final QName _detailed = new QName("detailed"); private static final QName _status = new QName("status"); private static final QName _value = new QName("value"); - private static final QName c_encoding = new QName("c", XProcConstants.NS_XPROC_STEP, "encoding"); - private static final QName c_body = new QName("c", XProcConstants.NS_XPROC_STEP, "body"); - private static final QName c_json = new QName("c", XProcConstants.NS_XPROC_STEP, "json"); + private static final QName c_encoding = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "encoding"); + private static final QName c_body = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "body"); + private static final QName c_json = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "json"); private static final QName _content_type = new QName("content-type"); private final static int bufsize = 8192; - private final static QName serializerAttrs[] = { + private final static QName[] serializerAttrs = { _byte_order_mark, _cdata_section_elements, _doctype_public, @@ -114,8 +115,8 @@ public class Zip extends DefaultStep { private ReadablePipe source = null; private ReadablePipe manifest = null; private WritablePipe result = null; - private Map zipManifest = new LinkedHashMap (); - private Map srcManifest = new LinkedHashMap (); + private final Map zipManifest = new LinkedHashMap (); + private final Map srcManifest = new LinkedHashMap (); /* Creates a new instance of Unzip */ public Zip(XProcRuntime runtime, XAtomicStep step) { @@ -265,16 +266,13 @@ private void readFile(TreeWriter tree, URI id, String zipFn, final DatatypeFacto private void readStream(TreeWriter tree, URI id, InputStream stream, final DatatypeFactory dfactory) throws IOException { - ZipInputStream zipStream = new ZipInputStream(stream); - try { + try (ZipInputStream zipStream = new ZipInputStream(stream)) { ZipEntry entry = zipStream.getNextEntry(); while (entry != null) { processEntry(tree, entry, dfactory); entry = zipStream.getNextEntry(); } - } finally { - zipStream.close(); } } @@ -463,11 +461,7 @@ public void delete(ZipInputStream inZip, ZipOutputStream outZip) { ZipEntry entry; while ((entry = inZip.getNextEntry()) != null) { String name = entry.getName(); - boolean delete = false; - - if (zipManifest.containsKey(name)) { - delete = true; - } + boolean delete = zipManifest.containsKey(name); if (!delete) { outZip.putNextEntry(entry); @@ -583,9 +577,9 @@ protected void store(FileToZip file, XdmNode doc, OutputStream out) throws Saxon XdmNode root = S9apiUtils.getDocumentElement(doc); assert root != null; - if (((XProcConstants.NS_XPROC_STEP.equals(root.getNodeName().getNamespaceURI()) + if (((XProcConstants.NS_XPROC_STEP == root.getNodeName().getNamespaceUri() && "base64".equals(root.getAttributeValue(_encoding))) - || ("".equals(root.getNodeName().getNamespaceURI()) + || (NamespaceUri.NULL == root.getNodeName().getNamespaceUri() && "base64".equals(root.getAttributeValue(c_encoding))))) { storeBinary(file, doc, out); } else if (XProcConstants.c_result.equals(root.getNodeName()) @@ -597,9 +591,9 @@ protected void store(FileToZip file, XdmNode doc, OutputStream out) throws Saxon && ("application/json".equals(root.getAttributeValue(_content_type)) || "text/json".equals(root.getAttributeValue(_content_type)))) || c_json.equals(root.getNodeName())) - || JSONtoXML.JSONX_NS.equals(root.getNodeName().getNamespaceURI()) - || JSONtoXML.JXML_NS.equals(root.getNodeName().getNamespaceURI()) - || JSONtoXML.MLJS_NS.equals(root.getNodeName().getNamespaceURI()))) { + || JSONtoXML.JSONX_NS == root.getNodeName().getNamespaceUri() + || JSONtoXML.JXML_NS == root.getNodeName().getNamespaceUri() + || JSONtoXML.MLJS_NS == root.getNodeName().getNamespaceUri())) { storeJSON(file, doc, out); } else { storeXML(file, doc, out); diff --git a/src/main/java/com/xmlcalabash/extensions/fileutils/Head.java b/src/main/java/com/xmlcalabash/extensions/fileutils/Head.java index 998f5bbd..7efe9222 100644 --- a/src/main/java/com/xmlcalabash/extensions/fileutils/Head.java +++ b/src/main/java/com/xmlcalabash/extensions/fileutils/Head.java @@ -40,7 +40,7 @@ public class Head extends DefaultStep { private static final QName _href = new QName("href"); private static final QName _count = new QName("count"); private static final QName _fail_on_error = new QName("fail-on-error"); - private static final QName c_line = new QName("c", XProcConstants.NS_XPROC_STEP, "line"); + private static final QName c_line = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "line"); private WritablePipe result = null; diff --git a/src/main/java/com/xmlcalabash/extensions/fileutils/Info.java b/src/main/java/com/xmlcalabash/extensions/fileutils/Info.java index 09d84ea0..90f55492 100644 --- a/src/main/java/com/xmlcalabash/extensions/fileutils/Info.java +++ b/src/main/java/com/xmlcalabash/extensions/fileutils/Info.java @@ -50,12 +50,12 @@ public class Info extends DefaultStep { private static final QName _auth_method = new QName("auth_method"); private static final QName _send_authorization = new QName("send-authorization"); private static final QName _fail_on_error = new QName("fail-on-error"); - protected final static QName c_uri = new QName("c", XProcConstants.NS_XPROC_STEP, "uri"); - protected final static QName c_directory = new QName("c", XProcConstants.NS_XPROC_STEP, "directory"); - protected final static QName c_file = new QName("c", XProcConstants.NS_XPROC_STEP, "file"); - protected final static QName c_other = new QName("c", XProcConstants.NS_XPROC_STEP, "other"); - protected final static QName c_error = new QName("c", XProcConstants.NS_XPROC_STEP, "error"); - protected final static QName err_fu01 = new QName("err", XProcConstants.NS_XPROC_ERROR, "FU01"); + protected final static QName c_uri = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "uri"); + protected final static QName c_directory = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "directory"); + protected final static QName c_file = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "file"); + protected final static QName c_other = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "other"); + protected final static QName c_error = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "error"); + protected final static QName err_fu01 = XProcConstants.qNameFor(XProcConstants.NS_XPROC_ERROR, "FU01"); private static final QName _uri = new QName("uri"); private static final QName _readable = new QName("readable"); diff --git a/src/main/java/com/xmlcalabash/extensions/fileutils/Tail.java b/src/main/java/com/xmlcalabash/extensions/fileutils/Tail.java index e2ff5cac..6ed011e8 100644 --- a/src/main/java/com/xmlcalabash/extensions/fileutils/Tail.java +++ b/src/main/java/com/xmlcalabash/extensions/fileutils/Tail.java @@ -41,7 +41,7 @@ public class Tail extends DefaultStep { private static final QName _href = new QName("href"); private static final QName _count = new QName("count"); private static final QName _fail_on_error = new QName("fail-on-error"); - private static final QName c_line = new QName("c", XProcConstants.NS_XPROC_STEP, "line"); + private static final QName c_line = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "line"); private WritablePipe result = null; diff --git a/src/main/java/com/xmlcalabash/extensions/osutils/Cwd.java b/src/main/java/com/xmlcalabash/extensions/osutils/Cwd.java index cdfd3333..dc70d422 100644 --- a/src/main/java/com/xmlcalabash/extensions/osutils/Cwd.java +++ b/src/main/java/com/xmlcalabash/extensions/osutils/Cwd.java @@ -54,7 +54,7 @@ public void run() throws SaxonApiException { tree.startDocument(step.getNode().getBaseURI()); tree.addStartElement(XProcConstants.c_result); - tree.addStartElement(new QName("c", XProcConstants.NS_XPROC_STEP, "cwd")); + tree.addStartElement(XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "cwd")); tree.addText(System.getProperty("user.dir")); tree.addEndElement(); diff --git a/src/main/java/com/xmlcalabash/extensions/osutils/Env.java b/src/main/java/com/xmlcalabash/extensions/osutils/Env.java index e6fd39a7..4c8720af 100644 --- a/src/main/java/com/xmlcalabash/extensions/osutils/Env.java +++ b/src/main/java/com/xmlcalabash/extensions/osutils/Env.java @@ -35,7 +35,7 @@ "{http://xmlcalabash.com/ns/extensions/osutils}env") public class Env extends DefaultStep { - private static final QName c_env = new QName("c", XProcConstants.NS_XPROC_STEP, "env"); + private static final QName c_env = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "env"); private static final QName _name = new QName("name"); private static final QName _value = new QName("value"); diff --git a/src/main/java/com/xmlcalabash/io/PipeLogger.java b/src/main/java/com/xmlcalabash/io/PipeLogger.java index 990bd9fb..198cbca0 100644 --- a/src/main/java/com/xmlcalabash/io/PipeLogger.java +++ b/src/main/java/com/xmlcalabash/io/PipeLogger.java @@ -25,8 +25,8 @@ * To change this template use File | Settings | File Templates. */ public class PipeLogger { - private static final QName cx_basename = new QName("cx", XProcConstants.NS_CALABASH_EX, "basename"); - private static final QName cx_logstyle = new QName("cx", XProcConstants.NS_CALABASH_EX, "logstyle"); + private static final QName cx_basename = XProcConstants.qNameFor("cx", XProcConstants.NS_CALABASH_EX, "basename"); + private static final QName cx_logstyle = XProcConstants.qNameFor("cx", XProcConstants.NS_CALABASH_EX, "logstyle"); private Log log = null; private Serializer serializer = null; private PrintStream stream = null; diff --git a/src/main/java/com/xmlcalabash/io/ReadableData.java b/src/main/java/com/xmlcalabash/io/ReadableData.java index 0ab969b1..62e239d4 100644 --- a/src/main/java/com/xmlcalabash/io/ReadableData.java +++ b/src/main/java/com/xmlcalabash/io/ReadableData.java @@ -51,11 +51,11 @@ */ public class ReadableData implements ReadablePipe { public static final QName _contentType = new QName("","content-type"); - public static final QName c_contentType = new QName("c",XProcConstants.NS_XPROC_STEP, "content-type"); + public static final QName c_contentType = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "content-type"); public static final QName _encoding = new QName("","encoding"); - public static final QName c_encoding = new QName("c",XProcConstants.NS_XPROC_STEP, "encoding"); + public static final QName c_encoding = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "encoding"); private String contentType = null; - private Logger logger = LoggerFactory.getLogger(ReadablePipe.class); + private final Logger logger = LoggerFactory.getLogger(ReadablePipe.class); private int pos = 0; private QName wrapper = null; private String uri = null; diff --git a/src/main/java/com/xmlcalabash/io/ReadableInline.java b/src/main/java/com/xmlcalabash/io/ReadableInline.java index cf42f6bd..a4f90249 100644 --- a/src/main/java/com/xmlcalabash/io/ReadableInline.java +++ b/src/main/java/com/xmlcalabash/io/ReadableInline.java @@ -26,6 +26,7 @@ import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.util.*; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.om.NodeInfo; import net.sf.saxon.om.TreeInfo; import net.sf.saxon.s9api.*; @@ -48,7 +49,7 @@ public class ReadableInline implements ReadablePipe { private Step reader = null; /* Creates a new instance of ReadableInline */ - public ReadableInline(XProcRuntime runtime, Vector nodes, HashSet excludeNS) { + public ReadableInline(XProcRuntime runtime, Vector nodes, HashSet excludeNS) { this.runtime = runtime; documents = new DocumentSequence(runtime); XdmDestination dest = new XdmDestination(); diff --git a/src/main/java/com/xmlcalabash/library/AddAttribute.java b/src/main/java/com/xmlcalabash/library/AddAttribute.java index c97183da..0d7b7be3 100644 --- a/src/main/java/com/xmlcalabash/library/AddAttribute.java +++ b/src/main/java/com/xmlcalabash/library/AddAttribute.java @@ -20,6 +20,7 @@ package com.xmlcalabash.library; import com.xmlcalabash.core.XMLCalabash; +import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.io.ReadablePipe; @@ -32,6 +33,7 @@ import net.sf.saxon.event.ReceiverOption; import net.sf.saxon.om.AttributeInfo; import net.sf.saxon.om.AttributeMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmNode; @@ -106,11 +108,9 @@ public void run() throws SaxonApiException { if ("xmlns".equals(attrName.getLocalName()) || "xmlns".equals(attrName.getPrefix()) - || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attrName.getNamespaceURI()) - || (!"xml".equals(attrName.getPrefix()) - && XMLConstants.XML_NS_URI.equals(attrName.getNamespaceURI())) - || ("xml".equals(attrName.getPrefix()) - && !XMLConstants.XML_NS_URI.equals(attrName.getNamespaceURI()))) { + || attrName.getNamespaceUri() == XProcConstants.NS_XML_ATTR + || (!"xml".equals(attrName.getPrefix()) && attrName.getNamespaceUri() == XProcConstants.NS_XML) + || ("xml".equals(attrName.getPrefix()) && attrName.getNamespaceUri() != XProcConstants.NS_XML)) { throw XProcException.stepError(59); } @@ -137,12 +137,12 @@ public AttributeMap processAttributes(XdmNode node, AttributeMap matchingAttribu public boolean processStartElement(XdmNode node, AttributeMap attributes) { QName instanceAttrName = attrName; - if (attrName.getNamespaceURI() != null && !"".equals(attrName.getNamespaceURI())) { + if (attrName.getNamespaceUri() != NamespaceUri.NULL) { // If the requested prefix is already bound to something else, drop it String prefix = attrName.getPrefix(); for (AttributeInfo attr : attributes) { if (prefix.equals(attr.getNodeName().getPrefix()) - && !attrName.getNamespaceURI().equals(attr.getNodeName().getURI())) { + && attrName.getNamespaceUri() != NamespaceUri.of(attr.getNodeName().getURI())) { prefix = ""; } } @@ -163,7 +163,7 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { } } - instanceAttrName = new QName(aprefix, attrName.getNamespaceURI(), attrName.getLocalName()); + instanceAttrName = new QName(aprefix, attrName.getNamespaceUri().toString(), attrName.getLocalName()); } } diff --git a/src/main/java/com/xmlcalabash/library/Compare.java b/src/main/java/com/xmlcalabash/library/Compare.java index f30b7dc1..09118868 100644 --- a/src/main/java/com/xmlcalabash/library/Compare.java +++ b/src/main/java/com/xmlcalabash/library/Compare.java @@ -49,7 +49,7 @@ type = "{http://www.w3.org/ns/xproc}compare") public class Compare extends DefaultStep { - private static final QName c_result = new QName("c", XProcConstants.NS_XPROC_STEP, "result"); + private static final QName c_result = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "result"); private static final QName doca = new QName("","doca"); private static final QName docb = new QName("","docb"); private static final QName _fail_if_not_equal = new QName("","fail-if-not-equal"); diff --git a/src/main/java/com/xmlcalabash/library/Count.java b/src/main/java/com/xmlcalabash/library/Count.java index 3863db93..6b766970 100644 --- a/src/main/java/com/xmlcalabash/library/Count.java +++ b/src/main/java/com/xmlcalabash/library/Count.java @@ -41,7 +41,7 @@ type = "{http://www.w3.org/ns/xproc}count") public class Count extends DefaultStep { - private static final QName c_result = new QName("c", XProcConstants.NS_XPROC_STEP, "result"); + private static final QName c_result = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "result"); private static final QName _limit = new QName("limit"); private ReadablePipe source = null; private WritablePipe result = null; diff --git a/src/main/java/com/xmlcalabash/library/DefaultStep.java b/src/main/java/com/xmlcalabash/library/DefaultStep.java index cae34c4c..0dcbad8e 100644 --- a/src/main/java/com/xmlcalabash/library/DefaultStep.java +++ b/src/main/java/com/xmlcalabash/library/DefaultStep.java @@ -13,6 +13,7 @@ import net.sf.saxon.lib.NamespaceConstant; import net.sf.saxon.om.NamespaceBinding; import net.sf.saxon.om.NamespaceMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.SaxonApiUncheckedException; @@ -55,7 +56,7 @@ public class DefaultStep implements XProcStep { public static final QName _standalone = new QName("", "standalone"); public static final QName _undeclare_prefixes = new QName("", "undeclare-prefixes"); public static final QName _version = new QName("", "version"); - public static final QName cx_message = new QName(XProcConstants.NS_CALABASH_EX, "message"); + public static final QName cx_message = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "message"); protected Logger logger = null; private HashMap options = null; @@ -171,7 +172,7 @@ public void run() throws SaxonApiException { public void run(String addnLog) { String type = null; - if (XProcConstants.NS_XPROC.equals(step.getType().getNamespaceURI())) { + if (XProcConstants.NS_XPROC == step.getType().getNamespaceUri()) { type = step.getType().getLocalName(); } else { type = step.getType().getClarkName(); @@ -183,7 +184,7 @@ public void run(String addnLog) { } } - protected String prefixFor(NamespaceMap nsmap, String preferredPrefix, String uri) { + protected String prefixFor(NamespaceMap nsmap, String preferredPrefix, NamespaceUri uri) { if (preferredPrefix == null) { return prefixFor(nsmap, uri); } @@ -192,16 +193,16 @@ protected String prefixFor(NamespaceMap nsmap, String preferredPrefix, String ur return "xml"; } - String curMapping = nsmap.getURI(preferredPrefix); - if (curMapping == null || uri.equals(curMapping)) { + NamespaceUri curMapping = nsmap.getURIForPrefix(preferredPrefix, false); + if (curMapping == null || uri.equals(curMapping.toString())) { return preferredPrefix; } else { return prefixFor(nsmap, uri); } } - protected String prefixFor(NamespaceMap nsmap, String uri) { - if (NamespaceConstant.XML.equals(uri)) { + protected String prefixFor(NamespaceMap nsmap, NamespaceUri uri) { + if (uri == XProcConstants.NS_XML) { return "xml"; } @@ -312,7 +313,7 @@ public Serializer makeSerializer() { return serializer; } - public Vector evaluateXPath(XdmNode doc, HashMap nsBindings, String xpath, HashMap globals) { + public Vector evaluateXPath(XdmNode doc, HashMap nsBindings, String xpath, HashMap globals) { Vector results = new Vector (); try { diff --git a/src/main/java/com/xmlcalabash/library/DirectoryList.java b/src/main/java/com/xmlcalabash/library/DirectoryList.java index fdede0f7..0f635366 100644 --- a/src/main/java/com/xmlcalabash/library/DirectoryList.java +++ b/src/main/java/com/xmlcalabash/library/DirectoryList.java @@ -62,9 +62,9 @@ public class DirectoryList extends DefaultStep { private static final QName _path = new QName("", "path"); private static final QName _include_filter = new QName("", "include-filter"); private static final QName _exclude_filter = new QName("", "exclude-filter"); - private static final QName c_directory = new QName("c", XProcConstants.NS_XPROC_STEP, "directory"); - private static final QName c_file = new QName("c", XProcConstants.NS_XPROC_STEP, "file"); - private static final QName px_show_excluded = new QName(XProcConstants.NS_CALABASH_EX, "show-excluded"); + private static final QName c_directory = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "directory"); + private static final QName c_file = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "file"); + private static final QName px_show_excluded = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "show-excluded"); private WritablePipe result = null; private String inclFilter = null; private String exclFilter = null; diff --git a/src/main/java/com/xmlcalabash/library/Error.java b/src/main/java/com/xmlcalabash/library/Error.java index db2ea232..55d21438 100644 --- a/src/main/java/com/xmlcalabash/library/Error.java +++ b/src/main/java/com/xmlcalabash/library/Error.java @@ -31,6 +31,7 @@ import net.sf.saxon.om.AttributeMap; import net.sf.saxon.om.EmptyAttributeMap; import net.sf.saxon.om.NamespaceMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmNode; @@ -48,7 +49,7 @@ type = "{http://www.w3.org/ns/xproc}error") public class Error extends DefaultStep { - private static final QName c_error = new QName("c", XProcConstants.NS_XPROC_STEP, "error"); + private static final QName c_error = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "error"); private static final QName _name = new QName("name"); private static final QName _code = new QName("code"); private static final QName _code_prefix = new QName("code-prefix"); @@ -86,17 +87,17 @@ public void run() throws SaxonApiException { RuntimeValue codeNameValue = getOption(_code); String codeNameStr = codeNameValue.getString(); String cpfx = getOption(_code_prefix, (String) null); - String cns = getOption(_code_namespace, (String) null); + NamespaceUri cns = NamespaceUri.of(getOption(_code_namespace, (String) null)); - if (cpfx == null && cns != null) { + if (cpfx == null && cns != NamespaceUri.NULL) { cpfx = "ERR"; } - if (cpfx != null && cns == null) { + if (cpfx != null && cns == NamespaceUri.NULL) { throw XProcException.dynamicError(34, "You can't specify a prefix without a namespace"); } - if (cns != null && codeNameStr.contains(":")) { + if (cns != NamespaceUri.NULL && codeNameStr.contains(":")) { throw XProcException.dynamicError(34, "You can't specify a namespace if the code name contains a colon"); } @@ -104,11 +105,11 @@ public void run() throws SaxonApiException { if (codeNameStr.contains(":")) { errorCode = new QName(codeNameStr, codeNameValue.getNode()); } else { - errorCode = new QName(cpfx == null ? "" : cpfx, cns, codeNameStr); + errorCode = new QName(cpfx == null ? "" : cpfx, cns.toString(), codeNameStr); } cpfx = errorCode.getPrefix(); - cns = errorCode.getNamespaceURI(); + cns = errorCode.getNamespaceUri(); TreeWriter treeWriter = new TreeWriter(runtime); treeWriter.startDocument(step.getNode().getBaseURI()); diff --git a/src/main/java/com/xmlcalabash/library/Exec.java b/src/main/java/com/xmlcalabash/library/Exec.java index 61f2013f..ab4c75a4 100644 --- a/src/main/java/com/xmlcalabash/library/Exec.java +++ b/src/main/java/com/xmlcalabash/library/Exec.java @@ -65,9 +65,9 @@ type = "{http://www.w3.org/ns/xproc}exec") public class Exec extends DefaultStep { - private static final QName c_result = new QName("c", XProcConstants.NS_XPROC_STEP, "result"); - private static final QName c_line = new QName("c", XProcConstants.NS_XPROC_STEP, "line"); - private static final QName cx_show_stderr = new QName("cx", XProcConstants.NS_CALABASH_EX, "show-stderr"); + private static final QName c_result = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "result"); + private static final QName c_line = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "line"); + private static final QName cx_show_stderr = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "show-stderr"); private static final QName _command = new QName("", "command"); private static final QName _args = new QName("", "args"); diff --git a/src/main/java/com/xmlcalabash/library/Hash.java b/src/main/java/com/xmlcalabash/library/Hash.java index eaa4e35d..c3454198 100644 --- a/src/main/java/com/xmlcalabash/library/Hash.java +++ b/src/main/java/com/xmlcalabash/library/Hash.java @@ -62,9 +62,9 @@ public class Hash extends DefaultStep implements ProcessMatchingNodes { private static final QName _crc = new QName("", "crc"); private static final QName _md = new QName("", "md"); private static final QName _sha = new QName("", "sha"); - private static final QName _hmac = new QName("cx", XProcConstants.NS_CALABASH_EX, "hmac"); - private static final QName _accessKey = new QName("cx", XProcConstants.NS_CALABASH_EX, "accessKey"); - private HashMap params = new HashMap (); + private static final QName _hmac = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "hmac"); + private static final QName _accessKey = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "accessKey"); + private final HashMap params = new HashMap (); protected static final String logger = "org.xproc.library.hash"; private ReadablePipe source = null; private WritablePipe result = null; diff --git a/src/main/java/com/xmlcalabash/library/HttpRequest.java b/src/main/java/com/xmlcalabash/library/HttpRequest.java index eb55bc7e..7511fc4d 100644 --- a/src/main/java/com/xmlcalabash/library/HttpRequest.java +++ b/src/main/java/com/xmlcalabash/library/HttpRequest.java @@ -31,6 +31,7 @@ import com.xmlcalabash.util.*; import net.sf.saxon.om.AttributeMap; import net.sf.saxon.om.EmptyAttributeMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.om.SingletonAttributeMap; import net.sf.saxon.s9api.*; import org.apache.http.*; @@ -75,12 +76,12 @@ type = "{http://www.w3.org/ns/xproc}http-request") public class HttpRequest extends DefaultStep { - private static final QName c_request = new QName("c", XProcConstants.NS_XPROC_STEP, "request"); - private static final QName cx_timeout = new QName("cx",XProcConstants.NS_CALABASH_EX,"timeout"); - private static final QName cx_cookies = new QName("cx",XProcConstants.NS_CALABASH_EX,"cookies"); - private static final QName cx_save_cookies = new QName("cx",XProcConstants.NS_CALABASH_EX,"save-cookies"); - private static final QName cx_use_cookies = new QName("cx",XProcConstants.NS_CALABASH_EX,"use-cookies"); - private static final QName cx_send_binary = new QName("cx", XProcConstants.NS_CALABASH_EX, "send-binary"); + private static final QName c_request = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "request"); + private static final QName cx_timeout = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX,"timeout"); + private static final QName cx_cookies = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX,"cookies"); + private static final QName cx_save_cookies = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX,"save-cookies"); + private static final QName cx_use_cookies = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX,"use-cookies"); + private static final QName cx_send_binary = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "send-binary"); public static final QName _href = new QName("", "href"); public static final QName _detailed = new QName("", "detailed"); @@ -105,7 +106,7 @@ public class HttpRequest extends DefaultStep { private boolean detailed = false; private boolean sendAuthorization = false; private URI requestURI = null; - private Vector
headers = new Vector
(); + private final Vector
headers = new Vector
(); private String overrideContentType = null; private String headerContentType = null; private boolean encodeBinary = false; @@ -157,7 +158,7 @@ public void run() throws SaxonApiException { || _override_content_type.equals(name)) { // nop } else { - if (XMLConstants.DEFAULT_NS_PREFIX.equals(name.getNamespaceURI())) { + if (name.getNamespaceUri() == NamespaceUri.NULL) { throw new XProcException(step.getNode(), "Unsupported attribute on c:request for p:http-request: " + name); } } @@ -278,7 +279,7 @@ public void run() throws SaxonApiException { if (name == null) { continue; // this can't happen, right? } - if (name.toLowerCase().equals("content-type")) { + if (name.equalsIgnoreCase("content-type")) { // We'll deal with the content-type header later headerContentType = event.getAttributeValue(_value).toLowerCase(); } else { @@ -411,6 +412,32 @@ public void run() throws SaxonApiException { // Read the response body. if (httpResult.getEntity() != null) { InputStream bodyStream = httpResult.getEntity().getContent(); + + // 15 Apr 2023, I'm suddenly getting an exception: + // + // org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected + // + // on some connections. (Some connections to tests.xproc.org, for example). I've no idea how to + // fix them, and I see a few places on the web where others are having this problem. + // Apparently when http uses a chunked encoding it's supposed to send a final zero-length + // chunk and this error arises if the server doesn't. I'm just going to paper over it because + // what else can I do? + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + byte[] buf = new byte[4096]; + int len = bodyStream.read(buf); + while (len >= 0) { + baos.write(buf, 0, len); + len = bodyStream.read(buf); + } + } catch (ConnectionClosedException ex) { + if (!ex.getMessage().contains("closing chunk expected")) { + throw ex; + } + } + bodyStream = new ByteArrayInputStream(baos.toByteArray()); + readBodyContent(tree, bodyStream, httpResult); } else { throw XProcException.dynamicError(6, "Reading HTTP response on " + getStep().getName()); @@ -526,7 +553,7 @@ private void doPutOrPostSinglepart(HttpEntityEnclosingRequest method, XdmNode bo if (bodyDescription != null) { for (Header header : headers) { - if (header.getName().toLowerCase().equals("content-description")) { + if (header.getName().equalsIgnoreCase("content-description")) { String headDescription = header.getValue(); descriptionHeader = true; if (!bodyDescription.equals(headDescription)) { @@ -542,7 +569,7 @@ private void doPutOrPostSinglepart(HttpEntityEnclosingRequest method, XdmNode bo if (bodyId != null) { for (Header header : headers) { - if (header.getName().toLowerCase().equals("content-id")) { + if (header.getName().equalsIgnoreCase("content-id")) { String headId = header.getValue(); idHeader = true; if (!bodyId.equals(headId)) { @@ -558,7 +585,7 @@ private void doPutOrPostSinglepart(HttpEntityEnclosingRequest method, XdmNode bo if (bodyDisposition != null) { for (Header header : headers) { - if (header.getName().toLowerCase().equals("content-disposition")) { + if (header.getName().equalsIgnoreCase("content-disposition")) { String headDisposition = header.getValue(); dispositionHeader = true; if (!bodyDisposition.equals(headDisposition)) { diff --git a/src/main/java/com/xmlcalabash/library/LabelElements.java b/src/main/java/com/xmlcalabash/library/LabelElements.java index bcc7fa6e..609d1ae5 100644 --- a/src/main/java/com/xmlcalabash/library/LabelElements.java +++ b/src/main/java/com/xmlcalabash/library/LabelElements.java @@ -72,7 +72,7 @@ public class LabelElements extends DefaultStep implements ProcessMatchingNodes { private static final QName _match = new QName("match"); private static final QName _label = new QName("label"); private static final QName _replace = new QName("replace"); - private static final QName p_index = new QName("p", XProcConstants.NS_XPROC, "index"); + private static final QName p_index = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "index"); private ReadablePipe source = null; private WritablePipe result = null; private ProcessMatch matcher = null; @@ -159,8 +159,8 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { NamespaceMap nsmap = node.getUnderlyingNode().getAllNamespaces(); AttributeMap amap = EmptyAttributeMap.getInstance(); - String prefix = prefixFor(nsmap, attribute.getPrefix(), attribute.getNamespaceURI()); - NodeName aname = new FingerprintedQName(prefix, attribute.getNamespaceURI(), attribute.getLocalName()); + String prefix = prefixFor(nsmap, attribute.getPrefix(), attribute.getNamespaceUri()); + NodeName aname = new FingerprintedQName(prefix, attribute.getNamespaceUri(), attribute.getLocalName()); boolean found = false; for (AttributeInfo ainfo : attributes) { diff --git a/src/main/java/com/xmlcalabash/library/Load.java b/src/main/java/com/xmlcalabash/library/Load.java index d10500bd..68ec0383 100644 --- a/src/main/java/com/xmlcalabash/library/Load.java +++ b/src/main/java/com/xmlcalabash/library/Load.java @@ -47,7 +47,7 @@ public class Load extends DefaultStep { private static final QName _href = new QName("href"); private static final QName _dtd_validate = new QName("dtd-validate"); - private static final QName err_XD0011 = new QName("err", XProcConstants.NS_XPROC_ERROR, "XD0011"); + private static final QName err_XD0011 = XProcConstants.qNameFor("err", XProcConstants.NS_XPROC_ERROR, "XD0011"); private WritablePipe result = null; private URI href = null; diff --git a/src/main/java/com/xmlcalabash/library/NamespaceRename.java b/src/main/java/com/xmlcalabash/library/NamespaceRename.java index 70c2db18..6b24d213 100644 --- a/src/main/java/com/xmlcalabash/library/NamespaceRename.java +++ b/src/main/java/com/xmlcalabash/library/NamespaceRename.java @@ -20,6 +20,7 @@ package com.xmlcalabash.library; import com.xmlcalabash.core.XMLCalabash; +import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.io.ReadablePipe; @@ -29,14 +30,7 @@ import com.xmlcalabash.util.ProcessMatch; import com.xmlcalabash.util.ProcessMatchingNodes; import net.sf.saxon.event.ReceiverOption; -import net.sf.saxon.om.AttributeInfo; -import net.sf.saxon.om.AttributeMap; -import net.sf.saxon.om.FingerprintedQName; -import net.sf.saxon.om.NameOfNode; -import net.sf.saxon.om.NamespaceBinding; -import net.sf.saxon.om.NamespaceMap; -import net.sf.saxon.om.NodeInfo; -import net.sf.saxon.om.NodeName; +import net.sf.saxon.om.*; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmNode; @@ -64,8 +58,8 @@ public class NamespaceRename extends DefaultStep implements ProcessMatchingNodes private ReadablePipe source = null; private WritablePipe result = null; private ProcessMatch matcher = null; - private String from = null; - private String to = null; + private NamespaceUri from = null; + private NamespaceUri to = null; private String applyTo = null; /* Creates a new instance of NamespaceRename */ @@ -90,21 +84,21 @@ public void run() throws SaxonApiException { super.run(); if (getOption(_from) != null) { - from = getOption(_from).getString(); + from = NamespaceUri.of(getOption(_from).getString()); } else { - from = ""; + from = NamespaceUri.NULL; } if (getOption(_to) != null) { - to = getOption(_to).getString(); + to = NamespaceUri.of(getOption(_to).getString()); } else { - to = ""; + to = NamespaceUri.NULL; } applyTo = getOption(_apply_to, "all"); - if (XMLConstants.XML_NS_URI.equals(from) || XMLConstants.XML_NS_URI.equals(to) - || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(from) || XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(to)) { + if (from == XProcConstants.NS_XML || to == XProcConstants.NS_XML + || from == XProcConstants.NS_XML_ATTR || to == XProcConstants.NS_XML_ATTR) { throw XProcException.stepError(14); } @@ -147,7 +141,7 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { AttributeMap startAttr = inode.attributes(); if (!"attributes".equals(applyTo)) { - if (from.equals(node.getNodeName().getNamespaceURI())) { + if (from == node.getNodeName().getNamespaceUri()) { String prefix = node.getNodeName().getPrefix(); startName = new FingerprintedQName(prefix, to, node.getNodeName().getLocalName()); startType = Untyped.INSTANCE; @@ -160,9 +154,9 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { for (AttributeInfo attr : inode.attributes()) { NodeName nameCode = attr.getNodeName(); SimpleType atype = attr.getType(); - String uri = nameCode.getURI(); + NamespaceUri uri = NamespaceUri.of(nameCode.getURI()); - if (from.equals(uri)) { + if (from == uri) { startAttr = startAttr.remove(nameCode); String pfx = nameCode.getPrefix(); @@ -182,8 +176,9 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { NodeName nameCode = attr.getNodeName(); SimpleType atype = attr.getType(); - String uri = nameCode.getURI(); - if (from.equals(uri)) { + NamespaceUri uri = NamespaceUri.of(nameCode.getURI()); + + if (from == uri) { startAttr = startAttr.remove(nameCode); String pfx = prefixFor(newNS, from); nameCode = new FingerprintedQName(pfx, from, nameCode.getLocalPart()); @@ -201,9 +196,9 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { startAttr = startAttr.remove(nameCode); String pfx = nameCode.getPrefix(); - String uri = nameCode.getURI(); + NamespaceUri uri = NamespaceUri.of(nameCode.getURI()); - if (from.equals(uri)) { + if (from == uri) { pfx = prefixFor(newNS, to); nameCode = new FingerprintedQName(pfx,to,nameCode.getLocalPart()); newNS = newNS.put(pfx, to); diff --git a/src/main/java/com/xmlcalabash/library/Parameters.java b/src/main/java/com/xmlcalabash/library/Parameters.java index 756845de..35c22c5d 100644 --- a/src/main/java/com/xmlcalabash/library/Parameters.java +++ b/src/main/java/com/xmlcalabash/library/Parameters.java @@ -29,6 +29,7 @@ import com.xmlcalabash.util.TypeUtils; import net.sf.saxon.om.AttributeMap; import net.sf.saxon.om.EmptyAttributeMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmAtomicValue; @@ -48,9 +49,9 @@ type = "{http://www.w3.org/ns/xproc}parameters") public class Parameters extends DefaultStep { - private static final QName c_param_set = new QName("c", XProcConstants.NS_XPROC_STEP, "param-set"); - private static final QName c_param = new QName("c", XProcConstants.NS_XPROC_STEP, "param"); - private static final QName cx_item = new QName("cx", XProcConstants.NS_CALABASH_EX, "item"); + private static final QName c_param_set = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "param-set"); + private static final QName c_param = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "param"); + private static final QName cx_item = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "item"); private static final QName _name = new QName("name"); private static final QName _namespace = new QName("namespace"); private static final QName _value = new QName("value"); @@ -90,8 +91,8 @@ public void run() throws SaxonApiException { AttributeMap attr = EmptyAttributeMap.getInstance(); String value = parameters.get(param).getStringValue().getStringValue(); attr = attr.put(TypeUtils.attributeInfo(_name, param.getLocalName())); - if (param.getNamespaceURI() != null && !"".equals(param.getNamespaceURI())) { - attr = attr.put(TypeUtils.attributeInfo(_namespace, param.getNamespaceURI())); + if (param.getNamespaceUri() != NamespaceUri.NULL) { + attr = attr.put(TypeUtils.attributeInfo(_namespace, param.getNamespaceUri().toString())); } else { // I'm not really sure about this... attr = attr.put(TypeUtils.attributeInfo(_namespace, "")); @@ -118,7 +119,7 @@ public void run() throws SaxonApiException { QName type = next.isAtomicValue() ? ((XdmAtomicValue) next).getPrimitiveTypeName() : null; if (type != null) { - if (XProcConstants.NS_XMLSCHEMA.equals(type.getNamespaceURI())) { + if (XProcConstants.NS_XMLSCHEMA == type.getNamespaceUri()) { itemattr = itemattr.put(TypeUtils.attributeInfo(_type, type.getLocalName())); } else { itemattr = itemattr.put(TypeUtils.attributeInfo(_type, type.getClarkName())); diff --git a/src/main/java/com/xmlcalabash/library/Rename.java b/src/main/java/com/xmlcalabash/library/Rename.java index 3fb1c894..de301a92 100644 --- a/src/main/java/com/xmlcalabash/library/Rename.java +++ b/src/main/java/com/xmlcalabash/library/Rename.java @@ -32,10 +32,7 @@ import com.xmlcalabash.model.RuntimeValue; import com.xmlcalabash.util.S9apiUtils; import com.xmlcalabash.util.TypeUtils; -import net.sf.saxon.om.AttributeInfo; -import net.sf.saxon.om.AttributeMap; -import net.sf.saxon.om.FingerprintedQName; -import net.sf.saxon.om.NamespaceMap; +import net.sf.saxon.om.*; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmNode; @@ -141,11 +138,11 @@ public AttributeMap processAttributes(XdmNode node, AttributeMap matchingAttribu NamespaceMap nsmap = node.getUnderlyingNode().getAllNamespaces(); for (AttributeInfo attr : matchingAttributes) { String prefix = newName.getPrefix(); - String uri = newName.getNamespaceURI(); + NamespaceUri uri = newName.getNamespaceUri(); String localName = newName.getLocalName(); - if (uri == null || "".equals(uri)) { - FingerprintedQName fqName = new FingerprintedQName("", "", localName); + if (uri == NamespaceUri.NULL) { + FingerprintedQName fqName = new FingerprintedQName("", NamespaceUri.NULL, localName); AttributeInfo ainfo = new AttributeInfo(fqName, attr.getType(), attr.getValue(), attr.getLocation(), attr.getProperties()); alist.add(ainfo); } else { @@ -155,11 +152,11 @@ public AttributeMap processAttributes(XdmNode node, AttributeMap matchingAttribu int count = 1; String checkPrefix = prefix; - String nsURI = nsmap.getURI(checkPrefix); + NamespaceUri nsURI = nsmap.getNamespaceUri(checkPrefix); while (nsURI != null && !nsURI.equals(uri)) { count += 1; checkPrefix = prefix + count; - nsURI = nsmap.getURI(checkPrefix); + nsURI = nsmap.getNamespaceUri(checkPrefix); } prefix = checkPrefix; @@ -195,7 +192,7 @@ public void processComment(XdmNode node) { @Override public void processPI(XdmNode node) { - if (!"".equals(newName.getNamespaceURI())) { + if (newName.getNamespaceUri() != NamespaceUri.NULL) { throw XProcException.stepError(13); } matcher.addPI(newName.getLocalName(), node.getStringValue()); diff --git a/src/main/java/com/xmlcalabash/library/Store.java b/src/main/java/com/xmlcalabash/library/Store.java index 0c9c73df..fc2448db 100644 --- a/src/main/java/com/xmlcalabash/library/Store.java +++ b/src/main/java/com/xmlcalabash/library/Store.java @@ -29,6 +29,7 @@ import com.xmlcalabash.util.*; import net.sf.saxon.om.AttributeMap; import net.sf.saxon.om.EmptyAttributeMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.Serializer; @@ -56,10 +57,10 @@ public class Store extends DefaultStep { private static final QName _href = new QName("href"); private static final QName _content_type = new QName("content-type"); - private static final QName c_encoding = new QName("c", XProcConstants.NS_XPROC_STEP, "encoding"); - private static final QName c_body = new QName("c", XProcConstants.NS_XPROC_STEP, "body"); - private static final QName c_json = new QName("c", XProcConstants.NS_XPROC_STEP, "json"); - private static final QName cx_decode = new QName("cx", XProcConstants.NS_CALABASH_EX, "decode"); + private static final QName c_encoding = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "encoding"); + private static final QName c_body = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "body"); + private static final QName c_json = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "json"); + private static final QName cx_decode = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "decode"); private ReadablePipe source = null; private WritablePipe result = null; @@ -128,9 +129,9 @@ public void run() throws SaxonApiException { String contentType = root.getAttributeValue(_content_type); URI contentId; if (("true".equals(decode) || "1".equals(decode) || method != CompressionMethod.NONE) - && ((XProcConstants.NS_XPROC_STEP.equals(root.getNodeName().getNamespaceURI()) + && ((XProcConstants.NS_XPROC_STEP == root.getNodeName().getNamespaceUri() && "base64".equals(root.getAttributeValue(_encoding))) - || ("".equals(root.getNodeName().getNamespaceURI()) + || (root.getNodeName().getNamespaceUri() == NamespaceUri.NULL && "base64".equals(root.getAttributeValue(c_encoding))))) { contentId = storeBinary(doc, href, base, contentType); } else if (("true".equals(decode) || "1".equals(decode)) @@ -143,9 +144,9 @@ public void run() throws SaxonApiException { && ("application/json".equals(contentType) || "text/json".equals(contentType))) || c_json.equals(root.getNodeName())) - || JSONtoXML.JSONX_NS.equals(root.getNodeName().getNamespaceURI()) - || JSONtoXML.JXML_NS.equals(root.getNodeName().getNamespaceURI()) - || JSONtoXML.MLJS_NS.equals(root.getNodeName().getNamespaceURI()))) { + || JSONtoXML.JSONX_NS == root.getNodeName().getNamespaceUri() + || JSONtoXML.JXML_NS == root.getNodeName().getNamespaceUri() + || JSONtoXML.MLJS_NS == root.getNodeName().getNamespaceUri())) { contentId = storeJSON(doc, href, base, contentType); } else { contentId = storeXML(doc, href, base, contentType); diff --git a/src/main/java/com/xmlcalabash/library/StringReplace.java b/src/main/java/com/xmlcalabash/library/StringReplace.java index e39ac9be..e55e907b 100644 --- a/src/main/java/com/xmlcalabash/library/StringReplace.java +++ b/src/main/java/com/xmlcalabash/library/StringReplace.java @@ -29,6 +29,7 @@ import net.sf.saxon.event.ReceiverOption; import net.sf.saxon.om.AttributeInfo; import net.sf.saxon.om.AttributeMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.om.NodeName; import net.sf.saxon.s9api.Axis; import net.sf.saxon.s9api.QName; @@ -57,8 +58,8 @@ public class StringReplace extends DefaultStep implements ProcessMatchingNodes { private WritablePipe result = null; private ProcessMatch matcher = null; private RuntimeValue replace = null; - private HashMap rns = new HashMap<>(); - private static HashMap atomicStepsGetNoInScopeOptions = new HashMap<>(); + private final HashMap rns = new HashMap<>(); + private static final HashMap atomicStepsGetNoInScopeOptions = new HashMap<>(); /* Creates a new instance of StringReplace */ public StringReplace(XProcRuntime runtime, XAtomicStep step) { diff --git a/src/main/java/com/xmlcalabash/library/Template.java b/src/main/java/com/xmlcalabash/library/Template.java index 04422f4f..3fecafbc 100644 --- a/src/main/java/com/xmlcalabash/library/Template.java +++ b/src/main/java/com/xmlcalabash/library/Template.java @@ -31,10 +31,7 @@ import com.xmlcalabash.util.ProcessMatch; import com.xmlcalabash.util.ProcessMatchingNodes; import com.xmlcalabash.util.S9apiUtils; -import net.sf.saxon.om.AttributeInfo; -import net.sf.saxon.om.AttributeMap; -import net.sf.saxon.om.NamespaceBinding; -import net.sf.saxon.om.NodeInfo; +import net.sf.saxon.om.*; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XdmAtomicValue; @@ -192,7 +189,7 @@ private Vector parse(XdmNode node, String value) { String ptext = ""; String ch = ""; - HashMap nsbindings = new HashMap<> (); + HashMap nsbindings = new HashMap<> (); // FIXME: Surely there's a better way to do this? XdmNode parent = node; @@ -206,7 +203,7 @@ private Vector parse(XdmNode node, String value) { if (parent.getNodeKind() == XdmNodeKind.ELEMENT) { NodeInfo inode = parent.getUnderlyingNode(); for (NamespaceBinding bind : inode.getAllNamespaces().getNamespaceBindings()) { - nsbindings.put(bind.getPrefix(), bind.getURI()); + nsbindings.put(bind.getPrefix(), bind.getNamespaceUri()); } } diff --git a/src/main/java/com/xmlcalabash/library/UnescapeMarkup.java b/src/main/java/com/xmlcalabash/library/UnescapeMarkup.java index 1cf38e6c..6a79d6a8 100644 --- a/src/main/java/com/xmlcalabash/library/UnescapeMarkup.java +++ b/src/main/java/com/xmlcalabash/library/UnescapeMarkup.java @@ -28,6 +28,7 @@ import com.xmlcalabash.util.*; import net.sf.saxon.om.FingerprintedQName; import net.sf.saxon.om.NamespaceMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.om.NodeInfo; import net.sf.saxon.s9api.*; import nu.validator.htmlparser.common.XmlViolationPolicy; @@ -58,7 +59,7 @@ public class UnescapeMarkup extends DefaultStep { private static final QName _charset = new QName("charset"); private ReadablePipe source = null; private WritablePipe result = null; - private String namespace = null; + private NamespaceUri namespace = null; /* * Creates a new instance of UnescapeMarkup @@ -88,7 +89,7 @@ public void run() throws SaxonApiException { contentType = HttpUtils.baseContentType(contentType); if (getOption(_namespace) != null) { - namespace = getOption(_namespace).getString(); + namespace = NamespaceUri.of(getOption(_namespace).getString()); } String encoding = null; @@ -186,7 +187,7 @@ private void remapDefaultNamespace(TreeWriter tree, XdmNode unescnode) { if (unescnode.getNodeKind() == XdmNodeKind.ELEMENT) { NodeInfo inode = unescnode.getUnderlyingNode(); NamespaceMap nsmap = inode.getAllNamespaces(); - if (!"".equals(nsmap.getDefaultNamespace())) { + if (nsmap.getDefaultNamespace() != NamespaceUri.NULL) { nsmap = nsmap.put("", namespace); } diff --git a/src/main/java/com/xmlcalabash/library/ValidateWithSCH.java b/src/main/java/com/xmlcalabash/library/ValidateWithSCH.java index 4d5e0f90..45002e4e 100644 --- a/src/main/java/com/xmlcalabash/library/ValidateWithSCH.java +++ b/src/main/java/com/xmlcalabash/library/ValidateWithSCH.java @@ -1,6 +1,7 @@ package com.xmlcalabash.library; import com.xmlcalabash.core.XMLCalabash; +import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.io.ReadablePipe; @@ -9,6 +10,7 @@ import com.xmlcalabash.runtime.XAtomicStep; import com.xmlcalabash.util.S9apiUtils; import net.sf.saxon.Configuration; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.om.StructuredQName; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; @@ -191,8 +193,8 @@ public void run() throws SaxonApiException { } private boolean checkFailedAssert(XdmNode doc) { - HashMap nsBindings = new HashMap<> (); - nsBindings.put("svrl", "http://purl.oclc.org/dsdl/svrl"); + HashMap nsBindings = new HashMap<> (); + nsBindings.put("svrl", NamespaceUri.of("http://purl.oclc.org/dsdl/svrl")); String xpath = "//svrl:failed-assert|//svrl:successful-report"; Vector results = new Vector (); @@ -220,7 +222,7 @@ private boolean checkFailedAssert(XdmNode doc) { Throwable sae = saue.getCause(); if (sae instanceof XPathException) { XPathException xe = (XPathException) sae; - if ("http://www.w3.org/2005/xqt-errors".equals(xe.getErrorCodeNamespace()) && "XPDY0002".equals(xe.getErrorCodeLocalPart())) { + if (xe.getErrorCodeNamespace() == XProcConstants.NS_XQT_ERRORS && "XPDY0002".equals(xe.getErrorCodeLocalPart())) { throw XProcException.dynamicError(26, step.getNode(), "Expression refers to context when none is available: " + xpath); } else { throw saue; diff --git a/src/main/java/com/xmlcalabash/library/ValidateWithXSD.java b/src/main/java/com/xmlcalabash/library/ValidateWithXSD.java index 52271ceb..8e3fc29b 100644 --- a/src/main/java/com/xmlcalabash/library/ValidateWithXSD.java +++ b/src/main/java/com/xmlcalabash/library/ValidateWithXSD.java @@ -35,6 +35,7 @@ import net.sf.saxon.event.NamespaceReducer; import net.sf.saxon.om.AttributeMap; import net.sf.saxon.om.EmptyAttributeMap; +import net.sf.saxon.om.NamespaceUri; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -87,7 +88,7 @@ public class ValidateWithXSD extends DefaultStep { private static final QName _try_namespaces = new QName("", "try-namespaces"); private static final QName _line = new QName("line"); private static final QName _column = new QName("column"); - private static final QName cx_version = new QName(XProcConstants.NS_CALABASH_EX, "version"); + private static final QName cx_version =XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "version"); private static final Class[] paramTypes = new Class[] {}; private ReadablePipe source = null; @@ -163,8 +164,8 @@ public void validateWithSaxonSA(SchemaManager manager) throws SaxonApiException XdmNode doc = source.read(); docBaseURI = doc.getBaseURI(); - String namespace = S9apiUtils.getDocumentElement(doc).getNodeName().getNamespaceURI(); - boolean tryNamespaces = getOption(_try_namespaces, false) && !"".equals(namespace); + NamespaceUri namespace = S9apiUtils.getDocumentElement(doc).getNodeName().getNamespaceUri(); + boolean tryNamespaces = getOption(_try_namespaces, false) && namespace != NamespaceUri.NULL; // Populate the URI cache so that URI references in schema documents will find // the schemas provided preferentially @@ -173,7 +174,7 @@ public void validateWithSaxonSA(SchemaManager manager) throws SaxonApiException XdmNode schemaNode = schemas.read(); String targetNS = schemaNode.getBaseURI().toASCIIString(); logger.debug(MessageFormatter.nodeMessage(step.getNode(), "Caching input schema: " + targetNS)); - if (targetNS.equals(namespace)) { + if (targetNS.equals(namespace.toString())) { tryNamespaces = false; } schemaDocuments.add(schemaNode); diff --git a/src/main/java/com/xmlcalabash/library/WWWFormURLDecode.java b/src/main/java/com/xmlcalabash/library/WWWFormURLDecode.java index 6ecb718c..b2418545 100644 --- a/src/main/java/com/xmlcalabash/library/WWWFormURLDecode.java +++ b/src/main/java/com/xmlcalabash/library/WWWFormURLDecode.java @@ -48,9 +48,9 @@ public class WWWFormURLDecode extends DefaultStep { public static final QName _value = new QName("", "value"); public static final QName _name = new QName("", "name"); - public static final QName c_paramset = new QName("c",XProcConstants.NS_XPROC_STEP,"param-set"); - public static final QName c_param = new QName("c", XProcConstants.NS_XPROC_STEP, "param"); - private static final QName cx_encoding = new QName("cx", XProcConstants.NS_CALABASH_EX, "encoding"); + public static final QName c_paramset = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP,"param-set"); + public static final QName c_param = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "param"); + private static final QName cx_encoding = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "encoding"); private WritablePipe result = null; /* Creates a new instance of FormURLDecode */ diff --git a/src/main/java/com/xmlcalabash/library/Wrap.java b/src/main/java/com/xmlcalabash/library/Wrap.java index 606a8a4a..a99ad094 100644 --- a/src/main/java/com/xmlcalabash/library/Wrap.java +++ b/src/main/java/com/xmlcalabash/library/Wrap.java @@ -117,7 +117,7 @@ public void run() throws SaxonApiException { inGroup.push(false); XdmNode doc = source.read(); - wrapperCode = new FingerprintedQName(wrapper.getPrefix(), wrapper.getNamespaceURI(), wrapper.getLocalName()); + wrapperCode = new FingerprintedQName(wrapper.getPrefix(), wrapper.getNamespaceUri(), wrapper.getLocalName()); matcher = new ProcessMatch(runtime, this); matcher.match(doc,getOption(_match)); diff --git a/src/main/java/com/xmlcalabash/library/XInclude.java b/src/main/java/com/xmlcalabash/library/XInclude.java index 5418e97c..b9039d3b 100644 --- a/src/main/java/com/xmlcalabash/library/XInclude.java +++ b/src/main/java/com/xmlcalabash/library/XInclude.java @@ -38,11 +38,7 @@ import com.xmlcalabash.util.TypeUtils; import com.xmlcalabash.util.XPointer; import net.sf.saxon.event.ReceiverOption; -import net.sf.saxon.om.AttributeInfo; -import net.sf.saxon.om.AttributeMap; -import net.sf.saxon.om.EmptyAttributeMap; -import net.sf.saxon.om.FingerprintedQName; -import net.sf.saxon.om.NodeName; +import net.sf.saxon.om.*; import net.sf.saxon.s9api.Axis; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; @@ -73,18 +69,18 @@ type = "{http://www.w3.org/ns/xproc}xinclude") public class XInclude extends DefaultStep implements ProcessMatchingNodes { - private static final String localAttrNS = "http://www.w3.org/2001/XInclude/local-attributes"; - private static final String xiNS = "http://www.w3.org/2001/XInclude"; + private static final NamespaceUri localAttrNS = NamespaceUri.of("http://www.w3.org/2001/XInclude/local-attributes"); + private static final NamespaceUri xiNS = NamespaceUri.of("http://www.w3.org/2001/XInclude"); - private static final QName xi_include = new QName(xiNS,"include"); - private static final QName xi_fallback = new QName(xiNS,"fallback"); + private static final QName xi_include = XProcConstants.qNameFor(xiNS, "include"); + private static final QName xi_fallback = XProcConstants.qNameFor(xiNS,"fallback"); private static final QName _fixup_xml_base = new QName("", "fixup-xml-base"); private static final QName _fixup_xml_lang = new QName("", "fixup-xml-lang"); private static final QName _set_xml_id = new QName("", "set-xml-id"); private static final QName _accept = new QName("", "accept"); private static final QName _accept_language = new QName("", "accept-language"); - private static final QName cx_trim = new QName("cx", XProcConstants.NS_CALABASH_EX, "trim"); - private static final QName cx_read_limit = new QName("cx", XProcConstants.NS_CALABASH_EX, "read-limit"); + private static final QName cx_trim = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "trim"); + private static final QName cx_read_limit = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "read-limit"); private static final QName _encoding = new QName("", "encoding"); private static final QName _href = new QName("", "href"); private static final QName _parse = new QName("", "parse"); @@ -99,9 +95,9 @@ public class XInclude extends DefaultStep implements ProcessMatchingNodes { private ReadablePipe source = null; private WritablePipe result = null; - private Stack matcherStack = new Stack (); - private Stack inside = new Stack (); - private Stack setXmlId = new Stack (); + private final Stack matcherStack = new Stack (); + private final Stack inside = new Stack (); + private final Stack setXmlId = new Stack (); private boolean fixupBase = false; private boolean fixupLang = false; private boolean copyAttributes = false; @@ -164,8 +160,8 @@ public void run() throws SaxonApiException { private XdmNode expandXIncludes(XdmNode doc) { // Does this document include any xi:include elements? - HashMap xins = new HashMap<>(); - xins.put("xi", "http://www.w3.org/2001/XInclude"); + HashMap xins = new HashMap<>(); + xins.put("xi", NamespaceUri.of("http://www.w3.org/2001/XInclude")); Vector ebv = evaluateXPath(doc, xins,"//xi:include", new HashMap()); if (ebv.isEmpty()) { logger.trace(MessageFormatter.nodeMessage(doc, "Skipping expandXIncludes (no xi:includes): " + doc.getBaseURI())); @@ -233,7 +229,7 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { throw new XProcException(step.getNode(), "XInclude element must contain at most one xi:fallback element."); } fallback = child; - } else if (xiNS.equals(child.getNodeName().getNamespaceURI())) { + } else if (xiNS == child.getNodeName().getNamespaceUri()) { throw new XProcException(step.getNode(), "Element not allowed as child of XInclude: " + child.getNodeKind()); } } @@ -359,7 +355,6 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { if (xpointer == null) { matcher.addSubtree(subtree.getResult()); } else { - HashMap nsBindings = xpointer.xpathNamespaces(); Vector nodes = xpointer.selectNodes(runtime,subtree.getResult()); if (nodes == null) { logger.trace(MessageFormatter.nodeMessage(node, "XInclude parse failed: " + href)); @@ -570,16 +565,16 @@ public boolean processStartElement(XdmNode node, AttributeMap attributes) { for (AttributeInfo ainfo : xiattributes) { // Attribute must be in a namespace - String nsuri = ainfo.getNodeName().getURI(); - boolean copy = (nsuri != null && !"".equals(nsuri)); + NamespaceUri nsuri = NamespaceUri.of(ainfo.getNodeName().getURI()); + boolean copy = (nsuri != NamespaceUri.NULL); // But not in the XML namespace copy = copy && !XProcConstants.NS_XML.equals(nsuri); if (copy) { NodeName aname = ainfo.getNodeName(); - if (localAttrNS.equals(aname.getURI())) { - aname = new FingerprintedQName("", "", aname.getLocalPart()); + if (localAttrNS == NamespaceUri.of(aname.getURI())) { + aname = new FingerprintedQName("", NamespaceUri.NULL, aname.getLocalPart()); } copied.add(aname); diff --git a/src/main/java/com/xmlcalabash/library/XQuery.java b/src/main/java/com/xmlcalabash/library/XQuery.java index ce19d6c7..5d150b4c 100644 --- a/src/main/java/com/xmlcalabash/library/XQuery.java +++ b/src/main/java/com/xmlcalabash/library/XQuery.java @@ -61,10 +61,10 @@ public class XQuery extends DefaultStep { private static final QName _content_type = new QName("content-type"); - private static final QName cx_decode = new QName("cx", XProcConstants.NS_CALABASH_EX, "decode"); + private static final QName cx_decode = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "decode"); private ReadablePipe source = null; - private HashMap params = new HashMap (); + private final HashMap params = new HashMap (); private ReadablePipe query = null; private WritablePipe result = null; diff --git a/src/main/java/com/xmlcalabash/library/XSLFormatter.java b/src/main/java/com/xmlcalabash/library/XSLFormatter.java index f4a9f08c..51322a1c 100644 --- a/src/main/java/com/xmlcalabash/library/XSLFormatter.java +++ b/src/main/java/com/xmlcalabash/library/XSLFormatter.java @@ -8,6 +8,7 @@ import java.util.Vector; import com.xmlcalabash.core.XMLCalabash; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; @@ -40,7 +41,7 @@ public class XSLFormatter extends DefaultStep { private static final QName _content_type = new QName("","content-type"); private ReadablePipe source = null; private WritablePipe result = null; - private Properties options = new Properties(); + private final Properties options = new Properties(); /* Creates a new instance of Unzip */ public XSLFormatter(XProcRuntime runtime, XAtomicStep step) { @@ -56,8 +57,8 @@ public void setOutput(String port, WritablePipe pipe) { } public void setParameter(QName name, RuntimeValue value) { - if (!"".equals(name.getNamespaceURI())) { - throw new XProcException(step.getNode(), "The p:xsl-formatter parameters are in no namespace: " + name + " (" + name.getNamespaceURI() + ")"); + if (name.getNamespaceUri() != NamespaceUri.NULL) { + throw new XProcException(step.getNode(), "The p:xsl-formatter parameters are in no namespace: " + name + " (" + name.getNamespaceUri() + ")"); } options.setProperty(name.getLocalName(), value.getString()); } diff --git a/src/main/java/com/xmlcalabash/library/XSLT.java b/src/main/java/com/xmlcalabash/library/XSLT.java index a0bb19a9..6a3fba2a 100644 --- a/src/main/java/com/xmlcalabash/library/XSLT.java +++ b/src/main/java/com/xmlcalabash/library/XSLT.java @@ -67,12 +67,12 @@ public class XSLT extends DefaultStep { private static final QName _output_base_uri = new QName("", "output-base-uri"); private static final QName _version = new QName("", "version"); private static final QName _content_type = new QName("content-type"); - private static final QName cx_decode = new QName("cx", XProcConstants.NS_CALABASH_EX, "decode"); + private static final QName cx_decode = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "decode"); private ReadablePipe sourcePipe = null; private ReadablePipe stylesheetPipe = null; private WritablePipe resultPipe = null; private WritablePipe secondaryPipe = null; - private HashMap params = new HashMap(); + private final HashMap params = new HashMap(); /* * Creates a new instance of XSLT diff --git a/src/main/java/com/xmlcalabash/model/Choose.java b/src/main/java/com/xmlcalabash/model/Choose.java index 81c7b1d4..5711c4b5 100644 --- a/src/main/java/com/xmlcalabash/model/Choose.java +++ b/src/main/java/com/xmlcalabash/model/Choose.java @@ -22,6 +22,7 @@ import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.XdmNode; import java.util.HashMap; @@ -93,7 +94,7 @@ protected void augmentIO() { } @Override - public HashSet getExcludeInlineNamespaces() { + public HashSet getExcludeInlineNamespaces() { return ((DeclareStep) parent).getExcludeInlineNamespaces(); } diff --git a/src/main/java/com/xmlcalabash/model/DeclareStep.java b/src/main/java/com/xmlcalabash/model/DeclareStep.java index d0d38d08..6d18eb8a 100644 --- a/src/main/java/com/xmlcalabash/model/DeclareStep.java +++ b/src/main/java/com/xmlcalabash/model/DeclareStep.java @@ -23,6 +23,7 @@ import com.xmlcalabash.core.XProcData; import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.XdmNode; @@ -44,7 +45,7 @@ public class DeclareStep extends CompoundStep implements DeclarationScope { private List importedLibs = new ArrayList<>(); private DeclarationScope parentScope = null; private Vector rest = null; - private HashSet excludedInlineNamespaces = null; + private HashSet excludedInlineNamespaces = null; private URI sourceImport = null; /* Creates a new instance of DeclareStep */ @@ -72,11 +73,11 @@ public void setDeclaredType(QName type) { declaredType = type; } - public void setExcludeInlineNamespaces(HashSet uris) { + public void setExcludeInlineNamespaces(HashSet uris) { excludedInlineNamespaces = uris; } - public HashSet getExcludeInlineNamespaces() { + public HashSet getExcludeInlineNamespaces() { return excludedInlineNamespaces; } diff --git a/src/main/java/com/xmlcalabash/model/ForEach.java b/src/main/java/com/xmlcalabash/model/ForEach.java index a0066b89..025d3af0 100644 --- a/src/main/java/com/xmlcalabash/model/ForEach.java +++ b/src/main/java/com/xmlcalabash/model/ForEach.java @@ -19,6 +19,7 @@ package com.xmlcalabash.model; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.XdmNode; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.core.XProcConstants; @@ -53,7 +54,7 @@ public DeclareStep getDeclaration() { } @Override - public HashSet getExcludeInlineNamespaces() { + public HashSet getExcludeInlineNamespaces() { return ((DeclareStep) parent).getExcludeInlineNamespaces(); } diff --git a/src/main/java/com/xmlcalabash/model/Group.java b/src/main/java/com/xmlcalabash/model/Group.java index 2b7faa37..c4679f2a 100644 --- a/src/main/java/com/xmlcalabash/model/Group.java +++ b/src/main/java/com/xmlcalabash/model/Group.java @@ -19,6 +19,7 @@ package com.xmlcalabash.model; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.XdmNode; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.core.XProcConstants; @@ -39,7 +40,7 @@ public Group(XProcRuntime xproc, XdmNode node, String name) { } @Override - public HashSet getExcludeInlineNamespaces() { + public HashSet getExcludeInlineNamespaces() { return ((DeclareStep) parent).getExcludeInlineNamespaces(); } diff --git a/src/main/java/com/xmlcalabash/model/InlineBinding.java b/src/main/java/com/xmlcalabash/model/InlineBinding.java index afb43056..9b73d51c 100644 --- a/src/main/java/com/xmlcalabash/model/InlineBinding.java +++ b/src/main/java/com/xmlcalabash/model/InlineBinding.java @@ -22,6 +22,7 @@ import java.util.Vector; import java.util.HashSet; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.XdmNode; import net.sf.saxon.s9api.XdmValue; import com.xmlcalabash.core.XProcRuntime; @@ -35,7 +36,7 @@ public class InlineBinding extends Binding { XdmNode root = null; Vector nodes = null; - HashSet excludeNS = null; + HashSet excludeNS = null; /* Creates a new instance of InlineBinding */ public InlineBinding(XProcRuntime xproc, XdmNode node) { @@ -48,11 +49,11 @@ public void addNode(XdmNode node) { nodes.add(node); } - public void excludeNamespaces(HashSet exclude) { + public void excludeNamespaces(HashSet exclude) { excludeNS = exclude; } - public HashSet getExcludedNamespaces() { + public HashSet getExcludedNamespaces() { return excludeNS; } @@ -61,11 +62,11 @@ public Vector nodes() { } protected void dump(int depth) { - String indent = ""; + StringBuilder sb = new StringBuilder(); for (int count = 0; count < depth; count++) { - indent += " "; + sb.append(" "); } - logger.trace(indent + "inline binding"); + logger.trace(sb.append("inline binding").toString()); } } diff --git a/src/main/java/com/xmlcalabash/model/NamespaceBinding.java b/src/main/java/com/xmlcalabash/model/NamespaceBinding.java index b9956278..cd5598a4 100644 --- a/src/main/java/com/xmlcalabash/model/NamespaceBinding.java +++ b/src/main/java/com/xmlcalabash/model/NamespaceBinding.java @@ -21,6 +21,7 @@ import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.Axis; import net.sf.saxon.s9api.XdmNode; import net.sf.saxon.s9api.XdmSequenceIterator; @@ -40,8 +41,8 @@ public class NamespaceBinding { private XProcRuntime runtime = null; private String binding = null; private String expr = null; - private HashSet except = new HashSet (); // Default is nothing excluded - private HashMap nsBindings = new HashMap (); + private HashSet except = new HashSet<> (); // Default is nothing excluded + private HashMap nsBindings = new HashMap<> (); public NamespaceBinding(XProcRuntime xproc, XdmNode node) { runtime = xproc; @@ -50,7 +51,7 @@ public NamespaceBinding(XProcRuntime xproc, XdmNode node) { XdmSequenceIterator nsIter = node.axisIterator(Axis.NAMESPACE); while (nsIter.hasNext()) { XdmNode ns = nsIter.next(); - nsBindings.put((ns.getNodeName()==null ? "" : ns.getNodeName().getLocalName()),ns.getStringValue()); + nsBindings.put((ns.getNodeName()==null ? "" : ns.getNodeName().getLocalName()),NamespaceUri.of(ns.getStringValue())); } } @@ -82,15 +83,15 @@ public String getXPath() { return expr; } - public HashMap getNamespaceBindings() { + public HashMap getNamespaceBindings() { return nsBindings; } - public void addExcludedNamespace(String exclude) { + public void addExcludedNamespace(NamespaceUri exclude) { except.add(exclude); } - public HashSet getExcludedNamespaces() { + public HashSet getExcludedNamespaces() { return except; } } diff --git a/src/main/java/com/xmlcalabash/model/Otherwise.java b/src/main/java/com/xmlcalabash/model/Otherwise.java index cf8a5912..38e7a5d7 100644 --- a/src/main/java/com/xmlcalabash/model/Otherwise.java +++ b/src/main/java/com/xmlcalabash/model/Otherwise.java @@ -19,6 +19,7 @@ package com.xmlcalabash.model; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.XdmNode; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.core.XProcConstants; @@ -47,7 +48,7 @@ public DeclareStep getDeclaration() { } @Override - public HashSet getExcludeInlineNamespaces() { + public HashSet getExcludeInlineNamespaces() { return ((DeclareStep) parent).getExcludeInlineNamespaces(); } } diff --git a/src/main/java/com/xmlcalabash/model/Parser.java b/src/main/java/com/xmlcalabash/model/Parser.java index e37758c1..b17c28b2 100644 --- a/src/main/java/com/xmlcalabash/model/Parser.java +++ b/src/main/java/com/xmlcalabash/model/Parser.java @@ -10,6 +10,7 @@ import com.xmlcalabash.util.URIUtils; import net.sf.saxon.PreparedStylesheet; import net.sf.saxon.functions.FunctionLibrary; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.query.QueryModule; import net.sf.saxon.query.StaticQueryContext; import net.sf.saxon.query.XQueryExpression; @@ -41,12 +42,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Vector; +import java.util.*; /** * @@ -54,17 +50,17 @@ */ public class Parser { // TODO: Make new QName() values throughout static - private static QName px_name = new QName(XProcConstants.NS_CALABASH_EX,"name"); + private static QName px_name = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX,"name"); private static QName _name = new QName("name"); private static QName _href = new QName("href"); private static QName _type = new QName("type"); private static QName _version = new QName("version"); private static QName _namespace = new QName("namespace"); - private static QName err_XS0063 = new QName(XProcConstants.NS_XPROC_ERROR, "XS0063"); - private static QName p_use_when = new QName(XProcConstants.NS_XPROC, "use-when"); + private static QName err_XS0063 = XProcConstants.qNameFor(XProcConstants.NS_XPROC_ERROR, "XS0063"); + private static QName p_use_when = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "use-when"); private static QName _use_when = new QName("use-when"); private static QName _exclude_inline_prefixes = new QName("exclude-inline-prefixes"); - private static QName cx_import = new QName(XProcConstants.NS_CALABASH_EX, "import"); + private static QName cx_import = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "import"); private XProcRuntime runtime = null; private boolean loadingStandardLibrary = false; @@ -271,7 +267,7 @@ private PipelineLibrary readLibrary(XdmNode node, URI baseURI) { } else { Step substep = readStep(library, library, node); - if (XProcConstants.NS_CALABASH_EX.equals(substep.getDeclaredType().getNamespaceURI()) + if (XProcConstants.NS_CALABASH_EX == substep.getDeclaredType().getNamespaceUri() && (substep.getDeclaredType().getLocalName().startsWith("anonymousType"))) { throw XProcException.staticError(53, node, "No type attribute on imported pipeline."); } @@ -652,8 +648,8 @@ private Input readInput(Step parent, XdmNode node) { input.setSequence(true); } - input.setDebugReader(node.getAttributeValue(new QName(XProcConstants.NS_CALABASH_EX, "debug-reader")) != null); - input.setDebugWriter(node.getAttributeValue(new QName(XProcConstants.NS_CALABASH_EX, "debug-writer")) != null); + input.setDebugReader(node.getAttributeValue(XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "debug-reader")) != null); + input.setDebugWriter(node.getAttributeValue(XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "debug-writer")) != null); if (select != null) { input.setSelect(select); @@ -851,12 +847,12 @@ private InlineBinding readInline(Step parent, XdmNode node) { inline.addNode(child); } - HashSet excludeURIs = S9apiUtils.excludeInlinePrefixes(node, node.getAttributeValue(_exclude_inline_prefixes)); + HashSet excludeURIs = S9apiUtils.excludeInlinePrefixes(node, node.getAttributeValue(_exclude_inline_prefixes)); while (!(parent instanceof DeclareStep)) { parent = parent.parent; } - HashSet excluded = ((DeclareStep) parent).getExcludeInlineNamespaces(); + HashSet excluded = ((DeclareStep) parent).getExcludeInlineNamespaces(); if (excluded != null) { excludeURIs.addAll(excluded); } @@ -887,7 +883,7 @@ private Option readOption(Step parent, XdmNode node) { oname = new QName(name); } - if (XProcConstants.NS_XPROC.equals(oname.getNamespaceURI())) { + if (XProcConstants.NS_XPROC == oname.getNamespaceUri()) { throw XProcException.staticError(28, node, "You cannot specify an option in the p: namespace."); } @@ -951,7 +947,7 @@ private Variable readVariable(Step parent, XdmNode node) { oname = new QName("", name); } - if (XProcConstants.NS_XPROC.equals(oname.getNamespaceURI())) { + if (XProcConstants.NS_XPROC == oname.getNamespaceUri()) { throw XProcException.staticError(28, node, "You cannot specify a variable in the p: namespace."); } @@ -992,7 +988,7 @@ private void readNamespaceBindings(Step parent, EndPoint endpoint, XdmNode node, // Is this really the best way? try { QName n = new QName(pfx+":localName",snode); - nsbinding.addExcludedNamespace(n.getNamespaceURI()); + nsbinding.addExcludedNamespace(n.getNamespaceUri()); } catch (IllegalArgumentException iae) { // Bad prefix throw XProcException.staticError(51, node, "Unbound prefix in except-prefixes: " + pfx); @@ -1214,7 +1210,7 @@ private Step readStep(Step parent, DeclarationScope declScope, XdmNode node) { step.setDeclaration(decl); step.parent = parent; - boolean pStep = XProcConstants.NS_XPROC.equals(node.getNodeName().getNamespaceURI()); + boolean pStep = XProcConstants.NS_XPROC == node.getNodeName().getNamespaceUri(); // Store extension attributes and convert any option shortcut attributes into options for (XdmNode attr : new AxisNodes(node, Axis.ATTRIBUTE)) { @@ -1225,7 +1221,7 @@ private Step readStep(Step parent, DeclarationScope declScope, XdmNode node) { continue; } - if (XMLConstants.NULL_NS_URI.equals(aname.getNamespaceURI())) { + if (NamespaceUri.NULL == aname.getNamespaceUri()) { if (!"name".equals(aname.getLocalName())) { Option option = new Option(runtime, node); option.setName(new QName("", aname.getLocalName())); @@ -1276,7 +1272,7 @@ private DeclareStep readDeclareStep(XdmNode node, DeclarationScope declScope) { } type = new QName(typeName, node); - if (!loadingStandardLibrary && XProcConstants.NS_XPROC.equals(type.getNamespaceURI())) { + if (!loadingStandardLibrary && XProcConstants.NS_XPROC == type.getNamespaceUri()) { throw XProcException.staticError(25, node, "Type cannot be in the p: namespace."); } } @@ -1296,7 +1292,7 @@ private DeclareStep readDeclareStep(XdmNode node, DeclarationScope declScope) { // Store extension attributes and convert any option shortcut attributes into options for (XdmNode attr : new AxisNodes(node, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); - if (XMLConstants.NULL_NS_URI.equals(aname.getNamespaceURI())) { + if (NamespaceUri.NULL == aname.getNamespaceUri()) { if (!"type".equals(aname.getLocalName()) && !"name".equals(aname.getLocalName()) && !"version".equals(aname.getLocalName()) && !"use-when".equals(aname.getLocalName()) && !"psvi-required".equals(aname.getLocalName()) && !"xpath-version".equals(aname.getLocalName()) @@ -1312,7 +1308,7 @@ private DeclareStep readDeclareStep(XdmNode node, DeclarationScope declScope) { step.setPsviRequired(psviRequired); step.setXPathVersion(xpathVersion); - HashSet excludeURIs = S9apiUtils.excludeInlinePrefixes(node, node.getAttributeValue(_exclude_inline_prefixes)); + HashSet excludeURIs = S9apiUtils.excludeInlinePrefixes(node, node.getAttributeValue(_exclude_inline_prefixes)); // if parent is a p:library, p:declare-step or p:pipeline, get the exclusions from there too... if (S9apiUtils.getParent(node) != null) { XdmNode parent = node.getParent(); @@ -1320,10 +1316,8 @@ private DeclareStep readDeclareStep(XdmNode node, DeclarationScope declScope) { && (XProcConstants.p_library.equals(parent.getNodeName()) || XProcConstants.p_pipeline.equals(parent.getNodeName()) || XProcConstants.p_declare_step.equals(parent.getNodeName()))) { - HashSet pexcl = S9apiUtils.excludeInlinePrefixes(parent, parent.getAttributeValue(_exclude_inline_prefixes)); - for (String uri : pexcl) { - excludeURIs.add(uri); - } + HashSet pexcl = S9apiUtils.excludeInlinePrefixes(parent, parent.getAttributeValue(_exclude_inline_prefixes)); + excludeURIs.addAll(pexcl); } } @@ -1760,12 +1754,9 @@ private Catch readCatch(Step parent, XdmNode node) { // ================================================================================================ private HashSet checkAttributes(XdmNode node, String[] attrs, boolean optionShortcutsOk) { - HashSet hash = null; + HashSet hash = new HashSet<> (); if (attrs != null) { - hash = new HashSet (); - for (String attr : attrs) { - hash.add(attr); - } + hash.addAll(Arrays.asList(attrs)); } HashSet options = null; @@ -1775,14 +1766,14 @@ private HashSet checkAttributes(XdmNode node, String[] attrs, boolean op QName aname = attr.getNodeName(); // The use-when attribute is always ok - if ((XProcConstants.NS_XPROC.equals(node.getNodeName().getNamespaceURI()) + if ((XProcConstants.NS_XPROC == node.getNodeName().getNamespaceUri() && aname.equals(_use_when)) - || (!XProcConstants.NS_XPROC.equals(node.getNodeName().getNamespaceURI()) + || (XProcConstants.NS_XPROC != node.getNodeName().getNamespaceUri() && aname.equals(p_use_when))) { continue; } - if ("".equals(aname.getNamespaceURI())) { + if (NamespaceUri.NULL == aname.getNamespaceUri()) { if (hash.contains(aname.getLocalName())) { // ok } else if (optionShortcutsOk) { @@ -1795,7 +1786,7 @@ private HashSet checkAttributes(XdmNode node, String[] attrs, boolean op } else { runtime.error(null, node, "Attribute \"" + aname + "\" not allowed on " + node.getNodeName(), XProcConstants.staticError(8)); } - } else if (XProcConstants.NS_XPROC.equals(aname.getNamespaceURI())) { + } else if (XProcConstants.NS_XPROC == aname.getNamespaceUri()) { runtime.error(null, node, "Attribute \"" + aname + "\" not allowed on " + node.getNodeName(), XProcConstants.staticError(8)); return null; } @@ -1809,9 +1800,9 @@ private HashSet checkAttributes(XdmNode node, String[] attrs, boolean op private void checkExtensionAttributes(XdmNode node, SourceArtifact src) { for (XdmNode attr : new AxisNodes(node, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); - if ("".equals(aname.getNamespaceURI())) { + if (NamespaceUri.NULL == aname.getNamespaceUri()) { // nop - } else if (XProcConstants.NS_XPROC.equals(aname.getNamespaceURI())) { + } else if (XProcConstants.NS_XPROC == aname.getNamespaceUri()) { runtime.error(null, node, "Attribute \"" + aname + "\" not allowed on " + node.getNodeName(), XProcConstants.staticError(8)); } else { src.addExtensionAttribute(attr); diff --git a/src/main/java/com/xmlcalabash/model/RuntimeValue.java b/src/main/java/com/xmlcalabash/model/RuntimeValue.java index b9d9b67f..64bcd001 100644 --- a/src/main/java/com/xmlcalabash/model/RuntimeValue.java +++ b/src/main/java/com/xmlcalabash/model/RuntimeValue.java @@ -22,6 +22,7 @@ import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; import net.sf.saxon.lib.NamespaceConstant; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.Axis; import net.sf.saxon.s9api.ItemType; import net.sf.saxon.s9api.ItemTypeFactory; @@ -48,7 +49,7 @@ public class RuntimeValue { private String value = null; private XdmNode node = null; private boolean initialized = false; - private HashMap nsBindings = null; + private HashMap nsBindings = null; public RuntimeValue() { // nop; returns an uninitialized value @@ -59,7 +60,7 @@ public RuntimeValue(String value, XdmNode node) { this.node = node; initialized = true; - nsBindings = new HashMap (); + nsBindings = new HashMap<> (); XdmSequenceIterator nsIter = node.axisIterator(Axis.NAMESPACE); while (nsIter.hasNext()) { XdmNode ns = nsIter.next(); @@ -68,22 +69,22 @@ public RuntimeValue(String value, XdmNode node) { if (nodeName == null) { // Huh? - nsBindings.put("", uri); + nsBindings.put("", NamespaceUri.of(uri)); } else { String localName = nodeName.getLocalName(); - nsBindings.put(localName,uri); + nsBindings.put(localName, NamespaceUri.of(uri)); } } } - public RuntimeValue(String value, XdmNode node, HashMap nsBindings) { + public RuntimeValue(String value, XdmNode node, HashMap nsBindings) { this.value = value; this.node = node; this.nsBindings = nsBindings; initialized = true; } - public RuntimeValue(String value, Vector generalValue, XdmNode node, HashMap nsBindings) { + public RuntimeValue(String value, Vector generalValue, XdmNode node, HashMap nsBindings) { this.value = value; this.generalValue = generalValue; this.node = node; @@ -160,7 +161,7 @@ public URI getBaseURI() { return node.getBaseURI(); } - public HashMap getNamespaceBindings() { + public HashMap getNamespaceBindings() { return nsBindings; } diff --git a/src/main/java/com/xmlcalabash/model/Step.java b/src/main/java/com/xmlcalabash/model/Step.java index 36f59ee8..07567461 100644 --- a/src/main/java/com/xmlcalabash/model/Step.java +++ b/src/main/java/com/xmlcalabash/model/Step.java @@ -40,9 +40,9 @@ * @author ndw */ public class Step extends SourceArtifact { - private static final QName cx_depend = new QName("cx",XProcConstants.NS_CALABASH_EX,"depend"); - private static final QName cx_depends = new QName("cx",XProcConstants.NS_CALABASH_EX,"depends"); - private static final QName cx_dependson = new QName("cx",XProcConstants.NS_CALABASH_EX,"dependson"); + private static final QName cx_depend = XProcConstants.qNameFor("cx",XProcConstants.NS_CALABASH_EX,"depend"); + private static final QName cx_depends = XProcConstants.qNameFor("cx",XProcConstants.NS_CALABASH_EX,"depends"); + private static final QName cx_dependson = XProcConstants.qNameFor("cx",XProcConstants.NS_CALABASH_EX,"dependson"); protected QName stepType = null; protected String stepName = null; @@ -718,7 +718,7 @@ protected boolean checkBinding(Input input) { if ("error".equals(pipe.getPort()) && XProcConstants.p_catch.equals(fromstep.getType())) { catchErrors = true; } else { - if (XProcConstants.NS_XPROC.equals(fromstep.getType().getNamespaceURI()) + if (XProcConstants.NS_XPROC == fromstep.getType().getNamespaceUri() && getVersion() > 1.0) { // Nevermind, it's ok to bind to unknown ports in this case input.setSequence(true); @@ -1265,7 +1265,7 @@ protected void dump(int depth) { indent += " "; } - if (getType().getNamespaceURI().equals(XProcConstants.NS_XPROC)) { + if (getType().getNamespaceUri() == XProcConstants.NS_XPROC) { logger.trace(indent + getType().getLocalName() + " " + getName()); } else { logger.trace(indent + "XProcStep " + getName() + " (" + getType() + ")"); diff --git a/src/main/java/com/xmlcalabash/model/Try.java b/src/main/java/com/xmlcalabash/model/Try.java index f9871d1c..5e97f2e4 100644 --- a/src/main/java/com/xmlcalabash/model/Try.java +++ b/src/main/java/com/xmlcalabash/model/Try.java @@ -21,6 +21,7 @@ import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.core.XProcRuntime; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.XdmNode; import java.util.HashMap; @@ -48,7 +49,7 @@ public DeclareStep getDeclaration() { } @Override - public HashSet getExcludeInlineNamespaces() { + public HashSet getExcludeInlineNamespaces() { return ((DeclareStep) parent).getExcludeInlineNamespaces(); } diff --git a/src/main/java/com/xmlcalabash/model/Viewport.java b/src/main/java/com/xmlcalabash/model/Viewport.java index 7a563b60..479d8746 100644 --- a/src/main/java/com/xmlcalabash/model/Viewport.java +++ b/src/main/java/com/xmlcalabash/model/Viewport.java @@ -19,6 +19,7 @@ package com.xmlcalabash.model; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.XdmNode; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.core.XProcConstants; @@ -52,7 +53,7 @@ public DeclareStep getDeclaration() { } @Override - public HashSet getExcludeInlineNamespaces() { + public HashSet getExcludeInlineNamespaces() { return ((DeclareStep) parent).getExcludeInlineNamespaces(); } diff --git a/src/main/java/com/xmlcalabash/model/When.java b/src/main/java/com/xmlcalabash/model/When.java index 80af5675..cbd0c301 100644 --- a/src/main/java/com/xmlcalabash/model/When.java +++ b/src/main/java/com/xmlcalabash/model/When.java @@ -19,6 +19,7 @@ package com.xmlcalabash.model; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.XdmNode; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.core.XProcConstants; @@ -56,7 +57,7 @@ public String getTest() { } @Override - public HashSet getExcludeInlineNamespaces() { + public HashSet getExcludeInlineNamespaces() { return ((DeclareStep) parent).getExcludeInlineNamespaces(); } diff --git a/src/main/java/com/xmlcalabash/piperack/BaseStatus.java b/src/main/java/com/xmlcalabash/piperack/BaseStatus.java index 69436987..941e377e 100644 --- a/src/main/java/com/xmlcalabash/piperack/BaseStatus.java +++ b/src/main/java/com/xmlcalabash/piperack/BaseStatus.java @@ -79,7 +79,7 @@ private String exceptionMessage(Throwable exception) { loc = err.getLocator(); if (err.getErrorCode() != null) { QName n = err.getErrorCode(); - qCode = new StructuredQName(n.getPrefix(),n.getNamespaceURI(),n.getLocalName()); + qCode = new StructuredQName(n.getPrefix(),n.getNamespaceUri(),n.getLocalName()); } if (err.getStep() != null) { message = message + err.getStep() + ":"; diff --git a/src/main/java/com/xmlcalabash/piperack/Pipeline.java b/src/main/java/com/xmlcalabash/piperack/Pipeline.java index 2b943e5b..32cab902 100644 --- a/src/main/java/com/xmlcalabash/piperack/Pipeline.java +++ b/src/main/java/com/xmlcalabash/piperack/Pipeline.java @@ -87,7 +87,7 @@ protected Representation get(Variant variant) { NamespaceMap nsmap = NamespaceMap.emptyMap(); if (!"".equals(name.getPrefix())) { - nsmap = nsmap.put(name.getPrefix(), name.getNamespaceURI()); + nsmap = nsmap.put(name.getPrefix(), name.getNamespaceUri()); } tree.addStartElement(pr_name, EmptyAttributeMap.getInstance(), nsmap); @@ -118,7 +118,7 @@ protected Representation get(Variant variant) { NamespaceMap nsmap = NamespaceMap.emptyMap(); if (!"".equals(name.getPrefix())) { - nsmap = nsmap.put(name.getPrefix(), name.getNamespaceURI()); + nsmap = nsmap.put(name.getPrefix(), name.getNamespaceUri()); } tree.addStartElement(pr_name, EmptyAttributeMap.getInstance(), nsmap); diff --git a/src/main/java/com/xmlcalabash/runtime/XAtomicStep.java b/src/main/java/com/xmlcalabash/runtime/XAtomicStep.java index 983b1e46..dc788bd9 100644 --- a/src/main/java/com/xmlcalabash/runtime/XAtomicStep.java +++ b/src/main/java/com/xmlcalabash/runtime/XAtomicStep.java @@ -29,6 +29,7 @@ import com.xmlcalabash.util.S9apiUtils; import com.xmlcalabash.util.TypeUtils; import net.sf.saxon.om.NamespaceMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.Axis; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; @@ -66,7 +67,7 @@ public class XAtomicStep extends XStep { private final static QName _namespace = new QName("", "namespace"); private final static QName _value = new QName("", "value"); private final static QName _type = new QName("", "type"); - private final static QName cx_item = new QName("cx", XProcConstants.NS_CALABASH_EX, "item"); + private final static QName cx_item = XProcConstants.qNameFor("cx", XProcConstants.NS_CALABASH_EX, "item"); protected HashMap> inputs = new HashMap> (); protected HashMap outputs = new HashMap (); @@ -212,7 +213,7 @@ protected void computeParameters(XProcStep xstep) throws SaxonApiException { loopdone = true; for (Parameter p : step.parameters()) { - if (XProcConstants.NS_XPROC.equals(p.getName().getNamespaceURI())) { + if (XProcConstants.NS_XPROC == p.getName().getNamespaceUri()) { throw XProcException.dynamicError(31); } @@ -245,8 +246,8 @@ protected void computeParameters(XProcStep xstep) throws SaxonApiException { // Check the attributes... for (XdmNode attr : new AxisNodes(docelem, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); - if ("".equals(aname.getNamespaceURI()) - || XProcConstants.NS_XPROC.equals(aname.getNamespaceURI())) { + if (aname.getNamespaceUri() == NamespaceUri.NULL + || XProcConstants.NS_XPROC == aname.getNamespaceUri()) { throw XProcException.dynamicError(14, step.getNode(), "Attribute not allowed"); } } @@ -434,7 +435,7 @@ private void parseParameterNode(XProcStep impl, XdmNode pnode) { Parameter p = new Parameter(step.getXProc(),pnode); String port = p.getPort(); String name = pnode.getAttributeValue(_name); - String ns = pnode.getAttributeValue(_namespace); + NamespaceUri ns = NamespaceUri.of(pnode.getAttributeValue(_namespace)); QName pname = null; if (ns == null) { @@ -449,15 +450,15 @@ private void parseParameterNode(XProcStep impl, XdmNode pnode) { name = name.substring(pos); QName testNode = new QName(name,pnode); - if (!ns.equals(testNode.getNamespaceURI())) { + if (ns != testNode.getNamespaceUri()) { throw XProcException.dynamicError(25); } } - pname = new QName(ns,name); + pname = new QName(ns.toString(), name); } - if (XProcConstants.NS_XPROC.equals(pname.getNamespaceURI())) { + if (XProcConstants.NS_XPROC == pname.getNamespaceUri()) { throw XProcException.dynamicError(31); } @@ -465,7 +466,7 @@ private void parseParameterNode(XProcStep impl, XdmNode pnode) { for (XdmNode attr : new AxisNodes(pnode, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); - if ("".equals(aname.getNamespaceURI())) { + if (aname.getNamespaceUri() == NamespaceUri.NULL) { if (!aname.equals(_name) && !aname.equals(_namespace) && !aname.equals(_value)) { throw XProcException.dynamicError(14); } @@ -483,7 +484,7 @@ private void parseParameterValueNode(XProcStep impl, XdmNode pnode) { Parameter p = new Parameter(step.getXProc(),pnode); String port = p.getPort(); String name = pnode.getAttributeValue(_name); - String ns = pnode.getAttributeValue(_namespace); + NamespaceUri ns = NamespaceUri.of(pnode.getAttributeValue(_namespace)); QName pname = null; if (ns == null) { @@ -494,27 +495,27 @@ private void parseParameterValueNode(XProcStep impl, XdmNode pnode) { name = name.substring(pos); QName testNode = new QName(name,pnode); - if (!ns.equals(testNode.getNamespaceURI())) { + if (ns != testNode.getNamespaceUri()) { throw XProcException.dynamicError(25); } } - pname = new QName(ns,name); + pname = new QName(ns.toString(), name); } p.setName(pname); for (XdmNode attr : new AxisNodes(pnode, Axis.ATTRIBUTE)) { QName aname = attr.getNodeName(); - if ("".equals(aname.getNamespaceURI())) { + if (aname.getNamespaceUri() == NamespaceUri.NULL) { if (!aname.equals(_name) && !aname.equals(_namespace)) { throw XProcException.dynamicError(14); } } } - StringBuffer stringValue = new StringBuffer(); - Vector items = new Vector (); + StringBuilder stringValue = new StringBuilder(); + Vector items = new Vector<> (); for (XdmNode child : new AxisNodes(runtime, pnode, Axis.CHILD, AxisNodes.PIPELINE)) { if (child.getNodeKind() == XdmNodeKind.ELEMENT) { if (!child.getNodeName().equals(cx_item)) { @@ -557,7 +558,7 @@ private void parseParameterValueNode(XProcStep impl, XdmNode pnode) { } } - RuntimeValue value = new RuntimeValue(stringValue.toString(), items, pnode, new HashMap ()); + RuntimeValue value = new RuntimeValue(stringValue.toString(), items, pnode, new HashMap<> ()); if (port != null) { impl.setParameter(port,pname,value); @@ -567,7 +568,7 @@ private void parseParameterValueNode(XProcStep impl, XdmNode pnode) { } protected RuntimeValue computeValue(ComputableValue var) { - HashMap nsBindings = new HashMap<> (); + HashMap nsBindings = new HashMap<> (); HashMap globals = inScopeOptions; XdmNode doc = null; @@ -587,7 +588,7 @@ protected RuntimeValue computeValue(ComputableValue var) { } for (NamespaceBinding nsbinding : var.getNamespaceBindings()) { - HashMap localBindings = new HashMap<> (); + HashMap localBindings = new HashMap<> (); // Compute the namespaces associated with this binding if (nsbinding.getBinding() != null) { @@ -605,7 +606,7 @@ protected RuntimeValue computeValue(ComputableValue var) { // Make sure the namespace bindings for evaluating the XPath expr are correct NamespaceMap nsmap = nsbinding.getNode().getUnderlyingNode().getAllNamespaces(); nsmap.iteratePrefixes().forEachRemaining(prefix -> { - xcomp.declareNamespace(prefix, nsmap.getURIForPrefix(prefix, "".equals(prefix))); + xcomp.declareNamespace(prefix, nsmap.getURIForPrefix(prefix, "".equals(prefix)).toString()); }); for (QName varname : globals.keySet()) { @@ -643,13 +644,13 @@ protected RuntimeValue computeValue(ComputableValue var) { while (nsIter.hasNext()) { XdmNode ns = nsIter.next(); QName prefix = ns.getNodeName(); - localBindings.put(prefix == null ? "" : prefix.getLocalName(),ns.getStringValue()); + localBindings.put(prefix == null ? "" : prefix.getLocalName(),NamespaceUri.of(ns.getStringValue())); } } catch (SaxonApiException sae) { throw new XProcException(sae); } } else if (nsbinding.getNamespaceBindings() != null) { - HashMap bindings = nsbinding.getNamespaceBindings(); + HashMap bindings = nsbinding.getNamespaceBindings(); for (String prefix : bindings.keySet()) { if ("".equals(prefix) || prefix == null) { // nop; the default namespace never plays a role in XPath expression evaluation @@ -661,7 +662,7 @@ protected RuntimeValue computeValue(ComputableValue var) { // Remove the excluded ones HashSet prefixes = new HashSet (); - for (String uri : nsbinding.getExcludedNamespaces()) { + for (NamespaceUri uri : nsbinding.getExcludedNamespaces()) { for (String prefix : localBindings.keySet()) { if (uri.equals(localBindings.get(prefix))) { prefixes.add(prefix); @@ -740,8 +741,8 @@ protected RuntimeValue computeValue(ComputableValue var) { if (varrefstr.contains(":")) { String vpfx = varrefstr.substring(0, varrefstr.indexOf(":")); String vlocal = varrefstr.substring(varrefstr.indexOf(":")+1); - String vns = nsBindings.get(vpfx); - varname = new QName(vpfx, vns, vlocal); + NamespaceUri vns = nsBindings.get(vpfx); + varname = new QName(vpfx, vns.toString(), vlocal); } else { varname = new QName("", varrefstr); } @@ -757,10 +758,10 @@ protected RuntimeValue computeValue(ComputableValue var) { XdmNode node = (XdmNode) results.get(0); nsBindings.clear(); - XdmSequenceIterator nsIter = node.axisIterator(Axis.NAMESPACE); + XdmSequenceIterator nsIter = node.axisIterator(Axis.NAMESPACE); while (nsIter.hasNext()) { - XdmNode ns = (XdmNode) nsIter.next(); - nsBindings.put((ns.getNodeName()==null ? "" : ns.getNodeName().getLocalName()),ns.getStringValue()); + XdmNode ns = nsIter.next(); + nsBindings.put((ns.getNodeName()==null ? "" : ns.getNodeName().getLocalName()),NamespaceUri.of(ns.getStringValue())); } } @@ -771,7 +772,7 @@ protected RuntimeValue computeValue(ComputableValue var) { } } - protected Vector evaluateXPath(XdmNode doc, HashMap nsBindings, String xpath, HashMap globals) { + protected Vector evaluateXPath(XdmNode doc, HashMap nsBindings, String xpath, HashMap globals) { Vector results = new Vector (); HashMap boundOpts = new HashMap (); diff --git a/src/main/java/com/xmlcalabash/runtime/XPipeline.java b/src/main/java/com/xmlcalabash/runtime/XPipeline.java index e7303c27..1f9b3d75 100644 --- a/src/main/java/com/xmlcalabash/runtime/XPipeline.java +++ b/src/main/java/com/xmlcalabash/runtime/XPipeline.java @@ -35,8 +35,8 @@ * To change this template use File | Settings | File Templates. */ public class XPipeline extends XCompoundStep { - private static final QName c_param_set = new QName("c", XProcConstants.NS_XPROC_STEP, "param-set"); - private static final QName c_param = new QName("c", XProcConstants.NS_XPROC_STEP, "param"); + private static final QName c_param_set = XProcConstants.qNameFor("c", XProcConstants.NS_XPROC_STEP, "param-set"); + private static final QName c_param = XProcConstants.qNameFor("c", XProcConstants.NS_XPROC_STEP, "param"); private static final QName _name = new QName("name"); private static final QName _namespace = new QName("namespace"); private static final QName _value = new QName("value"); @@ -162,8 +162,8 @@ private void setupParameters() { AttributeMap attr = EmptyAttributeMap.getInstance(); attr = attr.put(TypeUtils.attributeInfo(_name, name.getLocalName())); - if (name.getNamespaceURI() != null) { - attr = attr.put(TypeUtils.attributeInfo(_namespace, name.getNamespaceURI())); + if (name.getNamespaceUri() != null) { + attr = attr.put(TypeUtils.attributeInfo(_namespace, name.getNamespaceUri().toString())); } attr = attr.put(TypeUtils.attributeInfo(_value, getParameter(port, name).getString())); diff --git a/src/main/java/com/xmlcalabash/runtime/XSelect.java b/src/main/java/com/xmlcalabash/runtime/XSelect.java index b68b204a..480b1753 100644 --- a/src/main/java/com/xmlcalabash/runtime/XSelect.java +++ b/src/main/java/com/xmlcalabash/runtime/XSelect.java @@ -111,7 +111,7 @@ private void readSource() { } for (String prefix : bindings.getNamespaceBindings().keySet()) { - xcomp.declareNamespace(prefix, bindings.getNamespaceBindings().get(prefix)); + xcomp.declareNamespace(prefix, bindings.getNamespaceBindings().get(prefix).toString()); } XPathExecutable xexec = xcomp.compile(select); diff --git a/src/main/java/com/xmlcalabash/runtime/XStep.java b/src/main/java/com/xmlcalabash/runtime/XStep.java index e887b19e..f02a7c43 100644 --- a/src/main/java/com/xmlcalabash/runtime/XStep.java +++ b/src/main/java/com/xmlcalabash/runtime/XStep.java @@ -98,7 +98,7 @@ public XOutput getOutput(String port) { if (xoutputs.containsKey(port)) { return xoutputs.get(port); } else { - if (XProcConstants.NS_XPROC.equals(step.getType().getNamespaceURI()) + if (XProcConstants.NS_XPROC == step.getType().getNamespaceUri() && step.getStep().getVersion() > 1.0) { return null; } else { @@ -155,7 +155,7 @@ public void setParameter(String port, QName name, RuntimeValue value) { throw new XProcException(step.getNode(), "Duplicate parameter: " + name); } - if (XProcConstants.NS_XPROC.equals(name.getNamespaceURI())) { + if (XProcConstants.NS_XPROC == name.getNamespaceUri()) { throw XProcException.dynamicError(31); } @@ -168,11 +168,7 @@ public Set getOptions() { } public RuntimeValue getOption(QName name) { - if (options.containsKey(name)) { - return options.get(name); - } else { - return null; - } + return options.getOrDefault(name, null); } public void setOption(QName name, RuntimeValue value) { diff --git a/src/main/java/com/xmlcalabash/runtime/XTry.java b/src/main/java/com/xmlcalabash/runtime/XTry.java index 63fadc3b..db8a99f4 100644 --- a/src/main/java/com/xmlcalabash/runtime/XTry.java +++ b/src/main/java/com/xmlcalabash/runtime/XTry.java @@ -30,13 +30,13 @@ * To change this template use File | Settings | File Templates. */ public class XTry extends XCompoundStep { - private static final QName c_errors = new QName("c", XProcConstants.NS_XPROC_STEP, "errors"); - private static final QName c_error = new QName("c", XProcConstants.NS_XPROC_STEP, "error"); - private static QName _href = new QName("", "href"); - private static QName _line = new QName("", "line"); - private static QName _column = new QName("", "column"); - private static QName _code = new QName("", "code"); - private Vector errors = new Vector (); + private static final QName c_errors = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "errors"); + private static final QName c_error = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "error"); + private static final QName _href = new QName("", "href"); + private static final QName _line = new QName("", "line"); + private static final QName _column = new QName("", "column"); + private static final QName _code = new QName("", "code"); + private final Vector errors = new Vector (); public XTry(XProcRuntime runtime, Step step, XCompoundStep parent) { super(runtime, step, parent); @@ -142,12 +142,12 @@ public void run() throws SaxonApiException { message = underlying.getMessage(); } if (code != null) { - qCode = new StructuredQName(code.getPrefix(), code.getNamespaceURI(), code.getLocalName()); + qCode = new StructuredQName(code.getPrefix(), code.getNamespaceUri(), code.getLocalName()); } } if (qCode != null) { - nsmap = nsmap.put(qCode.getPrefix(), qCode.getNamespaceBinding().getURI()); + nsmap = nsmap.put(qCode.getPrefix(), qCode.getNamespaceBinding().getNamespaceUri()); alist.add(new AttributeInfo(TypeUtils.fqName(_code), BuiltInAtomicType.ANY_ATOMIC, qCode.getDisplayName(), null, ReceiverOption.NONE)); } diff --git a/src/main/java/com/xmlcalabash/util/AxisNodes.java b/src/main/java/com/xmlcalabash/util/AxisNodes.java index e2901801..cb55bf2c 100644 --- a/src/main/java/com/xmlcalabash/util/AxisNodes.java +++ b/src/main/java/com/xmlcalabash/util/AxisNodes.java @@ -52,8 +52,8 @@ public class AxisNodes implements Iterable { private static final int VALID_BITS = PIPELINE; protected Logger logger = LoggerFactory.getLogger(AxisNodes.class); - private static QName use_when = new QName("", "use-when"); - private static QName p_use_when = new QName(XProcConstants.NS_XPROC, "use-when"); + private static final QName use_when = new QName("", "use-when"); + private static final QName p_use_when = XProcConstants.qNameFor(XProcConstants.NS_XPROC, "use-when"); private AxisNodesIter iter = null; private XProcRuntime runtime = null; private int filter = ALL; @@ -87,7 +87,7 @@ public Iterator iterator() { } private class AxisNodesIter implements Iterator { - private XdmSequenceIterator iter = null; + private XdmSequenceIterator iter = null; private XdmNode next = null; private boolean finished = false; private boolean hasNext = false; @@ -171,11 +171,9 @@ private boolean ok(XdmNode node) { && node.getNodeKind() == XdmNodeKind.ELEMENT) { String expr = null; - if (XProcConstants.NS_XPROC.equals(node.getNodeName().getNamespaceURI())) { + if (XProcConstants.NS_XPROC == node.getNodeName().getNamespaceUri()) { expr = node.getAttributeValue(use_when); - } - - if (!XProcConstants.NS_XPROC.equals(node.getNodeName().getNamespaceURI())) { + } else { expr = node.getAttributeValue(p_use_when); } @@ -224,7 +222,7 @@ private boolean useWhen(XdmNode element, String xpath) { Throwable sae = saue.getCause(); if (sae instanceof XPathException) { XPathException xe = (XPathException) sae; - if ("http://www.w3.org/2005/xqt-errors".equals(xe.getErrorCodeNamespace()) && "XPDY0002".equals(xe.getErrorCodeLocalPart())) { + if (xe.getErrorCodeNamespace() == XProcConstants.NS_XQT_ERRORS && "XPDY0002".equals(xe.getErrorCodeLocalPart())) { throw XProcException.dynamicError(26, element, "Expression refers to context when none is available: " + xpath); } else { throw saue; diff --git a/src/main/java/com/xmlcalabash/util/DefaultXMLCalabashConfigurer.java b/src/main/java/com/xmlcalabash/util/DefaultXMLCalabashConfigurer.java index 410117ef..83777049 100644 --- a/src/main/java/com/xmlcalabash/util/DefaultXMLCalabashConfigurer.java +++ b/src/main/java/com/xmlcalabash/util/DefaultXMLCalabashConfigurer.java @@ -24,7 +24,7 @@ public class DefaultXMLCalabashConfigurer implements XMLCalabashConfigurer { private static final QName _href = new QName("href"); private static final QName _dtd_validate = new QName("dtd-validate"); - private final static QName cx_filemask = new QName("cx", XProcConstants.NS_CALABASH_EX,"filemask"); + private final static QName cx_filemask = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX,"filemask"); protected XProcRuntime runtime = null; public DefaultXMLCalabashConfigurer(XProcRuntime runtime) { diff --git a/src/main/java/com/xmlcalabash/util/DefaultXProcMessageListener.java b/src/main/java/com/xmlcalabash/util/DefaultXProcMessageListener.java index 8c754b5a..ecc49bf6 100644 --- a/src/main/java/com/xmlcalabash/util/DefaultXProcMessageListener.java +++ b/src/main/java/com/xmlcalabash/util/DefaultXProcMessageListener.java @@ -79,7 +79,7 @@ private String exceptionMessage(Throwable exception) { loc = err.getLocator(); if (err.getErrorCode() != null) { QName n = err.getErrorCode(); - qCode = new StructuredQName(n.getPrefix(),n.getNamespaceURI(),n.getLocalName()); + qCode = new StructuredQName(n.getPrefix(),n.getNamespaceUri(),n.getLocalName()); } if (err.getStep() != null) { message = message + err.getStep() + ":"; diff --git a/src/main/java/com/xmlcalabash/util/JSONtoXML.java b/src/main/java/com/xmlcalabash/util/JSONtoXML.java index ef20cdc8..1b192849 100644 --- a/src/main/java/com/xmlcalabash/util/JSONtoXML.java +++ b/src/main/java/com/xmlcalabash/util/JSONtoXML.java @@ -4,6 +4,7 @@ import com.xmlcalabash.core.XProcException; import net.sf.saxon.om.AttributeMap; import net.sf.saxon.om.EmptyAttributeMap; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.om.SingletonAttributeMap; import net.sf.saxon.s9api.Processor; import net.sf.saxon.s9api.QName; @@ -31,37 +32,37 @@ public class JSONtoXML { public static final String JXML = "jxml"; public static final String MARKLOGIC = "marklogic"; - public static final String JSONX_NS = "http://www.ibm.com/xmlns/prod/2009/jsonx"; - public static final String MLJS_NS = "http://marklogic.com/json"; - public static final String JXML_NS = "http://www.xmlsh.org/jxml"; + public static final NamespaceUri JSONX_NS = NamespaceUri.of("http://www.ibm.com/xmlns/prod/2009/jsonx"); + public static final NamespaceUri MLJS_NS = NamespaceUri.of("http://marklogic.com/json"); + public static final NamespaceUri JXML_NS = NamespaceUri.of("http://www.xmlsh.org/jxml"); private static final QName _type = new QName("", "type"); private static final QName _name = new QName("", "name"); - private static final QName c_json = new QName("c", XProcConstants.NS_XPROC_STEP, "json"); - private static final QName c_pair = new QName("c", XProcConstants.NS_XPROC_STEP, "pair"); - private static final QName c_item = new QName("c", XProcConstants.NS_XPROC_STEP, "item"); + private static final QName c_json = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "json"); + private static final QName c_pair = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "pair"); + private static final QName c_item = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "item"); private static final QName _json = new QName("json"); private static final QName _pair = new QName("pair"); private static final QName _item = new QName("item"); - private static final QName j_object = new QName("j", JSONX_NS, "object"); - private static final QName j_array = new QName("j", JSONX_NS, "array"); - private static final QName j_string = new QName("j", JSONX_NS, "string"); - private static final QName j_number = new QName("j", JSONX_NS, "number"); - private static final QName j_boolean = new QName("j", JSONX_NS, "boolean"); - private static final QName j_null = new QName("j", JSONX_NS, "null"); + private static final QName j_object = XProcConstants.qNameFor("j", JSONX_NS, "object"); + private static final QName j_array = XProcConstants.qNameFor("j", JSONX_NS, "array"); + private static final QName j_string = XProcConstants.qNameFor("j", JSONX_NS, "string"); + private static final QName j_number = XProcConstants.qNameFor("j", JSONX_NS, "number"); + private static final QName j_boolean = XProcConstants.qNameFor("j", JSONX_NS, "boolean"); + private static final QName j_null = XProcConstants.qNameFor("j", JSONX_NS, "null"); - private static final QName mj_json = new QName("j", MLJS_NS, "json"); + private static final QName mj_json = XProcConstants.qNameFor("j", MLJS_NS, "json"); - private static final QName jx_object = new QName("j", JXML_NS, "object"); - private static final QName jx_member = new QName("j", JXML_NS, "member"); - private static final QName jx_boolean = new QName("j", JXML_NS, "boolean"); - private static final QName jx_array = new QName("j", JXML_NS, "array"); - private static final QName jx_string = new QName("j", JXML_NS, "string"); - private static final QName jx_number = new QName("j", JXML_NS, "number"); - private static final QName jx_null = new QName("j", JXML_NS, "null"); + private static final QName jx_object = XProcConstants.qNameFor("j", JXML_NS, "object"); + private static final QName jx_member = XProcConstants.qNameFor("j", JXML_NS, "member"); + private static final QName jx_boolean = XProcConstants.qNameFor("j", JXML_NS, "boolean"); + private static final QName jx_array = XProcConstants.qNameFor("j", JXML_NS, "array"); + private static final QName jx_string = XProcConstants.qNameFor("j", JXML_NS, "string"); + private static final QName jx_number = XProcConstants.qNameFor("j", JXML_NS, "number"); + private static final QName jx_null = XProcConstants.qNameFor("j", JXML_NS, "null"); public static boolean knownFlavor(String jsonFlavor) { return (JSONtoXML.CALABASH_DEPRECATED.equals(jsonFlavor) @@ -231,7 +232,7 @@ private static void serializeMarkLogic(TreeWriter tree, Object json, String name } } - QName elemName = new QName("j", MLJS_NS, localName.toString()); + QName elemName = XProcConstants.qNameFor("j", MLJS_NS, localName.toString()); if (json instanceof JSONObject) { tree.addStartElement(elemName, SingletonAttributeMap.of(TypeUtils.attributeInfo(_type, "object"))); diff --git a/src/main/java/com/xmlcalabash/util/NodeToBytes.java b/src/main/java/com/xmlcalabash/util/NodeToBytes.java index 32969942..14cd5f22 100644 --- a/src/main/java/com/xmlcalabash/util/NodeToBytes.java +++ b/src/main/java/com/xmlcalabash/util/NodeToBytes.java @@ -27,6 +27,7 @@ import com.xmlcalabash.library.DefaultStep; import com.xmlcalabash.model.RuntimeValue; import com.xmlcalabash.runtime.XAtomicStep; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.Serializer; @@ -43,10 +44,10 @@ public class NodeToBytes { private static final QName _encoding = new QName("encoding"); private static final QName _content_type = new QName("content-type"); - private static final QName c_encoding = new QName("c", XProcConstants.NS_XPROC_STEP, "encoding"); - private static final QName c_body = new QName("c", XProcConstants.NS_XPROC_STEP, "body"); - private static final QName c_json = new QName("c", XProcConstants.NS_XPROC_STEP, "json"); - private static final QName cx_decode = new QName("cx", XProcConstants.NS_CALABASH_EX, "decode"); + private static final QName c_encoding = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "encoding"); + private static final QName c_body = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "body"); + private static final QName c_json = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "json"); + private static final QName cx_decode = XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, "decode"); private NodeToBytes() { // you aren't allowed to do this @@ -56,20 +57,22 @@ public static byte[] convert(XProcRuntime runtime, XdmNode doc, boolean decode) ByteArrayOutputStream stream = new ByteArrayOutputStream(); XdmNode root = S9apiUtils.getDocumentElement(doc); + assert root != null; + if (decode - && ((XProcConstants.NS_XPROC_STEP.equals(root.getNodeName().getNamespaceURI()) + && ((XProcConstants.NS_XPROC_STEP == root.getNodeName().getNamespaceUri()) && "base64".equals(root.getAttributeValue(_encoding))) - || ("".equals(root.getNodeName().getNamespaceURI()) - && "base64".equals(root.getAttributeValue(c_encoding))))) { + || (root.getNodeName().getNamespaceUri() == NamespaceUri.NULL) + && "base64".equals(root.getAttributeValue(c_encoding))) { storeBinary(doc, stream); } else if (runtime.transparentJSON() && (((c_body.equals(root.getNodeName()) && ("application/json".equals(root.getAttributeValue(_content_type)) || "text/json".equals(root.getAttributeValue(_content_type)))) || c_json.equals(root.getNodeName())) - || JSONtoXML.JSONX_NS.equals(root.getNodeName().getNamespaceURI()) - || JSONtoXML.JXML_NS.equals(root.getNodeName().getNamespaceURI()) - || JSONtoXML.MLJS_NS.equals(root.getNodeName().getNamespaceURI()))) { + || JSONtoXML.JSONX_NS == root.getNodeName().getNamespaceUri() + || JSONtoXML.JXML_NS == root.getNodeName().getNamespaceUri() + || JSONtoXML.MLJS_NS == root.getNodeName().getNamespaceUri())) { storeJSON(doc, stream); } else { storeXML(runtime, doc, stream); diff --git a/src/main/java/com/xmlcalabash/util/ParseArgs.java b/src/main/java/com/xmlcalabash/util/ParseArgs.java index 15f20189..a811f1d2 100644 --- a/src/main/java/com/xmlcalabash/util/ParseArgs.java +++ b/src/main/java/com/xmlcalabash/util/ParseArgs.java @@ -1,6 +1,7 @@ package com.xmlcalabash.util; import com.xmlcalabash.core.XProcException; +import net.sf.saxon.om.NamespaceUri; import static com.xmlcalabash.util.Input.Type.DATA; import static com.xmlcalabash.util.Input.Type.XML; @@ -123,7 +124,7 @@ public UserArgs parse(String[] args) { if (arg.startsWith("-b") || arg.equals("--binding")) { KeyValuePair v = parseKeyValue("b", "binding"); - userArgs.addBinding(v.key, v.value); + userArgs.addBinding(v.key, NamespaceUri.of(v.value)); continue; } diff --git a/src/main/java/com/xmlcalabash/util/ProcessMatch.java b/src/main/java/com/xmlcalabash/util/ProcessMatch.java index b647ee45..d1b839cb 100644 --- a/src/main/java/com/xmlcalabash/util/ProcessMatch.java +++ b/src/main/java/com/xmlcalabash/util/ProcessMatch.java @@ -305,23 +305,22 @@ private void traverse(XdmNode node, boolean deep) { } private static class MatchingNamespaceResolver implements NamespaceResolver { - private HashMap ns = new HashMap (); + private HashMap ns = new HashMap (); - public MatchingNamespaceResolver(HashMap bindings) { + public MatchingNamespaceResolver(HashMap bindings) { ns = bindings; } - public String getURIForPrefix(String prefix, boolean useDefault) { + public NamespaceUri getURIForPrefix(String prefix, boolean useDefault) { if ("".equals(prefix) && !useDefault) { - return ""; + return NamespaceUri.NULL; } return ns.get(prefix); } public Iterator iteratePrefixes() { - Vector p = new Vector (); - p.addAll(ns.keySet()); + Vector p = new Vector<>(ns.keySet()); return p.iterator(); } } diff --git a/src/main/java/com/xmlcalabash/util/S9apiUtils.java b/src/main/java/com/xmlcalabash/util/S9apiUtils.java index 3248e9ad..e8cde2b7 100644 --- a/src/main/java/com/xmlcalabash/util/S9apiUtils.java +++ b/src/main/java/com/xmlcalabash/util/S9apiUtils.java @@ -242,8 +242,8 @@ public static InputSource xdmToInputSource(XProcRuntime runtime, XdmNode node) t return isource; } - public static HashSet excludeInlinePrefixes(XdmNode node, String prefixList) { - HashSet excludeURIs = new HashSet (); + public static HashSet excludeInlinePrefixes(XdmNode node, String prefixList) { + HashSet excludeURIs = new HashSet<> (); excludeURIs.add(XProcConstants.NS_XPROC); if (prefixList != null) { @@ -258,7 +258,7 @@ public static HashSet excludeInlinePrefixes(XdmNode node, String prefixL all = true; } else if ("#default".equals(pfx)) { found = true; - if (!"".equals(nsmap.getDefaultNamespace())) { + if (nsmap.getDefaultNamespace() != NamespaceUri.NULL) { excludeURIs.add(nsmap.getDefaultNamespace()); } } else { @@ -281,11 +281,11 @@ public static HashSet excludeInlinePrefixes(XdmNode node, String prefixL return excludeURIs; } - public static XdmNode removeNamespaces(XProcRuntime runtime, XdmNode node, HashSet excludeNS, boolean preserveUsed) { + public static XdmNode removeNamespaces(XProcRuntime runtime, XdmNode node, HashSet excludeNS, boolean preserveUsed) { return removeNamespaces(runtime.getProcessor(), node, excludeNS, preserveUsed); } - public static XdmNode removeNamespaces(Processor proc, XdmNode node, HashSet excludeNS, boolean preserveUsed) { + public static XdmNode removeNamespaces(Processor proc, XdmNode node, HashSet excludeNS, boolean preserveUsed) { TreeWriter tree = new TreeWriter(proc); tree.startDocument(node.getBaseURI()); removeNamespacesWriter(tree, node, excludeNS, preserveUsed); @@ -293,7 +293,7 @@ public static XdmNode removeNamespaces(Processor proc, XdmNode node, HashSet excludeNS, boolean preserveUsed) { + private static void removeNamespacesWriter(TreeWriter tree, XdmNode node, HashSet excludeNS, boolean preserveUsed) { if (node.getNodeKind() == XdmNodeKind.DOCUMENT) { XdmSequenceIterator iter = node.axisIterator(Axis.CHILD); while (iter.hasNext()) { @@ -301,8 +301,7 @@ private static void removeNamespacesWriter(TreeWriter tree, XdmNode node, HashSe removeNamespacesWriter(tree, cnode, excludeNS, preserveUsed); } } else if (node.getNodeKind() == XdmNodeKind.ELEMENT) { - boolean usesDefaultNS = ("".equals(node.getNodeName().getPrefix()) - && !"".equals(node.getNodeName().getNamespaceURI())); + boolean usesDefaultNS = ("".equals(node.getNodeName().getPrefix()) && node.getNodeName().getNamespaceUri() != NamespaceUri.NULL); NamespaceMap nsmap = node.getUnderlyingNode().getAllNamespaces(); boolean excludeDefault = false; @@ -311,7 +310,7 @@ private static void removeNamespacesWriter(TreeWriter tree, XdmNode node, HashSe Iterator pfxiter = nsmap.iteratePrefixes(); while (pfxiter.hasNext()) { String pfx = pfxiter.next(); - String uri = nsmap.getURIForPrefix(pfx, "".equals(pfx)); + NamespaceUri uri = nsmap.getURIForPrefix(pfx, "".equals(pfx)); boolean delete = excludeNS.contains(uri); excludeDefault = excludeDefault || ("".equals(pfx) && delete); @@ -334,8 +333,8 @@ private static void removeNamespacesWriter(TreeWriter tree, XdmNode node, HashSe NodeName newName = NameOfNode.makeName(inode); if (!preserveUsed) { NamespaceBinding binding = newName.getNamespaceBinding(); - if (excludeNS.contains(binding.getURI())) { - newName = new FingerprintedQName("", "", newName.getLocalPart()); + if (excludeNS.contains(binding.getNamespaceUri())) { + newName = new FingerprintedQName("", NamespaceUri.NULL, newName.getLocalPart()); } } diff --git a/src/main/java/com/xmlcalabash/util/StepErrorListener.java b/src/main/java/com/xmlcalabash/util/StepErrorListener.java index 6e57530a..191e943a 100644 --- a/src/main/java/com/xmlcalabash/util/StepErrorListener.java +++ b/src/main/java/com/xmlcalabash/util/StepErrorListener.java @@ -26,13 +26,13 @@ * This listener collects messages to send to the error port if applicable. */ public class StepErrorListener implements ErrorListener { - private static QName c_error = new QName(XProcConstants.NS_XPROC_STEP, "error"); - private static StructuredQName err_sxxp0003 = new StructuredQName("err", "http://www.w3.org/2005/xqt-errors", "SXXP0003"); - private static QName _type = new QName("", "type"); - private static QName _href = new QName("", "href"); - private static QName _line = new QName("", "line"); - private static QName _column = new QName("", "column"); - private static QName _code = new QName("", "code"); + private static final QName c_error = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "error"); + private static final StructuredQName err_sxxp0003 = new StructuredQName("err", NamespaceUri.of("http://www.w3.org/2005/xqt-errors"), "SXXP0003"); + private static final QName _type = new QName("", "type"); + private static final QName _href = new QName("", "href"); + private static final QName _line = new QName("", "line"); + private static final QName _column = new QName("", "column"); + private static final QName _code = new QName("", "code"); private XProcRuntime runtime = null; private URI baseURI = null; @@ -101,7 +101,7 @@ private boolean report(String type, TransformerException exception) { NamespaceMap nsmap = NamespaceMap.emptyMap(); if (qCode != null) { - nsmap = nsmap.put(qCode.getPrefix(), qCode.getNamespaceBinding().getURI()); + nsmap = nsmap.put(qCode.getPrefix(), qCode.getNamespaceBinding().getNamespaceUri()); alist.add(new AttributeInfo(TypeUtils.fqName(_code), BuiltInAtomicType.ANY_ATOMIC, qCode.getDisplayName(), null, ReceiverOption.NONE)); } diff --git a/src/main/java/com/xmlcalabash/util/TreeWriter.java b/src/main/java/com/xmlcalabash/util/TreeWriter.java index f27522c3..b9fb0504 100644 --- a/src/main/java/com/xmlcalabash/util/TreeWriter.java +++ b/src/main/java/com/xmlcalabash/util/TreeWriter.java @@ -230,7 +230,7 @@ public void addStartElement(XdmNode node, QName newName, URI overrideBaseURI, At receiver.setSystemId(overrideBaseURI.toASCIIString()); } - FingerprintedQName newNameOfNode = new FingerprintedQName(newName.getPrefix(),newName.getNamespaceURI(),newName.getLocalName()); + FingerprintedQName newNameOfNode = new FingerprintedQName(newName.getPrefix(),newName.getNamespaceUri(),newName.getLocalName()); addStartElement(newNameOfNode, attrs, inode.getSchemaType(), inscopeNS); } @@ -239,7 +239,7 @@ public void addStartElement(QName newName, AttributeMap attrs) { } public void addStartElement(QName newName, AttributeMap attrs, NamespaceMap nsmap) { - NodeName elemName = new FingerprintedQName(newName.getPrefix(), newName.getNamespaceURI(), newName.getLocalName()); + NodeName elemName = new FingerprintedQName(newName.getPrefix(), newName.getNamespaceUri(), newName.getLocalName()); addStartElement(elemName, attrs, Untyped.INSTANCE, nsmap); } @@ -261,10 +261,10 @@ public void addStartElement(NodeName elemName, AttributeMap attrs, SchemaType ty public void addStartElement(NodeName elemName, AttributeMap attrs, SchemaType typeCode, NamespaceMap nsmap) { // Sort out the namespaces... - nsmap = updateMap(nsmap, elemName.getPrefix(), elemName.getURI()); + nsmap = updateMap(nsmap, elemName.getPrefix(), elemName.getNamespaceUri()); for (AttributeInfo attr : attrs) { if (attr.getNodeName().getURI() != null && !"".equals(attr.getNodeName().getURI())) { - nsmap = updateMap(nsmap, attr.getNodeName().getPrefix(), attr.getNodeName().getURI()); + nsmap = updateMap(nsmap, attr.getNodeName().getPrefix(), attr.getNodeName().getNamespaceUri()); } } @@ -283,18 +283,19 @@ public void addStartElement(NodeName elemName, AttributeMap attrs, SchemaType ty } } - private NamespaceMap updateMap(NamespaceMap nsmap, String prefix, String uri) { - if (uri == null || "".equals(uri)) { + private NamespaceMap updateMap(NamespaceMap nsmap, String prefix, NamespaceUri uri) { + if (uri == NamespaceUri.NULL) { return nsmap; } if (prefix == null || "".equals(prefix)) { - if (!uri.equals(nsmap.getDefaultNamespace())) { + if (uri != nsmap.getDefaultNamespace()) { return nsmap.put("", uri); } + return nsmap; } - String curNS = nsmap.getURI(prefix); + NamespaceUri curNS = nsmap.getURIForPrefix(prefix, false); if (curNS == null) { return nsmap.put(prefix, uri); } else if (curNS.equals(uri)) { diff --git a/src/main/java/com/xmlcalabash/util/TypeUtils.java b/src/main/java/com/xmlcalabash/util/TypeUtils.java index dab233a0..9ab4f4d9 100644 --- a/src/main/java/com/xmlcalabash/util/TypeUtils.java +++ b/src/main/java/com/xmlcalabash/util/TypeUtils.java @@ -48,14 +48,14 @@ public class TypeUtils { private static final QName _ListOfQNames = new QName("ListOfQNames"); private static final QName _XPathExpression = new QName("XPathExpression"); private static final QName _NormalizationForm = new QName("NormalizationForm"); - private static final QName err_XD0045 = new QName(XProcConstants.NS_XPROC_ERROR, "XD0045"); + private static final QName err_XD0045 = XProcConstants.qNameFor(XProcConstants.NS_XPROC_ERROR, "XD0045"); private static int anonTypeCount = 0; public static QName generateUniqueType(String baseName) { anonTypeCount++; String localName = baseName + "_" + anonTypeCount; - return new QName(XProcConstants.NS_CALABASH_EX, localName); + return XProcConstants.qNameFor(XProcConstants.NS_CALABASH_EX, localName); } public static QName generateUniqueType() { @@ -116,7 +116,7 @@ public static void checkType(XProcRuntime runtime, String value, QName type, Xdm } public static FingerprintedQName fqName(QName name) { - return new FingerprintedQName(name.getPrefix(), name.getNamespaceURI(), name.getLocalName()); + return new FingerprintedQName(name.getPrefix(), name.getNamespaceUri(), name.getLocalName()); } public static AttributeInfo attributeInfo(QName name, String value) { diff --git a/src/main/java/com/xmlcalabash/util/UserArgs.java b/src/main/java/com/xmlcalabash/util/UserArgs.java index f92fb735..f2dab6d9 100644 --- a/src/main/java/com/xmlcalabash/util/UserArgs.java +++ b/src/main/java/com/xmlcalabash/util/UserArgs.java @@ -18,14 +18,12 @@ import javax.xml.transform.sax.SAXSource; import com.xmlcalabash.core.XProcConfiguration; +import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; import com.xmlcalabash.runtime.XLibrary; import com.xmlcalabash.util.Input.Type; -import net.sf.saxon.om.AttributeMap; -import net.sf.saxon.om.EmptyAttributeMap; -import net.sf.saxon.om.NamespaceMap; -import net.sf.saxon.om.SingletonAttributeMap; +import net.sf.saxon.om.*; import net.sf.saxon.s9api.DocumentBuilder; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; @@ -84,7 +82,7 @@ public class UserArgs { protected Input pipeline = null; protected List libraries = new ArrayList<>(); protected Map outputs = new HashMap<>(); - protected Map bindings = new HashMap<>(); + protected Map bindings = new HashMap<>(); protected List steps = new ArrayList<>(); protected StepArgs curStep = new StepArgs(); protected StepArgs lastStep = null; @@ -281,7 +279,7 @@ public void addOutput(String port, OutputStream outputStream) { outputs.put(port, new Output(outputStream)); } - public void addBinding(String prefix, String uri) { + public void addBinding(String prefix, NamespaceUri uri) { if (bindings.containsKey(prefix)) { throw new XProcException("Duplicate prefix binding: '" + prefix + "'."); } @@ -824,8 +822,8 @@ public XdmNode getImplicitPipeline(XProcRuntime runtime) throws IOException { if (!"*".equals(port)) { attr = attr.put(TypeUtils.attributeInfo(new QName("port"), port)); } - if (!pname.getPrefix().isEmpty() || !pname.getNamespaceURI().isEmpty()) { - nsmap = nsmap.put(pname.getPrefix(), pname.getNamespaceURI()); + if (!pname.getPrefix().isEmpty() || !pname.getNamespaceUri().isEmpty()) { + nsmap = nsmap.put(pname.getPrefix(), pname.getNamespaceUri()); } tree.addStartElement(p_with_param, attr, nsmap); @@ -922,8 +920,8 @@ private QName makeQName(String name) { if (!bindings.containsKey(prefix)) { throw new XProcException("Unbound prefix '" + prefix + "' in: '" + name + "'."); } - String uri = bindings.get(prefix); - qname = new QName(prefix, uri, name.substring(cpos + 1)); + NamespaceUri uri = bindings.get(prefix); + qname = XProcConstants.qNameFor(prefix, uri, name.substring(cpos + 1)); } else { qname = new QName("", name); } @@ -943,8 +941,8 @@ public void checkArgs() { } stepName = makeQName(plainStepName); - if ("".equals(stepName.getNamespaceURI())) { - stepName = new QName("p", "http://www.w3.org/ns/xproc", stepName.getLocalName()); + if (stepName.getNamespaceUri() == NamespaceUri.NULL) { + stepName = XProcConstants.qNameFor(XProcConstants.NS_XPROC, stepName.getLocalName()); } options.clear(); diff --git a/src/main/java/com/xmlcalabash/util/XMLtoJSON.java b/src/main/java/com/xmlcalabash/util/XMLtoJSON.java index 6d2a09b4..d774805c 100644 --- a/src/main/java/com/xmlcalabash/util/XMLtoJSON.java +++ b/src/main/java/com/xmlcalabash/util/XMLtoJSON.java @@ -29,15 +29,16 @@ public class XMLtoJSON { private static final int OBJECT = 1; private static final int ARRAY = 2; - private static QName _type = new QName("", "type"); - private static QName _name = new QName("", "name"); + private static final QName _type = new QName("", "type"); + private static final QName _name = new QName("", "name"); - private static final QName c_body = new QName("c", XProcConstants.NS_XPROC_STEP, "body"); + private static final QName c_body = XProcConstants.qNameFor(XProcConstants.NS_XPROC_STEP, "body"); public static String convert(XdmNode json) { JSONStringer js = new JSONStringer(); json = S9apiUtils.getDocumentElement(json); + assert json != null; if (c_body.equals(json.getNodeName())) { XdmNode jchild = null; @@ -70,15 +71,15 @@ public static String convert(XdmNode json) { private static void build(XdmNode json, JSONStringer js, int context) throws JSONException { String type = null; - if (JSONtoXML.JSONX_NS.equals(json.getNodeName().getNamespaceURI()) - || JSONtoXML.JXML_NS.equals(json.getNodeName().getNamespaceURI())) { + if (JSONtoXML.JSONX_NS == json.getNodeName().getNamespaceUri() + || JSONtoXML.JXML_NS == json.getNodeName().getNamespaceUri()) { type = json.getNodeName().getLocalName(); } else { type = json.getAttributeValue(_type); } String name = null; - if (JSONtoXML.MLJS_NS.equals(json.getNodeName().getNamespaceURI())) { + if (JSONtoXML.MLJS_NS == json.getNodeName().getNamespaceUri()) { name = json.getNodeName().getLocalName(); if (name.contains("_")) { if ("_".equals(name)) { diff --git a/src/main/java/com/xmlcalabash/util/XPointer.java b/src/main/java/com/xmlcalabash/util/XPointer.java index 9fa84fef..adf999e8 100644 --- a/src/main/java/com/xmlcalabash/util/XPointer.java +++ b/src/main/java/com/xmlcalabash/util/XPointer.java @@ -3,6 +3,7 @@ import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.XdmNode; @@ -39,12 +40,12 @@ public XPointer(XProcRuntime runtime, String xpointer, int readLimit) { } } - public HashMap xpathNamespaces() { - HashMap bindings = new HashMap (); + public HashMap xpathNamespaces() { + HashMap bindings = new HashMap<> (); for (XPointerScheme scheme : parts) { if (_xmlns.equals(scheme.getName())) { XPointerXmlnsScheme xmlns = (XPointerXmlnsScheme) scheme; - bindings.put(xmlns.getPrefix(), xmlns.getURI()); + bindings.put(xmlns.getPrefix(), NamespaceUri.of(xmlns.getURI())); } } return bindings; diff --git a/src/main/java/com/xmlcalabash/util/XPointerScheme.java b/src/main/java/com/xmlcalabash/util/XPointerScheme.java index ff32ca09..1e248c15 100644 --- a/src/main/java/com/xmlcalabash/util/XPointerScheme.java +++ b/src/main/java/com/xmlcalabash/util/XPointerScheme.java @@ -2,6 +2,7 @@ import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; import net.sf.saxon.s9api.SaxonApiException; import net.sf.saxon.s9api.XPathCompiler; @@ -74,7 +75,7 @@ public String textEquivalent() { return null; } - public Vector selectNodes(XProcRuntime runtime, XdmNode doc, HashMap nsBindings) { + public Vector selectNodes(XProcRuntime runtime, XdmNode doc, HashMap nsBindings) { String select = xpathEquivalent(); if (select == null) { diff --git a/src/main/java/com/xmlcalabash/util/XProcSystemPropertySet.java b/src/main/java/com/xmlcalabash/util/XProcSystemPropertySet.java index a6a64768..63bd55a8 100644 --- a/src/main/java/com/xmlcalabash/util/XProcSystemPropertySet.java +++ b/src/main/java/com/xmlcalabash/util/XProcSystemPropertySet.java @@ -3,6 +3,7 @@ import com.xmlcalabash.core.XProcConstants; import com.xmlcalabash.core.XProcException; import com.xmlcalabash.core.XProcRuntime; +import net.sf.saxon.om.NamespaceUri; import net.sf.saxon.s9api.QName; /** @@ -28,10 +29,10 @@ public interface XProcSystemPropertySet { XProcSystemPropertySet BUILTIN = new XProcSystemPropertySet() { @Override public String systemProperty(XProcRuntime runtime, QName propertyName) throws XProcException { - String uri = propertyName.getNamespaceURI(); + NamespaceUri uri = propertyName.getNamespaceUri(); String local = propertyName.getLocalName(); - if (uri.equals(XProcConstants.NS_XPROC)) { + if (uri == XProcConstants.NS_XPROC) { if ("episode".equals(local)) { return runtime.getEpisode(); } else if ("language".equals(local)) { @@ -53,7 +54,7 @@ public String systemProperty(XProcRuntime runtime, QName propertyName) throws XP } else { return null; } - } else if (uri.equals(XProcConstants.NS_CALABASH_EX)) { + } else if (uri == XProcConstants.NS_CALABASH_EX) { if ("transparent-json".equals(local)) { return runtime.transparentJSON() ? "true" : "false"; } else if ("json-flavor".equals(local)) {