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