> I have added something like this for <TD> and <A> tags for html.
> getNeedsLineBreak() returns true for most elements, but for <A> it returns
> false if it only contains IMG objects and TD does the same if it only
> contains IMG or A elements.
Thanks John. I took that same idea and applied it to the XML class.
> Unfortunately, pretty print seems to have broken when I started adding a
> SCRIPT element to the <HEAD>, but prior to this it was printing <TD> and <A>
> tags correctly.
Well, I'm not sure if there is a reason, but the getNeedLineBreak checks
were left out if the object was being printed to a PrintWriter. Here is
the patch for that. Oh, and after this patch is the patch to make XML
conform to white space handling AND pretty print. If this violates XML
white space handling, please let me know. Basically, if the tag being
printed ONLY has a StringElement as its child, then don't print the
newlines.
Index: ConcreteElement.java
===================================================================
RCS file:
/products/cvs/master/ecs/src/java/org/apache/ecs/ConcreteElement.java,v
retrieving revision 1.16
diff -r1.16 ConcreteElement.java
385,386c385,388
< out.write('\n');
< e.setTabLevel(tabLevel +
1);
---
> if (getNeedLineBreak()) {
> out.write('\n');
> e.setTabLevel(tabLevel + 1);
> }
394,395c396,399
< out.write('\n');
< putTabs(tabLevel + 1,
out);
---
> if (getNeedLineBreak()) {
> out.write('\n');
> putTabs(tabLevel + 1, out);
> }
408,410c412,416
< out.write('\n');
< if (tabLevel > 0)
< putTabs(tabLevel, out);
---
> if (getNeedLineBreak()) {
> out.write('\n');
> if (tabLevel > 0)
> putTabs(tabLevel, out);
> }
This is the second patch, the one for the XML pretty printing.
Index: XML.java
===================================================================
RCS file:
/products/cvs/master/ecs/src/java/org/apache/ecs/xml/XML.java,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 XML.java
64c64
< public class XML extends MultiPartElement
---
> public class XML extends MultiPartElement implements Printable
188c188,209
< }
\ No newline at end of file
---
>
> public boolean getNeedLineBreak() {
> boolean linebreak = true;
>
> java.util.Enumeration enum = elements();
>
> // if this tag has one child, and it's a String, then don't
> // do any linebreaks to preserve whitespace
> int i = 0;
> int j = 0;
> while (enum.hasMoreElements()) {
> i++;
> Object obj = enum.nextElement();
> if (obj instanceof StringElement)
> j++;
> }
> if (i ==j)
> linebreak = false;
>
> return linebreak;
> }
> }
Thanks, and let me know what you think,
Seth
--
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]