| 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.PropositionVo; |
| 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 | * Parse a proposition. |
| 26 | * |
| 27 | * @version $Revision: 1.1 $ |
| 28 | * @author Michael Meyling |
| 29 | */ |
| 30 | public class PropositionHandler extends AbstractSimpleHandler { |
| 31 | |
| 32 | /** Handler for proposition formula. */ |
| 33 | private final FormulaHandler formulaHandler; |
| 34 | |
| 35 | /** Handler for rule description. */ |
| 36 | private final LatexListHandler descriptionHandler; |
| 37 | |
| 38 | /** Handle informal proofs. */ |
| 39 | private final ProofHandler proofHandler; |
| 40 | |
| 41 | /** Handle formal proofs. */ |
| 42 | private final FormalProofHandler formalProofHandler; |
| 43 | |
| 44 | /** Proposition value object. */ |
| 45 | private PropositionVo proposition; |
| 46 | |
| 47 | |
| 48 | /** |
| 49 | * Deals with propositions. |
| 50 | * |
| 51 | * @param handler Parent handler. |
| 52 | */ |
| 53 | public PropositionHandler(final AbstractSimpleHandler handler) { |
| 54 | super(handler, "THEOREM"); |
| 55 | formulaHandler = new FormulaHandler(this); |
| 56 | descriptionHandler = new LatexListHandler(this, "DESCRIPTION"); |
| 57 | proofHandler = new ProofHandler(this); |
| 58 | formalProofHandler = new FormalProofHandler(this); |
| 59 | } |
| 60 | |
| 61 | public final void init() { |
| 62 | proposition = null; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get proposition. |
| 67 | * |
| 68 | * @return Proposition. |
| 69 | */ |
| 70 | public final PropositionVo getProposition() { |
| 71 | return proposition; |
| 72 | } |
| 73 | |
| 74 | public final void startElement(final String name, final SimpleAttributes attributes) |
| 75 | throws XmlSyntaxException { |
| 76 | if (getStartTag().equals(name)) { |
| 77 | proposition = new PropositionVo(); |
| 78 | } else if (formulaHandler.getStartTag().equals(name)) { |
| 79 | changeHandler(formulaHandler, name, attributes); |
| 80 | } else if (descriptionHandler.getStartTag().equals(name)) { |
| 81 | changeHandler(descriptionHandler, name, attributes); |
| 82 | } else if (proofHandler.getStartTag().equals(name)) { |
| 83 | changeHandler(proofHandler, name, attributes); |
| 84 | } else if (formalProofHandler.getStartTag().equals(name)) { |
| 85 | changeHandler(formalProofHandler, name, attributes); |
| 86 | } else { |
| 87 | throw XmlSyntaxException.createUnexpectedTagException(name); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | public final void endElement(final String name) throws XmlSyntaxException { |
| 92 | if (getStartTag().equals(name)) { |
| 93 | // nothing to do |
| 94 | } else if (formulaHandler.getStartTag().equals(name)) { |
| 95 | proposition.setFormula(formulaHandler.getFormula()); |
| 96 | } else if (descriptionHandler.getStartTag().equals(name)) { |
| 97 | proposition.setDescription(descriptionHandler.getLatexList()); |
| 98 | } else if (proofHandler.getStartTag().equals(name)) { |
| 99 | proposition.addProof(proofHandler.getProof()); |
| 100 | } else if (formalProofHandler.getStartTag().equals(name)) { |
| 101 | proposition.addFormalProof(formalProofHandler.getProof()); |
| 102 | } else { |
| 103 | throw XmlSyntaxException.createUnexpectedTagException(name); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | } |