Package javax.xml.stream

Examples of javax.xml.stream.XMLStreamWriter


               new SecurePart(new QName("urn:example:po", "PaymentInfo"), SecurePart.Modifier.Element);
        properties.addEncryptionPart(securePart);
       
        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");
       
        InputStream sourceDocument =
                this.getClass().getClassLoader().getResourceAsStream(
                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
       
        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();
       
        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
       
        Document document =
            XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here


               new SecurePart(new QName("urn:example:po", "PaymentInfo"), SecurePart.Modifier.Element);
        properties.addEncryptionPart(securePart);
       
        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");
       
        InputStream sourceDocument =
                this.getClass().getClassLoader().getResourceAsStream(
                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
       
        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();
       
        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
       
        Document document =
            XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

               new SecurePart(new QName("urn:example:po", "PaymentInfo"), SecurePart.Modifier.Element);
        properties.addEncryptionPart(securePart);
       
        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");
       
        InputStream sourceDocument =
                this.getClass().getClassLoader().getResourceAsStream(
                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
       
        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();
       
        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
       
        Document document =
            XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

               new SecurePart(new QName("urn:example:po", "PaymentInfo"), SecurePart.Modifier.Element);
        properties.addEncryptionPart(securePart);
       
        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");
       
        InputStream sourceDocument =
                this.getClass().getClassLoader().getResourceAsStream(
                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
       
        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();
       
        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
       
        Document document =
            XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

        OutputProcessorChainImpl outputProcessorChain = new OutputProcessorChainImpl(securityContext);
        outputProcessorChain.addProcessor(new EventWriterProcessor(securityStringWriter));
        XMLSecurityStreamWriter xmlSecurityStreamWriter = new XMLSecurityStreamWriter(outputProcessorChain);

        StringWriter stdStringWriter = new StringWriter();
        XMLStreamWriter stdXmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(stdStringWriter);

        NamespaceContext namespaceContext = new NamespaceContext() {
            @Override
            public String getNamespaceURI(String prefix) {
                if ("t3".equals(prefix)) {
                    return "test3ns";
                }
                return null;
            }

            @Override
            public String getPrefix(String namespaceURI) {
                if ("test2ns".equals(namespaceURI)) {
                    return "t2";
                } else if ("test3ns".equals(namespaceURI)) {
                    return "t3";
                }
                return null;
            }

            @Override
            public Iterator<?> getPrefixes(String namespaceURI) {
                List<String> ns = new ArrayList<String>();
                ns.add(getPrefix(namespaceURI));
                return ns.iterator();
            }
        };

        xmlSecurityStreamWriter.setNamespaceContext(namespaceContext);
        stdXmlStreamWriter.setNamespaceContext(namespaceContext);
        xmlSecurityStreamWriter.writeStartDocument("UTF-8", "1.0");
        stdXmlStreamWriter.writeStartDocument("UTF-8", "1.0");

        xmlSecurityStreamWriter.writeDTD("<!DOCTYPE foobar [\n\t<!ENTITY x0 \"hello\">\n]>");
        stdXmlStreamWriter.writeDTD("<!DOCTYPE foobar [\n\t<!ENTITY x0 \"hello\">\n]>");

        xmlSecurityStreamWriter.writeStartElement("test1");
        stdXmlStreamWriter.writeStartElement("test1");

        xmlSecurityStreamWriter.writeDefaultNamespace("defaultns");
        stdXmlStreamWriter.writeDefaultNamespace("defaultns");

        xmlSecurityStreamWriter.writeNamespace("t2new", "test2ns");
        stdXmlStreamWriter.writeNamespace("t2new", "test2ns");

        xmlSecurityStreamWriter.writeStartElement("test2ns", "test2");
        stdXmlStreamWriter.writeStartElement("test2ns", "test2");

        xmlSecurityStreamWriter.writeNamespace("t2", "test2ns");
        stdXmlStreamWriter.writeNamespace("t2", "test2ns");

        xmlSecurityStreamWriter.writeStartElement("t3", "test3", "test3ns");
        stdXmlStreamWriter.writeStartElement("t3", "test3", "test3ns");

        xmlSecurityStreamWriter.writeNamespace("t3", "test3ns");
        stdXmlStreamWriter.writeNamespace("t3", "test3ns");

        xmlSecurityStreamWriter.writeNamespace("t4", "test4ns");
        stdXmlStreamWriter.writeNamespace("t4", "test4ns");

        xmlSecurityStreamWriter.writeStartElement("test4ns", "test4");
        stdXmlStreamWriter.writeStartElement("test4ns", "test4");

        xmlSecurityStreamWriter.writeAttribute("attr1", "attr1val");
        stdXmlStreamWriter.writeAttribute("attr1", "attr1val");

        xmlSecurityStreamWriter.writeAttribute("t2", "test2ns", "attr2", "attr2val");
        stdXmlStreamWriter.writeAttribute("t2", "test2ns", "attr2", "attr2val");

        xmlSecurityStreamWriter.writeAttribute("test3ns", "attr3", "attr3val");
        stdXmlStreamWriter.writeAttribute("test3ns", "attr3", "attr3val");

        xmlSecurityStreamWriter.writeEmptyElement("test1");
        stdXmlStreamWriter.writeEmptyElement("test1");

        xmlSecurityStreamWriter.setPrefix("t2new", "test2ns");
        stdXmlStreamWriter.setPrefix("t2new", "test2ns");

        xmlSecurityStreamWriter.writeEmptyElement("test2ns", "test2");
        stdXmlStreamWriter.writeEmptyElement("test2ns", "test2");

        xmlSecurityStreamWriter.writeEmptyElement("t2", "test2ns", "test2");
        stdXmlStreamWriter.writeEmptyElement("t2", "test2ns", "test2");

        xmlSecurityStreamWriter.writeEmptyElement("test2ns", "test2");
        stdXmlStreamWriter.writeEmptyElement("test2ns", "test2");

        xmlSecurityStreamWriter.writeEmptyElement("t3", "test3", "test3ns");
        stdXmlStreamWriter.writeEmptyElement("t3", "test3", "test3ns");

        xmlSecurityStreamWriter.writeCharacters("\n");
        stdXmlStreamWriter.writeCharacters("\n");

        xmlSecurityStreamWriter.writeCData("Hi");
        stdXmlStreamWriter.writeCData("Hi");

        xmlSecurityStreamWriter.writeComment("this is a comment");
        stdXmlStreamWriter.writeComment("this is a comment");

        xmlSecurityStreamWriter.writeCharacters("abcdcba".toCharArray(), 3, 1);
        stdXmlStreamWriter.writeCharacters("abcdcba".toCharArray(), 3, 1);

        xmlSecurityStreamWriter.writeEntityRef("x0");
        stdXmlStreamWriter.writeEntityRef("x0");

        xmlSecurityStreamWriter.writeEndElement();
        stdXmlStreamWriter.writeEndElement();

        xmlSecurityStreamWriter.writeProcessingInstruction("PI");
        stdXmlStreamWriter.writeProcessingInstruction("PI");

        xmlSecurityStreamWriter.writeProcessingInstruction("PI", "there");
        stdXmlStreamWriter.writeProcessingInstruction("PI", "there");

        Assert.assertEquals(xmlSecurityStreamWriter.getPrefix("test4ns"), stdXmlStreamWriter.getPrefix("test4ns"));

        stdXmlStreamWriter.close();
        xmlSecurityStreamWriter.close();

        XMLAssert.assertXMLEqual(stdStringWriter.toString(), securityStringWriter.toString());
    }
View Full Code Here

                new SecurePart(new QName("urn:example:po", "PurchaseOrder"), SecurePart.Modifier.Content);
        properties.addEncryptionPart(encryptionSecurePart);

        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");

        InputStream sourceDocument =
                this.getClass().getClassLoader().getResourceAsStream(
                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);

        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();

        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
        Document document =
                XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

                new SecurePart(new QName("urn:example:po", "PurchaseOrder"), SecurePart.Modifier.Content);
        properties.addEncryptionPart(encryptionSecurePart);

        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");

        InputStream sourceDocument =
                this.getClass().getClassLoader().getResourceAsStream(
                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);

        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();

        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
        Document document =
                XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

                new SecurePart(new QName("urn:example:po", "PurchaseOrder"), SecurePart.Modifier.Content);
        properties.addEncryptionPart(encryptionSecurePart);

        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");

        InputStream sourceDocument =
                this.getClass().getClassLoader().getResourceAsStream(
                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);

        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();

        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
        Document document =
                XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

               new SecurePart(new QName("urn:example:po", "PurchaseOrder"), SecurePart.Modifier.Element);
        properties.addEncryptionPart(securePart);
       
        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");
       
        InputStream sourceDocument =
                this.getClass().getClassLoader().getResourceAsStream(
                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
       
        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();
       
        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
       
        Document document =
            XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

               new SecurePart(new QName("ns.com", "elem"), SecurePart.Modifier.Element);
        properties.addEncryptionPart(securePart);
       
        OutboundXMLSec outboundXMLSec = XMLSec.getOutboundXMLSec(properties);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = outboundXMLSec.processOutMessage(baos, "UTF-8");
       
        final String DATA1 =
                "<ns:root xmlns:ns=\"ns.com\"><ns:elem xmlns:ns2=\"ns2.com\">11</ns:elem></ns:root>";
        InputStream sourceDocument = new ByteArrayInputStream(DATA1.getBytes("UTF8"));
        XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(sourceDocument);
       
        XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
        xmlStreamWriter.close();
       
        // System.out.println("Got:\n" + new String(baos.toByteArray(), "UTF-8"));
       
        Document document =
            XMLUtils.createDocumentBuilder(false).parse(new ByteArrayInputStream(baos.toByteArray()));
View Full Code Here

TOP

Related Classes of javax.xml.stream.XMLStreamWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.