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.base.module.Subsection; |
19 | import org.qedeq.kernel.se.dto.module.SubsectionVo; |
20 | import org.qedeq.kernel.xml.common.XmlSyntaxException; |
21 | import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler; |
22 | import org.qedeq.kernel.xml.handler.common.SimpleAttributes; |
23 | |
24 | |
25 | /** |
26 | * Parses subsection data. |
27 | * |
28 | * @version $Revision: 1.1 $ |
29 | * @author Michael Meyling |
30 | */ |
31 | public class SubsectionHandler extends AbstractSimpleHandler { |
32 | |
33 | /** Handler for subsection title. */ |
34 | private final LatexListHandler titleHandler; |
35 | |
36 | /** Handler for subsection text. */ |
37 | private final LatexListHandler latexHandler; |
38 | |
39 | /** Subsection. */ |
40 | private SubsectionVo subsection; |
41 | |
42 | |
43 | /** |
44 | * Constructor. |
45 | * |
46 | * @param handler Parent handler. |
47 | */ |
48 | public SubsectionHandler(final AbstractSimpleHandler handler) { |
49 | super(handler, "SUBSECTION"); |
50 | titleHandler = new LatexListHandler(this, "TITLE"); |
51 | latexHandler = new LatexListHandler(this, "TEXT"); |
52 | subsection = new SubsectionVo(); |
53 | } |
54 | |
55 | public final void init() { |
56 | subsection = null; |
57 | } |
58 | |
59 | /** |
60 | * Get subsection. |
61 | * |
62 | * @return Subsection. |
63 | */ |
64 | public final Subsection getSubsection() { |
65 | return subsection; |
66 | } |
67 | |
68 | public final void startElement(final String name, final SimpleAttributes attributes) |
69 | throws XmlSyntaxException { |
70 | if (getStartTag().equals(name)) { |
71 | subsection = new SubsectionVo(); |
72 | subsection.setId(attributes.getString("id")); |
73 | subsection.setLevel(attributes.getString("level")); |
74 | } else if (titleHandler.getStartTag().equals(name)) { |
75 | changeHandler(titleHandler, name, attributes); |
76 | } else if (latexHandler.getStartTag().equals(name)) { |
77 | changeHandler(latexHandler, name, attributes); |
78 | } else { |
79 | throw XmlSyntaxException.createUnexpectedTagException(name); |
80 | } |
81 | } |
82 | |
83 | public final void endElement(final String name) throws XmlSyntaxException { |
84 | if (getStartTag().equals(name)) { |
85 | // thats why we handle it |
86 | } else if (titleHandler.getStartTag().equals(name)) { |
87 | subsection.setTitle(titleHandler.getLatexList()); |
88 | } else if (latexHandler.getStartTag().equals(name)) { |
89 | subsection.setLatex(latexHandler.getLatexList()); |
90 | } else { |
91 | throw XmlSyntaxException.createUnexpectedTagException(name); |
92 | } |
93 | } |
94 | |
95 | } |