Package org.apache.commons.betwixt.io

Examples of org.apache.commons.betwixt.io.BeanWriter


        Element element = new Element();
        element.setValue("<greeting>What Ho Jeeves!</greeting>");
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        writer.getBindingConfiguration().setMapIDs(false);
        XMLBeanInfo elementInfo = writer.getXMLIntrospector().introspect(Element.class);
        elementInfo.getElementDescriptor().getElementDescriptors()[0]
            .getOptions().addOption(MixedContentEncodingStrategy.ENCODING_OPTION_NAME, "CDATA")
        
        writer.setEndOfLine("\n"); //force to \n so expected values match for sure
        writer.write(element);
       
        String expected = "<?xml version='1.0'?><Element>\n<value><![CDATA[<greeting>What Ho Jeeves!</greeting>]]></value>\n</Element>\n";
        String xml = out.getBuffer().toString();
        
        assertEquals(expected,xml);
View Full Code Here


        Element element = new Element();
        element.setValue("<greeting>What Ho Jeeves!</greeting>");
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        writer.getBindingConfiguration().setMapIDs(false);
        XMLBeanInfo elementInfo = writer.getXMLIntrospector().introspect(Element.class);
        elementInfo.getElementDescriptor().getElementDescriptors()[0]
            .getOptions().addOption("org.apache.commons.betwixt.mixed-content-encoding", "escaped");
        writer.setEndOfLine("\n"); //force to \n so expected values match for sure
        writer.write(element);
       
        String expected = "<?xml version='1.0'?><Element>\n<value>&lt;greeting&gt;What Ho Jeeves!&lt;/greeting&gt;</value>\n</Element>\n";
        String xml = out.getBuffer().toString();
        
        assertEquals(expected,xml);
View Full Code Here

                            true);
    }
   
    public void testBeanWriterWorksWithAnAddMethodAndACollection() throws Exception {

        BeanWriter bw = new BeanWriter();
        try {
            bw.write(new BeanWithAddMethod());
        } catch (IllegalArgumentException e) {
            fail("BeanWriter fails when a method is just called add(<type>) and there is also a collection");
        }
    }
View Full Code Here

        bean.setB("<strong>weak</strong>");
        bean.setC("<strong>weak</strong>");
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        writer.getBindingConfiguration().setMapIDs(false);
        writer.setEndOfLine("\n"); //force to \n so expected values match for sure
        writer.write(bean);
       
        String expected = "<?xml version='1.0'?>" +
            "<greek-abc>\n" +
            "<alpha><![CDATA[<strong>weak</strong>]]></alpha>\n" +
            "<beta>&lt;strong&gt;weak&lt;/strong&gt;</beta>\n" +
View Full Code Here

   
    public void testWriteSimpleDotBetwixtWithNamespaces() throws Exception {
        PersonWithNamespace bean = new PersonWithNamespace("Robert", "Burrell", "Donkin");
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getBindingConfiguration().setMapIDs(false);
        writer.getXMLIntrospector().getConfiguration().getPrefixMapper()
            .setPrefix("http://jakarta.apache.org/commons/betwixt/PersonWithNamespaceExample", "pn");
        writer.write(bean);
       
        String xml = out.getBuffer().toString();
       
        String expected = "<?xml version='1.0'?>" +
                        "<pn:person " +
View Full Code Here

        Element element = new Element();
        element.setValue("<greeting>What Ho Jeeves!</greeting>");
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        writer.getBindingConfiguration().setMapIDs(false);
        writer.setMixedContentEncodingStrategy(new TestBaseMixedContentEncoding(false));
        writer.setEndOfLine("\n"); //force to \n so expected values match for sure
        writer.write(element);
       
        String expected = "<?xml version='1.0'?><Element>\n<value>&lt;greeting&gt;What Ho Jeeves!&lt;/greeting&gt;</value>\n</Element>\n";
        String xml = out.getBuffer().toString();
        
        assertEquals(expected,xml);
View Full Code Here

        Element element = new Element();
        element.setValue("<greeting>What Ho Jeeves!</greeting>");
       
        StringWriter out = new StringWriter();
        out.write("<?xml version='1.0'?>");
        BeanWriter writer = new BeanWriter(out);
        writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        writer.getBindingConfiguration().setMapIDs(false);
        writer.setMixedContentEncodingStrategy(new TestBaseMixedContentEncoding(true));
        writer.setEndOfLine("\n"); //force to \n so expected values match for sure
        writer.write(element);
       
        String expected = "<?xml version='1.0'?><Element>\n<value><![CDATA[<greeting>What Ho Jeeves!</greeting>]]></value>\n</Element>\n";
        String xml = out.getBuffer().toString();
        
        assertEquals(expected,xml);     
View Full Code Here

    }

    public void testHasClassElementWithoutDotBetwixtFile() throws Exception {
        // configure bean writer with counting suppression strategy...
        StringWriter buffer = new StringWriter();
        BeanWriter beanWriter = new BeanWriter(buffer);
        beanWriter.getXMLIntrospector().getConfiguration().setPropertySuppressionStrategy(
                new PropertySuppressionStrategy() {

                    public boolean suppressProperty(Class clazz, Class propertyType,
                            String propertyName) {
                        return false;
                    }
                });

        // test with class without dot-betwixt file...
        Object bean = new Locale("de", "de"); // just a bean with some properties
        beanWriter.write(bean);

        // was the class element written?..
        assertTrue(buffer.toString().indexOf("<class>" + bean.getClass().getName() + "</class>") > 0)
    }
View Full Code Here

    }

    public void testHasClassElementWithDotBetwixtFile() throws Exception {
        // configure bean writer with counting suppression strategy...
        StringWriter buffer = new StringWriter();
        BeanWriter beanWriter = new BeanWriter(buffer);
        beanWriter.getXMLIntrospector().getConfiguration().setPropertySuppressionStrategy(
                new PropertySuppressionStrategy() {

                    public boolean suppressProperty(Class clazz, Class propertyType,
                            String propertyName) {
                        return false;
                    }
                });

        // test with class without dot-betwixt file...
        Object bean = new SimpleClass();
        beanWriter.write(bean);

        // was the class element written?..
        assertTrue(buffer.toString().indexOf("<class>" + bean.getClass().getName() + "</class>") > 0);
    }
View Full Code Here

        alphaBean.addChild(betaBeanTwo);
        BetaBean betaBeanThree = new BetaBean("THREE");
        alphaBean.put("Key", betaBeanThree);
       
        StringWriter out = new StringWriter();
        BeanWriter writer = new BeanWriter(out);
        writer.getBindingConfiguration().setMapIDs(false);
        writer.getBindingConfiguration().setObjectStringConverter(new PrependingConverter());
        writer.write(alphaBean);
       
        String xml = "<alpha>" +
                "        <name>BananasSIX</name>" +
                "        <betaBean>" +
                "            <name>PeachONE</name>" +
View Full Code Here

TOP

Related Classes of org.apache.commons.betwixt.io.BeanWriter

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.