HeaderHandler.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.HeaderVo;
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  * Parse header informations.
026  *
027  @version $Revision: 1.1 $
028  @author  Michael Meyling
029  */
030 public class HeaderHandler extends AbstractSimpleHandler {
031 
032     /** Value object for module header. */
033     private HeaderVo header;
034 
035     /** Handler for module specification. */
036     private final SpecificationHandler specificationHandler;
037 
038     /** Handler for module title. */
039     private final LatexListHandler titleHandler;
040 
041     /** Handler for module abstract. */
042     private final LatexListHandler abstractHandler;
043 
044     /** Handler for list of module authors. */
045     private final AuthorListHandler authorListHandler;
046 
047     /** Handler for list of module imports. */
048     private final ImportListHandler importListHandler;
049 
050     /** Handler for list of modules that need this one. */
051     private final UsedByListHandler usedbyListHandler;
052 
053 
054     /**
055      * Deals with header of qedeq file.
056      *
057      @param   handler Parent handler.
058      */
059     public HeaderHandler(final AbstractSimpleHandler handler) {
060         super(handler, "HEADER");
061         titleHandler = new LatexListHandler(this, "TITLE");
062         abstractHandler = new LatexListHandler(this, "ABSTRACT");
063         specificationHandler = new SpecificationHandler(this);
064         authorListHandler = new AuthorListHandler(this);
065         importListHandler = new ImportListHandler(this);
066         usedbyListHandler = new UsedByListHandler(this);
067     }
068 
069     public final void init() {
070         header = null;
071     }
072 
073     /**
074      * Get header of qedeq module.
075      *
076      @return  Header of qedeq module.
077      */
078     public final HeaderVo getHeader() {
079         return header;
080     }
081 
082     public final void startElement(final String name, final SimpleAttributes attributes)
083             throws XmlSyntaxException {
084         if (getStartTag().equals(name)) {
085             header = new HeaderVo();
086             header.setEmail(attributes.getString("email"));
087         else if (specificationHandler.getStartTag().equals(name)) {
088             changeHandler(specificationHandler, name, attributes);
089         else if (titleHandler.getStartTag().equals(name)) {
090             changeHandler(titleHandler, name, attributes);
091         else if (abstractHandler.getStartTag().equals(name)) {
092             changeHandler(abstractHandler, name, attributes);
093         else if (authorListHandler.getStartTag().equals(name)) {
094             changeHandler(authorListHandler, name, attributes);
095         else if (importListHandler.getStartTag().equals(name)) {
096             changeHandler(importListHandler, name, attributes);
097         else if (usedbyListHandler.getStartTag().equals(name)) {
098             changeHandler(usedbyListHandler, name, attributes);
099         else {
100             throw XmlSyntaxException.createUnexpectedTagException(name);
101         }
102     }
103 
104     public final void endElement(final String namethrows 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 }