1 16 package org.outerj.daisy.diff; 17 18 import org.xml.sax.ContentHandler ; 19 import org.xml.sax.helpers.AttributesImpl ; 20 21 25 public class HtmlSaxDiffOutput implements DiffOutput { 26 private ContentHandler consumer; 27 private DiffLineType currentLineType; 28 29 public HtmlSaxDiffOutput(ContentHandler consumer) { 30 this.consumer = consumer; 31 } 32 33 public void startLine(DiffLineType type) throws Exception { 34 this.currentLineType = type; 35 AttributesImpl attrs = new AttributesImpl (); 36 attrs.addAttribute("", "class", "class", "CDATA", "diff-" + type.toString()); 37 consumer.startElement("", "div", "div", attrs); 38 } 39 40 public void addUnchangedText(String text) throws Exception { 41 consumer.characters(text.toCharArray(), 0, text.length()); 42 } 43 44 public void addChangedText(String text) throws Exception { 45 AttributesImpl attrs = new AttributesImpl (); 46 attrs.addAttribute("", "class", "class", "CDATA", "diff-" + currentLineType.toString()); 47 consumer.startElement("", "span", "span", attrs); 48 consumer.characters(text.toCharArray(), 0, text.length()); 49 consumer.endElement("", "span", "span"); 50 } 51 52 public void endLine() throws Exception { 53 consumer.endElement("", "div", "div"); 54 } 55 56 public void skippedLines(int linesSkipped) throws Exception { 57 AttributesImpl attrs = new AttributesImpl (); 58 attrs.addAttribute("", "class", "class", "CDATA", "diff-skipped"); 59 consumer.startElement("", "div", "div", attrs); 60 String message = "(" + linesSkipped + " empty lines skipped)"; 61 consumer.characters(message.toCharArray(), 0, message.length()); 62 consumer.endElement("", "div", "div"); 63 } 64 } 65 | Popular Tags |