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 2010 Paul Gearon.
*
* 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 spark.protocol;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import spark.api.exception.SparqlException;
import spark.api.rdf.Literal;
import spark.api.rdf.RDFNode;
import spark.api.uris.XsdTypes;
import spark.spi.rdf.BlankNodeImpl;
import spark.spi.rdf.NamedNodeImpl;
import spark.spi.rdf.PlainLiteralImpl;
import spark.spi.rdf.TypedLiteralImpl;
/**
* Contains the results of a query operation.
*/
class XMLResultSetParser extends DefaultHandler {
public enum Element { SPARQL, HEAD, RESULTS, VARIABLE, LINK, RESULT, BINDING, URI, LITERAL, BNODE, BOOLEAN };
public enum ParseState {
STOPPED, STARTED, HEAD_SECT, AFTER_HEAD, READING_BOOLEAN, RESULTS_SECT,
RESULT_SECT, RESULT_BINDING, URI_BINDING, BNODE_BINDING, LITERAL_BINDING
};
private static final String VAR_NAME = "name";
private static final String HREF = "href";
private static final String LANG = "xml:lang";
private static final String DATATYPE = "datatype";
/** The state of the parser */
private ParseState state = ParseState.STOPPED;
/** An ordered list of variables in this result */
private List vars = new ArrayList();
/** A list of links in the header */
private List links = new ArrayList();
/** Number of rows in the results. */
private int rows = 0;
/** The current variable being bound. Only valid during a result section. */
private String bindingVar = null;
/** The language tag of the literal being scanned. Only valid during a "literal" section. */
private String literalLang = null;
/** The datatype of the literal being scanned. Only valid during a "literal" section. */
private URI literalType = null;
/** The current set of bindings being scanned. Only valid during a "result" section. */
private Map bindingMap = null;
/** The number of variables defined in this result. Initialized when the header is finalized. */
private int width = 0;
/** The data */
private List