Пример #1
0
        public static string UriPrefixString(UriPrefix prefix)
        {
            switch (prefix)
            {
            case UriPrefix.Null:
                return("");

            case UriPrefix.HttpWww:
                return("http://www.");

            case UriPrefix.HttpsWww:
                return("https://www.");

            case UriPrefix.Http:
                return("http://");

            case UriPrefix.Https:
                return("https://");

            case UriPrefix.Tel:
                return("tel:");

            case UriPrefix.MailTo:
                return("mailto:");

            case UriPrefix.FtpAnonymous:
                return("ftp://*****:*****@");

            case UriPrefix.FtpFtp:
                return("ftp://ftp.");

            case UriPrefix.Ftps:
                return("ftps://");

            case UriPrefix.Sftp:
                return("sftp://");

            case UriPrefix.Smb:
                return("smb://");

            case UriPrefix.Nfs:
                return("nfs://");

            case UriPrefix.Ftp:
                return("ftp://");

            case UriPrefix.Dav:
                return("dav://");

            case UriPrefix.News:
                return("news:");

            case UriPrefix.Telnet:
                return("telnet://");

            case UriPrefix.Imap:
                return("imap:");

            case UriPrefix.Rtsp:
                return("rtsp://");

            case UriPrefix.Urn:
                return("urn:");

            case UriPrefix.Pop:
                return("pop:");

            case UriPrefix.Sip:
                return("sip:");

            case UriPrefix.Sips:
                return("sips:");

            case UriPrefix.Tftp:
                return("tftp:");

            case UriPrefix.Btspp:
                return("btspp://");

            case UriPrefix.Btl2cap:
                return("btl2cap://");

            case UriPrefix.Btgoep:
                return("btgoep://");

            case UriPrefix.Tcpobex:
                return("tcpobex://");

            case UriPrefix.Irdaobex:
                return("irdaobex://");

            case UriPrefix.File:
                return("file://");

            case UriPrefix.UrnEpcId:
                return("urn:epc:id:");

            case UriPrefix.UrnEpcTag:
                return("urn:epc:tag:");

            case UriPrefix.UrnEpcPat:
                return("urn:epc:pat:");

            case UriPrefix.UrnEpcRaw:
                return("urn:epc:raw:");

            case UriPrefix.UrnEpc:
                return("urn:epc:");

            case UriPrefix.UrnNfc:
                return("urn:nfc:");

            default:
                return("");
            }
        }
Пример #2
0
        /// <summary>
        /// Generates Output for a given Node
        /// </summary>
        /// <param name="context">Writer Context</param>
        /// <param name="n">Node</param>
        /// <param name="t">Triple being written</param>
        private void GenerateNodeOutput(HtmlWriterContext context, INode n, Triple t)
        {
            // Embed RDFa on the Node Output
            bool rdfASerializable = false;

            if (t != null)
            {
                if (t.Predicate.NodeType == NodeType.Uri)
                {
                    // Use @about to specify the Subject
                    if (t.Subject.NodeType == NodeType.Uri)
                    {
                        rdfASerializable = true;
                        context.HtmlWriter.AddAttribute("about", context.UriFormatter.FormatUri(t.Subject.ToString()));
                    }
                    else if (t.Subject.NodeType == NodeType.Blank)
                    {
                        rdfASerializable = true;
                        context.HtmlWriter.AddAttribute("about", "[" + t.Subject.ToString() + "]");
                    }
                    else
                    {
                        RaiseWarning("Cannot serialize a Triple since the Subject is not a URI/Blank Node: " + t.Subject.ToString());
                    }

                    // Then if we can serialize this Triple we serialize the Predicate
                    if (rdfASerializable)
                    {
                        // Get the CURIE for the Predicate
                        String curie;
                        String tempNamespace;
                        if (context.QNameMapper.ReduceToQName(t.Predicate.ToString(), out curie, out tempNamespace))
                        {
                            // Extract the Namespace and make sure it's registered on this Attribute
                            String ns = curie.Substring(0, curie.IndexOf(':'));
                            context.HtmlWriter.AddAttribute("xmlns:" + ns, context.UriFormatter.FormatUri(context.QNameMapper.GetNamespaceUri(ns)));
                        }
                        else
                        {
                            RaiseWarning("Cannot serialize a Triple since the Predicate cannot be reduced to a QName: " + t.Predicate.ToString());
                            rdfASerializable = false;
                        }

                        if (rdfASerializable)
                        {
                            switch (t.Object.NodeType)
                            {
                            case NodeType.Blank:
                            case NodeType.Uri:
                                // If the Object is a URI or a Blank then we specify the predicate with @rel
                                context.HtmlWriter.AddAttribute("rel", curie);
                                break;

                            case NodeType.Literal:
                                // If the Object is a Literal we specify the predicate with @property
                                context.HtmlWriter.AddAttribute("property", curie);
                                break;

                            default:
                                RaiseWarning("Cannot serialize a Triple since the Object is not a URI/Blank/Literal Node: " + t.Object.ToString());
                                rdfASerializable = false;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    RaiseWarning("Cannot serialize a Triple since the Predicate is not a URI Node: " + t.Predicate.ToString());
                }
            }

            String qname;

            switch (n.NodeType)
            {
            case NodeType.Blank:
                if (rdfASerializable)
                {
                    // Need to embed the CURIE for the BNode in the @resource attribute
                    context.HtmlWriter.AddAttribute("resource", "[" + n.ToString() + "]");
                }

                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, CssClassBlankNode);
                context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Span);
                context.HtmlWriter.WriteEncodedText(n.ToString());
                context.HtmlWriter.RenderEndTag();
                break;

            case NodeType.Literal:
                ILiteralNode lit = (ILiteralNode)n;
                if (lit.DataType != null)
                {
                    if (rdfASerializable)
                    {
                        // Need to embed the datatype in the @datatype attribute
                        String dtcurie, dtnamespace;
                        if (context.QNameMapper.ReduceToQName(lit.DataType.AbsoluteUri, out dtcurie, out dtnamespace))
                        {
                            // Extract the Namespace and make sure it's registered on this Attribute
                            String ns = dtcurie.Substring(0, dtcurie.IndexOf(':'));
                            context.HtmlWriter.AddAttribute("xmlns:" + ns, context.UriFormatter.FormatUri(context.QNameMapper.GetNamespaceUri(ns)));
                            context.HtmlWriter.AddAttribute("datatype", dtcurie);
                        }
                    }

                    context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, CssClassLiteral);
                    context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Span);
                    if (lit.DataType.AbsoluteUri.Equals(Parsing.RdfSpecsHelper.RdfXmlLiteral))
                    {
                        context.HtmlWriter.Write(lit.Value);
                    }
                    else
                    {
                        context.HtmlWriter.WriteEncodedText(lit.Value);
                    }
                    context.HtmlWriter.RenderEndTag();

                    // Output the Datatype
                    context.HtmlWriter.WriteEncodedText("^^");
                    context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Href, lit.DataType.AbsoluteUri);
                    context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, CssClassDatatype);
                    context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A);
                    if (context.QNameMapper.ReduceToQName(lit.DataType.AbsoluteUri, out qname))
                    {
                        context.HtmlWriter.WriteEncodedText(qname);
                    }
                    else
                    {
                        context.HtmlWriter.WriteEncodedText(lit.DataType.AbsoluteUri);
                    }
                    context.HtmlWriter.RenderEndTag();
                }
                else
                {
                    if (rdfASerializable)
                    {
                        if (!lit.Language.Equals(String.Empty))
                        {
                            // Need to add the language as an xml:lang attribute
                            context.HtmlWriter.AddAttribute("xml:lang", lit.Language);
                        }
                    }
                    context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, CssClassLiteral);
                    context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Span);
                    context.HtmlWriter.WriteEncodedText(lit.Value);
                    context.HtmlWriter.RenderEndTag();
                    if (!lit.Language.Equals(String.Empty))
                    {
                        context.HtmlWriter.WriteEncodedText("@");
                        context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, CssClassLangSpec);
                        context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Span);
                        context.HtmlWriter.WriteEncodedText(lit.Language);
                        context.HtmlWriter.RenderEndTag();
                    }
                }
                break;

            case NodeType.GraphLiteral:
                // Error
                throw new RdfOutputException(WriterErrorMessages.GraphLiteralsUnserializable("HTML"));

            case NodeType.Uri:
                if (rdfASerializable && !UriPrefix.Equals(String.Empty))
                {
                    // If the URIs are being prefixed with something then we need to set the original
                    // URI in the resource attribute to generate the correct triple
                    context.HtmlWriter.AddAttribute("resource", n.ToString());
                }

                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Class, CssClassUri);
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Href, UriPrefix + n.ToString());
                context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A);
                if (context.QNameMapper.ReduceToQName(n.ToString(), out qname))
                {
                    context.HtmlWriter.WriteEncodedText(qname);
                }
                else
                {
                    context.HtmlWriter.WriteEncodedText(n.ToString());
                }
                context.HtmlWriter.RenderEndTag();
                break;

            default:
                throw new RdfOutputException(WriterErrorMessages.UnknownNodeTypeUnserializable("HTML"));
            }
        }
Пример #3
0
 public UriPayload(UriPrefix prefix, string data)
 {
     Prefix = prefix;
     Data   = data;
 }