Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart9.png 30% of files have more coverage
14   155   10   1,75
2   45   0,71   8
8     1,25  
1    
 
  AbstractSimpleHandler       Line # 31 14 10 83,3% 0.8333333
 
  (133)
 
1    /* $Id: AbstractSimpleHandler.java,v 1.1 2008/07/26 08:00:50 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.kernel.xml.parser;
19   
20    import org.qedeq.kernel.xml.common.XmlSyntaxException;
21   
22   
23    /**
24    * Simple handler that gets SAX parser events. These events were received by the
25    * {@link org.qedeq.kernel.xml.parser.SaxDefaultHandler} and are delegated to the
26    * current {@link AbstractSimpleHandler}.
27    *
28    * @version $Revision: 1.1 $
29    * @author Michael Meyling
30    */
 
31    public abstract class AbstractSimpleHandler {
32   
33    /** This handler gets the original SAX events. */
34    private final SaxDefaultHandler defaultHandler;
35   
36    /** Start tag for this handler .*/
37    private final String startTag;
38   
39    /**
40    * Constructor.
41    *
42    * @param defaultHandler Original SAX event handler.
43    * @param startTag Start tag for this handler.
44    */
 
45  234 toggle public AbstractSimpleHandler(final SaxDefaultHandler defaultHandler, final String startTag) {
46  234 this.defaultHandler = defaultHandler;
47  234 this.startTag = startTag;
48    }
49   
50    /**
51    * Constructor.
52    *
53    * @param defaultHandler Original SAX event handler.
54    */
 
55  137 toggle public AbstractSimpleHandler(final SaxDefaultHandler defaultHandler) {
56  137 this.defaultHandler = defaultHandler;
57  137 this.startTag = null;
58    }
59   
60    /**
61    * Constructor, should be used for creating handlers within handlers.
62    *
63    * @param handler Already existing simple handler.
64    * @param startTag Start tag for this handler.
65    */
 
66  6860 toggle public AbstractSimpleHandler(final AbstractSimpleHandler handler, final String startTag) {
67  6860 this.defaultHandler = handler.defaultHandler;
68  6860 this.startTag = startTag;
69    }
70   
71    /**
72    * Constructor, should be used for creating handlers within handlers.
73    *
74    * @param handler Already existing simple handler.
75    */
 
76  840 toggle public AbstractSimpleHandler(final AbstractSimpleHandler handler) {
77  840 this.defaultHandler = handler.defaultHandler;
78  840 this.startTag = null;
79    }
80   
81    /**
82    * Must be called before a handler should parse a new section.
83    */
84    public abstract void init();
85   
86    /**
87    * Called at begin of element <code>elementName</code>. Must be overwritten.
88    *
89    * @param elementName Tag name.
90    * @param attributes Tag attributes.
91    * @throws XmlSyntaxException There is a semantic error in this event occurrence.
92    */
93    public abstract void startElement(final String elementName, final SimpleAttributes attributes)
94    throws XmlSyntaxException;
95   
96    /**
97    * Called at end of element <code>elementName</code>. Must be overwritten.
98    *
99    * @param elementName Tag name.
100    * @throws XmlSyntaxException There is a semantic error in this event occurrence.
101    */
102    public abstract void endElement(final String elementName) throws XmlSyntaxException;
103   
104    /**
105    * Called at end of element <code>elementName</code>. Must be overwritten if you expect
106    * character data.
107    *
108    * @param elementName Tag name.
109    * @param value String value.
110    * @throws XmlSyntaxException There is a semantic error in this event occurrence.
111    */
 
112  0 toggle public void characters(final String elementName, final String value) throws XmlSyntaxException {
113    // default implementation
114  0 throw XmlSyntaxException.createUnexpectedTextDataException(elementName, value);
115    }
116   
117    /**
118    * Change current handler to new one. The new handler gets automatically a
119    * <code>beginElement</code> event.
120    *
121    * @param newHandler Handler that gets all the events now.
122    * @param elementName Current element name.
123    * @param attributes Current element attributes.
124    * @throws XmlSyntaxException New handler detected semantical problems.
125    */
 
126  12384 toggle public final void changeHandler(final AbstractSimpleHandler newHandler,
127    final String elementName, final SimpleAttributes attributes)
128    throws XmlSyntaxException {
129  12384 if (newHandler.getStartTag() != null && !newHandler.getStartTag().equals(elementName)) {
130  0 throw new RuntimeException(newHandler.getClass().getName() + " has start tag \""
131    + newHandler.getStartTag() + "\", but should start with tag \""
132    + elementName + "\"");
133    }
134  12384 defaultHandler.changeHandler(newHandler, elementName, attributes);
135    }
136   
137    /**
138    * Get current tag level.
139    *
140    * @return Current level.
141    */
 
142  3028 toggle public final int getLevel() {
143  3028 return defaultHandler.getLevel();
144    }
145   
146    /**
147    * Get start tag for this handler. Could be <code>null</code> if there is no specific start tag.
148    *
149    * @return Start tag.
150    */
 
151  143330 toggle public final String getStartTag() {
152  143330 return startTag;
153    }
154   
155    }