@Test public void testXmlBuilderPretty() throws Exception { assertEquals("<root attr1=\"av1+&amp;&amp;\" attr2=\"av2zzz\">&amp;testValue</root>\n", this.handlerPretty .tag("root").attr("attr1", "av1+&&").attr("attr2", "av2zzz") .chars("&testValue") .end() .toXml()); assertEquals("<root attr1=\"av1+&amp;&amp;\" attr2=\"av2zzz\"><![CDATA[&testValue]]></root>\n", this.handlerPretty .tag("root").attr("attr1", "av1+&&").attr("attr2", "av2zzz") .cdata("&testValue") .end() .toXml()); assertEquals("<root>\n <sub1><![CDATA[&testValue]]></sub1>\n</root>\n", this.handlerPretty .tag("root") .tag("sub1") .cdata("&testValue") .end() .end() .toXml()); assertEquals("<root>\n" + " <sub1><![CDATA[&testValue]]></sub1>\n" + " <sub2>&amp;testValue 2\n" + "another line</sub2>\n" + " <bool>true</bool>\n" + " <chars>&amp;chars</chars>\n" + " <cdata><![CDATA[&chars]]></cdata>\n" + " <num-bd>30</num-bd>\n" + " <num-int>31</num-int>\n" + " <num-long>32</num-long>\n" + "</root>\n", this.handlerPretty .tag("root") .tag("sub1") .cdata("&testValue") .end() .tag("sub2") .chars("&testValue 2") .chars("\nanother line") .end() .tagBool("bool", true) .tagChars("chars", "&chars") .tagCdata("cdata", "&chars") .tagNum("num-bd", new BigDecimal("30")) .tagNum("num-int", 31) .tagNum("num-long", 32L) .end() .toXml()); final Map<String, String> names = new HashMap<>(); names.put("en", "english"); names.put("de", "deutch"); final I18NModel displayName = new StringI18NModel(names); assertEquals("<root>\n" + " <display-name>\n" + " <i18n lang=\"de\"><![CDATA[deutch]]></i18n>\n" + " <i18n lang=\"en\"><![CDATA[english]]></i18n>\n" + " </display-name>\n" + "</root>\n", this.handlerPretty .tag("root") .tagI18n("display-name", displayName) .end() .toXml()); final Attributable attr = this.context.mock(Attributable.class); final AttrValue av1 = this.context.mock(AttrValue.class, "av1"); final AttrValue av2 = this.context.mock(AttrValue.class, "av2"); this.context.checking(new Expectations() {{ allowing(attr).getAllAttributes(); will(returnValue(Arrays.asList(av1, av2))); allowing(av1).getAttrvalueId(); will(returnValue(1L)); allowing(av1).getAttributeCode(); will(returnValue("CODE1")); allowing(av1).getGuid(); will(returnValue("GUID1")); allowing(av1).getVal(); will(returnValue("val1")); allowing(av1).getDisplayVal(); will(returnValue(displayName)); allowing(av2).getAttrvalueId(); will(returnValue(2L)); allowing(av2).getAttributeCode(); will(returnValue("CODE2")); allowing(av2).getGuid(); will(returnValue("GUID2")); allowing(av2).getVal(); will(returnValue("val2")); allowing(av2).getDisplayVal(); will(returnValue(displayName)); }}); assertEquals("<root>\n" + " <custom-attributes>\n" + " <custom-attribute id=\"1\" guid=\"GUID1\" attribute=\"CODE1\">\n" + " <custom-value><![CDATA[val1]]></custom-value>\n" + " <custom-display-value>\n" + " <i18n lang=\"de\"><![CDATA[deutch]]></i18n>\n" + " <i18n lang=\"en\"><![CDATA[english]]></i18n>\n" + " </custom-display-value>\n" + " </custom-attribute>\n" + " <custom-attribute id=\"2\" guid=\"GUID2\" attribute=\"CODE2\">\n" + " <custom-value><![CDATA[val2]]></custom-value>\n" + " <custom-display-value>\n" + " <i18n lang=\"de\"><![CDATA[deutch]]></i18n>\n" + " <i18n lang=\"en\"><![CDATA[english]]></i18n>\n" + " </custom-display-value>\n" + " </custom-attribute>\n" + " </custom-attributes>\n" + "</root>\n", this.handlerPretty .tag("root") .tagExt(attr) .end() .toXml()); final Seoable seoable = this.context.mock(Seoable.class); final Seo seo = this.context.mock(Seo.class); this.context.checking(new Expectations() {{ allowing(seoable).getSeo(); will(returnValue(seo)); allowing(seo).getUri(); will(returnValue("abc")); allowing(seo).getTitle(); will(returnValue("title")); allowing(seo).getDisplayTitle(); will(returnValue(displayName)); allowing(seo).getMetakeywords(); will(returnValue("keyword")); allowing(seo).getDisplayMetakeywords(); will(returnValue(displayName)); allowing(seo).getMetadescription(); will(returnValue("description")); allowing(seo).getDisplayMetadescription(); will(returnValue(displayName)); }}); assertEquals("<root>\n" + " <seo>\n" + " <uri><![CDATA[abc]]></uri>\n" + " <meta-title><![CDATA[title]]></meta-title>\n" + " <meta-title-display>\n" + " <i18n lang=\"de\"><![CDATA[deutch]]></i18n>\n" + " <i18n lang=\"en\"><![CDATA[english]]></i18n>\n" + " </meta-title-display>\n" + " <meta-keywords><![CDATA[keyword]]></meta-keywords>\n" + " <meta-keywords-display>\n" + " <i18n lang=\"de\"><![CDATA[deutch]]></i18n>\n" + " <i18n lang=\"en\"><![CDATA[english]]></i18n>\n" + " </meta-keywords-display>\n" + " <meta-description><![CDATA[description]]></meta-description>\n" + " <meta-description-display>\n" + " <i18n lang=\"de\"><![CDATA[deutch]]></i18n>\n" + " <i18n lang=\"en\"><![CDATA[english]]></i18n>\n" + " </meta-description-display>\n" + " </seo>\n" + "</root>\n", this.handlerPretty .tag("root") .tagSeo(seoable) .end() .toXml()); }
protected Tag tag(final String name) { return new Tag(name, this.prettyPrint); }
AbstractXmlEntityHandler implements XmlEntityExportHandler<T> { protected Tag tag(final String name) { return new Tag(name, this.prettyPrint); } }
AbstractXmlEntityHandler implements XmlEntityExportHandler<T> { protected Tag tag(final String name) { return new Tag(name, this.prettyPrint); } protected  AbstractXmlEntityHandler(final String rootTag); }
AbstractXmlEntityHandler implements XmlEntityExportHandler<T> { protected Tag tag(final String name) { return new Tag(name, this.prettyPrint); } protected  AbstractXmlEntityHandler(final String rootTag); @Override void startXml(final OutputStreamWriter writer); @Override void endXml(final OutputStreamWriter writer); void setPrettyPrint(final boolean prettyPrint); }
AbstractXmlEntityHandler implements XmlEntityExportHandler<T> { protected Tag tag(final String name) { return new Tag(name, this.prettyPrint); } protected  AbstractXmlEntityHandler(final String rootTag); @Override void startXml(final OutputStreamWriter writer); @Override void endXml(final OutputStreamWriter writer); void setPrettyPrint(final boolean prettyPrint);  }