1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.tika.sax;
18
19 import java.io.StringReader;
20 import java.net.ConnectException;
21
22 import javax.xml.parsers.SAXParser;
23 import javax.xml.parsers.SAXParserFactory;
24
25 import junit.framework.TestCase;
26
27 import org.xml.sax.InputSource;
28 import org.xml.sax.helpers.DefaultHandler;
29
30
31
32
33 public class OfflineContentHandlerTest extends TestCase {
34
35 private SAXParser parser;
36
37 private DefaultHandler offline;
38
39 protected void setUp() throws Exception {
40 parser = SAXParserFactory.newInstance().newSAXParser();
41 offline = new OfflineContentHandler(new DefaultHandler());
42 }
43
44 public void testExternalDTD() throws Exception {
45 String xml =
46 "<!DOCTYPE foo SYSTEM \"http://127.234.172.38:7845/bar\"><foo/>";
47 try {
48 parser.parse(new InputSource(new StringReader(xml)), offline);
49 } catch (ConnectException e) {
50 fail("Parser tried to access the external DTD:" + e);
51 }
52 }
53
54 public void testExternalEntity() throws Exception {
55 String xml =
56 "<!DOCTYPE foo ["
57 + " <!ENTITY bar SYSTEM \"http://127.234.172.38:7845/bar\">"
58 + " ]><foo>&bar;</foo>";
59 try {
60 parser.parse(new InputSource(new StringReader(xml)), offline);
61 } catch (ConnectException e) {
62 fail("Parser tried to access the external DTD:" + e);
63 }
64 }
65
66 }