Project Report: fawkez

Packagesummary org.jcoderz.phoenix.chart2d

org.jcoderz.phoenix.chart2d.Chart2DParser

LineHitsNoteSource
1  /*
2   * $Id: Chart2DParser.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.phoenix.chart2d;
34  
35  
36  import java.io.IOException;
37  import java.io.InputStream;
38  import java.net.URL;
39  import java.util.Stack;
40  
41  import javax.xml.parsers.ParserConfigurationException;
42  import javax.xml.parsers.SAXParserFactory;
43  
44  import org.xml.sax.Attributes;
45  import org.xml.sax.ContentHandler;
46  import org.xml.sax.EntityResolver;
47  import org.xml.sax.ErrorHandler;
48  import org.xml.sax.InputSource;
49  import org.xml.sax.Locator;
50  import org.xml.sax.SAXException;
51  import org.xml.sax.SAXParseException;
52  import org.xml.sax.XMLReader;
53  import org.xml.sax.helpers.AttributesImpl;
54  
55  
56  /**
57   * The class reads XML documents according to specified DTD and
58   * translates all related events into Chart2DHandler events.
59   * <p>
60   * Usage sample:
61   * 
62   * <pre>
63   *         Chart2DParser parser = new Chart2DParser(...);
64   *         parser.parse(new InputSource(&quot;...&quot;));
65   * </pre>
66   * 
67   * <p>
68   * <b>Warning:</b> the class is machine generated. DO NOT MODIFY
69   * </p>
70   */
71 (1)public class Chart2DParser implements ContentHandler
72  {
73     private static final String UNEXPECTED_CHARACTERS_EVENT
74         = "Unexpected characters() event! (Missing DTD?)";
75     private final StringBuffer mBuffer;
76     private final Chart2DHandler mHandler;
77     private final Stack mContext;
78     private final EntityResolver mResolver;
79     private final EntityResolver mRootResolver;
80  
81     /**
82      * Creates a parser instance.
83      * @param hdlr handler interface implementation (never
84      *        <code>null</code>
85      * @param rslvr SAX entity resolver implementation or
86      *        <code>null</code>. It is recommended that it could be
87      *        able to resolve at least the DTD.
88      */
89     public Chart2DParser (final Chart2DHandler hdlr, final EntityResolver rslvr)
900    {
910       mRootResolver = rslvr;
92  
930       mResolver = new MyResolver();
940       mHandler = hdlr;
950       mBuffer = new StringBuffer();
960       mContext = new Stack();
970    }
98  
99     /** {@inheritDoc} */
100     public final void setDocumentLocator (Locator locator)
101     {
102         // NOOP
1030    }
104  
105     /** {@inheritDoc} */
106     public final void startDocument ()
107           throws SAXException
108     {
109        // NOOP
1100    }
111  
112     /** {@inheritDoc} */
113     public final void endDocument ()
114           throws SAXException
115     {
116        // NOOP
1170    }
118  
119     /** {@inheritDoc} */
120 (2)   public final void startElement (String ns, String name, String qname,
121           Attributes attrs)
122           throws SAXException
123     {
1240       dispatch(true);
1250       mContext.push(new Object[] {qname, new AttributesImpl(attrs)});
1260       if ("GraphLabelsLinesStyle".equals(name))
127        {
1280          mHandler.handleGraphLabelsLinesStyle(attrs);
129        }
1300       else if ("Category".equals(name))
131        {
1320          mHandler.startCategory(attrs);
133        }
1340       else if ("MultiColorsProperties".equals(name))
135        {
1360          mHandler.startMultiColorsProperties(attrs);
137        }
1380       else if ("LBChart2D".equals(name))
139        {
1400          mHandler.startLBChart2D(attrs);
141        }
1420       else if ("Dataset".equals(name))
143        {
1440          mHandler.startDataset(attrs);
145        }
1460       else if ("PieChart2DProperties".equals(name))
147        {
1480          mHandler.handlePieChart2DProperties(attrs);
149        }
1500       else if ("GraphChart2DProperties".equals(name))
151        {
1520          mHandler.startGraphChart2DProperties(attrs);
153        }
1540       else if ("Chart2D".equals(name))
155        {
1560          mHandler.startChart2D(attrs);
157        }
1580       else if ("LLChart2D".equals(name))
159        {
1600          mHandler.startLLChart2D(attrs);
161        }
1620       else if ("GraphNumbersLinesStyle".equals(name))
163        {
1640          mHandler.handleGraphNumbersLinesStyle(attrs);
165        }
1660       else if ("PieChart2D".equals(name))
167        {
1680          mHandler.startPieChart2D(attrs);
169        }
1700       else if ("Object2DProperties".equals(name))
171        {
1720          mHandler.handleObject2DProperties(attrs);
173        }
1740       else if ("WarningRegionProperties".equals(name))
175        {
1760          mHandler.handleWarningRegionProperties(attrs);
177        }
1780       else if ("Chart2DProperties".equals(name))
179        {
1800          mHandler.handleChart2DProperties(attrs);
181        }
1820       else if ("Set".equals(name))
183        {
1840          mHandler.startSet(attrs);
185        }
1860       else if ("GraphProperties".equals(name))
187        {
1880          mHandler.startGraphProperties(attrs);
189        }
1900       else if ("LegendProperties".equals(name))
191        {
1920          mHandler.startLegendProperties(attrs);
193        }
1940    }
195  
196     /** {@inheritDoc} */
197     public final void endElement (String ns, String name, String qname)
198           throws SAXException
199     {
2000       dispatch(false);
2010       mContext.pop();
2020       if ("Category".equals(name))
203        {
2040          mHandler.endCategory();
205        }
2060       else if ("MultiColorsProperties".equals(name))
207        {
2080          mHandler.endMultiColorsProperties();
209        }
2100       else if ("LBChart2D".equals(name))
211        {
2120          mHandler.endLBChart2D();
213        }
2140       else if ("Dataset".equals(name))
215        {
2160          mHandler.endDataset();
217        }
2180       else if ("GraphChart2DProperties".equals(name))
219        {
2200          mHandler.endGraphChart2DProperties();
221        }
2220       else if ("Chart2D".equals(name))
223        {
2240          mHandler.endChart2D();
225        }
2260       else if ("LLChart2D".equals(name))
227        {
2280          mHandler.endLLChart2D();
229        }
2300       else if ("PieChart2D".equals(name))
231        {
2320          mHandler.endPieChart2D();
233        }
2340       else if ("Set".equals(name))
235        {
2360          mHandler.endSet();
237        }
2380       else if ("GraphProperties".equals(name))
239        {
2400          mHandler.endGraphProperties();
241        }
2420       else if ("LegendProperties".equals(name))
243        {
2440          mHandler.endLegendProperties();
245        }
2460    }
247  
248     /** {@inheritDoc} */
249     public final void characters (char[] chars, int start, int len)
250           throws SAXException
251     {
2520       mBuffer.append(chars, start, len);
2530    }
254  
255     /** {@inheritDoc} */
256     public final void ignorableWhitespace (char[] chars, int start, int len)
257           throws SAXException
258     {
259          // NOOP
2600    }
261  
262     /** {@inheritDoc} */
263     public final void processingInstruction (String target, String data)
264           throws SAXException
265     {
266         // NOOP
2670    }
268  
269     /** {@inheritDoc} */
270     public final void startPrefixMapping (final String prefix, final String uri)
271           throws SAXException
272     {
273         // NOOP
2740    }
275  
276     /** {@inheritDoc} */
277     public final void endPrefixMapping (final String prefix)
278           throws SAXException
279     {
280         // NOOP
2810    }
282  
283     /** {@inheritDoc} */
284     public final void skippedEntity (String name)
285           throws SAXException
286     {
287         // NOOP
2880    }
289  
290 (3)   private void dispatch (final boolean fireOnlyIfMixed)
291           throws SAXException
292     {
2930       if (fireOnlyIfMixed && (mBuffer.length() == 0))
294        {
2950          return; // skip it
296        }
297  
2980       final Object[] ctx = (Object[]) mContext.peek();
2990       final String here = (String) ctx[0];
3000(4)      final Attributes attrs = (Attributes) ctx[1];
3010       if ("LegendLabelsTexts".equals(here))
302        {
3030          if (fireOnlyIfMixed)
304           {
3050(5)            throw new IllegalStateException(
306                    UNEXPECTED_CHARACTERS_EVENT);
307           }
3080          mHandler.handleLegendLabelsTexts((mBuffer.length() == 0)
309                 ? null : mBuffer.toString(), attrs);
310        }
3110       else if ("AxisLabelText".equals(here))
312        {
3130          if (fireOnlyIfMixed)
314           {
3150(6)            throw new IllegalStateException(
316                    UNEXPECTED_CHARACTERS_EVENT);
317           }
3180          mHandler.handleAxisLabelText((mBuffer.length() == 0)
319                 ? null : mBuffer.toString(), attrs);
320        }
3210       else if ("Data".equals(here))
322        {
3230          if (fireOnlyIfMixed)
324           {
3250(7)            throw new IllegalStateException(
326                    UNEXPECTED_CHARACTERS_EVENT);
327           }
3280          mHandler.handleData((mBuffer.length() == 0)
329                 ? null : mBuffer.toString(), attrs);
330        }
3310       else if ("ColorsCustom".equals(here))
332        {
3330          if (fireOnlyIfMixed)
334           {
3350(8)            throw new IllegalStateException(
336                    UNEXPECTED_CHARACTERS_EVENT);
337           }
3380          mHandler.handleColorsCustom((mBuffer.length() == 0)
339                 ? null : mBuffer.toString(), attrs);
340        }
341        else
342        {
343           // do not care
344        }
3450       mBuffer.delete(0, mBuffer.length());
3460    }
347  
348     /**
349      * The recognizer entry method taking an InputSource.
350      * @param input InputSource to be parsed.
351      * @throws java.io.IOException on I/O error.
352      * @throws SAXException propagated exception thrown by a
353      *         DocumentHandler.
354      * @throws javax.xml.parsers.ParserConfigurationException a parser
355      *         satisfining requested configuration can not be created.
356      * @throws javax.xml.parsers.FactoryConfigurationError if the
357      *         implementation can not be instantiated.
358      */
359     public void parse (final InputSource input)
360           throws SAXException, ParserConfigurationException, IOException
361     {
3620       parse(input, this);
3630    }
364  
365     /**
366      * The recognizer entry method taking a URL.
367      * @param url URL source to be parsed.
368      * @throws java.io.IOException on I/O error.
369      * @throws SAXException propagated exception thrown by a
370      *         DocumentHandler.
371      * @throws javax.xml.parsers.ParserConfigurationException a parser
372      *         satisfining requested configuration can not be created.
373      * @throws javax.xml.parsers.FactoryConfigurationError if the
374      *         implementation can not be instantiated.
375      */
376     public void parse (final java.net.URL url)
377           throws SAXException, ParserConfigurationException, IOException
378     {
3790       parse(new InputSource(url.toExternalForm()), this);
3800    }
381  
382     /**
383      * The recognizer entry method taking an Inputsource.
384      * @param input InputSource to be parsed.
385      * @throws java.io.IOException on I/O error.
386      * @throws SAXException propagated exception thrown by a
387      *         DocumentHandler.
388      * @throws javax.xml.parsers.ParserConfigurationException a parser
389      *         satisfining requested configuration can not be created.
390      * @throws javax.xml.parsers.FactoryConfigurationError if the
391      *         implementation can not be instantiated.
392      */
393     public static void parse (final InputSource input,
394 (9)         final Chart2DHandler handler)
395           throws SAXException, ParserConfigurationException, IOException
396     {
3970(10)      parse(input, new Chart2DParser(handler, null));
3980    }
399  
400     /**
401      * The recognizer entry method taking a URL.
402      * @param url URL source to be parsed.
403      * @throws java.io.IOException on I/O error.
404      * @throws SAXException propagated exception thrown by a
405      *         DocumentHandler.
406      * @throws javax.xml.parsers.ParserConfigurationException a parser
407      *         satisfining requested configuration can not be created.
408      * @throws javax.xml.parsers.FactoryConfigurationError if the
409      *         implementation can not be instantiated.
410      */
411 (11)   public static void parse (final URL url, final Chart2DHandler handler)
412           throws SAXException, ParserConfigurationException, IOException
413     {
4140       parse(new InputSource(url.toExternalForm()), handler);
4150    }
416  
417     private static void parse (final InputSource input,
418           final Chart2DParser recognizer)
419           throws SAXException, ParserConfigurationException, IOException
420     {
4210       final SAXParserFactory factory = SAXParserFactory.newInstance();
4220       factory.setValidating(true); // the code was generated according
423        // DTD
4240       factory.setNamespaceAware(true); // the code was generated
425        // according DTD
4260       final XMLReader parser = factory.newSAXParser().getXMLReader();
4270       parser.setContentHandler(recognizer);
4280       parser.setErrorHandler(recognizer.getDefaultErrorHandler());
4290       if (recognizer.mResolver != null)
430        {
4310          parser.setEntityResolver(recognizer.mResolver);
432        }
4330       parser.parse(input);
4340    }
435  
436     /**
437      * Creates default error handler used by this parser.
438      * @return org.xml.sax.ErrorHandler implementation
439      */
440     protected ErrorHandler getDefaultErrorHandler ()
441     {
4420(12)      return new ErrorHandler()
4430       {
444           public void error (SAXParseException ex)
445                 throws SAXException
446           {
4470             if (mContext.isEmpty())
448              {
4490(13)               System.err.println("Missing DOCTYPE.");
450              }
4510             throw ex;
452           }
453  
454           public void fatalError (SAXParseException ex)
455                 throws SAXException
456           {
4570             throw ex;
458           }
459  
460           public void warning (SAXParseException ex)
461                 throws SAXException
462           {
463              // ignore
4640          }
465        };
466     }
467  
468  
4690    class MyResolver implements EntityResolver
470     {
471        public InputSource resolveEntity (String publicId, String systemId)
472              throws SAXException, IOException
473        {
4740          InputSource result = null;
4750(14)         if ((systemId != null && systemId.equals("chart2d.dtd"))
476                 || (publicId != null && publicId.equals("chart2d.dtd"))
477                 || (systemId != null && systemId
478                       .equals("-//The jCoderZ Project//Chart2D//EN"))
479                 || (publicId != null && publicId
480                       .equals("-//The jCoderZ Project//Chart2D//EN")))
481           {
482              // return a special input source
4830             final InputStream s
484                  = getClass().getResourceAsStream("chart2d.dtd");
4850             if (s != null)
486              {
4870                result = new InputSource(s);
488              }
4890          }
490           else
491           {
492              // use the default behaviour
4930             if (mRootResolver != null)
494              {
4950                result = mRootResolver.resolveEntity(publicId, systemId);
496              }
497           }
4980          return result;
499        }
500     }
501  }

Findings in this File

c (1) 71 : 0 Type Javadoc comment is missing an @author tag.
c (2) 120 : 4 Cyclomatic Complexity is 18 (max allowed is 12).
c (3) 290 : 4 Cyclomatic Complexity is 15 (max allowed is 12).
w (4) 300 : 0 method org.jcoderz.phoenix.chart2d.Chart2DParser.dispatch(boolean) accesses list or array with constant index
i (5) 305 : 0 method org.jcoderz.phoenix.chart2d.Chart2DParser.dispatch(boolean) throws exception with static message string
i (6) 315 : 0 method org.jcoderz.phoenix.chart2d.Chart2DParser.dispatch(boolean) throws exception with static message string
i (7) 325 : 0 method org.jcoderz.phoenix.chart2d.Chart2DParser.dispatch(boolean) throws exception with static message string
i (8) 335 : 0 method org.jcoderz.phoenix.chart2d.Chart2DParser.dispatch(boolean) throws exception with static message string
c (9) 394 : 31 Expected @param tag for 'handler'.
w (10) 397 : 0 class org.jcoderz.phoenix.chart2d.Chart2DParser 'overloads' a method with both instance and static versions
c (11) 411 : 66 Expected @param tag for 'handler'.
d (12) 442 : 14 Anonymous inner class length is 23 lines (max allowed is 20).
d (13) 449 : 16 System.out.print is used
i (14) 475 : 0 method org.jcoderz.phoenix.chart2d.Chart2DParser$MyResolver.resolveEntity(String, String) makes literal string comparisons passing the literal as an argument