Exemple #1
0
        /// <summary>
        /// Attempts to resolve a QName or URI Token into a URI Node and produces appropriate error messages if this fails
        /// </summary>
        /// <param name="handler">Results Handler</param>
        /// <param name="t">Token to resolve</param>
        /// <returns></returns>
        /// <remarks>
        /// It is <strong>not</strong> recommended to use this overload since an <see cref="IRdfHandler">IRdfHandler</see> cannot resolve QNames
        /// </remarks>
        internal static INode TryResolveUri(ISparqlResultsHandler handler, IToken t)
        {
            switch (t.TokenType)
            {
            case Token.QNAME:
                throw new RdfException("Unable to resolve the QName since a Results Handler does not have a Namespace Map that can be used to resolve QNames");

            case Token.URI:
                try
                {
                    String uri = Tools.ResolveUri(t.Value, String.Empty);
                    return(handler.CreateUriNode(new Uri(uri)));
                }
                catch (UriFormatException formatEx)
                {
                    throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx);
                }
                catch (RdfException rdfEx)
                {
                    throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx);
                }

            default:
                throw ParserHelper.Error("Unexpected Token '" + t.GetType().ToString() + "' encountered, expected a URI/QName Token to resolve into a URI", t);
            }
        }
Exemple #2
0
        private INode GetSparqlValue(XElement binding, ISparqlResultsHandler resultSetHandler)
        {
            if (binding.Nodes().OfType <XElement>().Count() == 1)
            {
                var element = binding.Nodes().OfType <XElement>().First();

                if (element.Name.LocalName == "uri")
                {
                    string uri = element.Value;
                    return(resultSetHandler.CreateUriNode(new Uri(uri)));
                }
                else if (element.Name.LocalName == "literal")
                {
                    string value = element.Value;

                    if (element.Attribute("type") != null)
                    {
                        var type = element.Attribute("type").Value;
                        if (type.StartsWith("xsd:"))
                        {
                            type = "http://www.w3.org/2001/XMLSchema#" + type.Substring(4);
                        }

                        var uriType = new Uri(type);
                        return(resultSetHandler.CreateLiteralNode(value, uriType));
                    }
                    else if (element.Attribute("lang") != null)
                    {
                        var lang = element.Attribute("lang").Value;
                        return(resultSetHandler.CreateLiteralNode(value, lang));
                    }
                    else
                    {
                        return(resultSetHandler.CreateLiteralNode(value));
                    }
                }
                else if (element.Name.LocalName == "unbound")
                {
                    return(null);
                }
            }

            throw new NotImplementedException();
        }
Exemple #3
0
        /// <summary>
        /// Attempts to resolve a QName or URI Token into a URI Node and produces appropriate error messages if this fails
        /// </summary>
        /// <param name="handler">Results Handler</param>
        /// <param name="t">Token to resolve</param>
        /// <returns></returns>
        /// <remarks>
        /// It is <strong>not</strong> recommended to use this overload since an <see cref="IRdfHandler">IRdfHandler</see> cannot resolve QNames
        /// </remarks>
        internal static INode TryResolveUri(ISparqlResultsHandler handler, IToken t)
        {
            switch (t.TokenType)
            {
                case Token.QNAME:
                    throw new RdfException("Unable to resolve the QName since a Results Handler does not have a Namespace Map that can be used to resolve QNames");

                case Token.URI:
                    try
                    {
                        String uri = Tools.ResolveUri(t.Value, String.Empty);
                        return handler.CreateUriNode(UriFactory.Create(uri));
                    }
                    catch (UriFormatException formatEx)
                    {
                        throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx);
                    }
                    catch (RdfException rdfEx)
                    {
                        throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx);
                    }

                default:
                    throw ParserHelper.Error("Unexpected Token '" + t.GetType().ToString() + "' encountered, expected a URI/QName Token to resolve into a URI", t);
            }
        }