| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| IndexEntry |
|
| 2.5;2.5 |
| 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.cpe; | |
| 20 | ||
| 21 | import java.io.Serializable; | |
| 22 | import java.io.UnsupportedEncodingException; | |
| 23 | import java.net.URLDecoder; | |
| 24 | ||
| 25 | /** | |
| 26 | * A CPE entry containing the name, vendor, product, and version. | |
| 27 | * | |
| 28 | * @author Jeremy Long (jeremy.long@owasp.org) | |
| 29 | */ | |
| 30 | 3902 | public class IndexEntry implements Serializable { |
| 31 | ||
| 32 | /** | |
| 33 | * the serial version uid. | |
| 34 | */ | |
| 35 | static final long serialVersionUID = 8011924485946326934L; | |
| 36 | /** | |
| 37 | * The vendor name. | |
| 38 | */ | |
| 39 | private String vendor; | |
| 40 | /** | |
| 41 | * The documentId. | |
| 42 | */ | |
| 43 | private String documentId; | |
| 44 | ||
| 45 | /** | |
| 46 | * Get the value of documentId. | |
| 47 | * | |
| 48 | * @return the value of documentId | |
| 49 | */ | |
| 50 | public String getDocumentId() { | |
| 51 | 0 | if (documentId == null && vendor != null && product != null) { |
| 52 | 0 | documentId = vendor + ":" + product; |
| 53 | } | |
| 54 | 0 | return documentId; |
| 55 | } | |
| 56 | ||
| 57 | /** | |
| 58 | * Set the value of documentId. | |
| 59 | * | |
| 60 | * @param documentId new value of documentId | |
| 61 | */ | |
| 62 | public void setDocumentId(String documentId) { | |
| 63 | 0 | this.documentId = documentId; |
| 64 | 0 | } |
| 65 | ||
| 66 | /** | |
| 67 | * Get the value of vendor. | |
| 68 | * | |
| 69 | * @return the value of vendor | |
| 70 | */ | |
| 71 | public String getVendor() { | |
| 72 | 452 | return vendor; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Set the value of vendor. | |
| 77 | * | |
| 78 | * @param vendor new value of vendor | |
| 79 | */ | |
| 80 | public void setVendor(String vendor) { | |
| 81 | 3901 | this.vendor = vendor; |
| 82 | 3901 | } |
| 83 | /** | |
| 84 | * The product name. | |
| 85 | */ | |
| 86 | private String product; | |
| 87 | ||
| 88 | /** | |
| 89 | * Get the value of product. | |
| 90 | * | |
| 91 | * @return the value of product | |
| 92 | */ | |
| 93 | public String getProduct() { | |
| 94 | 808 | return product; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Set the value of product. | |
| 99 | * | |
| 100 | * @param product new value of product | |
| 101 | */ | |
| 102 | public void setProduct(String product) { | |
| 103 | 3901 | this.product = product; |
| 104 | 3901 | } |
| 105 | /** | |
| 106 | * The search score. | |
| 107 | */ | |
| 108 | private float searchScore; | |
| 109 | ||
| 110 | /** | |
| 111 | * Get the value of searchScore. | |
| 112 | * | |
| 113 | * @return the value of searchScore | |
| 114 | */ | |
| 115 | public float getSearchScore() { | |
| 116 | 0 | return searchScore; |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * Set the value of searchScore. | |
| 121 | * | |
| 122 | * @param searchScore new value of searchScore | |
| 123 | */ | |
| 124 | public void setSearchScore(float searchScore) { | |
| 125 | 417 | this.searchScore = searchScore; |
| 126 | 417 | } |
| 127 | ||
| 128 | /** | |
| 129 | * <p>Parses a name attribute value, from the cpe.xml, into its | |
| 130 | * corresponding parts: vendor, product.</p> | |
| 131 | * <p>Example:</p> | |
| 132 | * <code>nbsp;nbsp;nbsp;cpe:/a:apache:struts:1.1:rc2</code> | |
| 133 | * | |
| 134 | * <p>Results in:</p> <ul> <li>Vendor: apache</li> <li>Product: struts</li> | |
| 135 | * </ul> | |
| 136 | * <p>If it is necessary to parse the CPE into more parts (i.e. to include | |
| 137 | * version and revision) then you should use the | |
| 138 | * {@link org.owasp.dependencycheck.dependency.VulnerableSoftware#parseName VulnerableSoftware.parseName()}. | |
| 139 | * | |
| 140 | * @param cpeName the cpe name | |
| 141 | * @throws UnsupportedEncodingException should never be thrown... | |
| 142 | */ | |
| 143 | public void parseName(String cpeName) throws UnsupportedEncodingException { | |
| 144 | 1 | if (cpeName != null && cpeName.length() > 7) { |
| 145 | 1 | final String[] data = cpeName.substring(7).split(":"); |
| 146 | 1 | if (data.length >= 1) { |
| 147 | 1 | vendor = URLDecoder.decode(data[0].replace("+", "%2B"), "UTF-8"); |
| 148 | 1 | if (data.length >= 2) { |
| 149 | 1 | product = URLDecoder.decode(data[1].replace("+", "%2B"), "UTF-8"); |
| 150 | } | |
| 151 | } | |
| 152 | } | |
| 153 | 1 | } |
| 154 | ||
| 155 | @Override | |
| 156 | public int hashCode() { | |
| 157 | 0 | int hash = 7; |
| 158 | 0 | hash = 97 * hash + (this.getDocumentId() != null ? this.getDocumentId().hashCode() : 0); |
| 159 | 0 | return hash; |
| 160 | } | |
| 161 | ||
| 162 | @Override | |
| 163 | public boolean equals(Object obj) { | |
| 164 | 3586 | if (obj == null) { |
| 165 | 0 | return false; |
| 166 | } | |
| 167 | 3586 | if (getClass() != obj.getClass()) { |
| 168 | 0 | return false; |
| 169 | } | |
| 170 | 3586 | final IndexEntry other = (IndexEntry) obj; |
| 171 | 3586 | if ((this.vendor == null) ? (other.vendor != null) : !this.vendor.equals(other.vendor)) { |
| 172 | 2633 | return false; |
| 173 | } | |
| 174 | 953 | if ((this.product == null) ? (other.product != null) : !this.product.equals(other.product)) { |
| 175 | 953 | return false; |
| 176 | } | |
| 177 | 0 | return true; |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * Standard implementation of toString showing vendor and product. | |
| 182 | * | |
| 183 | * @return the string representation of the object | |
| 184 | */ | |
| 185 | @Override | |
| 186 | public String toString() { | |
| 187 | 0 | return "IndexEntry{" + "vendor=" + vendor + ", product=" + product + '}'; |
| 188 | } | |
| 189 | } |