Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis D'Entremont2006-10-13 19:14:44 +0000
committerCurtis D'Entremont2006-10-13 19:14:44 +0000
commitebefd0ee634c33f186ad4297a3102a4955f15ee2 (patch)
treee70a3ac4331ff9610f038ee485ba5690719997a7 /org.eclipse.ua.tests/base/org/eclipse/ua/tests/util
parent8086790b674c974c31df4b5b3f4cf3daa5370f96 (diff)
downloadeclipse.platform.ua-ebefd0ee634c33f186ad4297a3102a4955f15ee2.tar.gz
eclipse.platform.ua-ebefd0ee634c33f186ad4297a3102a4955f15ee2.tar.xz
eclipse.platform.ua-ebefd0ee634c33f186ad4297a3102a4955f15ee2.zip
fixed failing tests (transformers randomly reorder attributes, so can't use direct string comparison)
Diffstat (limited to 'org.eclipse.ua.tests/base/org/eclipse/ua/tests/util')
-rw-r--r--org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/XMLUtil.java86
1 files changed, 81 insertions, 5 deletions
diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/XMLUtil.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/XMLUtil.java
index 19d2bfb7b..8456f4f2d 100644
--- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/XMLUtil.java
+++ b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/XMLUtil.java
@@ -11,12 +11,23 @@
package org.eclipse.ua.tests.util;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
import junit.framework.Assert;
-import org.eclipse.help.internal.dynamic.DOMProcessorHandler;
-import org.eclipse.help.internal.dynamic.XMLProcessor;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
/**
* A utility class for working with XML.
@@ -30,9 +41,74 @@ public class XMLUtil extends Assert {
}
public static void assertXMLEquals(String msg, InputStream in1, InputStream in2) throws Exception {
- XMLProcessor processor = new XMLProcessor(new DOMProcessorHandler[0]);
- String s1 = FileUtil.readString(processor.process(in1, null));
- String s2 = FileUtil.readString(processor.process(in2, null));
+ String s1 = process(in1);
+ String s2 = process(in2);
assertEquals(msg, s1, s2);
}
+
+ private static String process(InputStream in) throws Exception {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ SAXParser parser = factory.newSAXParser();
+ Handler handler = new Handler();
+ parser.parse(in, handler);
+ return handler.toString();
+ }
+
+ private static class Handler extends DefaultHandler {
+
+ private StringBuffer buf = new StringBuffer();
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+ buf.append('<');
+ buf.append(qName);
+
+ List list = new ArrayList();
+ for (int i=0;i<attributes.getLength();++i) {
+ list.add(attributes.getQName(i));
+ }
+ Collections.sort(list);
+ Iterator iter = list.iterator();
+ while (iter.hasNext()) {
+ String name = (String)iter.next();
+ buf.append(' ');
+ buf.append(name);
+ buf.append('=');
+ buf.append('"');
+ buf.append(attributes.getValue(name));
+ buf.append('"');
+ }
+ buf.append('>');
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+ buf.append('<');
+ buf.append('/');
+ buf.append(qName);
+ buf.append('>');
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
+ */
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ buf.append(ch, start, length);
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#resolveEntity(java.lang.String, java.lang.String)
+ */
+ public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException {
+ return new InputSource(new StringReader("")); //$NON-NLS-1$
+ }
+
+ public String toString() {
+ return buf.toString();
+ }
+ }
}

Back to the top