| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CweHandler |
|
| 2.0;2 |
| 1 | /* | |
| 2 | * This file is part of dependency-check-core. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | * | |
| 16 | * Copyright (c) 2012 Jeremy Long. All Rights Reserved. | |
| 17 | */ | |
| 18 | package org.owasp.dependencycheck.data.cwe; | |
| 19 | ||
| 20 | import java.util.HashMap; | |
| 21 | import org.xml.sax.Attributes; | |
| 22 | import org.xml.sax.SAXException; | |
| 23 | import org.xml.sax.helpers.DefaultHandler; | |
| 24 | ||
| 25 | /** | |
| 26 | * A SAX Handler that will parse the CWE XML. | |
| 27 | * | |
| 28 | * @author Jeremy Long <jeremy.long@owasp.org> | |
| 29 | */ | |
| 30 | 0 | public class CweHandler extends DefaultHandler { |
| 31 | ||
| 32 | /** | |
| 33 | * a HashMap containing the CWE data. | |
| 34 | */ | |
| 35 | 0 | private final HashMap<String, String> cwe = new HashMap<String, String>(); |
| 36 | ||
| 37 | /** | |
| 38 | * Returns the HashMap of CWE entries (CWE-ID, Full CWE Name). | |
| 39 | * | |
| 40 | * @return a HashMap of CWE entries <String, String> | |
| 41 | */ | |
| 42 | public HashMap<String, String> getCwe() { | |
| 43 | return cwe; | |
| 44 | } | |
| 45 | ||
| 46 | @Override | |
| 47 | public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { | |
| 48 | ||
| 49 | 0 | if ("Weakness".equals(qName) || "Category".equals(qName)) { |
| 50 | 0 | final String id = "CWE-" + attributes.getValue("ID"); |
| 51 | 0 | final String name = attributes.getValue("Name"); |
| 52 | 0 | cwe.put(id, name); |
| 53 | } | |
| 54 | 0 | } |
| 55 | } |