View Javadoc

1   package org.paneris.jammyjoes.mail;
2   
3   import java.io.IOException;
4   import java.io.OutputStream;
5   
6   import com.quiotix.html.parser.HtmlDocument;
7   import com.quiotix.html.parser.HtmlParser;
8   import com.quiotix.html.parser.ParseException;
9   
10  public class HtmlImageParser implements ImageParser {
11  
12    private HtmlDocument doc;
13    private NewsletterInterface newsletter;
14  
15    public HtmlImageParser(NewsletterInterface newsletter) throws ParseException, IOException {
16      HtmlParser parser = new HtmlParser(newsletter.getInputStream());
17      doc = parser.HtmlDocument();
18      this.newsletter = newsletter;
19    }
20  
21    public String getText() {
22      StringOutputStream out = new StringOutputStream();
23      doc.accept(new ImageTranslator(out, newsletter));
24      return out.buffer.toString();
25    }
26    
27    private class StringOutputStream extends OutputStream {
28      
29      public StringBuffer buffer = new StringBuffer();
30      
31      public void write(int b) throws IOException {
32        buffer.append((char)b);
33      }
34    }
35  
36  }