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.SectionVo; |
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 | * Handle sections. |
26 | * |
27 | * @version $Revision: 1.1 $ |
28 | * @author Michael Meyling |
29 | */ |
30 | public class SectionHandler extends AbstractSimpleHandler { |
31 | |
32 | /** Tag for introduction part. */ |
33 | public static final String INTRODUCTION_TAG = "INTRODUCTION"; |
34 | |
35 | /** Tag for section part. */ |
36 | public static final String SECTION_TAG = "SECTION"; |
37 | |
38 | /** Tag for title part. */ |
39 | public static final String TITLE_TAG = "TITLE"; |
40 | |
41 | /** Handle section title. */ |
42 | private final LatexListHandler titleHandler; |
43 | |
44 | /** Handle section introduction. */ |
45 | private final LatexListHandler introductionHandler; |
46 | |
47 | /** Handle single subsection. */ |
48 | private final SubsectionListHandler subsectionListHandler; |
49 | |
50 | /** Section value object. */ |
51 | private SectionVo section; |
52 | |
53 | |
54 | /** |
55 | * Constructor. |
56 | * |
57 | * @param handler |
58 | * Parent handler. |
59 | */ |
60 | public SectionHandler(final AbstractSimpleHandler handler) { |
61 | super(handler, SECTION_TAG); |
62 | titleHandler = new LatexListHandler(this, TITLE_TAG); |
63 | introductionHandler = new LatexListHandler(this, INTRODUCTION_TAG); |
64 | subsectionListHandler = new SubsectionListHandler(this); |
65 | } |
66 | |
67 | public final void init() { |
68 | section = null; |
69 | } |
70 | |
71 | /** |
72 | * Get section. |
73 | * |
74 | * @return Section. |
75 | */ |
76 | public final SectionVo getSection() { |
77 | return section; |
78 | } |
79 | |
80 | public final void startElement(final String name, final SimpleAttributes attributes) |
81 | throws XmlSyntaxException { |
82 | if (getStartTag().equals(name)) { |
83 | section = new SectionVo(); |
84 | section.setNoNumber(attributes.getBoolean("noNumber")); |
85 | } else if (TITLE_TAG.equals(name)) { |
86 | changeHandler(titleHandler, name, attributes); |
87 | } else if (INTRODUCTION_TAG.equals(name)) { |
88 | changeHandler(introductionHandler, name, attributes); |
89 | } else if ("SUBSECTIONS".equals(name)) { |
90 | changeHandler(subsectionListHandler, name, attributes); |
91 | } else { |
92 | throw XmlSyntaxException.createUnexpectedTagException(name); |
93 | } |
94 | } |
95 | |
96 | public final void endElement(final String name) throws XmlSyntaxException { |
97 | if (getStartTag().equals(name)) { |
98 | // nothing to do |
99 | } else if (TITLE_TAG.equals(name)) { |
100 | section.setTitle(titleHandler.getLatexList()); |
101 | } else if (INTRODUCTION_TAG.equals(name)) { |
102 | section.setIntroduction(introductionHandler.getLatexList()); |
103 | } else if ("SUBSECTIONS".equals(name)) { |
104 | section.setSubsectionList(subsectionListHandler.getSubsectionList()); |
105 | } else { |
106 | throw XmlSyntaxException.createUnexpectedTagException(name); |
107 | } |
108 | } |
109 | |
110 | |
111 | } |