|
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.common.XmlFileExceptionList; |
|
28 |
| import org.qedeq.kernel.trace.Trace; |
|
29 |
| import org.qedeq.kernel.xml.parser.SaxDefaultHandler; |
|
30 |
| import org.qedeq.kernel.xml.parser.SaxParser; |
|
31 |
| import org.qedeq.kernel.xml.parser.DefaultXmlFileExceptionList; |
|
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 |
82
| public static List getOperatorList(final String from) throws XmlFileExceptionList {
|
|
59 |
82
| final String method = "List getOperatorList(String)";
|
|
60 |
82
| URL url = null;
|
|
61 |
82
| try {
|
|
62 |
82
| Trace.begin(LoadXmlOperatorListUtility.class, method);
|
|
63 |
82
| Trace.param(LoadXmlOperatorListUtility.class, method, "from", from);
|
|
64 |
82
| url = LoadXmlOperatorListUtility.class.getResource("/" + from);
|
|
65 |
82
| if (url == null) {
|
|
66 |
0
| throw new FileNotFoundException(from);
|
|
67 |
| } |
|
68 |
82
| SaxDefaultHandler handler = new SaxDefaultHandler();
|
|
69 |
82
| ParserHandler simple = new ParserHandler(handler);
|
|
70 |
82
| handler.setBasisDocumentHandler(simple);
|
|
71 |
82
| SaxParser parser = new SaxParser(handler);
|
|
72 |
82
| parser.parse(url);
|
|
73 |
82
| return simple.getOperators();
|
|
74 |
| } catch (RuntimeException e) { |
|
75 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
|
76 |
0
| throw new DefaultXmlFileExceptionList(e);
|
|
77 |
| } catch (IOException e) { |
|
78 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
|
79 |
0
| throw new DefaultXmlFileExceptionList(e);
|
|
80 |
| } catch (ParserConfigurationException e) { |
|
81 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
|
82 |
0
| final DefaultXmlFileExceptionList list = new DefaultXmlFileExceptionList();
|
|
83 |
0
| list.add(e);
|
|
84 |
0
| throw list;
|
|
85 |
| } catch (final SAXParseException e) { |
|
86 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
|
87 |
0
| final DefaultXmlFileExceptionList list = new DefaultXmlFileExceptionList();
|
|
88 |
0
| list.add(e);
|
|
89 |
0
| throw list;
|
|
90 |
| } catch (SAXException e) { |
|
91 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
|
92 |
0
| final DefaultXmlFileExceptionList list = new DefaultXmlFileExceptionList();
|
|
93 |
0
| list.add(e);
|
|
94 |
0
| throw list;
|
|
95 |
| } catch (javax.xml.parsers.FactoryConfigurationError e) { |
|
96 |
0
| Trace.trace(LoadXmlOperatorListUtility.class, method, e);
|
|
97 |
0
| final String msg = "SAX Parser not in classpath, "
|
|
98 |
| + "add for example \"xercesImpl.jar\" and \"xml-apis.jar\"."; |
|
99 |
0
| final DefaultXmlFileExceptionList list = new DefaultXmlFileExceptionList();
|
|
100 |
0
| list.add(new IOException(msg));
|
|
101 |
0
| throw list;
|
|
102 |
| } finally { |
|
103 |
82
| Trace.end(LoadXmlOperatorListUtility.class, method);
|
|
104 |
| } |
|
105 |
| } |
|
106 |
| |
|
107 |
| } |