File: UnTagHandler.java

package info (click to toggle)
lib-xp-java 0.5-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,652 kB
  • ctags: 2,424
  • sloc: java: 8,085; makefile: 53; sh: 17; xml: 7
file content (47 lines) | stat: -rw-r--r-- 793 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import org.xml.sax.HandlerBase;
import org.xml.sax.AttributeList;

public class UnTagHandler extends HandlerBase {

    private StringBuffer buffer = new StringBuffer();
    
    public void characters(char[] content, int start, int len) {   
	while (len-- > 0) {
	    appendChar (content[start++]);
	}
    }

    public void endElement (String name) {
	flushChars();
    }   
    
    public void endDocument() {
	flushChars();
    }
    
    private void flushChars() {
	if (buffer.length() > 0) {
	    System.out.print (buffer.toString());
	    buffer.setLength(0);
	}
    }
    
    private void appendChar(char c) {
	switch (c) {
	case '\n':
	    flushChars();
	    System.out.println ("");
	    break;
	case '\r':
	    break;
	default:
	    buffer.append(c);
	    break;
	}
    }

}