예제 #1
0
파일: Hxs.cs 프로젝트: SamB/PackageThis
        public void Transform(string contentId, string metadataXml, string annotationsXml,
            string versionId, string docTitle, Content contentDataSet)
        {
            XsltArgumentList arguments = new XsltArgumentList();
            Link link = new Link(contentDataSet, links);
            XmlDocument metadata = new XmlDocument();
            XmlDocument annotations = new XmlDocument();

            string filename = Path.Combine(withinHxsDir, contentId + ".htm");

            string xml;
            if (File.Exists(filename))
            {
                StreamReader sr = new StreamReader(filename);
                xml = sr.ReadToEnd();
                sr.Close();
            }
            else  //Default to Simple headers only
            {
                xml = "<div class=\"topic\" xmlns=\"http://www.w3.org/1999/xhtml\">" + Environment.NewLine +
                      "  <div class=\"majorTitle\">" + docTitle + "</div>" + Environment.NewLine +
                      "  <div class=\"title\">" + docTitle + "</div>" + Environment.NewLine +
                      "  <div id=\"mainSection\">" + Environment.NewLine +
                      "    <div id=\"mainBody\">" + Environment.NewLine +
                      "      <p></p>" + Environment.NewLine +                //RWC: Too difficult to add child link list like MSDN Online. Just leave blank.
                      "    </div>" + Environment.NewLine +
                      "  </div>" + Environment.NewLine +
                      "</div>" + Environment.NewLine;
            }

            metadata.LoadXml(metadataXml);
            annotations.LoadXml(annotationsXml);

            // Do transform

            arguments.AddParam("metadata", "", metadata.CreateNavigator());
            arguments.AddParam("annotations", "", annotations.CreateNavigator());
            arguments.AddParam("version", "", versionId);
            arguments.AddParam("locale", "", locale);

            arguments.AddExtensionObject("urn:Link", link);

            TextReader tr = new StringReader(xml);
            XmlReader xr = XmlReader.Create(tr);

            using (StreamWriter sw = new StreamWriter(filename, false, Encoding.UTF8))
            {
                try
                {
                    xform.Transform(xr, arguments, sw);

                }
                catch //(Exception ex)
                {
                    return;
                }
            }
        }
예제 #2
0
파일: Chm.cs 프로젝트: SamB/PackageThis
        public void Transform(string contentId, string metadataXml, string annotationsXml,
            string versionId, string docTitle, Content contentDataSet)
        {
            XsltArgumentList arguments = new XsltArgumentList();
            Link link = new Link(contentDataSet, links);
            XmlDocument metadata = new XmlDocument();
            XmlDocument annotations = new XmlDocument();

            string filename = Path.Combine(withinChmDir, contentId + ".htm");

            string xml;
            if (File.Exists(filename))
            {
                StreamReader sr = new StreamReader(filename);
                xml = sr.ReadToEnd();
                sr.Close();
            }
            else  //Probably a node file that simply lists its children -- We will deal with this at a later date
            {
                xml = "<div class=\"topic\" xmlns=\"http://www.w3.org/1999/xhtml\">" + Environment.NewLine +
                      "  <div class=\"majorTitle\">" + docTitle + "</div>" + Environment.NewLine +
                      "  <div class=\"title\">" + docTitle + "</div>" + Environment.NewLine +
                      "  <div id=\"mainSection\">" + Environment.NewLine +
                      "    <div id=\"mainBody\">" + Environment.NewLine +
                      "      <p></p>" + Environment.NewLine +                //RWC: Too difficult to add child link list like MSDN Online. Just leave blank.
                      "    </div>" + Environment.NewLine +
                      "  </div>" + Environment.NewLine +
                      "</div>" + Environment.NewLine;
            }

            int codePage = new CultureInfo(locale).TextInfo.ANSICodePage;

            // We use these fallbacks because &nbsp; is unknown under DBCS like Japanese
            // and translated to ? by default.
            Encoding encoding = Encoding.GetEncoding(codePage,
                new EncoderReplacementFallback(" "),
                new DecoderReplacementFallback(" "));

            metadata.LoadXml(metadataXml);
            annotations.LoadXml(annotationsXml);

            arguments.AddParam("metadata", "", metadata.CreateNavigator());
            arguments.AddParam("annotations", "", annotations.CreateNavigator());
            arguments.AddParam("version", "", versionId);
            arguments.AddParam("locale", "", locale);
            arguments.AddParam("charset", "", encoding.WebName);

            arguments.AddExtensionObject("urn:Link", link);

            TextReader tr = new StringReader(xml);
            XmlReader xr = XmlReader.Create(tr);

            using (StreamWriter sw = new StreamWriter(filename, false, encoding))
            {
                try
                {
                    xform.Transform(xr, arguments, sw);

                }
                catch //(Exception ex)
                {
                    return;
                }
            }
        }