⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rdfxmlparser.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	private URI _buildURIFromReference(String uriReference)		throws SAXException	{		org.openrdf.util.uri.URI relUri = new org.openrdf.util.uri.URI(uriReference);		if (_verifyData) {			if (relUri.isRelative() && !relUri.isSelfReference() && // Relative URI that is not a self-reference				_baseURI.isOpaque())			{				sendError("Relative URI '" + uriReference +						"' cannot be resolved using the opaque base URI '" + _baseURI + "'");			}		}		String uriString = _baseURI.resolve(relUri).toString();		return _createURI(uriString);	}	private URI _createURI(String uri)		throws SAXException	{		try {			return _valueFactory.createURI(uri);		}		catch (Exception e) {			throw new SAXException(e);		}	}	private BNode _createBNode()		throws SAXException	{		try {			return _valueFactory.createBNode();		}		catch (Exception e) {			throw new SAXException(e);		}	}	private BNode _createBNode(String nodeID)		throws SAXException	{		if (_verifyData) {			// Check if 'nodeID' is a legal NCName			if (!XmlUtil.isNCName(nodeID)) {				sendError("Not an XML Name: " + nodeID);			}		}		// Maybe the node ID has been used before:		BNode result = (BNode)_bNodeIdMap.get(nodeID);		if (result == null) {			// This is a new node ID, create a new BNode object for it			try {				if (_preserveBNodeIds) {					result = _valueFactory.createBNode(nodeID);				}				else {					result = _valueFactory.createBNode();				}			}			catch (Exception e) {				throw new SAXException(e);			}			// Remember it, the nodeID might occur again.			_bNodeIdMap.put(nodeID, result);		}		return result;	}	private Literal _createLiteral(String label, String lang, String datatype)		throws SAXException	{		URI dtURI = null;		if (datatype != null) {			if (_datatypeHandling == DT_VERIFY) {				if (!XmlDatatypeUtil.isValidValue(label, datatype)) {					sendError("'" + label + "' is not a valid value for datatype " + datatype);				}			}			else if (_datatypeHandling == DT_NORMALIZE) {				try {					label = XmlDatatypeUtil.normalize(label, datatype);				}				catch (IllegalArgumentException e) {					sendError("'" + label + "' is not a valid value for datatype " + datatype + ": " + e.getMessage());				}			}			dtURI = _createURI(datatype);		}		try {			if (dtURI != null) {				return _valueFactory.createLiteral(label, dtURI);			}			else if (lang != null) {				return _valueFactory.createLiteral(label, lang);			}			else {				return _valueFactory.createLiteral(label);			}		}		catch (Exception e) {			throw new SAXException(e);		}	}	private Object _peekStack(int distFromTop) {		return _elementStack.get(_elementStack.size() - 1 - distFromTop);	}	private boolean _topIsProperty() {		return			_elementStack.isEmpty() ||			_peekStack(0) instanceof PropertyElement;	}	/**	 * Checks whether the node element name is from the RDF namespace and, if so, if it is	 * allowed to be used in a node element. If the name is equal to one of the disallowed	 * names (RDF, ID, about, parseType, resource, nodeID, datatype and li), an error is	 * generated. If the name is not defined in the RDF namespace, but it claims that it	 * is from this namespace, a warning is generated.	 **/	private void _checkNodeEltName(String namespaceURI, String localName, String qName)		throws SAXException	{		if (RDF.NAMESPACE.equals(namespaceURI)) {			if (localName.equals("Description") ||				localName.equals("Seq") ||				localName.equals("Bag") ||				localName.equals("Alt") ||				localName.equals("Statement") ||				localName.equals("Property") ||				localName.equals("List") ||				localName.equals("subject") ||				localName.equals("predicate") ||				localName.equals("object") ||				localName.equals("type") ||				localName.equals("value") ||				localName.equals("first") ||				localName.equals("rest") ||				localName.equals("nil") ||				localName.startsWith("_"))			{				// These are OK			}			else if (				localName.equals("li") ||				localName.equals("RDF") ||				localName.equals("ID") ||				localName.equals("about") ||				localName.equals("parseType") ||				localName.equals("resource") ||				localName.equals("nodeID") ||				localName.equals("datatype"))			{				sendError("<" + qName + "> not allowed as node element");			}			else if (				localName.equals("bagID") ||				localName.equals("aboutEach") ||				localName.equals("aboutEachPrefix"))			{				sendError(qName + " is no longer a valid RDF name");			}			else {				sendWarning("unknown rdf element <" + qName + ">");			}		}	}	/**	 * Checks whether the property element name is from the RDF namespace and, if so,	 * if it is allowed to be used in a property element. If the name is equal to one of	 * the disallowed names (RDF, ID, about, parseType, resource and li), an error is	 * generated. If the name is not defined in the RDF namespace, but it claims that it	 * is from this namespace, a warning is generated.	 **/	private void _checkPropertyEltName(String namespaceURI, String localName, String qName)		throws SAXException	{		if (RDF.NAMESPACE.equals(namespaceURI)) {			if (localName.equals("li") ||				localName.equals("Seq") ||				localName.equals("Bag") ||				localName.equals("Alt") ||				localName.equals("Statement") ||				localName.equals("Property") ||				localName.equals("List") ||				localName.equals("subject") ||				localName.equals("predicate") ||				localName.equals("object") ||				localName.equals("type") ||				localName.equals("value") ||				localName.equals("first") ||				localName.equals("rest") ||				localName.equals("nil") ||				localName.startsWith("_"))			{				// These are OK			}			else if (				localName.equals("Description") ||				localName.equals("RDF") ||				localName.equals("ID") ||				localName.equals("about") ||				localName.equals("parseType") ||				localName.equals("resource") ||				localName.equals("nodeID") ||				localName.equals("datatype"))			{				sendError("<" + qName + "> not allowed as property element");			}			else if (				localName.equals("bagID") ||				localName.equals("aboutEach") ||				localName.equals("aboutEachPrefix"))			{				sendError(qName + " is no longer a valid RDF name");			}			else {				sendWarning("unknown rdf element <" + qName + ">");			}		}	}	/**	 * Checks whether 'atts' contains attributes from the RDF namespace that are not	 * allowed as attributes. If such an attribute is found, an error is generated and	 * the attribute is removed from 'atts'. If the attribute is not defined in the RDF	 * namespace, but it claims that it is from this namespace, a warning is generated.	 **/	private void _checkRdfAtts(Atts atts)		throws SAXException	{		Iterator iter = atts.iterator();		while (iter.hasNext()) {			Att att = (Att)iter.next();			if (RDF.NAMESPACE.equals(att.getNamespace())) {				String localName = att.getLocalName();				if (localName.equals("Seq") ||					localName.equals("Bag") ||					localName.equals("Alt") ||					localName.equals("Statement") ||					localName.equals("Property") ||					localName.equals("List") ||					localName.equals("subject") ||					localName.equals("predicate") ||					localName.equals("object") ||					localName.equals("type") ||					localName.equals("value") ||					localName.equals("first") ||					localName.equals("rest") ||					localName.equals("nil") ||					localName.startsWith("_"))				{					// These are OK				}				else if (					localName.equals("Description") ||					localName.equals("li") ||					localName.equals("RDF") ||					localName.equals("ID") ||					localName.equals("about") ||					localName.equals("parseType") ||					localName.equals("resource") ||					localName.equals("nodeID") ||					localName.equals("datatype"))				{					sendError("'" + att.getQName() + "' not allowed as attribute name");					iter.remove();				}				else if (					localName.equals("bagID") ||					localName.equals("aboutEach") ||					localName.equals("aboutEachPrefix"))				{					sendError(att.getQName() + " is no longer a valid RDF name");				}				else {					sendWarning("unknown rdf attribute '" + att.getQName() + "'");				}			}		}	}	/**	 * Checks whether 'atts' is empty. If this is not the case, a warning is generated	 * for each attribute that is still present.	 **/	private void _checkNoMoreAtts(Atts atts)		throws SAXException	{		if (atts.size() > 0) {			Iterator iter = atts.iterator();			while (iter.hasNext()) {				Att att = (Att)iter.next();				sendError("unexpected attribute '" + att.getQName() + "'");				iter.remove();			}		}	}	/**	 * Reports a stament to the configured StatementHandler.	 *	 * @param subject The statement's subject.	 * @param predicate The statement's predicate.	 * @param object The statement's object.	 * @exception SAXException If the configured StatementHandler throws a	 * StatementHandlerException, which will be wrapped in a SAXException.	 **/	private void _reportStatement(Resource subject, URI predicate, Value object)		throws SAXException	{		try {			_statementHandler.handleStatement(subject, predicate, object);		}		catch (StatementHandlerException e) {			// Wrap exception in a SAXException, it will be unwrapped in the			// parse() method			throw new SAXException(e);		}	}	void sendWarning(String msg) {		if (_errorListener != null) {			Locator loc = _saxFilter.getLocator();			if (loc == null) {				_errorListener.warning(msg, -1, -1);			}			else {				_errorListener.warning(msg, loc.getLineNumber(), loc.getColumnNumber());			}		}	}	void sendError(String msg)		throws SAXException	{		if (_errorListener != null) {			Locator loc = _saxFilter.getLocator();			if (loc == null) {				_errorListener.error(msg, -1, -1);			}			else {				_errorListener.error(msg, loc.getLineNumber(), loc.getColumnNumber());			}		}		if (_stopAtFirstError) {			throw new SAXException(msg);		}	}	void sendFatalError(String msg)		throws SAXException	{		if (_errorListener != null) {			Locator loc = _saxFilter.getLocator();			if (loc == null) {				_errorListener.fatalError(msg, -1, -1);			}			else {				_errorListener.fatalError(msg, loc.getLineNumber(), loc.getColumnNumber());			}		}		throw new SAXException(msg);	}/*------------------------------------------------+| Inner classes NodeElement and PropertyElement   |+------------------------------------------------*/	static class NodeElement {		private Resource _resource;		private boolean _isVolatile = false;;		private int _liCounter = 1;		public NodeElement(Resource resource) {			_resource = resource;		}		public Resource getResource() {			return _resource;		}		public void setIsVolatile(boolean isVolatile) {			_isVolatile = isVolatile;		}		public boolean isVolatile() {			return _isVolatile;		}		public int getNextLiCounter() {			return _liCounter++;		}	}	static class PropertyElement {		/** The property URI. **/		private URI _uri;		/** An optional reification identifier. **/		private URI _reificationURI;		/** An optional datatype. **/		private String _datatype;		/** Flag indicating whether this PropertyElement has an		 * attribute <tt>rdf:parseType="Collection"</tt>.  **/		private boolean _parseCollection = false;		/** The resource that was used to append the last part		 * of an rdf:List. **/		private Resource _lastListResource;		public PropertyElement(URI uri) {			_uri = uri;		}		public URI getURI() {			return _uri;		}		public boolean isReified() {			return _reificationURI != null;		}		public void setReificationURI(URI reifURI) {			_reificationURI = reifURI;		}		public URI getReificationURI() {			return _reificationURI;		}		public void setDatatype(String datatype) {			_datatype = datatype;		}		public String getDatatype() {			return _datatype;		}		public boolean parseCollection() {			return _parseCollection;		}		public void setParseCollection(boolean parseCollection) {			_parseCollection = parseCollection;		}		public Resource getLastListResource() {			return _lastListResource;		}		public void setLastListResource(Resource resource) {			_lastListResource = resource;		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -