/// <summary> /// Attempts to resolve a QName or URI Token into a URI Node and produces appropriate error messages if this fails /// </summary> /// <param name="context">Parser Context</param> /// <param name="t">Token to resolve</param> /// <returns></returns> public static INode TryResolveUri(IStoreParserContext context, IToken t) { switch (t.TokenType) { case Token.QNAME: try { return(context.Handler.CreateUriNode(UriFactory.Create(Tools.ResolveQName(t.Value, context.Namespaces, context.BaseUri)))); } #if PORTABLE catch (FormatException formatEx) #else catch (UriFormatException formatEx) #endif { throw new RdfParseException("Unable to resolve the QName '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx); } catch (RdfException rdfEx) { throw new RdfParseException("Unable to resolve the QName '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx); } case Token.URI: try { String uri = Tools.ResolveUri(t.Value, context.BaseUri.ToSafeString()); return(context.Handler.CreateUriNode(UriFactory.Create(uri))); } #if PORTABLE catch (FormatException formatEx) #else catch (UriFormatException formatEx) #endif { 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); } }
/// <summary> /// Attempts to resolve a QName or URI Token into a URI Node and produces appropriate error messages if this fails /// </summary> /// <param name="context">Parser Context</param> /// <param name="t">Token to resolve</param> /// <returns></returns> public static INode TryResolveUri(IStoreParserContext context, IToken t) { switch (t.TokenType) { case Token.QNAME: try { return context.Handler.CreateUriNode(new Uri(Tools.ResolveQName(t.Value, context.Namespaces, context.BaseUri))); } catch (UriFormatException formatEx) { throw new RdfParseException("Unable to resolve the QName '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx); } catch (RdfException rdfEx) { throw new RdfParseException("Unable to resolve the QName '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx); } case Token.URI: try { String uri = Tools.ResolveUri(t.Value, context.BaseUri.ToSafeString()); return context.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); } }