1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.qedeq.kernel.xml.handler.parser; |
19 |
| |
20 |
| import java.io.FileNotFoundException; |
21 |
| import java.io.IOException; |
22 |
| import java.net.URL; |
23 |
| import java.util.List; |
24 |
| |
25 |
| import javax.xml.parsers.ParserConfigurationException; |
26 |
| |
27 |
| import org.qedeq.kernel.log.Trace; |
28 |
| import org.qedeq.kernel.xml.mapper.XmlFilePositionException; |
29 |
| import org.qedeq.kernel.xml.parser.SaxDefaultHandler; |
30 |
| import org.qedeq.kernel.xml.parser.SaxParser; |
31 |
| import org.qedeq.kernel.xml.parser.SyntaxException; |
32 |
| import org.xml.sax.SAXException; |
33 |
| import org.xml.sax.SAXParseException; |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| public final class LoadXmlOperatorListUtility { |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
0
| private LoadXmlOperatorListUtility() {
|
48 |
| |
49 |
| } |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
81
| public static List getOperatorList(final String from) throws XmlFilePositionException {
|
59 |
81
| final String method = "generate(String, String, String, String)";
|
60 |
81
| URL url = null;
|
61 |
81
| try {
|
62 |
81
| Trace.begin(LoadXmlOperatorListUtility.class, method);
|
63 |
81
| Trace.param(LoadXmlOperatorListUtility.class, method, "from", from);
|
64 |
81
| url = LoadXmlOperatorListUtility.class.getResource("/" + from);
|
65 |
81
| if (url == null) {
|
66 |
0
| throw new FileNotFoundException(from);
|
67 |
| } |
68 |
81
| SaxDefaultHandler handler = new SaxDefaultHandler();
|
69 |
81
| ParserHandler simple = new ParserHandler(handler);
|
70 |
81
| handler.setBasisDocumentHandler(simple);
|
71 |
81
| SaxParser parser = new SaxParser(handler);
|
72 |
81
| try {
|
73 |
81
| parser.parse(url);
|
74 |
| } catch (SAXException ex) { |
75 |
0
| if (parser.getExceptionList().size() > 0) {
|
76 |
0
| final Exception exc = parser.getExceptionList().get(0);
|
77 |
0
| if (exc instanceof SyntaxException) {
|
78 |
0
| throw new XmlFilePositionException((SyntaxException) exc);
|
79 |
| } |
80 |
| } |
81 |
0
| throw ex;
|
82 |
| } |
83 |
| |
84 |
81
| return simple.getOperators();
|
85 |
| } catch (RuntimeException e) { |
86 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
87 |
0
| throw new XmlFilePositionException(url, e);
|
88 |
| } catch (IOException e) { |
89 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
90 |
0
| throw new XmlFilePositionException(url, e);
|
91 |
| } catch (ParserConfigurationException e) { |
92 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
93 |
0
| throw new XmlFilePositionException(url, e);
|
94 |
| } catch (final SAXParseException e) { |
95 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
96 |
0
| throw new XmlFilePositionException(url, e);
|
97 |
| } catch (SAXException e) { |
98 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
99 |
0
| throw new XmlFilePositionException(url, e);
|
100 |
| } catch (javax.xml.parsers.FactoryConfigurationError e) { |
101 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
102 |
0
| final String msg = "SAX Parser not in classpath, "
|
103 |
| + "add for example \"xercesImpl.jar\" and \"xml-apis.jar\"."; |
104 |
0
| throw new XmlFilePositionException(url, new IOException(msg));
|
105 |
| } finally { |
106 |
81
| Trace.end(LoadXmlOperatorListUtility.class, method);
|
107 |
| } |
108 |
| } |
109 |
| |
110 |
| } |