stephan 2003/04/09 04:12:20
Modified: src/test/org/apache/cocoon/components/resolver/test
ResolverImplTestCase.xtest
src/test/org/apache/cocoon/generation
FileGeneratorTestCase.xtest
src/test/org/apache/cocoon/transformation
AbstractTransformerTestCase.java
src/test/org/apache/cocoon/xml WhitespaceFilter.java
Log:
Updating whitespacer filter.
Setting log level to WARN for reducing verbosity.
Revision Changes Path
1.5 +1 -1
cocoon-2.1/src/test/org/apache/cocoon/components/resolver/test/ResolverImplTestCase.xtest
Index: ResolverImplTestCase.xtest
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/test/org/apache/cocoon/components/resolver/test/ResolverImplTestCase.xtest,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ResolverImplTestCase.xtest 8 Apr 2003 18:51:03 -0000 1.4
+++ ResolverImplTestCase.xtest 9 Apr 2003 11:12:19 -0000 1.5
@@ -95,7 +95,7 @@
</stream>
</targets>
<categories>
- <category name="test" log-level="DEBUG">
+ <category name="test" log-level="WARN">
<log-target id-ref="root"/>
</category>
</categories>
1.5 +1 -9
cocoon-2.1/src/test/org/apache/cocoon/generation/FileGeneratorTestCase.xtest
Index: FileGeneratorTestCase.xtest
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/test/org/apache/cocoon/generation/FileGeneratorTestCase.xtest,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FileGeneratorTestCase.xtest 8 Apr 2003 18:51:03 -0000 1.4
+++ FileGeneratorTestCase.xtest 9 Apr 2003 11:12:20 -0000 1.5
@@ -18,17 +18,9 @@
</stream>
</targets>
<categories>
- <category name="test" log-level="DEBUG">
+ <category name="test" log-level="WARN">
<log-target id-ref="root"/>
</category>
- <!-- Uncomment for ComponentManager and RoleManager debug
- <category name="cm" log-level="DEBUG">
- <log-target id-ref="root"/>
- </category>
- <category name="rm" log-level="DEBUG">
- <log-target id-ref="root"/>
- </category>
- -->
</categories>
</logkit>
1.3 +28 -11
cocoon-2.1/src/test/org/apache/cocoon/transformation/AbstractTransformerTestCase.java
Index: AbstractTransformerTestCase.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/test/org/apache/cocoon/transformation/AbstractTransformerTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractTransformerTestCase.java 12 Mar 2003 15:02:17 -0000 1.2
+++ AbstractTransformerTestCase.java 9 Apr 2003 11:12:20 -0000 1.3
@@ -55,6 +55,11 @@
import java.util.Map;
import java.util.Vector;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
import org.apache.avalon.excalibur.testcase.ExcaliburTestCase;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
@@ -70,6 +75,7 @@
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -142,8 +148,6 @@
*/
public final void testTransformer() {
- try {
-
ComponentSelector selector = null;
Transformer transformer = null;
SourceResolver resolver = null;
@@ -165,6 +169,8 @@
TestStep test;
int count = 0;
+ getLogger().debug("Count of test steps: "+teststeps.size());
+
for (Enumeration e = teststeps.elements(); e.hasMoreElements();
) {
test = (TestStep) e.nextElement();
count++;
@@ -230,9 +236,6 @@
(test.assertiontype>=EQUAL) &&
(test.assertiontype<=NOTIDENTICAL));
- // NEVER USED!
- //NodeList childs =
assertiondocument.getDocumentElement().getChildNodes();
-
switch (test.assertiontype) {
case EQUAL :
document.getDocumentElement().normalize();
@@ -309,11 +312,6 @@
if (parser!=null)
this.manager.release((Component) parser);
}
-
- } catch (Exception excep)
- {
- excep.printStackTrace();
- }
}
/**
@@ -323,6 +321,25 @@
* @return Diff object describing differences in documents
*/
public final Diff compareXML(Document control, Document test) {
+
+ /*TransformerFactory factory = (TransformerFactory)
TransformerFactory.newInstance();
+ try
+ {
+ javax.xml.transform.Transformer serializer =
factory.newTransformer();
+ System.out.println("Control document:");
+ serializer.transform(new DOMSource(control), new
StreamResult(System.out));
+ System.out.println();
+
+ serializer = factory.newTransformer();
+ System.out.println("Test document:");
+ serializer.transform(new DOMSource(test), new
StreamResult(System.out));
+ System.out.println();
+ }
+ catch (TransformerException te)
+ {
+ te.printStackTrace();
+ }*/
+
return new Diff(control, test);
}
1.2 +48 -26
cocoon-2.1/src/test/org/apache/cocoon/xml/WhitespaceFilter.java
Index: WhitespaceFilter.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/test/org/apache/cocoon/xml/WhitespaceFilter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WhitespaceFilter.java 9 Mar 2003 00:10:42 -0000 1.1
+++ WhitespaceFilter.java 9 Apr 2003 11:12:20 -0000 1.2
@@ -9,7 +9,7 @@
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice,
+ 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@@ -17,12 +17,12 @@
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
- include the following acknowledgment: "This product includes software
- developed by the Apache Software Foundation (http://www.apache.org/)."
- Alternately, this acknowledgment may appear in the software itself, if
+ include the following acknowledgment: "This product includes software
+ developed by the Apache Software Foundation (http://www.apache.org/)."
+ Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
- 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
+ 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
@@ -33,7 +33,7 @@
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
@@ -52,6 +52,7 @@
import org.apache.cocoon.xml.AbstractXMLPipe;
+import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -62,8 +63,8 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a>
* @version CVS $Id$
*/
-public class WhitespaceFilter extends AbstractXMLPipe
-{
+public class WhitespaceFilter extends AbstractXMLPipe {
+ private StringBuffer buffer = null;
/**
* Create a new WhitespaceFilter.
@@ -81,28 +82,18 @@
* @param start The start position in the array.
* @param len The number of characters to read from the array.
*
- * @throws SAXException
+ * @throws SAXException
*/
public void characters(char c[], int start, int len) throws SAXException
{
if (contentHandler==null) {
return;
}
- for (int i = start; i<start+len; i++)
- if ( !Character.isWhitespace(c[i])) {
- StringBuffer buffer = new StringBuffer();
-
- for (int j = i; j<start+len; j++)
- if ((c[j]!='\n') && (c[j]!='\r')) {
- buffer.append(c[j]);
- }
- if (buffer.length()>0) {
-
contentHandler.characters(buffer.toString().toCharArray(),
- 0, buffer.length());
- }
- return;
- }
- // otherwise ignore characters
+ if (buffer==null) {
+ buffer = new StringBuffer();
+ }
+
+ buffer.append(c, start, len);
}
/**
@@ -112,10 +103,41 @@
* @param start The start position in the array.
* @param len The number of characters to read from the array.
*
- * @throws SAXException
+ * @throws SAXException
*/
public void ignorableWhitespace(char c[], int start,
int len) throws SAXException {
// ignore
+ }
+
+ /**
+ * Receive notification of the beginning of an element.
+ *
+ * @param namespaceURI
+ * @param localName
+ * @param qName
+ * @param atts
+ *
+ * @throws SAXException
+ */
+ public void startElement(String namespaceURI, String localName,
+ String qName,
+ Attributes atts) throws SAXException {
+ if (buffer!=null) {
+ String text = buffer.toString();
+
+ text = text.replace('\n', ' ');
+ text = text.replace('\r', ' ');
+ text = text.trim();
+
+ if (text.length()>0) {
+ contentHandler.characters(text.toCharArray(), 0,
+ text.length());
+ }
+
+ buffer = null;
+ }
+
+ contentHandler.startElement(namespaceURI, localName, qName, atts);
}
}