1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 import java.nio.charset.StandardCharsets;
24 import javax.annotation.concurrent.ThreadSafe;
25 import org.apache.commons.lang3.StringUtils;
26 import org.apache.commons.lang3.builder.EqualsBuilder;
27 import org.apache.commons.lang3.builder.HashCodeBuilder;
28
29
30
31
32
33
34 @ThreadSafe
35 public class IndexEntry implements Serializable {
36
37
38
39
40 private static final long serialVersionUID = 8011924485946326934L;
41
42
43
44 private String vendor;
45
46
47
48 private int documentId;
49
50
51
52 private String product;
53
54
55
56 private float searchScore;
57
58
59
60
61
62
63 public int getDocumentId() {
64 return documentId;
65 }
66
67
68
69
70
71
72 public void setDocumentId(int documentId) {
73 this.documentId = documentId;
74 }
75
76
77
78
79
80
81 public String getVendor() {
82 return vendor;
83 }
84
85
86
87
88
89
90 public void setVendor(String vendor) {
91 this.vendor = vendor;
92 }
93
94
95
96
97
98
99 public String getProduct() {
100 return product;
101 }
102
103
104
105
106
107
108 public void setProduct(String product) {
109 this.product = product;
110 }
111
112
113
114
115
116
117 public float getSearchScore() {
118 return searchScore;
119 }
120
121
122
123
124
125
126 public void setSearchScore(float searchScore) {
127 this.searchScore = searchScore;
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 public void parseName(String cpeName) throws UnsupportedEncodingException {
149 if (cpeName != null && cpeName.length() > 7) {
150 final String cpeNameWithoutPrefix = cpeName.substring(7);
151 final String[] data = StringUtils.split(cpeNameWithoutPrefix, ':');
152 if (data.length >= 1) {
153 vendor = URLDecoder.decode(data[0].replace("+", "%2B"), StandardCharsets.UTF_8.name());
154 if (data.length >= 2) {
155 product = URLDecoder.decode(data[1].replace("+", "%2B"), StandardCharsets.UTF_8.name());
156 }
157 }
158 }
159 }
160
161 @Override
162 public int hashCode() {
163 return new HashCodeBuilder(5, 27)
164 .append(documentId)
165 .append(vendor)
166 .append(product)
167 .append(searchScore)
168 .build();
169 }
170
171 @Override
172 public boolean equals(Object obj) {
173 if (obj == null || !(obj instanceof IndexEntry)) {
174 return false;
175 }
176 if (this == obj) {
177 return true;
178 }
179 final IndexEntry rhs = (IndexEntry) obj;
180 return new EqualsBuilder()
181 .append(vendor, rhs.vendor)
182 .append(product, rhs.product)
183 .isEquals();
184 }
185
186
187
188
189
190
191 @Override
192 public String toString() {
193 return "IndexEntry{" + "vendor=" + vendor + ", product=" + product + "', score=" + searchScore + "}";
194 }
195 }