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.LatexVo;
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 header informations.
26   *
27   * @version $Revision: 1.1 $
28   * @author  Michael Meyling
29   */
30  public class LatexHandler extends AbstractSimpleHandler {
31  
32      /** Text language. */
33      private String language;
34  
35      /** LaTeX text. */
36      private LatexVo latex;
37  
38      /** Character data. */
39      private String data;
40  
41  
42      /**
43       * Handles LaTeX tags.
44       *
45       * @param   handler Handler that uses this handler.
46       * @param   startTag    This is the starting tag.
47       */
48      public LatexHandler(final AbstractSimpleHandler handler, final String startTag) {
49          super(handler, startTag);
50      }
51  
52      public final void init() {
53          latex = null;
54      }
55  
56      /**
57       * Get parsed result.
58       *
59       * @return  LaTeX text part.
60       */
61      public final LatexVo getLatex() {
62          return latex;
63      }
64  
65      public final void startElement(final String name, final SimpleAttributes attributes)
66              throws XmlSyntaxException {
67          if (getStartTag().equals(name)) {
68              // ignore
69          } else if ("LATEX".equals(name)) {
70              this.data = null;
71              language = attributes.getString("language");
72          } else {
73              throw XmlSyntaxException.createUnexpectedTagException(name);
74          }
75      }
76  
77      public void endElement(final String name) throws XmlSyntaxException {
78          if (getStartTag().equals(name)) {
79              // ignore
80          } else if ("LATEX".equals(name)) {
81              latex = new LatexVo(language, data);
82          } else {
83              throw XmlSyntaxException.createUnexpectedTagException(name);
84          }
85      }
86  
87      public void characters(final String name, final String data) throws XmlSyntaxException {
88          if (getStartTag().equals(name)) {
89              // ignore
90          } else if ("LATEX".equals(name)) {
91              this.data = data;
92          } else {
93              throw XmlSyntaxException.createUnexpectedTextDataException(name, data);
94          }
95      }
96  
97  }