CVS Update: xmlpull-api-v1/src/java/samples

Aleksander Andrzej Slominski <[email protected]> Wed, 30 Jul 2003 12:07:05 -0500 (EST)
Newsgroups gmane.text.xml.xmlpull.devel
Message-ID <[email protected]>
aslom       03/07/30 12:07:05

  Modified:    src/java/samples XmlPullCount.java
  Log:
  updated sample to allow verbose output
  
  Revision  Changes    Path
  1.4       +43 -0     xmlpull-api-v1/src/java/samples/XmlPullCount.java
  
  Index: XmlPullCount.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/samples/XmlPullCount.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -t -w -r1.3 -r1.4
  --- XmlPullCount.java	3 May 2003 06:37:45 -0000	1.3
  +++ XmlPullCount.java	30 Jul 2003 17:07:04 -0000	1.4
  @@ -30,6 +30,7 @@
       int countChars;
       int countAttribs;
       int countSTags;
  +    boolean verbose;
   
       public static void main (String args[])
           throws XmlPullParserException, IOException
  @@ -46,6 +47,7 @@
   
           XmlPullCount app = new XmlPullCount();
   
  +        app.verbose = false;
           for(int c = 0; c < 2; ++c) {
               System.err.println("run#"+c);
               app.resetCounters();
  @@ -90,14 +92,55 @@
               if(eventType == XmlPullParser.START_TAG) {
                   ++countSTags;
                   countAttribs += xpp.getAttributeCount();
  +                if(verbose) {
  +                    System.err.println("START_TAG "+xpp.getName());
  +                }
               } else if(eventType == XmlPullParser.TEXT) {
                   //char ch[] = xpp.getTextCharacters(holderForStartAndLength);
                   xpp.getTextCharacters(holderForStartAndLength);
                   //int start = holderForStartAndLength[0];
                   int length = holderForStartAndLength[1];
                   countChars += length;
  +                if(verbose) {
  +                    System.err.println("TEXT '"+printable(xpp.getText())+"'");
  +                }
  +            } else if(verbose && eventType == XmlPullParser.TEXT) {
  +                    System.err.println("END_TAG "+xpp.getName());
               }
               eventType = xpp.next();
           }
       }
  +
  +
  +    protected String printable(char ch) {
  +        if(ch == '\n') {
  +            return "\\n";
  +        } else if(ch == '\r') {
  +            return "\\r";
  +        } else if(ch == '\t') {
  +            return "\\t";
  +        } if(ch > 127 || ch < 32) {
  +            StringBuffer buf = new StringBuffer("\\u");
  +            String hex = Integer.toHexString((int)ch);
  +            for (int i = 0; i < 4-hex.length(); i++)
  +            {
  +                buf.append('0');
  +            }
  +            buf.append(hex);
  +            return buf.toString();
  +        }
  +        return ""+ch;
   }
  +
  +    protected String printable(String s) {
  +        if(s == null) return null;
  +        StringBuffer buf = new StringBuffer();
  +        for(int i = 0; i < s.length(); ++i) {
  +            buf.append(printable(s.charAt(i)));
  +        }
  +        s = buf.toString();
  +        return s;
  +    }
  +
  +}
  +
  
  
  


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/sO0ANB/LIdGAA/ySSFAA/2U_rlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/