From 58d68d340fc62830eeb86aa568a6d82cd059db06 Mon Sep 17 00:00:00 2001 From: Dick Fickling Date: Fri, 22 Jun 2012 13:27:38 -0400 Subject: [PATCH] TSK-507: Allow .001 files for single raw file (awaiting GUI feedback) --- .../autopsy/casemodule/AddImageAction.java | 2 +- .../casemodule/AddImageVisualPanel1.form | 109 +------ .../casemodule/AddImageVisualPanel1.java | 305 +++--------------- .../casemodule/AddImageWizardPanel1.java | 15 +- .../casemodule/AddImageWizardPanel2.java | 6 +- .../casemodule/AddImageWizardPanel3.java | 4 +- .../autopsy/casemodule/Bundle.properties | 6 - .../sleuthkit/autopsy/casemodule/Case.java | 210 +++--------- .../autopsy/casemodule/CaseOpenAction.java | 3 +- .../casemodule/CasePropertiesAction.java | 2 +- .../casemodule/CasePropertiesForm.java | 4 +- .../autopsy/casemodule/GeneralFilter.java | 28 +- .../autopsy/casemodule/XMLCaseManagement.java | 260 --------------- 13 files changed, 135 insertions(+), 819 deletions(-) diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageAction.java b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageAction.java index 196092ebed..3e09bc5c7a 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageAction.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageAction.java @@ -60,7 +60,7 @@ public final class AddImageAction extends CallableSystemAction implements Presen // String: time zone that the image is from static final String TIMEZONE_PROP = "timeZone"; // String[]: array of paths to each image selected - static final String IMGPATHS_PROP = "imgPaths"; + static final String IMGPATH_PROP = "imgPath"; // CleanupTask: task to clean up the database file if wizard errors/is cancelled after it is created static final String IMAGECLEANUPTASK_PROP = "finalFileCleanup"; // int: the next availble id for a new image diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.form b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.form index 809858410c..113a33f79e 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.form +++ b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.form @@ -1,4 +1,4 @@ - +
@@ -6,9 +6,6 @@ - - - @@ -31,22 +28,7 @@ - - - - - - - - - - - - - - - @@ -63,6 +45,10 @@ + + + + @@ -73,85 +59,29 @@ - - - - - - - - - + - - - + - + - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -159,13 +89,6 @@ - - - - - - - @@ -199,16 +122,6 @@ - - - - - - - - - - diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.java b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.java index e554e7ec62..35abc8d7bd 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageVisualPanel1.java @@ -19,19 +19,17 @@ package org.sleuthkit.autopsy.casemodule; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; +import java.util.List; import java.util.SimpleTimeZone; import java.util.TimeZone; -import javax.swing.JCheckBox; -import javax.swing.event.DocumentEvent; -import javax.swing.filechooser.FileFilter; import javax.swing.JFileChooser; import javax.swing.JPanel; import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import org.openide.DialogDescriptor; -import org.openide.DialogDisplayer; -import org.openide.NotifyDescriptor; /** * The "Add Image" wizard panel 1. This class is used to design the "form" of @@ -42,17 +40,19 @@ import org.openide.NotifyDescriptor; final class AddImageVisualPanel1 extends JPanel implements DocumentListener { private JFileChooser fc = new JFileChooser(); - private FileFilter filter; - static final String[] imgExt = {".img", ".dd"}; - static final String imgDesc = "Raw Images (*.img, *.dd)"; - static GeneralFilter imgFilter = new GeneralFilter(imgExt, imgDesc, false); - static final String[] splitExt = {".*\\.[0-9][0-9][0-9]", ".*\\.[a-z][a-z]"}; - static final String splitDesc = "Split Part (*.001, *.002, etc)"; - static GeneralFilter splitFilter = new GeneralFilter(splitExt, splitDesc, true); - static final String[] encasExt = {".*\\.e[0-9][0-9]", ".*\\.e[a-z][a-z]"}; + static final List rawExt = Arrays.asList(new String[]{".img", ".dd", ".001", ".aa"}); + static final String rawDesc = "Raw Images (*.img, *.dd, *.001, *.aa)"; + static GeneralFilter rawFilter = new GeneralFilter(rawExt, rawDesc); + static final List encaseExt = Arrays.asList(new String[]{".e01", ".eaa"}); static final String encaseDesc = "Encase Images (*.e01, *.eAA)"; - static GeneralFilter encaseFilter = new GeneralFilter(encasExt, encaseDesc, true); - private boolean multi = false; + static GeneralFilter encaseFilter = new GeneralFilter(encaseExt, encaseDesc); + static final List allExt = new ArrayList(); + { + allExt.addAll(rawExt); + allExt.addAll(encaseExt); + } + static final String allDesc = "All Supported Types"; + static GeneralFilter allFilter = new GeneralFilter(allExt, allDesc); private AddImageWizardPanel1 wizPanel; /** @@ -62,20 +62,15 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { AddImageVisualPanel1(AddImageWizardPanel1 wizPanel) { initComponents(); this.wizPanel = wizPanel; - fc.setDragEnabled(multi); + fc.setDragEnabled(false); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); - fc.setMultiSelectionEnabled(multi); - fc.addChoosableFileFilter(imgFilter); - filter = imgFilter; - buttonGroup1.add(encase); - buttonGroup1.add(rawSingle); - buttonGroup1.add(rawSplit); + fc.setMultiSelectionEnabled(false); + fc.addChoosableFileFilter(allFilter); + fc.addChoosableFileFilter(rawFilter); + fc.addChoosableFileFilter(encaseFilter); + fc.setFileFilter(allFilter); imgPathTextField.getDocument().addDocumentListener(this); imgPathTextField.setText(""); - jLabel1.setText(""); - rawSingle.setSelected(true); - rawSplit.setSelected(false); - encase.setSelected(false); createTimeZoneList(); } @@ -91,16 +86,16 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { } /** - * Gets the array of image paths from the Image Path Text Field. + * Gets the image path from the Image Path Text Field. * - * @return imagePaths the array of image paths + * @return imagePath the image path */ - public String[] getImagePaths() { - String[] imgPath = Case.convertImgPath(imgPathTextField.getText()); - if (Case.checkMultiplePathExist(imgPath)) { + public String getImagePath() { + String imgPath = imgPathTextField.getText(); + if (Case.pathExists(imgPath)) { return imgPath; } else { - return new String[0]; + return ""; } } @@ -115,27 +110,6 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { boolean getNoFatOrphans() { return noFatOrphansCheckbox.isSelected(); } - - - - /** - * Gets the type of the image that's selected. - * - * @return imgType the type of the image that selected - */ - public String getImgType() { - if (rawSingle.isSelected()) { - return "Raw Single"; - } - if (rawSplit.isSelected()) { - return "Raw Split"; - } - if (encase.isSelected()) { - return "EnCase"; - } else { - return "Nothing Selected"; - } - } /** * Gets the time zone that selected on the drop down list. @@ -197,57 +171,22 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); - rawSingle = new javax.swing.JRadioButton(); - rawSplit = new javax.swing.JRadioButton(); - imgTypeLabel = new javax.swing.JLabel(); - encase = new javax.swing.JRadioButton(); imgPathLabel = new javax.swing.JLabel(); - multipleSelectLabel = new javax.swing.JLabel(); imgPathTextField = new javax.swing.JTextField(); imgPathBrowserButton = new javax.swing.JButton(); this.imgPathBrowserButton.setDefaultCapable(true); this.imgPathBrowserButton.requestFocus(); imgInfoLabel = new javax.swing.JLabel(); - jLabel1 = new javax.swing.JLabel(); timeZoneComboBox = new javax.swing.JComboBox(); timeZoneLabel = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); noFatOrphansCheckbox = new javax.swing.JCheckBox(); optionsLabel1 = new javax.swing.JLabel(); - setMinimumSize(new java.awt.Dimension(559, 328)); setPreferredSize(new java.awt.Dimension(588, 328)); - org.openide.awt.Mnemonics.setLocalizedText(rawSingle, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.rawSingle.text")); // NOI18N - rawSingle.setRequestFocusEnabled(false); - rawSingle.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - rawSingleActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(rawSplit, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.rawSplit.text")); // NOI18N - rawSplit.setRequestFocusEnabled(false); - rawSplit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - rawSplitActionPerformed(evt); - } - }); - - org.openide.awt.Mnemonics.setLocalizedText(imgTypeLabel, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.imgTypeLabel.text")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(encase, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.encase.text")); // NOI18N - encase.setRequestFocusEnabled(false); - encase.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - encaseActionPerformed(evt); - } - }); - org.openide.awt.Mnemonics.setLocalizedText(imgPathLabel, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.imgPathLabel.text")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(multipleSelectLabel, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.multipleSelectLabel.text")); // NOI18N - imgPathTextField.setText(org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.imgPathTextField.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(imgPathBrowserButton, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.imgPathBrowserButton.text")); // NOI18N @@ -257,12 +196,9 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { } }); - imgInfoLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); + imgInfoLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(imgInfoLabel, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.imgInfoLabel.text")); // NOI18N - jLabel1.setForeground(new java.awt.Color(255, 0, 51)); - org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.jLabel1.text")); // NOI18N - timeZoneComboBox.setMaximumRowCount(30); org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel, org.openide.util.NbBundle.getMessage(AddImageVisualPanel1.class, "AddImageVisualPanel1.timeZoneLabel.text")); // NOI18N @@ -281,19 +217,7 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(10, 10, 10) - .addComponent(noFatOrphansCheckbox)) - .addComponent(imgTypeLabel) - .addGroup(layout.createSequentialGroup() - .addGap(10, 10, 10) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(rawSplit) - .addComponent(rawSingle) - .addComponent(encase))) - .addComponent(multipleSelectLabel) .addComponent(imgInfoLabel) - .addComponent(jLabel1) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addComponent(timeZoneLabel) @@ -306,7 +230,10 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(imgPathBrowserButton))) .addComponent(optionsLabel1) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addGap(10, 10, 10) + .addComponent(noFatOrphansCheckbox))) .addContainerGap(39, Short.MAX_VALUE)) ); layout.setVerticalGroup( @@ -314,84 +241,25 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(imgInfoLabel) - .addGap(19, 19, 19) - .addComponent(imgTypeLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(rawSingle) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(rawSplit) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(encase) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(imgPathLabel) .addComponent(imgPathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(imgPathBrowserButton)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(multipleSelectLabel) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGap(26, 26, 26) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(timeZoneLabel) .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(optionsLabel1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(noFatOrphansCheckbox) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(jLabel1) - .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(25, 25, 25)) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(20, 20, 20)) ); }// //GEN-END:initComponents - /** - * When the "rawSingle" radio button is selected. - * - * @param evt the action event - */ - private void rawSingleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rawSingleActionPerformed - rawSingle.setSelected(true); - rawSplit.setSelected(false); - encase.setSelected(false); - multipleSelectLabel.setText("Single Image: Multiple Select Disabled"); - filter = imgFilter; - multi = false; - this.updateUI(null); -}//GEN-LAST:event_rawSingleActionPerformed - - /** - * When the "rawSplit" radio button is selected. - * - * @param evt the action event - */ - private void rawSplitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rawSplitActionPerformed - rawSingle.setSelected(false); - rawSplit.setSelected(true); - encase.setSelected(false); - multipleSelectLabel.setText("Split Image: Multiple Select Enabled. Use Ctrl, Shift, " - + "or Drag to select multiple image parts"); - filter = splitFilter; - multi = true; - updateUI(null); -}//GEN-LAST:event_rawSplitActionPerformed - - /** - * When the "encase" radio button is selected. - * - * @param evt the action event - */ - private void encaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_encaseActionPerformed - rawSingle.setSelected(false); - rawSplit.setSelected(false); - encase.setSelected(true); - multipleSelectLabel.setText("EnCase Image: Multiple Select Enabled. Use Ctrl, Shift, " - + "or Drag to select multiple image parts"); - filter = encaseFilter; - multi = true; - updateUI(null); -}//GEN-LAST:event_encaseActionPerformed - /** * When the "Browse" button is pressed, open the file chooser window to * select the images. @@ -399,12 +267,7 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { * @param evt the action event */ private void imgPathBrowserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imgPathBrowserButtonActionPerformed - fc.resetChoosableFileFilters(); - fc.addChoosableFileFilter(filter); - fc.setFileFilter(filter); - fc.setMultiSelectionEnabled(multi); - fc.setDragEnabled(multi); - + String oldText = imgPathTextField.getText(); // set the current directory of the FileChooser if the ImagePath Field is valid File currentDir = new File(oldText); @@ -414,39 +277,8 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { int retval = fc.showOpenDialog(this); if (retval == JFileChooser.APPROVE_OPTION) { - File[] files = fc.getSelectedFiles(); - String path = ""; - if (multi) { - for (File file : files) { - path = path + "\"" + file.getPath() + "\" "; - } - imgPathTextField.setText(path); - } else { - path = fc.getSelectedFile().getPath(); - imgPathTextField.setText(path); - } - //if split image, and 1 chunk given, verify it's the first chunk - boolean invalidChunk = false; - String[] imgPath = Case.convertImgPath(imgPathTextField.getText()); - if (imgPath.length == 1 && multi == true) { - if (!imgPath[0].matches(".*\\.0.*1$") //001 - && !imgPath[0].matches(".*\\.[aA]{1,}$") //aaa - && !imgPath[0].matches(".*\\.[eE]{1}0.*1$") //E01 - ) { - NotifyDescriptor nd = new NotifyDescriptor.Confirmation("You need to select either all chunks or only the first chunk of a split image to add the entire image correctly. Are you sure you want to use this selection?", "Warning: First image chunk not selected", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE); - nd.setValue(NotifyDescriptor.NO_OPTION); - - Object res = DialogDisplayer.getDefault().notify(nd); - if (res != null && res == DialogDescriptor.NO_OPTION) { - invalidChunk = true; - } - } - } - - if (invalidChunk) { - imgPathTextField.setText(oldText); - return; - } + String path = fc.getSelectedFile().getPath(); + imgPathTextField.setText(path); } @@ -455,19 +287,13 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; - private javax.swing.JRadioButton encase; private javax.swing.JLabel imgInfoLabel; private javax.swing.JButton imgPathBrowserButton; private javax.swing.JLabel imgPathLabel; private static javax.swing.JTextField imgPathTextField; - private javax.swing.JLabel imgTypeLabel; - private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; - private javax.swing.JLabel multipleSelectLabel; private javax.swing.JCheckBox noFatOrphansCheckbox; private javax.swing.JLabel optionsLabel1; - private static javax.swing.JRadioButton rawSingle; - private javax.swing.JRadioButton rawSplit; private javax.swing.JComboBox timeZoneComboBox; private javax.swing.JLabel timeZoneLabel; // End of variables declaration//GEN-END:variables @@ -514,50 +340,13 @@ final class AddImageVisualPanel1 extends JPanel implements DocumentListener { * @param e the document event */ public void updateUI(DocumentEvent e) { - String[] imgPath = Case.convertImgPath(imgPathTextField.getText()); - boolean isExist = Case.checkMultiplePathExist(imgPath); - File imgFile = new File(imgPath[0]); + String imgPath = imgPathTextField.getText(); + boolean isExist = Case.pathExists(imgPath); + File imgFile = new File(imgPath); // check if the given paths exist and those are paths to image files - boolean isImagePath = true; - for (int i = 0; i < imgPath.length; i++) { - File tempImgFile = new File(imgPath[i]); - isImagePath = isImagePath && (Case.isPhysicalDrive(imgPath[i]) || (tempImgFile.exists() && !tempImgFile.isDirectory() - && (imgFilter.accept(tempImgFile) || splitFilter.accept(tempImgFile) - || encaseFilter.accept(tempImgFile)))); - } + boolean isImagePath = allFilter.accept(imgFile); - - if (isImagePath) { - Case currentCase = Case.getCurrentCase(); - File dbFile = new File(currentCase.getCaseDirectory() + File.separator + imgFile.getName() + ".db"); - - if (dbFile.exists()) { - String dbExist = "This database already exists. Do you want to overwrite the database?"; - NotifyDescriptor d = new NotifyDescriptor.Confirmation(dbExist, "Warning: Overwrite Database", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE); - d.setValue(NotifyDescriptor.NO_OPTION); - - isExist = false; - - Object res = DialogDisplayer.getDefault().notify(d); - if (res != null && res == DialogDescriptor.YES_OPTION) { - isExist = dbFile.delete(); - if (!isExist) { - jLabel1.setText("*Database for this image is already created and it can't be deleted because it's being used."); - } - } - if (res != null && res == DialogDescriptor.NO_OPTION) { - jLabel1.setText("*Database for this image exist. Either delete it or select another image."); - } - } - } else { - isExist = false; - } - - if (isExist) { - jLabel1.setText(""); - } - - this.wizPanel.enableNextButton(isExist); + this.wizPanel.enableNextButton(isExist && isImagePath); } } diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel1.java b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel1.java index 4063870630..a987418131 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel1.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel1.java @@ -22,20 +22,17 @@ package org.sleuthkit.autopsy.casemodule; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; -import java.io.IOException; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.JCheckBox; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.openide.WizardDescriptor; import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.sleuthkit.autopsy.coreutils.AutopsyPropFile; -import org.sleuthkit.autopsy.coreutils.Log; /** * The "Add Image" wizard panel1 handling the logic of selecting image file(s) @@ -211,18 +208,16 @@ class AddImageWizardPanel1 implements WizardDescriptor.Panel, */ @Override public void storeSettings(WizardDescriptor settings) { - settings.putProperty(AddImageAction.IMGPATHS_PROP, getComponent().getImagePaths()); + settings.putProperty(AddImageAction.IMGPATH_PROP, getComponent().getImagePath()); settings.putProperty(AddImageAction.TIMEZONE_PROP, getComponent().getSelectedTimezone()); // store the timezone settings.putProperty(AddImageAction.NOFATORPHANS_PROP, Boolean.valueOf(getComponent().getNoFatOrphans())); //settings.putProperty(AddImageAction.LOOKUPFILES_PROP, getComponent().getLookupFilesCheckboxChecked()); //settings.putProperty(AddImageAction.SOLR_PROP, getComponent().getIndexImageCheckboxChecked()); - + // Store the path to the first image selected into the properties file - if(getComponent().getImagePaths().length > 0){ - String firstImage = getComponent().getImagePaths()[0]; - String firstImagePath = firstImage.substring(0, firstImage.lastIndexOf(File.separator)+1); - AutopsyPropFile.getInstance().setProperty(PROP_LASTIMAGE, firstImagePath); - } + String firstImage = getComponent().getImagePath(); + String firstImagePath = firstImage.substring(0, firstImage.lastIndexOf(File.separator) + 1); + AutopsyPropFile.getInstance().setProperty(PROP_LASTIMAGE, firstImagePath); } diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel2.java b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel2.java index cea82741d5..0457c02d64 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel2.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel2.java @@ -50,7 +50,7 @@ import org.sleuthkit.datamodel.TskException; class AddImageWizardPanel2 implements WizardDescriptor.Panel { // the paths of the image files to be added - private String[] imgPaths; + private String imgPath; // the time zone where the image is added private String timeZone; //whether to not process FAT filesystem orphans @@ -190,7 +190,7 @@ class AddImageWizardPanel2 implements WizardDescriptor.Panel { public void readSettings(WizardDescriptor settings) { cleanupImage = null; imgAdded = false; - imgPaths = (String[]) settings.getProperty(AddImageAction.IMGPATHS_PROP); + imgPath = (String) settings.getProperty(AddImageAction.IMGPATH_PROP); timeZone = settings.getProperty(AddImageAction.TIMEZONE_PROP).toString(); noFatOrphans = ((Boolean) settings.getProperty(AddImageAction.NOFATORPHANS_PROP)).booleanValue(); @@ -278,7 +278,7 @@ class AddImageWizardPanel2 implements WizardDescriptor.Panel { process = currentCase.makeAddImageProcess(timeZone, true, noFatOrphans); cancelledWhileRunning.enable(); try { - process.run(imgPaths); + process.run(new String[]{imgPath}); } catch (TskCoreException ex) { logger.log(Level.WARNING, "Errors occurred while running add image. ", ex); //critical core/system error and process needs to be interrupted diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel3.java b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel3.java index 987ed115cc..28b3d362b0 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel3.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/AddImageWizardPanel3.java @@ -178,7 +178,7 @@ class AddImageWizardPanel3 implements WizardDescriptor.Panel { */ private void commitImage(WizardDescriptor settings) throws Exception { - String[] imgPaths = (String[]) settings.getProperty(AddImageAction.IMGPATHS_PROP); + String imgPath = (String) settings.getProperty(AddImageAction.IMGPATH_PROP); String timezone = settings.getProperty(AddImageAction.TIMEZONE_PROP).toString(); settings.putProperty(AddImageAction.IMAGEID_PROP, ""); SleuthkitJNI.CaseDbHandle.AddImageProcess process = (SleuthkitJNI.CaseDbHandle.AddImageProcess) settings.getProperty(AddImageAction.PROCESS_PROP); @@ -196,7 +196,7 @@ class AddImageWizardPanel3 implements WizardDescriptor.Panel { SleuthkitCase.dbWriteUnlock(); if (imageId != 0) { - newImage = Case.getCurrentCase().addImage(imgPaths, imageId, timezone); + newImage = Case.getCurrentCase().addImage(imgPath, imageId, timezone); settings.putProperty(AddImageAction.IMAGEID_PROP, imageId); } diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/Bundle.properties b/Case/src/org/sleuthkit/autopsy/casemodule/Bundle.properties index a29fc26e87..7950e0c13e 100755 --- a/Case/src/org/sleuthkit/autopsy/casemodule/Bundle.properties +++ b/Case/src/org/sleuthkit/autopsy/casemodule/Bundle.properties @@ -92,14 +92,8 @@ AddImageVisualPanel2.crDbLabel.text=Adding Image AddImageVisualPanel2.jLabel5.text=Processing Image and Adding to Database : AddImageVisualPanel2.progressLabel.text= AddImageVisualPanel2.jLabel1.text= We are now analyzing the disk image to extract volume and file system data and populate a local database. -AddImageVisualPanel1.jLabel1.text= AddImageVisualPanel1.timeZoneLabel.text=Please select the image timezone: -AddImageVisualPanel1.rawSingle.text=Raw Single (*.img, *.dd, etc) -AddImageVisualPanel1.rawSplit.text=Raw Split (*.001, *.002, *.aa, *.ab, etc) -AddImageVisualPanel1.imgTypeLabel.text=Image Type: -AddImageVisualPanel1.multipleSelectLabel.text=Single Image: Multiple Select Disabled AddImageVisualPanel1.imgPathTextField.text= -AddImageVisualPanel1.encase.text=EnCase (*.e01, *.e02, etc) AddImageVisualPanel1.imgPathLabel.text=Image Path: AddImageVisualPanel1.imgPathBrowserButton.text=Browse NewJPanel.jLabel1.text= diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/Case.java b/Case/src/org/sleuthkit/autopsy/casemodule/Case.java index 4405fe4b20..9599229ded 100755 --- a/Case/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -242,10 +242,15 @@ public class Case { } } - Map> getImagePaths() { - Map> imgPaths = new HashMap>(); + static Map getImagePaths(SleuthkitCase db) { //TODO: clean this up + Map imgPaths = new HashMap(); try { - imgPaths = db.getImagePaths(); + Map> imgPathsList = db.getImagePaths(); + for(Map.Entry> entry : imgPathsList.entrySet()) { + if(entry.getValue().size() > 0) { + imgPaths.put(entry.getKey(), entry.getValue().get(0)); + } + } } catch (TskException ex) { Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Error getting image paths", ex); } @@ -253,58 +258,37 @@ public class Case { } /** - * Ensure that all image paths point to valid image files - */ - private static void checkImagesExist(SleuthkitCase db) { - Map> imgPaths = new HashMap>(); - try { - imgPaths = db.getImagePaths(); - } catch (TskException ex) { - Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Error getting image paths", ex); - } - for (Map.Entry> entry : imgPaths.entrySet()) { + * Ensure that all image paths point to valid image files + */ + private static void checkImagesExist(SleuthkitCase db) { + Map imgPaths = getImagePaths(db); + for (Map.Entry entry : imgPaths.entrySet()) { JFileChooser fc = new JFileChooser(); FileFilter filter; long obj_id = entry.getKey(); - List paths = entry.getValue(); - boolean allFilesExist = true; - String pathString = ""; - for (String s : paths) { - allFilesExist &= isPhysicalDrive(s) || new File(s).exists(); - pathString += s + "\n"; - } - if (!allFilesExist) { - File f = new File(paths.get(0)); - if (AddImageVisualPanel1.encaseFilter.accept(f)) { - filter = AddImageVisualPanel1.encaseFilter; - } else if (AddImageVisualPanel1.splitFilter.accept(f)) { - filter = AddImageVisualPanel1.splitFilter; - } else { - filter = AddImageVisualPanel1.imgFilter; - } - fc.setMultiSelectionEnabled(true); + String path = entry.getValue(); + boolean fileExists = pathExists(path); + if (!fileExists) { + filter = AddImageVisualPanel1.allFilter; + fc.setMultiSelectionEnabled(false); fc.setFileFilter(filter); - int ret = JOptionPane.showConfirmDialog(null, appName + " has detected that one or more of the images associated with \n" + int ret = JOptionPane.showConfirmDialog(null, appName + " has detected that one of the images associated with \n" + "this case are missing. Would you like to search for them now?\n" - + "Previously, the image(s) were located at:\n" + pathString + + "Previously, the image was located at:\n" + path + "\nPlease note that you will still be able to browse directories and generate reports\n" - + "if you choose No, but you will not be able to view file content or run the ingest process.", "Missing Images", JOptionPane.YES_NO_OPTION); + + "if you choose No, but you will not be able to view file content or run the ingest process.", "Missing Image", JOptionPane.YES_NO_OPTION); if (ret == JOptionPane.YES_OPTION) { fc.showOpenDialog(null); - if (fc.getSelectedFiles().length == paths.size()) { //TODO: this is the extent of our equality checking...we should do more. - List newPaths = new ArrayList(); - for (File newFile : fc.getSelectedFiles()) { - newPaths.add(newFile.getPath()); - } - try { - db.setImagePaths(obj_id, newPaths); - } catch (TskException ex) { - Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Error setting image paths", ex); - } - } else { - Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Selected image files don't match old files!"); + String newPath = fc.getSelectedFile().getPath(); + try { + db.setImagePaths(obj_id, Arrays.asList(new String[]{newPath})); + } catch (TskException ex) { + Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Error setting image paths", ex); } + } else { + Logger.getLogger(Case.class.getName()).log(Level.WARNING, "Selected image files don't match old files!"); } + } } } @@ -316,12 +300,10 @@ public class Case { * @param imgId the ID of the image that being added * @param timeZone the timeZone of the image where it's added */ - Image addImage(String[] imgPaths, long imgId, String timeZone) throws Exception { - Log.get(this.getClass()).log(Level.INFO, "Adding image to Case. imgPaths: {0} ID: {1} TimeZone: {2}", new Object[]{Arrays.toString(imgPaths), imgId, timeZone}); + Image addImage(String imgPath, long imgId, String timeZone) throws Exception { + Log.get(this.getClass()).log(Level.INFO, "Adding image to Case. imgPath: {0} ID: {1} TimeZone: {2}", new Object[]{imgPath, imgId, timeZone}); try { - xmlcm.addImage(imgPaths, imgId, timeZone); // add the image to the document handler in the XML class and to the config file - xmlcm.writeFile(); // write any changes to the config file Image newImage = db.getImageById(imgId); pcs.firePropertyChange(CASE_ADD_IMAGE, null, newImage); // the new value is the instance of the image doAddImage(); @@ -434,46 +416,6 @@ public class Case { } } -// Not dealing with removing images for now. -// /** -// * Removes the image from this case -// * -// * @param givenID the ID of the image to be removed -// * @param givenPath the path of the image to be removed -// */ -// void removeImage(int givenID, String givenPath) throws Exception { -// Log.get(this.getClass()).log(Level.FINE, "Removing image.\ngivenID: {0}\ngivenPath: {1}", new Object[] {givenID, givenPath}); -// -// String[] tempPaths = xmlcm.getImageSet(givenID); -// String tempDb = xmlcm.getImageSetDbPath(givenID); -// -// if (tempPaths[0].equals(givenPath)) { -// xmlcm.removeImageSet(givenID); // make the changes in the config file -// try { -// xmlcm.writeFile(); -// } catch (Exception ex) { -// throw new Exception("Error while trying to remove the image from this case.", ex); -// } -// -// Image img = imageIdToData.get(givenID).image; // save the image that we want to delete temporarily -// -// imageIdToData.remove(givenID); -// -// pcs.firePropertyChange(CASE_DEL_IMAGE, givenID, img); // the old value is the image ID that removed, the new value is the instance of the image -// -// img.getSleuthkit().closeConnection(); // to make sure that we close the connection -// -// // need to remove the database as well?? -// File database = new File(tempDb); -// boolean test = database.delete(); // delete the database of the image that we remove -// if (!test) { -// database.deleteOnExit(); // delete on exit if the delete is not successful -// } -// } else { -// // throw an error here -// Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Couldn't remove image.", new Exception("Couldn't find the image in this case.")); -// } -// } /** * Checks whether there is a current case open. * @@ -597,9 +539,8 @@ public class Case { return pcs; } - String[] getImagePaths(Long imgID) { - List paths = getImagePaths().get(imgID); - return paths.toArray(new String[paths.size()]); + String getImagePaths(Long imgID) { + return getImagePaths(db).get(imgID); } /** @@ -607,7 +548,7 @@ public class Case { * @return imageIDs */ public Long[] getImageIDs() { - Set ids = getImagePaths().keySet(); + Set ids = getImagePaths(db).keySet(); return ids.toArray(new Long[ids.size()]); } @@ -637,11 +578,15 @@ public class Case { * @return time zones the set of time zones */ public Set getTimeZone() { - if (xmlcm == null) { - return new HashSet(); - } else { - return xmlcm.getTimeZone(); + Set timezones = new HashSet(); + for(Content c : getRootObjects()) { + try { + timezones.add(TimeZone.getTimeZone(c.getImage().getTimeZone())); + } catch (TskException ex) { + Logger.getLogger(Case.class.getName()).log(Level.INFO, "Error getting time zones", ex); + } } + return timezones; } public static synchronized void addPropertyChangeListener(PropertyChangeListener listener) { @@ -653,73 +598,24 @@ public class Case { } /** - * convert the image Path to array string - * @param imgPath the image path - * @return imgPath the converted image path + * Check if image from the given image path exists. + * @param imgPath the image path + * @return isExist whether the path exists */ - public static String[] convertImgPath(String imgPath) { - String[] result; - String unsplitPaths = imgPath; - int count = 0; - - for (int i = 0; i < unsplitPaths.length(); i++) { - if (unsplitPaths.charAt(i) == '\"') { - count++; - } - } - - if (count != 0) { - result = new String[count / 2]; - int start = 0; - int current = 0; - for (int i = 0; i < count / 2; i++) { - while (unsplitPaths.charAt(current) != '\"') { - current++; - } - start = current; - current++; - while (unsplitPaths.charAt(current) != '\"') { - current++; - } - result[i] = unsplitPaths.substring(start + 1, current); - current++; - } - } else { - result = new String[1]; - result[0] = unsplitPaths; - } - - return result; - } - - /** - * Check if all the images from the given image path exist. - * @param imgPaths the image paths - * @return isExist whether the multiple paths exist - */ - public static boolean checkMultiplePathExist(String[] imgPaths) { - boolean result = false; - int totalLength = imgPaths.length; - if (totalLength > 0) { - result = true; - for (int i = 0; i < totalLength; i++) { - String path = imgPaths[i]; - if (!new File(path).exists() && !isPhysicalDrive(path)) { - result = false; - break; - } - } - } - return result; + public static boolean pathExists(String imgPath) { + return new File(imgPath).isFile() || isPhysicalDrive(imgPath); } /** * Does the given string refer to a physical drive? */ - private static String pdisk = "\\\\.\\physicaldrive"; + private static final String pdisk = "\\\\.\\physicaldrive"; + private static final String dev = "/dev/"; static boolean isPhysicalDrive(String path) { - int endIndex = Math.min(path.length(), pdisk.length()); - return path.substring(0, endIndex).toLowerCase().equals(pdisk); + int pdiskEnd = Math.min(path.length(), pdisk.length()); + int devEnd = Math.min(path.length(), dev.length()); + return path.substring(0, pdiskEnd).toLowerCase().equals(pdisk) || + path.substring(0, devEnd).toLowerCase().equals(dev); } /** diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java b/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java index b8ee3830a6..ae4b189543 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java @@ -23,6 +23,7 @@ import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; +import java.util.Collections; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; @@ -43,7 +44,7 @@ public final class CaseOpenAction implements ActionListener { AutopsyPropFile AutopsyProperties = AutopsyPropFile.getInstance(); JFileChooser fc = new JFileChooser(); - GeneralFilter autFilter = new GeneralFilter(new String[]{".aut"}, "AUTOPSY File (*.aut)", false); + GeneralFilter autFilter = new GeneralFilter(Collections.singletonList(".aut"), "AUTOPSY File (*.aut)"); /** The constructor */ public CaseOpenAction() { diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/CasePropertiesAction.java b/Case/src/org/sleuthkit/autopsy/casemodule/CasePropertiesAction.java index f642ecb7d6..674e86483f 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/CasePropertiesAction.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/CasePropertiesAction.java @@ -77,7 +77,7 @@ public final class CasePropertiesAction extends CallableSystemAction { int totalImage = currentCase.getRootObjectsCount(); // put the image paths information into hashmap - Map> imgPaths = currentCase.getImagePaths(); + Map imgPaths = currentCase.getImagePaths(currentCase.getSleuthkitCase()); // create the case properties form CasePropertiesForm cpf = new CasePropertiesForm(currentCase, crDate, caseDir, imgPaths); diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/CasePropertiesForm.java b/Case/src/org/sleuthkit/autopsy/casemodule/CasePropertiesForm.java index 9c51e9a151..5a477b7bc9 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/CasePropertiesForm.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/CasePropertiesForm.java @@ -76,7 +76,7 @@ class CasePropertiesForm extends javax.swing.JPanel{ /** Creates new form CasePropertiesForm */ - CasePropertiesForm(Case currentCase, String crDate, String caseDir, Map> imgPaths) { + CasePropertiesForm(Case currentCase, String crDate, String caseDir, Map imgPaths) { initComponents(); caseNameTextField.setText(currentCase.getName()); caseNumberTextField.setText(currentCase.getNumber()); @@ -94,7 +94,7 @@ class CasePropertiesForm extends javax.swing.JPanel{ int i = 0; for(long key : imgPaths.keySet()){ - String path = imgPaths.get(key).get(0); + String path = imgPaths.get(key); String shortenPath = shrinkPath(path, 70); rows[i++] = new String[]{shortenPath}; } diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/GeneralFilter.java b/Case/src/org/sleuthkit/autopsy/casemodule/GeneralFilter.java index 390a09beb6..16620d9a07 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/GeneralFilter.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/GeneralFilter.java @@ -20,7 +20,7 @@ package org.sleuthkit.autopsy.casemodule; import java.io.File; -import java.util.regex.Pattern; +import java.util.List; import javax.swing.filechooser.FileFilter; /** @@ -28,14 +28,12 @@ import javax.swing.filechooser.FileFilter; */ public class GeneralFilter extends FileFilter{ - String[] ext; + List extensions; String desc; - boolean isMultiple; // whether the filter can accept multiple files. - public GeneralFilter(String[] ext, String desc, boolean isMultiple){ - this.ext = ext; + public GeneralFilter(List ext, String desc){ + this.extensions = ext; this.desc = desc; - this.isMultiple = isMultiple; } /** @@ -48,23 +46,13 @@ public class GeneralFilter extends FileFilter{ public boolean accept(File f) { if(f.isDirectory()){ return true; - } - else{ + } else { Boolean result = false; String name = f.getName().toLowerCase(); - if(isMultiple){ - for(int i = 0; i < ext.length; i++){ - String regex = ext[i]; - if (Pattern.matches(regex, name)){ - result = result || true; - } - } - } - else{ - for(int i = 0; i < ext.length; i++){ - if (name.endsWith(ext[i])) - result = result || true; + for (String ext : extensions) { + if (name.endsWith(ext)) { + result = result || true; } } return result; diff --git a/Case/src/org/sleuthkit/autopsy/casemodule/XMLCaseManagement.java b/Case/src/org/sleuthkit/autopsy/casemodule/XMLCaseManagement.java index 421fa99196..e582187ffe 100644 --- a/Case/src/org/sleuthkit/autopsy/casemodule/XMLCaseManagement.java +++ b/Case/src/org/sleuthkit/autopsy/casemodule/XMLCaseManagement.java @@ -59,19 +59,6 @@ public class XMLCaseManagement implements CaseConfigFileInterface{ final static String AUTOPSY_CRVERSION_NAME = "AutopsyCreatedVersion"; final static String AUTOPSY_MVERSION_NAME = "AutopsySavedVersion"; - // disk image paths - final static String IMAGES_NAME = "Images"; - final static String IMG_SET_NAME = "ImgSet"; - final static String IMG_PATH_NAME = "ImgPath"; - final static String IMG_DB_NAME = "ImgDb"; - final static String NEXT_ID_NAME = "NextID"; - - // image attribute - final static String IMG_SET_COUNT = "count"; - final static String IMG_SET_ID = "id"; - final static String IMG_PATH_ID = "idx"; - final static String TIMEZONE = "timezone"; - // folders inside case directory final static String LOG_FOLDER_NAME = "LogFolder"; final static String LOG_FOLDER_RELPATH = "Log"; @@ -473,196 +460,6 @@ public class XMLCaseManagement implements CaseConfigFileInterface{ } } - /** - * Gets image Element from the document handler - * - * @return imageElement the "Image" element - */ - private Element getImagesElement(){ - if(doc != null){ - return (Element) doc.getElementsByTagName(IMAGES_NAME).item(0); - } - else{ - return null; // should throw error or exception - } - } -// -// /** -// * Looks up for the Image Set Element in the document handler with the given -// * image ID. -// * -// * @param id the image ID -// * @return element the "ImageSet" element -// */ -// protected Element getImageSetElement(int id){ -// if(doc != null){ -// Element result = null; -// int totalImageSet = getImageSetCount(); -// -// for(int i = 0; i < totalImageSet; i++){ -// Element imageSetElement = (Element)getImagesElement().getElementsByTagName(IMG_SET_NAME).item(i); -// int imgSetID = Integer.parseInt(imageSetElement.getAttribute(IMG_SET_ID)); -// if(id == imgSetID){ -// result = imageSetElement; -// } -// } -// return result; -// } -// else{ -// return null; //TODO: should throw error or exception -// } -// } -// -// /** -// * Sets the ImgDb entry for corresponding image set in the document handler -// * -// * @param id the image ID -// * @param path the image path -// */ -// protected void setImageSetDbPath(int id, String path){ -// Element imgDbElement = (Element) getImageSetElement(id).getElementsByTagName(IMG_DB_NAME).item(0); -// imgDbElement.setTextContent(path); -// imgDbElement.setAttribute(RELATIVE_NAME, RELATIVE_TRUE); // depends on the path (relative or not) -// -// // if need to write the XML file immidiately, uncomment the code below -// // writeFile(); -// } -// - /** - * Returns number of image sets in this case - * - * @return imageSetCount total number of imageSet in this case - */ - protected int getImageSetCount(){ - return getImagesElement().getElementsByTagName(IMG_SET_NAME).getLength(); - } -// -// /** -// * Returns a set of image paths of the given image ID in this case -// * -// * @param id the image ID -// * @return imagePaths the image paths of the given imageID -// */ -// protected String[] getImageSet(int id){ -// Element imgSetElement = getImageSetElement(id); -// int totalImagePaths = imgSetElement.getElementsByTagName(IMG_PATH_NAME).getLength(); // or use the attribute count -// String[] result = new String[totalImagePaths]; -// -// for(int i = 0; i < totalImagePaths; i++){ -// Element imgPathElement = (Element) imgSetElement.getElementsByTagName(IMG_PATH_NAME).item(i); -// if(imgPathElement.getAttribute(RELATIVE_NAME).equals(RELATIVE_TRUE)){ -// result[i] = caseDirPath + File.separator + imgPathElement.getTextContent(); -// } -// else{ -// result[i] = imgPathElement.getTextContent(); -// } -// } -// return result; -// } -// -// /** -// * Returns absolute path of image database of the given image ID. -// * -// * @param id the image ID -// * @return dbPath the database path of the given image -// */ -// protected String getImageSetDbPath(int id){ -// Element imgDbElement = (Element) getImageSetElement(id).getElementsByTagName(IMG_DB_NAME).item(0); -// if(imgDbElement.getAttribute(RELATIVE_NAME).equals(RELATIVE_TRUE)){ -// return caseDirPath + File.separator + imgDbElement.getTextContent(); -// } -// else{ -// return imgDbElement.getTextContent(); -// } -// } -// -// /** -// * Gets the next free image ID and and increments the internal counter -// * -// * @return imageID the next free image ID -// */ -// @Override -// public int getNextImageID(){ -// Element imgElement = getImagesElement(); -// if(imgElement == null){ -// return -1; // which indicates the error -// } -// else{ -// String nextID = imgElement.getAttribute(NEXT_ID_NAME); -// int result = Integer.parseInt(nextID); -// -// // increment the nextID -// int incNextID = result + 1; -// getImagesElement().setAttribute(NEXT_ID_NAME, Integer.toString(incNextID)); -// -// // write the change to the config file immediately -// try{ -// writeFile(); -// } -// catch(Exception ex){ -// // TODO: throw exception further up -// Logger logger = Logger.getLogger(this.className); -// logger.log(Level.WARNING, "Error while trying to write the new NextID to the config file.", ex); -// } -// -// return result; -// } -// } -// -// /** -// * Returns an array of all image ID values in this case. -// * -// * @return imageIDs array of all image IDs in this case -// */ -// @Override -// public int[] getImageIDs() { -// int totalImageSet = getImageSetCount(); -// int[] result = new int[totalImageSet]; -// -// Element imgElement = getImagesElement(); -// for(int i = 0; i < totalImageSet; i++){ -// Element imgSetElement = (Element)imgElement.getElementsByTagName(IMG_SET_NAME).item(i); -// result[i] = Integer.parseInt(imgSetElement.getAttribute(IMG_SET_ID)); -// } -// -// return result; -// } -// -// /** -// * Returns the HashSet of all timezone values of all images in this case. -// * -// * @return imageIDs the HashSet of all timezone values -// */ - public HashSet getTimeZone() { - HashSet result = new HashSet(); - - int totalImageSet = getImageSetCount(); - Element imgElement = getImagesElement(); - for(int i = 0; i < totalImageSet; i++){ - Element imgSetElement = (Element)imgElement.getElementsByTagName(IMG_SET_NAME).item(i); - result.add(TimeZone.getTimeZone(imgSetElement.getAttribute(TIMEZONE))); - } - - return result; //TODO: get time zones from db - } -// -// /** -// * Removes the imageSet of the given image ID. -// * -// * @param imgID the image ID of the image that going to be removed -// */ -// public void removeImageSet(int imgID) { -// Element imgElement = getImagesElement(); -// Element selectedElement = getImageSetElement(imgID); -// imgElement.removeChild(selectedElement); // remove the imagesetElement -// doc.normalize(); -// -// // edit the modified data -// String newDate = dateFormat.format(new Date()); -// Element rootEl = getRootElement(); -// rootEl.getElementsByTagName(MODIFIED_DATE_NAME).item(0).setTextContent(newDate); -// } - /** * Initialize the basic values for a new case management file. * Note: this is the schema version 1.0 @@ -748,11 +545,6 @@ public class XMLCaseManagement implements CaseConfigFileInterface{ cacheElement.setAttribute(RELATIVE_NAME, "true"); caseElement.appendChild(cacheElement); - // create the new images - Element imagesElement = doc.createElement(IMAGES_NAME); // ... - imagesElement.setAttribute(NEXT_ID_NAME, Integer.toString(0)); // add nextID to 0 - rootElement.appendChild(imagesElement); - // write more code if needed ... } @@ -894,56 +686,4 @@ public class XMLCaseManagement implements CaseConfigFileInterface{ examiner = ""; } - /** - * Adds the image to the current document handler. - * - * @param images the paths of the images that want to be added - * @param currentID the ID of the image that want to be added - * @param timeZone the timeZone where the image is added - */ - protected void addImage(String[] images, long currentID, String timeZone) throws Exception { - - //String dbName = "image-" + currentID + ".db"; - - if (doc == null) { - throw new Exception("No case open."); - } else { - Element rootEl = getRootElement(); - - int imgCount = images.length; // how many given images to add to the config file - Element imagesElement = getImagesElement(); - - //int currentID = Integer.parseInt(imagesElement.getAttribute(NEXT_ID_NAME)); - - // add the latest image set - Element imgSetElement = doc.createElement(IMG_SET_NAME); // ... - imgSetElement.setAttribute(IMG_SET_COUNT, Integer.toString(imgCount)); - imgSetElement.setAttribute(IMG_SET_ID, Long.toString(currentID)); - imgSetElement.setAttribute(TIMEZONE, timeZone); - imagesElement.appendChild(imgSetElement); - - // add all the image Path -// for (int i = 0; i < imgCount; i++) { -// Element imgPathElement = doc.createElement(IMG_PATH_NAME); // ... -// imgPathElement.setAttribute(IMG_PATH_ID, Integer.toString(i)); -// imgPathElement.setAttribute(RELATIVE_NAME, "false"); -// imgPathElement.appendChild(doc.createTextNode(images[i])); -// imgSetElement.appendChild(imgPathElement); -// } -// -// // add the database -// Element imgDbElement = doc.createElement(IMG_DB_NAME); // ... -// imgDbElement.setAttribute(RELATIVE_NAME, "true"); -// imgDbElement.appendChild(doc.createTextNode(dbName)); -// //imgDbElement.appendChild(doc.createTextNode("image-" + currentID + ".db")); -// imgSetElement.appendChild(imgDbElement); - - // edit the modified data - String newDate = dateFormat.format(new Date()); - rootEl.getElementsByTagName(MODIFIED_DATE_NAME).item(0).setTextContent(newDate); - } - -// JOptionPane.showMessageDialog(caller, "Error while trying to add the image to XML config file.\n \nDetail: \n" + e.getMessage() + " (at " + className + ").", "Error", JOptionPane.ERROR_MESSAGE); - - } }