Project Report: fawkez

Packagesummary org.jcoderz.phoenix.templategen

org.jcoderz.phoenix.templategen.TemplateDescr

LineHitsNoteSource
1  /*
2   * $Id: TemplateDescr.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.templategen;
34  
35  import java.io.IOException;
36  import java.io.StringReader;
37  import java.util.ArrayList;
38  import java.util.HashMap;
39  import java.util.List;
40  import java.util.Map;
41  
42  import javax.xml.parsers.FactoryConfigurationError;
43  import javax.xml.parsers.ParserConfigurationException;
44  import javax.xml.parsers.SAXParser;
45  import javax.xml.parsers.SAXParserFactory;
46  
47  import org.xml.sax.Attributes;
48  import org.xml.sax.InputSource;
49  import org.xml.sax.SAXException;
50  import org.xml.sax.helpers.DefaultHandler;
51  
52  /**
53   * @author Albrecht Messner
54   */
550 public class TemplateDescr
56  {
570    private String mDescription = null;
580    private final Map mParameterMap = new HashMap();
590    private final List mParameterList = new ArrayList();
600    private final Map mFiles = new HashMap();
61  
62 (1)   public String getDescription ()
63     {
640       return mDescription;
65     }
66  
67 (2)   public Map getParameterMap ()
68     {
690       return mParameterMap;
70     }
71  
72 (3)   public List getParameterList ()
73     {
740       return mParameterList;
75     }
76  
77 (4)   public Map getFilesMap ()
78     {
790       return mFiles;
80     }
81  
82 (5)(6)   public void parseDescription (String xmlDescription)
83           throws IOException, ParserConfigurationException,
84                 SAXException, FactoryConfigurationError
85     {
860(7)      final DefaultHandler docHandler = new DefaultHandler() {
87  
880          private final StringBuffer mCharBuffer = new StringBuffer();
890          private Parameter mParam = null;
90  
91           /** {@inheritDoc} */
92           public void startElement (
93                 String uri,
94                 String localName,
95                 String qName,
96                 Attributes attributes)
97                 throws SAXException
98           {
99              try
100              {
1010                if ("parameter".equals(qName))
102                 {
1030                   final String name = attributes.getValue("name");
1040                   final int minLength
105                          = Integer.parseInt(attributes.getValue("minLength"));
1060                   final int maxLength
107                          = Integer.parseInt(attributes.getValue("maxLength"));
1080                   final boolean multiLine
109                          = Boolean.valueOf(attributes.getValue("multiLine"))
110                          .booleanValue();
1110                   mParam = new Parameter(name, minLength, maxLength, multiLine);
1120                }
1130                else if ("description".equals(qName))
114                 {
1150                   mCharBuffer.setLength(0);
116                 }
1170                else if ("default".equals(qName)
118                       || "regexp".equals(qName))
119                 {
1200                   if (mParam == null)
121                    {
1220(8)                     throw new SAXException(
123                             "'default' and 'regexp' tags may only occur "
124                             + " inside a 'parameter' tag");
125                    }
1260                   mCharBuffer.setLength(0);
127                 }
1280                else if ("file".equals(qName))
129                 {
1300                   final String source = attributes.getValue("source");
1310                   final String target = attributes.getValue("target");
1320                   mFiles.put(source, target);
133                 }
134              }
1350             catch (SAXException e)
136              {
1370(9)               e.printStackTrace();
1380                throw e;
139              }
1400             catch (RuntimeException e)
141              {
1420(10)               e.printStackTrace();
1430                throw e;
1440             }
1450          }
146  
147           /** {@inheritDoc} */
148           public void endElement (String uri, String localName, String qName)
149                 throws SAXException
150           {
151              try
152              {
1530(11)(12)               if (qName.equals("parameter"))
154                 {
1550                   mParameterMap.put(mParam.getName(), mParam);
1560                   mParameterList.add(mParam);
157  
158                    // System.out.println(param);
1590                   mParam = null;
160                 }
1610(13)(14)               else if (qName.equals("description"))
162                 {
1630                   if (mParam != null)
164                    {
1650                      mParam.setDescription(mCharBuffer.toString().trim());
166                    }
1670                   else if (mDescription == null)
168                    {
1690                      mDescription = mCharBuffer.toString().trim();
170                    }
171                    else
172                    {
1730(15)                     throw new SAXException(
174                             "'description' element not expected here");
175                    }
1760                   mCharBuffer.setLength(0);
177                 }
1780(16)(17)               else if (qName.equals("default"))
179                 {
1800                   mParam.setDefaultValue(mCharBuffer.toString().trim());
1810                   mCharBuffer.setLength(0);
182                 }
1830(18)(19)               else if (qName.equals("regexp"))
184                 {
1850                   mParam.setRegexp(mCharBuffer.toString().trim());
1860                   mCharBuffer.setLength(0);
187                 }
188              }
1890             catch (SAXException e)
190              {
1910(20)               e.printStackTrace();
1920                throw e;
193              }
1940             catch (RuntimeException e)
195              {
1960(21)               e.printStackTrace();
1970                throw e;
1980             }
1990          }
200  
201           /** {@inheritDoc} */
202           public void characters (char[] ch, int start, int length)
203                 throws SAXException
204           {
2050              mCharBuffer.append(ch, start, length);
2060          }
207        };
208  
2090       final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
2100       final StringReader sr = new StringReader(xmlDescription);
2110       parser.parse(new InputSource(sr), docHandler);
2120    }
213  
214     /** {@inheritDoc} */
215     public String toString ()
216     {
2170(22)      final StringBuffer sbuf = new StringBuffer();
2180(23)      sbuf.append("[ParameterDescription");
2190       sbuf.append("\n description=").append(mDescription);
2200       sbuf.append("\n files=").append(mFiles.toString());
2210       sbuf.append("\n parameters=");
2220       sbuf.append(mParameterMap.toString());
2230       sbuf.append(']');
2240       return sbuf.toString();
225     }
226  }

Findings in this File

c (1) 62 : 4 Missing a Javadoc comment.
c (2) 67 : 4 Missing a Javadoc comment.
c (3) 72 : 4 Missing a Javadoc comment.
c (4) 77 : 4 Missing a Javadoc comment.
d (5) 82 : 4 Method length is 128 lines (max allowed is 100).
c (6) 82 : 4 Missing a Javadoc comment.
d (7) 86 : 41 Anonymous inner class length is 122 lines (max allowed is 20).
i (8) 122 : 0 method org.jcoderz.phoenix.templategen.TemplateDescr$1.startElement(String, String, String, Attributes) throws exception with static message string
d (9) 137 : 16 Avoid printStackTrace(); use a logger call instead.
d (10) 142 : 16 Avoid printStackTrace(); use a logger call instead.
i (11) 153 : 0 method org.jcoderz.phoenix.templategen.TemplateDescr$1.endElement(String, String, String) makes literal string comparisons passing the literal as an argument
c (12) 153 : 20 Position literals first in String comparisons
i (13) 161 : 0 method org.jcoderz.phoenix.templategen.TemplateDescr$1.endElement(String, String, String) makes literal string comparisons passing the literal as an argument
c (14) 161 : 25 Position literals first in String comparisons
i (15) 173 : 0 method org.jcoderz.phoenix.templategen.TemplateDescr$1.endElement(String, String, String) throws exception with static message string
i (16) 178 : 0 method org.jcoderz.phoenix.templategen.TemplateDescr$1.endElement(String, String, String) makes literal string comparisons passing the literal as an argument
c (17) 178 : 25 Position literals first in String comparisons
i (18) 183 : 0 method org.jcoderz.phoenix.templategen.TemplateDescr$1.endElement(String, String, String) makes literal string comparisons passing the literal as an argument
c (19) 183 : 25 Position literals first in String comparisons
d (20) 191 : 16 Avoid printStackTrace(); use a logger call instead.
d (21) 196 : 16 Avoid printStackTrace(); use a logger call instead.
i (22) 217 : 26 StringBuffer constructor is initialized with size 16, but has at least 66 characters appended.
i (23) 218 : 18 StringBuffer.append is called 2 consecutive times with literal Strings. Use a single append with a single String.