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 | 0 | public HtmlImageParser(NewsletterInterface newsletter) throws ParseException, IOException { |
16 | 0 | HtmlParser parser = new HtmlParser(newsletter.getInputStream()); |
17 | 0 | doc = parser.HtmlDocument(); |
18 | 0 | this.newsletter = newsletter; |
19 | 0 | } |
20 | |
|
21 | |
public String getText() { |
22 | 0 | StringOutputStream out = new StringOutputStream(); |
23 | 0 | doc.accept(new ImageTranslator(out, newsletter)); |
24 | 0 | return out.buffer.toString(); |
25 | |
} |
26 | |
|
27 | 0 | private class StringOutputStream extends OutputStream { |
28 | |
|
29 | 0 | public StringBuffer buffer = new StringBuffer(); |
30 | |
|
31 | |
public void write(int b) throws IOException { |
32 | 0 | buffer.append((char)b); |
33 | 0 | } |
34 | |
} |
35 | |
|
36 | |
} |