1 package org.w3c.tidy; 2 3 import java.util.ArrayList ; 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 8 12 public class TestMessageListener implements TidyMessageListener 13 { 14 15 18 private String filename; 19 20 23 private List received = new ArrayList (); 24 25 29 public TestMessageListener(String filename) 30 { 31 this.filename = filename; 32 } 33 34 37 public void messageReceived(TidyMessage message) 38 { 39 received.add(message); 40 } 41 42 46 public String messagesToXml() 47 { 48 StringBuffer buffer = new StringBuffer (); 49 50 buffer.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); 51 buffer.append("<!-- expected messages for test "); 52 buffer.append(this.filename); 53 buffer.append("-->\n"); 54 55 buffer.append("<messages>\n"); 56 Iterator iterator = received.iterator(); 57 while (iterator.hasNext()) 58 { 59 TidyMessage msg = (TidyMessage) iterator.next(); 60 buffer.append(" <message>\n"); 61 62 buffer.append(" <code>"); 63 buffer.append(msg.getErrorCode()); 64 buffer.append("</code>\n"); 65 66 buffer.append(" <level>"); 67 buffer.append(msg.getLevel().getCode()); 68 buffer.append("</level>\n"); 69 70 buffer.append(" <line>"); 71 buffer.append(msg.getLine()); 72 buffer.append("</line>\n"); 73 74 buffer.append(" <column>"); 75 buffer.append(msg.getColumn()); 76 buffer.append("</column>\n"); 77 78 buffer.append(" <text><![CDATA["); 79 buffer.append(msg.getMessage()); 80 buffer.append("]]></text>\n"); 81 82 buffer.append(" </message>\n"); 83 } 84 85 buffer.append("</messages>\n"); 86 87 return buffer.toString(); 88 } 89 90 94 protected String getFilename() 95 { 96 return this.filename; 97 } 98 99 103 public List getReceived() 104 { 105 return this.received; 106 } 107 108 } 109 | Popular Tags |