View Javadoc

    1   /*
    2    * This file is part of dependency-check-core.
    3    *
    4    * Dependency-check-core is free software: you can redistribute it and/or modify it
    5    * under the terms of the GNU General Public License as published by the Free
    6    * Software Foundation, either version 3 of the License, or (at your option) any
    7    * later version.
    8    *
    9    * Dependency-check-core is distributed in the hope that it will be useful, but
    10   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12   * details.
    13   *
    14   * You should have received a copy of the GNU General Public License along with
    15   * dependency-check-core. If not, see http://www.gnu.org/licenses/.
    16   *
    17   * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
    18   */
    19  package org.owasp.dependencycheck.data.cwe;
    20
    21  import java.util.HashMap;
    22  import org.xml.sax.Attributes;
    23  import org.xml.sax.SAXException;
    24  import org.xml.sax.helpers.DefaultHandler;
    25
    26  /**
    27   * A SAX Handler that will parse the CWE XML.
    28   *
    29   * @author Jeremy Long (jeremy.long@owasp.org)
    30   */
    31  public class CweHandler extends DefaultHandler {
    32
    33      /**
    34       * a HashMap containing the CWE data.
    35       */
    36      private final HashMap<String, String> cwe = new HashMap<String, String>();
    37
    38      /**
    39       * Returns the HashMap of CWE entries (CWE-ID, Full CWE Name).
    40       *
    41       * @return a HashMap of CWE entries <String, String>
    42       */
    43      public HashMap<String, String> getCwe() {
    44          return cwe;
    45      }
    46
    47      @Override
    48      public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    49
    50          if ("Weakness".equals(qName) || "Category".equals(qName)) {
    51              final String id = "CWE-" + attributes.getValue("ID");
    52              final String name = attributes.getValue("Name");
    53              cwe.put(id, name);
    54          }
    55      }
    56  }