1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org |
2 | * |
3 | * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. |
4 | * |
5 | * "Hilbert II" is free software; you can redistribute |
6 | * it and/or modify it under the terms of the GNU General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | */ |
15 | |
16 | package org.qedeq.kernel.xml.handler.module; |
17 | |
18 | import org.qedeq.kernel.se.dto.module.HeaderVo; |
19 | import org.qedeq.kernel.xml.common.XmlSyntaxException; |
20 | import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler; |
21 | import org.qedeq.kernel.xml.handler.common.SimpleAttributes; |
22 | |
23 | |
24 | /** |
25 | * Parse header informations. |
26 | * |
27 | * @version $Revision: 1.1 $ |
28 | * @author Michael Meyling |
29 | */ |
30 | public class HeaderHandler extends AbstractSimpleHandler { |
31 | |
32 | /** Value object for module header. */ |
33 | private HeaderVo header; |
34 | |
35 | /** Handler for module specification. */ |
36 | private final SpecificationHandler specificationHandler; |
37 | |
38 | /** Handler for module title. */ |
39 | private final LatexListHandler titleHandler; |
40 | |
41 | /** Handler for module abstract. */ |
42 | private final LatexListHandler abstractHandler; |
43 | |
44 | /** Handler for list of module authors. */ |
45 | private final AuthorListHandler authorListHandler; |
46 | |
47 | /** Handler for list of module imports. */ |
48 | private final ImportListHandler importListHandler; |
49 | |
50 | /** Handler for list of modules that need this one. */ |
51 | private final UsedByListHandler usedbyListHandler; |
52 | |
53 | |
54 | /** |
55 | * Deals with header of qedeq file. |
56 | * |
57 | * @param handler Parent handler. |
58 | */ |
59 | public HeaderHandler(final AbstractSimpleHandler handler) { |
60 | super(handler, "HEADER"); |
61 | titleHandler = new LatexListHandler(this, "TITLE"); |
62 | abstractHandler = new LatexListHandler(this, "ABSTRACT"); |
63 | specificationHandler = new SpecificationHandler(this); |
64 | authorListHandler = new AuthorListHandler(this); |
65 | importListHandler = new ImportListHandler(this); |
66 | usedbyListHandler = new UsedByListHandler(this); |
67 | } |
68 | |
69 | public final void init() { |
70 | header = null; |
71 | } |
72 | |
73 | /** |
74 | * Get header of qedeq module. |
75 | * |
76 | * @return Header of qedeq module. |
77 | */ |
78 | public final HeaderVo getHeader() { |
79 | return header; |
80 | } |
81 | |
82 | public final void startElement(final String name, final SimpleAttributes attributes) |
83 | throws XmlSyntaxException { |
84 | if (getStartTag().equals(name)) { |
85 | header = new HeaderVo(); |
86 | header.setEmail(attributes.getString("email")); |
87 | } else if (specificationHandler.getStartTag().equals(name)) { |
88 | changeHandler(specificationHandler, name, attributes); |
89 | } else if (titleHandler.getStartTag().equals(name)) { |
90 | changeHandler(titleHandler, name, attributes); |
91 | } else if (abstractHandler.getStartTag().equals(name)) { |
92 | changeHandler(abstractHandler, name, attributes); |
93 | } else if (authorListHandler.getStartTag().equals(name)) { |
94 | changeHandler(authorListHandler, name, attributes); |
95 | } else if (importListHandler.getStartTag().equals(name)) { |
96 | changeHandler(importListHandler, name, attributes); |
97 | } else if (usedbyListHandler.getStartTag().equals(name)) { |
98 | changeHandler(usedbyListHandler, name, attributes); |
99 | } else { |
100 | throw XmlSyntaxException.createUnexpectedTagException(name); |
101 | } |
102 | } |
103 | |
104 | public final void endElement(final String name) throws XmlSyntaxException { |
105 | if (getStartTag().equals(name)) { |
106 | // nothing to do |
107 | } else if (specificationHandler.getStartTag().equals(name)) { |
108 | header.setSpecification(specificationHandler.getSpecification()); |
109 | } else if (titleHandler.getStartTag().equals(name)) { |
110 | header.setTitle(titleHandler.getLatexList()); |
111 | } else if (abstractHandler.getStartTag().equals(name)) { |
112 | header.setSummary(abstractHandler.getLatexList()); |
113 | } else if (authorListHandler.getStartTag().equals(name)) { |
114 | header.setAuthorList(authorListHandler.getAuthorList()); |
115 | } else if (importListHandler.getStartTag().equals(name)) { |
116 | header.setImportList(importListHandler.getImportList()); |
117 | } else if (usedbyListHandler.getStartTag().equals(name)) { |
118 | header.setUsedByList(usedbyListHandler.getUsedByList()); |
119 | } else { |
120 | throw XmlSyntaxException.createUnexpectedTagException(name); |
121 | } |
122 | } |
123 | |
124 | } |