View Javadoc

1   /* This file is part of the project "Hilbert II" - http://www.qedeq.org" target="alexandria_uri">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.ChapterVo;
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   * Handles a chapter.
25   *
26   * @author  Michael Meyling
27   */
28  public class ChapterHandler extends AbstractSimpleHandler {
29  
30      /** Handles chapter title information. */
31      private final LatexListHandler titleHandler;
32  
33      /** Handles chapter introduction. */
34      private final LatexListHandler introductionHandler;
35  
36      /** Handles sections. */
37      private final SectionHandler sectionHandler;
38  
39      /** Chapter value object. */
40      private ChapterVo chapter;
41  
42      /**
43       * Constructor.
44       *
45       * @param   handler Parent handler.
46       */
47      public ChapterHandler(final AbstractSimpleHandler handler) {
48          super(handler, "CHAPTER");
49          titleHandler = new LatexListHandler(this, "TITLE");
50          introductionHandler = new LatexListHandler(this, "INTRODUCTION");
51          sectionHandler = new SectionHandler(this);
52      }
53  
54      public void init() {
55          chapter = null;
56      }
57  
58      /**
59       * Get parsed chapter.
60       *
61       * @return  Chapter.
62       */
63      public final ChapterVo getChapter() {
64          return chapter;
65      }
66  
67      public final void startElement(final String name, final SimpleAttributes attributes)
68              throws XmlSyntaxException {
69          if (getStartTag().equals(name)) {
70              chapter = new ChapterVo();
71              chapter.setNoNumber(attributes.getBoolean("noNumber"));
72          } else if (titleHandler.getStartTag().equals(name)) {
73              changeHandler(titleHandler, name, attributes);
74          } else if (introductionHandler.getStartTag().equals(name)) {
75              changeHandler(introductionHandler, name, attributes);
76          } else if (sectionHandler.getStartTag().equals(name)) {
77              changeHandler(sectionHandler, 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              // nothing to do
86          } else if (titleHandler.getStartTag().equals(name)) {
87              chapter.setTitle(titleHandler.getLatexList());
88          } else if (introductionHandler.getStartTag().equals(name)) {
89              chapter.setIntroduction(introductionHandler.getLatexList());
90          } else if (sectionHandler.getStartTag().equals(name)) {
91              chapter.addSection(sectionHandler.getSection());
92          } else {
93              throw XmlSyntaxException.createUnexpectedTagException(name);
94          }
95      }
96  
97  
98  }