19 package org.sleuthkit.autopsy.externalresults;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
24 import org.openide.util.NbBundle;
29 import org.w3c.dom.Document;
30 import org.w3c.dom.Element;
31 import org.w3c.dom.NodeList;
40 private static final String
XSD_FILE =
"autopsy_external_results.xsd";
44 private List<ErrorInfo>
errors =
new ArrayList<>();
140 final Element rootElem = doc.getDocumentElement();
141 if (rootElem != null && rootElem.getNodeName().equals(
TagNames.
ROOT_ELEM.toString())) {
146 String errorMessage = NbBundle.getMessage(this.getClass(),
147 "ExternalResultsXMLParser.parse.errMsg1.text",
152 }
catch (Exception ex) {
153 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsXMLParser.parse.errMsg2.text", this.resultsFilePath);
161 return new ArrayList<>(this.
errors);
167 for (
int i = 0; i < derivedFilesListNodes.getLength(); ++i) {
168 Element derivedFilesListElem = (Element) derivedFilesListNodes.item(i);
171 for (
int j = 0; j < derivedFileNodes.getLength(); ++j) {
172 Element derivedFileElem = (Element) derivedFileNodes.item(j);
175 if (path.isEmpty()) {
180 if (parentFile.isEmpty()) {
183 this.resultsData.addDerivedFile(path, parentFile);
191 for (
int i = 0; i < artifactsListNodes.getLength(); ++i) {
192 Element artifactsListElem = (Element) artifactsListNodes.item(i);
195 for (
int j = 0; j < artifactNodes.getLength(); ++j) {
196 Element artifactElem = (Element) artifactNodes.item(j);
199 if (!type.isEmpty()) {
203 if (!sourceFilePath.isEmpty()) {
215 for (
int i = 0; i < attributeNodesList.getLength(); ++i) {
216 Element attributeElem = (Element) attributeNodesList.item(i);
218 if (type.isEmpty()) {
223 if (valueElem == null) {
226 final String value = valueElem.getTextContent();
227 if (value.isEmpty()) {
228 String errorMessage = NbBundle.getMessage(this.getClass(),
229 "ExternalResultsXMLParser.parseArtifactAttributes.errMsg1.text",
236 if (valueType.isEmpty()) {
242 artifact.addAttribute(type, value, valueType, sourceModule);
248 if (valueType.isEmpty()) {
256 String errorMessage = NbBundle.getMessage(this.getClass(),
257 "ExternalResultsXMLParser.parseAttributeValueType.errMsg1.text",
270 for (
int i = 0; i < reportsListNodes.getLength(); ++i) {
271 Element reportsListElem = (Element) reportsListNodes.item(i);
273 NodeList reportNodes = reportsListElem.getElementsByTagName(
TagNames.
REPORT_ELEM.toString());
274 for (
int j = 0; j < reportNodes.getLength(); ++j) {
275 Element reportElem = (Element) reportNodes.item(j);
278 if (path.isEmpty()) {
283 if (path.isEmpty()) {
288 this.resultsData.addReport(path, sourceModule, reportName);
294 final String attributeValue = element.getAttribute(attributeName);
295 if (attributeValue.isEmpty()) {
296 logger.log(Level.SEVERE,
"Found {0} element missing {1} attribute in {2}",
new Object[]{
297 element.getTagName(),
299 this.resultsFilePath});
301 return attributeValue;
306 Element childElement = this.
getChildElement(parentElement, childElementTagName);
307 if (childElement != null) {
308 content = childElement.getTextContent();
309 if (content.isEmpty()) {
310 String errorMessage = NbBundle.getMessage(this.getClass(),
311 "ExternalResultsXMLParser.getChildElementContent.errMsg1.text",
312 parentElement.getTagName(),
317 }
else if (required) {
318 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsXMLParser.getChildElementContent.errMsg2.text",
319 parentElement.getTagName(),
328 Element childElem = null;
329 NodeList childNodes = parentElement.getElementsByTagName(childElementTagName);
330 if (childNodes.getLength() > 0) {
331 childElem = (Element) childNodes.item(0);
332 if (childNodes.getLength() > 1) {
333 String errorMessage = NbBundle.getMessage(this.getClass(),
"ExternalResultsXMLParser.getChildElement.errMsg1.text",
335 parentElement.getTagName(),
345 this.errors.add(
new ErrorInfo(this.getClass().getSimpleName(), errorMessage));
350 this.errors.add(
new ErrorInfo(this.getClass().getSimpleName(), errorMessage, ex));
AttributeValues(final String text)
void parseDerivedFiles(Element rootElement)
static< T > Document loadDoc(Class< T > clazz, String xmlPath)
List< ErrorInfo > getErrorInfo()
final String resultsFilePath
static final String XSD_FILE
String parseArtifactAttributeValueType(Element valueElem)
String getElementAttributeValue(Element element, String attributeName)
AttributeNames(final String text)
Element getChildElement(Element parentElement, String childElementTagName)
void parseArtifacts(final Element root)
void parseArtifactAttributes(final Element artifactElem, ExternalResults.Artifact artifact)
static final Logger logger
void parseReports(Element root)
ExternalResultsXMLParser(Content dataSource, String resultsFilePath)
String getChildElementContent(Element parentElement, String childElementTagName, boolean required)
synchronized static Logger getLogger(String name)
TagNames(final String text)
void recordError(String errorMessage)
ExternalResults resultsData
void recordError(String errorMessage, Exception ex)