예제 #1
0
 @Override
 public void startElement(String uri, String localName, String name, Attributes atts)
     throws SAXException {
   super.startElement(uri, localName, name, atts);
   if (delta < -1) {
     super.characters(LINE_SEPARATOR, 0, LINE_SEPARATOR.length);
     for (int i = 0; i < level; ++i) {
       super.characters(new char[] {'\t'}, 0, 1);
     }
     delta = 0;
   }
   delta += 1;
   level += 1;
   indent = true;
 }
예제 #2
0
 /**
  * Print characters if they have other content than spaces, newlines, or tabs and put them on a
  * new, indented line if they are from another element than the characters printed before.
  */
 @Override
 public void characters(char[] ch, int start, int length) throws SAXException {
   boolean content = false;
   for (int i = start + length - 1; i >= start; --i) {
     if (ch[i] != ' ' && ch[i] != '\n' && ch[i] != '\t' && ch[i] != '\r') {
       content = true;
       break;
     }
   }
   if (content) {
     if (indent) {
       super.characters(LINE_SEPARATOR, 0, LINE_SEPARATOR.length);
       for (int i = 0; i < level; ++i) {
         super.characters(new char[] {'\t'}, 0, 1);
       }
       indent = false;
     }
     super.characters(ch, start, length);
   }
 }
예제 #3
0
 @Override
 public void endDocument() throws SAXException {
   super.endDocument();
   super.characters(LINE_SEPARATOR, 0, LINE_SEPARATOR.length);
 }