Child: [r15] (diff)

Download this file

SectionFiles.java    187 lines (153 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* SPDXVersion: SPDX-1.1
*
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
*
* Creator: Organization: TripleCheck (contact@triplecheck.de)
*
* Created: 2013-09-16T00:00:00Z
*
* LicenseName: NOASSERTION
*
* FileName: SectionFiles.java
*
* FileType: SOURCE
*
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
*
* FileComment: <text> Allows to handle an array of files that were
* reported on the SPDX document </text>
*/
package spdxlib;
import java.util.ArrayList;
public class SectionFiles {
public ArrayList<FileInfo>
files = new ArrayList();
public ArrayList<TagValue>
unknown = new ArrayList();
/**
* Parse the file tags section of the document
*/
public boolean parseTag(TagValue tag) {
// start a new entry
if(tag.title.equalsIgnoreCase("FileName")){
FileInfo file = new FileInfo();
file.tagFileName = tag;
files.add(file);
return true;
}
if(tag.title.equalsIgnoreCase("FileType")){
FileInfo file = getLastAddedFile();
file.tagFiletype = tag;
return true;
}
if(tag.title.equalsIgnoreCase("FileChecksum->SHA1")){
FileInfo file = getLastAddedFile();
file.tagFileChecksumSHA1 = tag;
return true;
}
if(tag.title.equalsIgnoreCase("LicenseConcluded")){
FileInfo file = getLastAddedFile();
file.tagLicenseConcluded = tag;
return true;
}
// add licenseInfoInFile handling here
if(tag.title.equalsIgnoreCase("LicenseInfoInFile")){
FileInfo file = getLastAddedFile();
file.addLicense(tag);
return true;
}
if(tag.title.equalsIgnoreCase("LicenseComments")){
FileInfo file = getLastAddedFile();
file.tagLicenseComments = tag;
return true;
}
if(tag.title.equalsIgnoreCase("FileCopyrightText")){
FileInfo file = getLastAddedFile();
file.tagFileCopyrightText = tag;
return true;
}
if(tag.title.equalsIgnoreCase("ArtifactOfProjectName")){
FileInfo file = getLastAddedFile();
file.tagArtifactOfProjectName = tag;
return true;
}
if(tag.title.equalsIgnoreCase("ArtifactOfProjectHomePage")){
FileInfo file = getLastAddedFile();
file.tagArtifactOfProjectHomePage = tag;
return true;
}
if(tag.title.equalsIgnoreCase("ArtifactOfProjectURI")){
FileInfo file = getLastAddedFile();
file.tagArtifactOfProjectURI = tag;
return true;
}
if(tag.title.equalsIgnoreCase("ArtifactOfProjectURI")){
FileInfo file = getLastAddedFile();
file.tagArtifactOfProjectURI = tag;
return true;
}
if(tag.title.equalsIgnoreCase("Comment")){
FileInfo file = getLastAddedFile();
file.tagComment = tag;
return true;
}
// non-standard tags
if(tag.title.equalsIgnoreCase("FilePath")){
FileInfo file = getLastAddedFile();
file.tagFilePath = tag;
return true;
}
if(tag.title.equalsIgnoreCase("FileSize")){
FileInfo file = getLastAddedFile();
file.tagFileSize = tag;
return true;
}
if(tag.title.equalsIgnoreCase("FileLOC")){
FileInfo file = getLastAddedFile();
file.tagFileLOC = tag;
return true;
}
if(tag.title.equalsIgnoreCase("FileChecksum->SHA256")){
FileInfo file = getLastAddedFile();
file.tagFileChecksumSHA256 = tag;
return true;
}
if(tag.title.equalsIgnoreCase("FileChecksum->MD5")){
FileInfo file = getLastAddedFile();
file.tagFileChecksumMD5 = tag;
return true;
}
if(tag.title.contains("FileChecksum->SSDEEP")){
FileInfo file = getLastAddedFile();
file.tagFileChecksumSSDEEP = tag;
return true;
}
// if not recognized, add it up
addUnknownTag(tag);
return false;
}
/*
* Provides the last added file object on our array
*/
private FileInfo getLastAddedFile() {
FileInfo result;
if(files.size()>0){
result = files.get(files.size()-1);
}else{
result = new FileInfo();
files.add(result);
}
return result;
}
/**
* Add up all unknown tags, they might be later
* proven as useful.
* @param tag
*/
private void addUnknownTag(TagValue tag) {
System.out.println("<files> Unknown tag: "
+ tag.title + " = " + tag.getValue());
unknown.add(tag);
}
}