001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2011, 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.base.module.Qedeq;
019 import org.qedeq.kernel.se.dto.module.QedeqVo;
020 import org.qedeq.kernel.xml.common.XmlSyntaxException;
021 import org.qedeq.kernel.xml.handler.common.AbstractSimpleHandler;
022 import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler;
023 import org.qedeq.kernel.xml.handler.common.SimpleAttributes;
024
025
026 /**
027 * Parses complete qedeq modules.
028 *
029 * @version $Revision: 1.1 $
030 * @author Michael Meyling
031 */
032 public class QedeqHandler extends AbstractSimpleHandler {
033
034 /** Module header handler. */
035 private final HeaderHandler headerHandler;
036
037 /** Handles a single chapter. */
038 private final ChapterHandler chapterHandler;
039
040 /** Handles a bibliography. */
041 private final LiteratureItemListHandler bibliographyHandler;
042
043 /** Root value object for a module. */
044 private QedeqVo qedeq;
045
046
047 /**
048 * Handle a qedeq module.
049 *
050 * @param defaultHandler Startup handler.
051 */
052 public QedeqHandler(final SaxDefaultHandler defaultHandler) {
053 super(defaultHandler, "QEDEQ");
054 headerHandler = new HeaderHandler(this);
055 chapterHandler = new ChapterHandler(this);
056 bibliographyHandler = new LiteratureItemListHandler(this);
057 }
058
059 public final void init() {
060 qedeq = null;
061 }
062
063 /**
064 * Get qedeq value object.
065 *
066 * @return Qedeq object.
067 */
068 public final Qedeq getQedeq() {
069 return qedeq;
070 }
071
072 public final void startElement(final String name, final SimpleAttributes attributes)
073 throws XmlSyntaxException {
074 if (getStartTag().equals(name)) {
075 qedeq = new QedeqVo();
076 } else if (headerHandler.getStartTag().equals(name)) {
077 changeHandler(headerHandler, name, attributes);
078 } else if (chapterHandler.getStartTag().equals(name)) {
079 changeHandler(chapterHandler, name, attributes);
080 } else if (bibliographyHandler.getStartTag().equals(name)) {
081 changeHandler(bibliographyHandler, name, attributes);
082 } else {
083 throw XmlSyntaxException.createUnexpectedTagException(name);
084 }
085 }
086
087 public final void endElement(final String name) throws XmlSyntaxException {
088 if (getStartTag().equals(name)) {
089 // nothing to do
090 } else if (headerHandler.getStartTag().equals(name)) {
091 qedeq.setHeader(headerHandler.getHeader());
092 } else if (chapterHandler.getStartTag().equals(name)) {
093 qedeq.addChapter(chapterHandler.getChapter());
094 } else if (bibliographyHandler.getStartTag().equals(name)) {
095 qedeq.setLiteratureItemList(bibliographyHandler.getLiteratureItemList());
096 } else {
097 throw XmlSyntaxException.createUnexpectedTagException(name);
098 }
099 }
100
101 }
|