Esempio n. 1
0
        /// <summary>
        /// Write XML document to the specified output stream.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static final void writeDoc(Document doc, OutputStream out) throws IOException
        private static void WriteDoc(Document doc, OutputStream @out)
        {
            try
            {
                TransformerFactory tf = TransformerFactory.newInstance();
                try
                {
                    tf.setAttribute("indent-number", new Integer(2));
                }
                catch (IllegalArgumentException)
                {
                    //Ignore the IAE. Should not fail the writeout even the
                    //transformer provider does not support "indent-number".
                }
                Transformer t = tf.newTransformer();
                t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.Doctype.SystemId);
                t.setOutputProperty(OutputKeys.INDENT, "yes");
                //Transformer resets the "indent" info if the "result" is a StreamResult with
                //an OutputStream object embedded, creating a Writer object on top of that
                //OutputStream object however works.
                t.transform(new DOMSource(doc), new StreamResult(new BufferedWriter(new OutputStreamWriter(@out, "UTF-8"))));
            }
            catch (TransformerException e)
            {
                throw new AssertionError(e);
            }
        }
Esempio n. 2
0
 public static string WriteToString(SsurgeonPattern pattern)
 {
     try
     {
         IList <SsurgeonPattern> patterns = new LinkedList <SsurgeonPattern>();
         patterns.Add(pattern);
         IDocument domDoc = CreatePatternXMLDoc(patterns);
         if (domDoc != null)
         {
             Transformer tformer = TransformerFactory.NewInstance().NewTransformer();
             tformer.SetOutputProperty(OutputKeys.Indent, "yes");
             StringWriter sw = new StringWriter();
             tformer.Transform(new DOMSource(domDoc), new StreamResult(sw));
             return(sw.ToString());
         }
         else
         {
             log.Warning("Was not able to create XML document for pattern list.");
         }
     }
     catch (Exception e)
     {
         log.Info("Error in writeToString, could not process pattern=" + pattern);
         log.Info(e);
         return(null);
     }
     return(string.Empty);
 }
Esempio n. 3
0
        public void Create_Transformer_From_Factory()
        {
            var transformerFactory = new TransformerFactory();
            var transformer        = transformerFactory.Create("tr");

            Assert.NotNull(transformer);
        }
Esempio n. 4
0
    public void Convert()
    {
        byte[]                file       = Files.toByteArray(new File(@"filename.doc"));
        AutoDetectParser      tikaParser = new AutoDetectParser();
        ByteArrayOutputStream output     = new ByteArrayOutputStream();
        SAXTransformerFactory factory    = (SAXTransformerFactory)TransformerFactory.newInstance();
        var inputStream = new ByteArrayInputStream(file);
        //           ToHTMLContentHandler handler = new ToHTMLContentHandler();
        var metaData = new Metadata();
        EncodingDetector encodingDetector = new UniversalEncodingDetector();
        var encode = encodingDetector.detect(inputStream, metaData) ?? new UTF_32();
        TransformerHandler handler = factory.newTransformerHandler();

        handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "html");
        handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
        handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, encode.toString());
        handler.setResult(new StreamResult(output));
        ContentHandler imageRewriting = new ImageRewritingContentHandler(handler);
        //  ExpandedTitleContentHandler handler1 = new ExpandedTitleContentHandler(handler);
        ParseContext context = new ParseContext();

        context.set(typeof(EmbeddedDocumentExtractor), new FileEmbeddedDocumentEtractor());
        tikaParser.parse(inputStream, imageRewriting, new Metadata(), context);

        byte[] array = output.toByteArray();
        System.IO.File.WriteAllBytes(@"C:\toHtml\text.html", array);
    }
 public void TypeDoesNotImplementTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
 public void CreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(xmlString))
     {
         TransformerFactory factory     = new TransformerFactory(configurationContext);
         ITransformer       transformer = factory.Create("ApplConfig1");
         Assert.IsNotNull(transformer);
     }
 }
Esempio n. 7
0
        public void Convert_Number_ToWords()
        {
            var transformerFactory = new TransformerFactory();
            var transformer        = transformerFactory.Create("tr");
            var result             = transformer.ToWords(123456789);

            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("tr-TR");

            Assert.Equal("YÜZ YİRMİ ÜÇ MİLYON DÖRT YÜZ ELLİ ALTI BİN YEDİ YÜZ SEKSEN DOKUZ", result.ToUpper());
        }
        public async Task Transform_To_String()
        {
            // Arrange
            var transformer = TransformerFactory.Create <Generic, string>();

            // Act
            var result = await transformer.Transform(new Generic { Name = "Krizanac, Matt" });

            // Assert
            StringAssert.AreEqualIgnoringCase("hello world", result);
        }
        public async Task Validate_ValidName()
        {
            // arrange
            var transformer = TransformerFactory.Create <Generic, Output>();

            // Act
            var result = await transformer.Validate(new Generic { Name = "Krizanac, Matt" });

            // Assert
            Assert.AreEqual(0, result.Count());
        }
 public void CreateTypedTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(typedXmlString))
     {
         TransformerFactory factory     = new TransformerFactory(configurationContext);
         ITransformer       transformer = factory.Create("TypedConfig");
         Assert.IsNotNull(transformer);
         XmlSerializerTransformer xmlTransformer = transformer as XmlSerializerTransformer;
         Assert.IsNotNull(xmlTransformer);
         Assert.AreEqual(1, xmlTransformer.GetTypes().Length);
     }
 }
        private TransformerHandler getTransformerHandler()
        {
            var factory = TransformerFactory.newInstance() as SAXTransformerFactory;
            TransformerHandler handler = factory.newTransformerHandler();

            handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "text");
            handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");

            _outputWriter = new StringWriter();
            handler.setResult(new StreamResult(_outputWriter));
            return(handler);
        }
Esempio n. 12
0
        public async Task Transform_To_Output()
        {
            // Arrange
            var transformer = TransformerFactory.Create <Generic, Output>();

            // Act
            var result = await transformer.Transform(new Generic { Name = "Krizanac, Matt" });

            // Assert
            StringAssert.AreEqualIgnoringCase("matt", result.FirstName);
            StringAssert.AreEqualIgnoringCase("krizanac", result.LastName);
        }
Esempio n. 13
0
        private static void Main(string[] args)
        {
            var optimusPrime = TransformerFactory.CreateTransformer(
                TransformerFactory.TransformerType.OptimusPrime, new LaserWeapon(), new OpticalScanner());
            var autoBotX5 = TransformerFactory.CreateTransformer(
                TransformerFactory.TransformerType.AutoBotX5, new LaserWeapon(), new EchoScanner());

            var game = new Game(optimusPrime, autoBotX5);

            game.Battle();
            game.ShowWinner();
        }
Esempio n. 14
0
        /// <summary>Transform input xml given a stylesheet.</summary>
        /// <param name="styleSheet">the style-sheet</param>
        /// <param name="xml">input xml data</param>
        /// <param name="out">output</param>
        /// <exception cref="Javax.Xml.Transform.TransformerConfigurationException"/>
        /// <exception cref="Javax.Xml.Transform.TransformerException"/>
        public static void Transform(InputStream styleSheet, InputStream xml, TextWriter
                                     @out)
        {
            // Instantiate a TransformerFactory
            TransformerFactory tFactory = TransformerFactory.NewInstance();
            // Use the TransformerFactory to process the
            // stylesheet and generate a Transformer
            Transformer transformer = tFactory.NewTransformer(new StreamSource(styleSheet));

            // Use the Transformer to transform an XML Source
            // and send the output to a Result object.
            transformer.Transform(new StreamSource(xml), new StreamResult(@out));
        }
Esempio n. 15
0
 public void CreateTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(xmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         ITransformer transformer = factory.Create("ApplConfig1");
         Assert.IsNotNull(transformer);
     }
 }
Esempio n. 16
0
 public void BadSectionTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("Foo");
     }
 }
Esempio n. 17
0
 public void BadTypeTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(badTypeXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }
Esempio n. 18
0
 public void CreateTypedTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(typedXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         ITransformer transformer = factory.Create("TypedConfig");
         Assert.IsNotNull(transformer);
         XmlSerializerTransformer xmlTransformer = transformer as XmlSerializerTransformer;
         Assert.IsNotNull(xmlTransformer);
         Assert.AreEqual(1, xmlTransformer.GetTypes().Length);
     }
 }
Esempio n. 19
0
 public void NoTransformerDefinedTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(noTransformerXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         ITransformer transformer = factory.Create("ApplConfig1");
         Assert.AreEqual(typeof(NullTransformer), transformer.GetType());
     }
 }
Esempio n. 20
0
 public void TypeDoesNotImplementTest()
 {
     using (ConfigurationContext configurationContext = CreateConfigurationContext(notImplXmlString))
     {
         TransformerFactory factory = new TransformerFactory(configurationContext);
         factory.Create("ApplConfig1");
     }
 }