sanders     02/02/02 19:21:46

  Modified:    proposal/vindico/src/java/org/apache/alexandria/util
                        XMLHelper.java
  Log:
  Silly exceptions.  Anyone have a better idea?
  
  Revision  Changes    Path
  1.5       +64 -43    
jakarta-alexandria/proposal/vindico/src/java/org/apache/alexandria/util/XMLHelper.java
  
  Index: XMLHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-alexandria/proposal/vindico/src/java/org/apache/alexandria/util/XMLHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLHelper.java    3 Feb 2002 02:20:13 -0000       1.4
  +++ XMLHelper.java    3 Feb 2002 03:21:46 -0000       1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-alexandria/proposal/vindico/src/java/org/apache/alexandria/util/XMLHelper.java,v
 1.4 2002/02/03 02:20:13 sanders Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/03 02:20:13 $
  + * $Header: 
/home/cvs/jakarta-alexandria/proposal/vindico/src/java/org/apache/alexandria/util/XMLHelper.java,v
 1.5 2002/02/03 03:21:46 sanders Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/03 03:21:46 $
    *
    * ====================================================================
    *
  @@ -65,6 +65,7 @@
   import java.util.Iterator;
   import java.io.Writer;
   import java.io.StringWriter;
  +import java.io.IOException;
   
   import org.apache.commons.collections.ArrayStack;
   
  @@ -74,7 +75,7 @@
    * indentation, elements, attributes, comments, and text in UTF-8.
    *
    * @author Scott Sanders
  - * @version $Revision: 1.4 $ $Date: 2002/02/03 02:20:13 $
  + * @version $Revision: 1.5 $ $Date: 2002/02/03 03:21:46 $
    */
   public class XMLHelper {
   
  @@ -92,7 +93,11 @@
   
       public XMLHelper() {
           buf = new StringWriter();
  -        buf.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  +        try {
  +            buf.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  +        } catch (IOException e) {
  +            //Do nothing
  +        }
       }
   
       public XMLHelper(Writer writer) {
  @@ -101,7 +106,7 @@
   
       private ArrayStack elementStack = new ArrayStack();
       private ArrayList attributes = new ArrayList();
  -    private Writer buf;// = new StringWriter();new StringBuffer("<?xml 
version=\"1.0\" encoding=\"UTF-8\"?>\n");
  +    private Writer buf;
       private boolean indent = false;
   
       public void setIndent(boolean indent) {
  @@ -121,12 +126,16 @@
       }
   
       public void popElement() {
  -        String name = elementStack.pop().toString();
  -        indent();
  -        buf.write(CLOSE);
  -        buf.write(name);
  -        buf.write(GT);
  -        newLine();
  +        try {
  +            String name = elementStack.pop().toString();
  +            indent();
  +            buf.write(CLOSE);
  +            buf.write(name);
  +            buf.write(GT);
  +            newLine();
  +        } catch (IOException e) {
  +            //Do nothing
  +        }
       }
   
       public void element(String elementName) {
  @@ -142,53 +151,65 @@
       }
   
       public void element(String elementName, String value, boolean isEmpty) {
  -        indent();
  -        if (!isEmpty) {
  -            elementStack.push(elementName);
  -        }
  -        buf.write(LT);
  -        buf.write(elementName);
  -        appendAttributes();
  -        if (isEmpty && value == null) {
  -            buf.write(EMPTY);
  -        } else {
  -            buf.write(GT);
  -            if (value != null) {
  -                buf.write(value);
  +        try {
  +            indent();
  +            if (!isEmpty) {
  +                elementStack.push(elementName);
               }
  -            if (isEmpty) {
  -                buf.write(CLOSE);
  -                buf.write(elementName);
  +            buf.write(LT);
  +            buf.write(elementName);
  +            appendAttributes();
  +            if (isEmpty && value == null) {
  +                buf.write(EMPTY);
  +            } else {
                   buf.write(GT);
  +                if (value != null) {
  +                    buf.write(value);
  +                }
  +                if (isEmpty) {
  +                    buf.write(CLOSE);
  +                    buf.write(elementName);
  +                    buf.write(GT);
  +                }
               }
  -        }
  -        if (value == null || isEmpty) {
  -            newLine();
  +            if (value == null || isEmpty) {
  +                newLine();
  +            }
  +        } catch (IOException e) {
  +            //Do nothing
           }
       }
   
       public void comment(String comment) {
  -        indent();
  -        buf.write(COMMENT_BEGIN);
  -        buf.write(comment);
  -        buf.write(COMMENT_END);
  -        newLine();
  +        try {
  +            indent();
  +            buf.write(COMMENT_BEGIN);
  +            buf.write(comment);
  +            buf.write(COMMENT_END);
  +            newLine();
  +        } catch (IOException e) {
  +            //Do nothing
  +        }
       }
   
       private void appendAttributes() {
  -        Iterator iter = attributes.iterator();
  -        while (iter.hasNext()) {
  -            String name = iter.next().toString();
  -            buf.write(name);
  +        try {
  +            Iterator iter = attributes.iterator();
  +            while (iter.hasNext()) {
  +                String name = iter.next().toString();
  +                buf.write(name);
  +            }
  +            clearAttributes();
  +        } catch (IOException e) {
  +            //Do nothing
           }
  -        clearAttributes();
       }
   
       private void clearAttributes() {
           attributes.clear();
       }
   
  -    private void indent() {
  +    private void indent() throws IOException {
           if (indent) {
               for (int i = 0; i < elementStack.size(); i++) {
                   buf.write(INDENT);
  @@ -196,7 +217,7 @@
           }
       }
   
  -    private void newLine() {
  +    private void newLine() throws IOException {
           if (indent) {
               buf.write(NEWLINE);
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to