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