[Yanel-commits] rev 44968 -
public/yanel/trunk/src/test/junit/org/wyona/yanel/core/serialization
guillaume at wyona.com
guillaume at wyona.com
Wed Oct 7 12:41:11 CEST 2009
Author: guillaume
Date: 2009-10-07 12:41:10 +0200 (Wed, 07 Oct 2009)
New Revision: 44968
Modified:
public/yanel/trunk/src/test/junit/org/wyona/yanel/core/serialization/SerializerFactoryTest.java
Log:
Fixed indentation.
Modified: public/yanel/trunk/src/test/junit/org/wyona/yanel/core/serialization/SerializerFactoryTest.java
===================================================================
--- public/yanel/trunk/src/test/junit/org/wyona/yanel/core/serialization/SerializerFactoryTest.java 2009-10-07 10:38:24 UTC (rev 44967)
+++ public/yanel/trunk/src/test/junit/org/wyona/yanel/core/serialization/SerializerFactoryTest.java 2009-10-07 10:41:10 UTC (rev 44968)
@@ -25,126 +25,126 @@
public class SerializerFactoryTest extends TestCase {
- private static final String[] defaultOutputProps = new String[] {"encoding", "UTF-8"};
+ private static final String[] defaultOutputProps = new String[] {"encoding", "UTF-8"};
- public void testGetSerializer() {
- doNotOutputXMLemptyTagsForEmptyHTMLelements();
- doNotIndentAfterInlineElementsEndTags();
- }
+ public void testGetSerializer() {
+ doNotOutputXMLemptyTagsForEmptyHTMLelements();
+ doNotIndentAfterInlineElementsEndTags();
+ }
- /**
- * Issue: 7285
- */
- private void doNotOutputXMLemptyTagsForEmptyHTMLelements() {
- assertAllSerializationsContain("<html><body><textarea/></body></html>", "<textarea></textarea>");
- }
+ /**
+ * Issue: 7285
+ */
+ private void doNotOutputXMLemptyTagsForEmptyHTMLelements() {
+ assertAllSerializationsContain("<html><body><textarea/></body></html>", "<textarea></textarea>");
+ }
- /**
- * Issue: 5145
- */
- private void doNotIndentAfterInlineElementsEndTags() {
- assertContains(WyonaUnconfiguredHTMLserialized("<html><body><p><a>link</a></p></body></html>", "indent", "yes"), "</a><");
- assertContains(WyonaHTMLserialized("<html><body><p><a>link</a></p></body></html>", "indent", "yes"), "</a><");
- assertDoesNotContain(ApacheUnconfiguredHTMLserialized("<html><body><p><a>link</a></p></body></html>", "indent", "yes"), "</a><");
- assertDoesNotContain(JAXPHTMLserialized("<html><body><p><a>link</a></p></body></html>", "indent", "yes"), "</a><");
- }
+ /**
+ * Issue: 5145
+ */
+ private void doNotIndentAfterInlineElementsEndTags() {
+ assertContains(WyonaUnconfiguredHTMLserialized("<html><body><p><a>link</a></p></body></html>", "indent", "yes"), "</a><");
+ assertContains(WyonaHTMLserialized("<html><body><p><a>link</a></p></body></html>", "indent", "yes"), "</a><");
+ assertDoesNotContain(ApacheUnconfiguredHTMLserialized("<html><body><p><a>link</a></p></body></html>", "indent", "yes"), "</a><");
+ assertDoesNotContain(JAXPHTMLserialized("<html><body><p><a>link</a></p></body></html>", "indent", "yes"), "</a><");
+ }
- private void assertAllSerializationsContain(String s, String s1, String... outputProps) {
- assertContains(JAXPHTMLserialized(s, outputProps), s1);
- assertContains(ApacheUnconfiguredHTMLserialized(s, outputProps), s1);
- assertContains(WyonaHTMLserialized(s, outputProps), s1);
- assertContains(WyonaUnconfiguredHTMLserialized(s, outputProps), s1);
- }
+ private void assertAllSerializationsContain(String s, String s1, String... outputProps) {
+ assertContains(JAXPHTMLserialized(s, outputProps), s1);
+ assertContains(ApacheUnconfiguredHTMLserialized(s, outputProps), s1);
+ assertContains(WyonaHTMLserialized(s, outputProps), s1);
+ assertContains(WyonaUnconfiguredHTMLserialized(s, outputProps), s1);
+ }
- private void assertContains(String s, String s1) {
- assertTrue(s+" should contain "+ s1, s.contains(s1));
- }
+ private void assertContains(String s, String s1) {
+ assertTrue(s+" should contain "+ s1, s.contains(s1));
+ }
- private void assertDoesNotContain(String s, String s1) {
- assertTrue(s+" should not contain "+ s1, ! s.contains(s1));
- }
+ private void assertDoesNotContain(String s, String s1) {
+ assertTrue(s+" should not contain "+ s1, ! s.contains(s1));
+ }
- private String JAXPHTMLserialized(String s, String... outputProps) {
- return serializedUsingJAXPAPI(s, join(join(defaultOutputProps, outputProps), OutputKeys.METHOD, "html"));
- }
+ private String JAXPHTMLserialized(String s, String... outputProps) {
+ return serializedUsingJAXPAPI(s, join(join(defaultOutputProps, outputProps), OutputKeys.METHOD, "html"));
+ }
- private String WyonaUnconfiguredHTMLserialized(String s, String... outputProps) {
- return serializedUsingApacheSerializerAPI(s, SerializerFactory.getSerializer(new Properties()), join(defaultOutputProps, outputProps));
- }
+ private String WyonaUnconfiguredHTMLserialized(String s, String... outputProps) {
+ return serializedUsingApacheSerializerAPI(s, SerializerFactory.getSerializer(new Properties()), join(defaultOutputProps, outputProps));
+ }
- private String WyonaHTMLserialized(String s, String... outputProps) {
- return serializedUsingApacheSerializerAPI(s, SerializerFactory.getSerializer(SerializerFactory.HTML_TRANSITIONAL_KEY), join(defaultOutputProps, outputProps));
- }
+ private String WyonaHTMLserialized(String s, String... outputProps) {
+ return serializedUsingApacheSerializerAPI(s, SerializerFactory.getSerializer(SerializerFactory.HTML_TRANSITIONAL_KEY), join(defaultOutputProps, outputProps));
+ }
- private String ApacheUnconfiguredHTMLserialized(String s, String... outputProps) {
- Serializer serializer = new ToHTMLStream();
- //serializer.setOutputFormat(OutputPropertiesFactory.getDefaultMethodProperties(Method.HTML));
- return serializedUsingApacheSerializerAPI(s, serializer, join(join(defaultOutputProps, outputProps), "method", "html"));
- }
+ private String ApacheUnconfiguredHTMLserialized(String s, String... outputProps) {
+ Serializer serializer = new ToHTMLStream();
+ //serializer.setOutputFormat(OutputPropertiesFactory.getDefaultMethodProperties(Method.HTML));
+ return serializedUsingApacheSerializerAPI(s, serializer, join(join(defaultOutputProps, outputProps), "method", "html"));
+ }
- private String serializedUsingJAXPAPI(String s, String... outputProps) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- SAXTransformerFactory thFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
- try {
- final TransformerHandler idth = thFactory.newTransformerHandler();
- idth.setResult(new StreamResult(baos));
- Properties outputProperties = collectProperties(outputProps);
- idth.getTransformer().setOutputProperties(outputProperties);
- return serialize(s, idth, baos, outputProperties.getProperty(OutputKeys.ENCODING));
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ private String serializedUsingJAXPAPI(String s, String... outputProps) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SAXTransformerFactory thFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
+ try {
+ final TransformerHandler idth = thFactory.newTransformerHandler();
+ idth.setResult(new StreamResult(baos));
+ Properties outputProperties = collectProperties(outputProps);
+ idth.getTransformer().setOutputProperties(outputProperties);
+ return serialize(s, idth, baos, outputProperties.getProperty(OutputKeys.ENCODING));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
- private String serializedUsingApacheSerializerAPI(String s, Serializer serializer, String... outputProps) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- serializer.setOutputStream(baos);
- try {
- ContentHandler ch = serializer.asContentHandler();
- Properties outputProperties = serializer.getOutputFormat();
- outputProperties.putAll(collectProperties(outputProps));
- serializer.setOutputFormat(outputProperties);
- return serialize(s, ch, baos, outputProperties.getProperty("encoding"));
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ private String serializedUsingApacheSerializerAPI(String s, Serializer serializer, String... outputProps) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ serializer.setOutputStream(baos);
+ try {
+ ContentHandler ch = serializer.asContentHandler();
+ Properties outputProperties = serializer.getOutputFormat();
+ outputProperties.putAll(collectProperties(outputProps));
+ serializer.setOutputFormat(outputProperties);
+ return serialize(s, ch, baos, outputProperties.getProperty("encoding"));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
- private String serialize(String s, ContentHandler ch, ByteArrayOutputStream baos, String encoding) {
- Reader r = new StringReader(s);
- try {
- XMLReader XMLReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
- XMLReader.setContentHandler(ch);
- XMLReader.parse(new InputSource(r));
- return baos.toString(encoding);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
+ private String serialize(String s, ContentHandler ch, ByteArrayOutputStream baos, String encoding) {
+ Reader r = new StringReader(s);
+ try {
+ XMLReader XMLReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+ XMLReader.setContentHandler(ch);
+ XMLReader.parse(new InputSource(r));
+ return baos.toString(encoding);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
- private Properties collectProperties(String... props) throws Exception {
- Properties properties = new Properties();
- if (props == null) {
- return properties;
- }
- int n = props.length;
- if (n % 2 != 0) throw new IllegalArgumentException("'props' argument must list pairs!");
- String propertyName = null;
- for (int i = 0; i < n; i++) {
- String ps = props[i];
- if (i % 2 == 0) {
- propertyName = ps;
- } else {
- String propertyValue = ps;
- properties.setProperty(propertyName, propertyValue);
- }
- }
- return properties;
- }
+ private Properties collectProperties(String... props) throws Exception {
+ Properties properties = new Properties();
+ if (props == null) {
+ return properties;
+ }
+ int n = props.length;
+ if (n % 2 != 0) throw new IllegalArgumentException("'props' argument must list pairs!");
+ String propertyName = null;
+ for (int i = 0; i < n; i++) {
+ String ps = props[i];
+ if (i % 2 == 0) {
+ propertyName = ps;
+ } else {
+ String propertyValue = ps;
+ properties.setProperty(propertyName, propertyValue);
+ }
+ }
+ return properties;
+ }
- private <T> T[] join(T[] a, T... a1) {
- List<T> l = new ArrayList<T>(Arrays.asList(a));
- l.addAll(Arrays.asList(a1));
- return l.toArray(a);
- }
+ private <T> T[] join(T[] a, T... a1) {
+ List<T> l = new ArrayList<T>(Arrays.asList(a));
+ l.addAll(Arrays.asList(a1));
+ return l.toArray(a);
+ }
}
More information about the Yanel-commits
mailing list