Пример #1
0
        public void testShouldWriteEmptEndTags()
        {
            StringWriter sw = new StringWriter();
            XmlWriter    xw = XmlWriter.Create(sw);
            XhtmlWriter  w  = new XhtmlWriter(xw);

            w.WriteStartDocument();
            w.WriteStartElement("html", XHTML_NAMESPACE);
            writeElement(w, "area");
            writeElement(w, "base");
            writeElement(w, "basefont");
            writeElement(w, "br");
            writeElement(w, "col");
            writeElement(w, "frame");
            writeElement(w, "hr");
            writeElement(w, "img");
            writeElement(w, "input");
            writeElement(w, "isindex");
            writeElement(w, "link");
            writeElement(w, "meta");
            writeElement(w, "param");
            w.WriteEndElement();
            w.WriteEndDocument();
            w.Close();
            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><area /><base /><basefont /><br /><col /><frame /><hr /><img /><input /><isindex /><link /><meta /><param /></html>",
                            sw.ToString());
        }
Пример #2
0
        public void PropertyLambdaFormatterNormalBehavior()
        {
            // Test read access of 'LambdaFormatter' Property.
            var actual = testObject.LambdaFormatter;

            Assert.IsNotNull(actual);

            // Test write access of 'LambdaFormatter' Property.
            var expected = new XhtmlWriter();

            testObject.LambdaFormatter = expected;
            actual = testObject.LambdaFormatter;
            Assert.AreSame(expected, actual);
        }
Пример #3
0
        public void testShouldWriteFullEndTags()
        {
            StringWriter sw = new StringWriter();
            XmlWriter    xw = XmlWriter.Create(sw);
            XhtmlWriter  w  = new XhtmlWriter(xw);

            w.WriteStartDocument();
            w.WriteStartElement("html", XHTML_NAMESPACE);
            writeElement(w, "script");
            writeElement(w, "p");
            w.WriteEndElement();
            w.WriteEndDocument();
            w.Close();
            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><script></script><p></p></html>",
                            sw.ToString());
        }
Пример #4
0
        public void testShouldWriteEmptEndTagsEvenWithAttrs()
        {
            StringWriter sw = new StringWriter();
            XmlWriter    xw = XmlWriter.Create(sw);
            XhtmlWriter  w  = new XhtmlWriter(xw);

            w.WriteStartDocument();
            w.WriteStartElement("html", XHTML_NAMESPACE);
            writeElementWithAttrs(w, "area");
            writeElementWithAttrs(w, "base");
            writeElementWithAttrs(w, "basefont");
            writeElementWithAttrs(w, "br");
            w.WriteEndElement();
            w.WriteEndDocument();
            w.Close();
            Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><area foo=\"bar\" /><base foo=\"bar\" /><basefont foo=\"bar\" /><br foo=\"bar\" /></html>",
                            sw.ToString());
        }
Пример #5
0
        public void EventTextChangedAddAndRemove()
        {
            string eventText = string.Empty;
            Action <object, TextWrittenEventArgs> body = (o, e) => eventText += e.Text;

            var formatter = new XhtmlWriter();

            Server.Default.LambdaFormatter = formatter;
            testObject.TextChanged        += new EventHandler <TextWrittenEventArgs>(body);
            var text     = "Buh";
            var expected = text + formatter.NewLine;

            formatter.WriteLine(text);
            Assert.AreEqual(expected, eventText);

            testObject.TextChanged -= new EventHandler <TextWrittenEventArgs>(body);
            formatter.WriteLine(text);
            Assert.AreEqual(expected, eventText);
        }
Пример #6
0
        protected void TransformToWriter(XmlInput defaultDocument, XsltArgumentList xsltArgs, XmlWriter targetWriter)
        {
            XmlWriter xmlWriter;

            if (SupportCharacterMaps && _characterMap != null && _characterMap.Count > 0)
            {
                xmlWriter = new CharacterMappingXmlWriter(targetWriter, _characterMap);
            }
            else
            {
                xmlWriter = targetWriter;
            }
            if (EnforceXHtmlOutput)
            {
                xmlWriter = new XhtmlWriter(xmlWriter);
            }
            var args      = AddExsltExtensionObjectsSync(xsltArgs);
            var xmlReader = defaultDocument.Source as XmlReader;

            if (xmlReader != null)
            {
                CompiledTransform.Transform(xmlReader, args, xmlWriter, defaultDocument.Resolver);
                return;
            }
            var nav = defaultDocument.Source as IXPathNavigable;

            if (nav != null)
            {
                if (defaultDocument.Resolver is DefaultXmlResolver)
                {
                    CompiledTransform.Transform(nav, args, xmlWriter);
                }
                else
                {
                    TransformXPathNavigable(nav, args, xmlWriter, defaultDocument.Resolver);
                }
                return;
            }
            var str = defaultDocument.Source as string;

            if (str != null)
            {
                using (var reader = XmlReader.Create(str, GetReaderSettings(defaultDocument)))
                {
                    CompiledTransform.Transform(reader, args, xmlWriter, defaultDocument.Resolver);
                }
                return;
            }
            var strm = defaultDocument.Source as Stream;

            if (strm != null)
            {
                using (var reader = XmlReader.Create(strm, GetReaderSettings(defaultDocument)))
                {
                    CompiledTransform.Transform(reader, args, xmlWriter, defaultDocument.Resolver);
                }
                return;
            }
            var txtReader = defaultDocument.Source as TextReader;

            if (txtReader != null)
            {
                using (var reader = XmlReader.Create(txtReader, GetReaderSettings(defaultDocument)))
                {
                    CompiledTransform.Transform(reader, args, xmlWriter, defaultDocument.Resolver);
                }
                return;
            }
            throw new Exception("Unexpected XmlInput");
        }
Пример #7
0
 /// <summary>
 /// Transforms to XmlWriter.
 /// </summary>        
 protected void TransformToWriter(XmlInput defaultDocument, XsltArgumentList xsltArgs, XmlWriter targetWriter)
 {
     XmlWriter xmlWriter;            
     if (this.supportCharacterMaps && this.characterMap != null && this.characterMap.Count > 0)
     {
         xmlWriter = new CharacterMappingXmlWriter(targetWriter, this.characterMap);
     }
     else
     {
         xmlWriter = targetWriter;
     }
     if (this.enforceXHTMLOutput)
     {
         xmlWriter = new XhtmlWriter(xmlWriter);
     }
     XsltArgumentList args = AddExsltExtensionObjectsSync(xsltArgs);
     XmlReader xmlReader = defaultDocument.source as XmlReader;
     if (xmlReader != null)
     {
         this.compiledTransform.Transform(xmlReader, args, xmlWriter, defaultDocument.resolver);
         return;
     }
     IXPathNavigable nav = defaultDocument.source as IXPathNavigable;
     if (nav != null)
     {
         if (defaultDocument.resolver is DefaultXmlResolver)
         {
             this.compiledTransform.Transform(nav, args, xmlWriter);
         }
         else
         {
             TransformIXPathNavigable(nav, args, xmlWriter, defaultDocument.resolver);
         }
         return;
     }
     string str = defaultDocument.source as string;
     if (str != null)
     {
         using (XmlReader reader = XmlReader.Create(str, GetReaderSettings(defaultDocument)))
         {
             this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver);
         }
         return;
     }
     Stream strm = defaultDocument.source as Stream;
     if (strm != null)
     {
         using (XmlReader reader = XmlReader.Create(strm, GetReaderSettings(defaultDocument)))
         {
             this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver);
         }
         return;
     }
     TextReader txtReader = defaultDocument.source as TextReader;
     if (txtReader != null)
     {
         using (XmlReader reader = XmlReader.Create(txtReader, GetReaderSettings(defaultDocument)))
         {
             this.compiledTransform.Transform(reader, args, xmlWriter, defaultDocument.resolver);
         }
         return;
     }
     throw new Exception("Unexpected XmlInput");
 }
Пример #8
0
 private static void writeElementWithAttrs(XhtmlWriter w, string name)
 {
     w.WriteStartElement(name, XHTML_NAMESPACE);
     w.WriteAttributeString("foo", "bar");
     w.WriteEndElement();
 }
Пример #9
0
 private static void writeElement(XhtmlWriter w, string name)
 {
     w.WriteStartElement(name, XHTML_NAMESPACE);
     w.WriteEndElement();
 }
Пример #10
0
 public void Construct()
 {
     this.testObject = new XhtmlWriter();
 }
Пример #11
0
 public void TearDown()
 {
     this.testObject = null;
 }
Пример #12
0
 public void SetUp()
 {
     this.testObject = new XhtmlWriter();
     this.eventText  = string.Empty;
 }
Пример #13
0
 private static T Dump <T>(this T o, string description, int?depth, bool toDataGrid, Action <ClickContext> onClick)
 {
     if (o != null)
     {
         Type type = o.GetType();
         if ((((!type.IsValueType && !type.IsPrimitive) && (type.Namespace != null)) && (type.Namespace.StartsWith("System.Threading.Tasks.Dataflow") && (type.GetInterface("System.Threading.Tasks.Dataflow.IDataflowBlock") != null))) && DataflowBridge.Dump(o, description))
         {
             return(o);
         }
     }
     if (depth < 0)
     {
         depth = null;
     }
     if (depth > 20)
     {
         depth = 20;
     }
     if (((depth.HasValue || toDataGrid) || !AppDomain.CurrentDomain.GetAssemblies().Any <Assembly>(a => a.FullName.StartsWith("PresentationCore,", StringComparison.InvariantCultureIgnoreCase))) || !WpfBridge.DumpWpfElement(o, description))
     {
         bool flag2;
         if ((!depth.HasValue && !toDataGrid) && (o is Control))
         {
             if (o is Form)
             {
                 ((Form)o).Show();
                 return(o);
             }
             PanelManager.DisplayControl((Control)o, description ?? "WinForms");
             return(o);
         }
         if ((o is XContainer) || (o is XmlDocument))
         {
             PanelManager.DisplaySyntaxColoredText(o.ToString(), SyntaxLanguageStyle.XML, description ?? "XML");
             return(o);
         }
         Server     currentServer = Server.CurrentServer;
         TextWriter writer        = (currentServer == null) ? null : currentServer.LambdaFormatter;
         Expression expr          = null;
         if (writer != null)
         {
             if (o is IQueryable)
             {
                 expr = ((IQueryable)o).Expression;
             }
             else if (o is Expression)
             {
                 expr = (Expression)o;
             }
         }
         if (expr != null)
         {
             string content = "";
             try
             {
                 ExpressionToken token = ExpressionToken.Visit(expr);
                 if (token != null)
                 {
                     content = token.ToString();
                 }
             }
             catch (Exception exception)
             {
                 Log.Write(exception, "Dump ExpressionToken Visit");
             }
             if (content.Length > 0)
             {
                 lock (writer)
                 {
                     if (!string.IsNullOrEmpty(description))
                     {
                         writer.WriteLine(new HeadingPresenter(description, content));
                     }
                     else
                     {
                         writer.WriteLine(content + "\r\n");
                     }
                 }
             }
         }
         if ((currentServer != null) && currentServer.WriteResultsToGrids)
         {
             toDataGrid = true;
         }
         if (toDataGrid && (o != null))
         {
             Type t = o.GetType();
             if (((!ExplorerGrid.IsAtomic(t) && (!t.IsArray || (t.GetArrayRank() == 1))) && (t.GetInterface("System.IObservable`1") == null)) && (t.GetCustomAttributes(typeof(MetaGraphNodeAttribute), false).Length == 0))
             {
                 return(o.Explore <T>(description));
             }
         }
         XhtmlWriter writer3 = (currentServer == null) ? null : currentServer.ResultsWriter;
         if (flag2 = o is Type)
         {
             ObjectNode.ExpandTypes = true;
         }
         try
         {
             if (!string.IsNullOrEmpty(description))
             {
                 HeadingPresenter presenter = new HeadingPresenter(description, o);
                 if (writer3 != null)
                 {
                     writer3.WriteDepth(presenter, depth, onClick);
                 }
                 else
                 {
                     Console.Write(presenter);
                 }
                 return(o);
             }
             if (writer3 != null)
             {
                 writer3.WriteLineDepth(o, depth, onClick);
             }
             else
             {
                 Console.WriteLine(o);
             }
         }
         finally
         {
             if (flag2)
             {
                 ObjectNode.ExpandTypes = false;
             }
         }
     }
     return(o);
 }