Example #1
0
        public void Add(string strFilename, bool bRelative)
        {
            string fn = strFilename;
            if (bRelative)
            {
                UriResolver ur = new UriResolver(_path, true);
                fn = ur.ToAbsolute(strFilename);
            }

            _list.Add(fn);
        }
Example #2
0
 public void ToRelativeTest()
 {
     string uri = string.Empty; // TODO: Initialize to an appropriate value
     bool bFolder = false; // TODO: Initialize to an appropriate value
     UriResolver target = new UriResolver(uri, bFolder); // TODO: Initialize to an appropriate value
     string absoluteUri = string.Empty; // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     actual = target.ToRelative(absoluteUri);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
        public void Add(XElement xe, UriResolver urSource, UriResolver urTarget)
        {
            string uri = urSource.ToAbsolute(xe.Attribute("src").Value);
            if (!_sm.Validate(uri))
                return;

            JavaScriptInfo jsi = new JavaScriptInfo();
            jsi.Element = xe;
            jsi.SourceUriResolver = urSource;
            jsi.TargetUriResolver = urTarget;

            System.IO.TextReader sr = _sm.GetTextReader(uri);
            jsi.Value = sr.ReadToEnd() + "\r\n";
            sr.Close();

               _jsElements.Add( jsi );
        }
Example #4
0
        public void AddFromCSS(CSSDocument doc, UriResolver urSource, UriResolver urTarget )
        {
            foreach (RuleSet rs in doc.RuleSets)
            {
                foreach (Declaration decl in rs.Declarations)
                {
                    foreach (Term t in decl.Expression.Terms)
                    {
                        if (t.Type != TermType.Url)
                            continue;

                        CssImageInfo cii = new CssImageInfo();
                        cii.Term = t;
                        cii.SourceUriResolver = urSource;
                        cii.TargetUriResolver = urTarget;
                        _ciiElements.Add(cii);
                    }
                }
            }
        }
Example #5
0
        public void Add(XElement xe, UriResolver urSource, UriResolver urTarget )
        {
            string uri = urSource.ToAbsolute( xe.Attribute("href").Value );
            if (!_sm.Validate(uri))
                return;

            CssInfo ci = new CssInfo();
            ci.Element = xe;
            ci.SourceUriResolver = urSource;
            ci.TargetUriResolver = urTarget;

            CSSParser parser = new CSSParser();
            ci.CSS = parser.ParseStream( _sm.GetTextStream(uri));
            _cssElements.Add(ci);

            //
            UriResolver SourceUriResolver = new UriResolver(uri, false);
            UriResolver TargetUriResolver = new UriResolver(urTarget.ToAbsolute("images\\"), true);

            _cim.AddFromCSS(ci.CSS, SourceUriResolver, TargetUriResolver);
        }
Example #6
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     UriResolver uiRes = new UriResolver(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, true);
     PageTextBox.Text = uiRes.ToAbsolute("Test\\Website\\index.html");
     OutputTextBox.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString();
 }
Example #7
0
        public void Release(SettingManager sm)
        {
            // to xhtml
            System.IO.StreamReader sr = new System.IO.StreamReader(sm.PageName);
            string xhtml = Html2XHtml(sr.ReadToEnd());
            sr.Close();

            // parse xhtml
            XmlReaderSettings xrs = new XmlReaderSettings();
            xrs.XmlResolver = new XHTMLResolver();
            xrs.ProhibitDtd = false;
            if (sm.IsHtmlCompress)
            {
                xrs.IgnoreComments = true;
                xrs.IgnoreProcessingInstructions = true;
                xrs.IgnoreWhitespace = true;
            }

            XDocument doc = XDocument.Load(XmlReader.Create(new System.IO.StringReader(xhtml), xrs), LoadOptions.None );

            //
            UriResolver SourceUriResolver = new UriResolver( sm.PageName, false );
            UriResolver TargetUriResolver = new UriResolver(sm.OutputPath, true);

            // init js manager
            JavaScriptManager jsm = new JavaScriptManager( sm );
            var js = from s in doc.Descendants()
                     where string.Compare( s.Name.LocalName, "script", true ) == 0 &&
                     string.Compare( s.Attribute("type").Value, "text/javascript", true ) == 0 &&
                     s.Attribute("src") != null
                     select s;
            foreach ( XElement xe in js )
                jsm.Add(xe, SourceUriResolver, TargetUriResolver);
            jsm.JSMin();

            // init css manager
            CssManager cm = new CssManager(sm);
            var css = from s in doc.Descendants()
                     where string.Compare( s.Name.LocalName, "link", true ) == 0 &&
                     string.Compare( s.Attribute("type").Value, "text/css", true ) == 0 &&
                     string.Compare( s.Attribute("rel").Value, "stylesheet", true ) == 0 &&
                     s.Attribute("href") != null
                     select s;
            foreach (XElement xe in css)
                cm.Add(xe, SourceUriResolver, TargetUriResolver);
            cm.CssMin();

            // init image manager

            // save html
            if ( !sm.IsHtmlCompress )
                doc.Save(TargetUriResolver.ToAbsolute( "index.html" ) );
            else
            {
                var nodes = from s in doc.DescendantNodes()
                           where s.NodeType == XmlNodeType.Comment &&
                           string.Compare( s.Parent.Name.LocalName, "script", true ) != 0
                           select s;

                nodes.Remove();
                doc.Save( TargetUriResolver.ToAbsolute("index.html"), SaveOptions.DisableFormatting );
            }
        }