Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xmlbeans.impl.xpath.saxon;
import net.sf.saxon.Configuration;
import net.sf.saxon.dom.DocumentWrapper;
import net.sf.saxon.dom.NodeOverNodeInfo;
import net.sf.saxon.ma.map.HashTrieMap;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NamespaceUri;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.query.DynamicQueryContext;
import net.sf.saxon.query.StaticQueryContext;
import net.sf.saxon.query.XQueryExpression;
import net.sf.saxon.str.StringView;
import net.sf.saxon.type.BuiltInAtomicType;
import net.sf.saxon.value.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.store.Cur;
import org.apache.xmlbeans.impl.store.Cursor;
import org.apache.xmlbeans.impl.store.Locale;
import org.apache.xmlbeans.impl.xpath.XQuery;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPathException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
public class SaxonXQuery implements XQuery {
private static final Logger LOG = LogManager.getLogger(SaxonXQuery.class);
private final XQueryExpression xquery;
private final String contextVar;
private final Configuration config;
private Cur _cur;
private long _version;
private XmlOptions _options;
/**
* Construct given an XQuery expression string.
*
* @param query The XQuery expression
* @param contextVar The name of the context variable
* @param boundary The offset of the end of the prolog
*/
public SaxonXQuery(final String query, String contextVar, Integer boundary, XmlOptions xmlOptions) {
assert !(contextVar.startsWith(".") || contextVar.startsWith(".."));
_options = xmlOptions;
config = new Configuration();
StaticQueryContext sc = config.newStaticQueryContext();
Map nsMap = xmlOptions.getLoadAdditionalNamespaces();
if (nsMap != null) {
for (Map.Entry entry : nsMap.entrySet()) {
sc.declareNamespace(entry.getKey(), NamespaceUri.of(entry.getValue()));
}
}
this.contextVar = contextVar;
//Saxon requires external variables at the end of the prolog...
try {
xquery = sc.compileQuery(
query.substring(0, boundary) + " declare variable $" + contextVar + " external;" + query.substring(boundary)
);
} catch (TransformerException e) {
throw new XmlRuntimeException(e);
}
}
public XmlObject[] objectExecute(Cur c, XmlOptions options) {
_version = c.getLocale().version();
_cur = c.weakCur(this);
this._options = options;
Map bindings = XmlOptions.maskNull(_options).getXqueryVariables();
List