([^\\<]+");
+ try {
+ fr = new FileReader(file);
+ br = new BufferedReader(fr);
+ StringBuilder sb = new StringBuilder(7000);
+ String str = null;
+ String id = null;
+ Document doc = new Document();
+ while ((str = br.readLine()) != null) {
+ sb.append(str);
+ //facts occur more often, do them first.
+ Matcher matcherFact = rxFact.matcher(str);
+ if (matcherFact.matches()) {
+ addVulnerableCpe(matcherFact.group(0), doc);
+ continue;
+ }
+ Matcher matcherEntry = rxEntry.matcher(str);
+ if (matcherEntry.matches()) {
+ id = matcherEntry.group(0);
+ Field name = new Field(Fields.CVE_ID, id, Field.Store.NO, Field.Index.ANALYZED);
+ name.setIndexOptions(IndexOptions.DOCS_ONLY);
+ doc.add(name);
+ continue;
+ }
+ Matcher matcherSummary = rxSummary.matcher(str);
+ if (matcherSummary.matches()) {
+ String summary = matcherSummary.group(0);
+ Field description = new Field(Fields.DESCRIPTION, summary, Field.Store.NO, Field.Index.ANALYZED);
+ description.setIndexOptions(IndexOptions.DOCS_ONLY);
+ doc.add(description);
+ continue;
+ }
+ Matcher matcherEntryEnd = rxEntryEnd.matcher(str);
+ if (matcherEntryEnd.matches()) {
+
+ Field xml = new Field(Fields.XML, sb.toString(), Field.Store.YES, Field.Index.NO);
+ doc.add(xml);
+
+ Term name = new Term(Fields.CVE_ID, LuceneUtils.escapeLuceneQuery(id));
+ indexWriter.updateDocument(name, doc);
+
+ doc = new Document();
+
+ }
+ }
+
+
+ } catch (FileNotFoundException ex) {
+ Logger.getLogger(NvdCveParser.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IOException ex) {
+ Logger.getLogger(NvdCveParser.class.getName()).log(Level.SEVERE, null, ex);
+ } finally {
+ try {
+ fr.close();
+ } catch (IOException ex) {
+ Logger.getLogger(NvdCveParser.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ try {
+ if (br != null) {
+ br.close();
+ }
+ } catch (IOException ex) {
+ Logger.getLogger(NvdCveParser.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ }
+
+
+ private void addVulnerableCpe(String cpe, Document doc) {
+ Field vulnerable = new Field(Fields.VULNERABLE_CPE, cpe, Field.Store.NO, Field.Index.ANALYZED);
+ vulnerable.setIndexOptions(IndexOptions.DOCS_ONLY);
+ doc.add(vulnerable);
+ }
+}
diff --git a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/package-info.java b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/package-info.java
index d0e4ee5f6..4453648c7 100644
--- a/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/package-info.java
+++ b/src/main/java/org/codesecure/dependencycheck/data/nvdcve/xml/package-info.java
@@ -4,7 +4,13 @@
* org.codesecure.dependencycheck.data.nvdcve.xml
*
*
- * Contains classes used to parse the NVD CVE XML file.
+ * Contains classes used to parse the NVD CVE XML file.
+ * The basic use is that the Importer is called to import
+ * an NVD CVE file. The Importer instantiates an Indexer object
+ * (which extends Index). The Indexer creates a partial-unmarshalling
+ * SAX parser (implemented in the NvdCveXmlFilter) that extracts
+ * VulnerabilityTypes (aka Entry) from the NVD CVE data file and
+ * stores these into a Lucene Index.
*
*