SectionHandler.java
001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002  *
003  * Copyright 2000-2013,  Michael Meyling <mime@qedeq.org>.
004  *
005  * "Hilbert II" is free software; you can redistribute
006  * it and/or modify it under the terms of the GNU General Public
007  * License as published by the Free Software Foundation; either
008  * version 2 of the License, or (at your option) any later version.
009  *
010  * This program is distributed in the hope that it will be useful,
011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013  * GNU General Public License for more details.
014  */
015 
016 package org.qedeq.kernel.xml.handler.module;
017 
018 import org.qedeq.kernel.se.dto.module.SectionVo;
019 import org.qedeq.kernel.xml.common.XmlSyntaxException;
020 import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler;
021 import org.qedeq.kernel.xml.handler.common.SimpleAttributes;
022 
023 
024 /**
025  * Handle sections.
026  *
027  @version $Revision: 1.1 $
028  @author  Michael Meyling
029  */
030 public class SectionHandler extends AbstractSimpleHandler {
031 
032     /** Tag for introduction part. */
033     public static final String INTRODUCTION_TAG = "INTRODUCTION";
034 
035     /** Tag for section part. */
036     public static final String SECTION_TAG = "SECTION";
037 
038     /** Tag for title part. */
039     public static final String TITLE_TAG = "TITLE";
040 
041     /** Handle section title. */
042     private final LatexListHandler titleHandler;
043 
044     /** Handle section introduction. */
045     private final LatexListHandler introductionHandler;
046 
047     /** Handle single subsection. */
048     private final SubsectionListHandler subsectionListHandler;
049 
050     /** Section value object. */
051     private SectionVo section;
052 
053 
054     /**
055      * Constructor.
056      *
057      @param handler
058      *            Parent handler.
059      */
060     public SectionHandler(final AbstractSimpleHandler handler) {
061         super(handler, SECTION_TAG);
062         titleHandler = new LatexListHandler(this, TITLE_TAG);
063         introductionHandler = new LatexListHandler(this, INTRODUCTION_TAG);
064         subsectionListHandler = new SubsectionListHandler(this);
065     }
066 
067     public final void init() {
068         section = null;
069     }
070 
071     /**
072      * Get section.
073      *
074      @return  Section.
075      */
076     public final SectionVo getSection() {
077         return section;
078     }
079 
080     public final void startElement(final String name, final SimpleAttributes attributes)
081             throws XmlSyntaxException {
082         if (getStartTag().equals(name)) {
083             section = new SectionVo();
084             section.setNoNumber(attributes.getBoolean("noNumber"));
085         else if (TITLE_TAG.equals(name)) {
086             changeHandler(titleHandler, name, attributes);
087         else if (INTRODUCTION_TAG.equals(name)) {
088             changeHandler(introductionHandler, name, attributes);
089         else if ("SUBSECTIONS".equals(name)) {
090             changeHandler(subsectionListHandler, name, attributes);
091         else {
092             throw XmlSyntaxException.createUnexpectedTagException(name);
093         }
094     }
095 
096     public final void endElement(final String namethrows XmlSyntaxException {
097         if (getStartTag().equals(name)) {
098             // nothing to do
099         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 }