mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-19 11:07:43 +00:00
Address some issues in PListViewer detected by Codacy/IDE
This commit is contained in:
parent
6ef7317c8a
commit
88edf39ca5
@ -16,7 +16,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.sleuthkit.autopsy.contentviewers;
|
package org.sleuthkit.autopsy.contentviewers;
|
||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
@ -56,13 +55,13 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
|||||||
import org.sleuthkit.datamodel.TskCoreException;
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PListViewer - a file viewer for binary plist files.
|
* PListViewer - a file viewer for binary plist files.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, ExplorerManager.Provider {
|
public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, ExplorerManager.Provider {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
private static final String[] MIMETYPES = new String[]{"application/x-bplist"};
|
private static final String[] MIMETYPES = new String[]{"application/x-bplist"};
|
||||||
private static final Logger LOGGER = Logger.getLogger(PListViewer.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(PListViewer.class.getName());
|
||||||
|
|
||||||
@ -77,7 +76,6 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
*/
|
*/
|
||||||
public PListViewer() {
|
public PListViewer() {
|
||||||
|
|
||||||
|
|
||||||
// Create an Outlineview and add to the panel
|
// Create an Outlineview and add to the panel
|
||||||
outlineView = new org.openide.explorer.view.OutlineView();
|
outlineView = new org.openide.explorer.view.OutlineView();
|
||||||
|
|
||||||
@ -108,7 +106,6 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
}
|
}
|
||||||
|
|
||||||
//outline.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
//outline.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||||
|
|
||||||
plistTableScrollPane.setViewportView(outlineView);
|
plistTableScrollPane.setViewportView(outlineView);
|
||||||
|
|
||||||
outline.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
|
outline.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
|
||||||
@ -116,6 +113,7 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
outline.setRowSelectionAllowed(false);
|
outline.setRowSelectionAllowed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* This method is called from within the constructor to initialize the form.
|
||||||
* WARNING: Do NOT modify this code. The content of this method is always
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
@ -180,8 +178,7 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
@NbBundle.Messages({"PListViewer.ExportSuccess.message=Plist file exported successfully",
|
@NbBundle.Messages({"PListViewer.ExportSuccess.message=Plist file exported successfully",
|
||||||
"PListViewer.ExportFailed.message=Plist file export failed.",
|
"PListViewer.ExportFailed.message=Plist file export failed.",})
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the Export button pressed action
|
* Handles the Export button pressed action
|
||||||
@ -257,7 +254,6 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
rootDict = null;
|
rootDict = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the given Plist file
|
* Process the given Plist file
|
||||||
*
|
*
|
||||||
@ -274,11 +270,12 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
LOGGER.log(Level.SEVERE, "Error reading bytes of plist file.", ex);
|
LOGGER.log(Level.SEVERE, "Error reading bytes of plist file.", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<PropKeyValue> plist = parsePList(plistFileBuf);
|
final List<PropKeyValue> plist;
|
||||||
|
try {
|
||||||
|
plist = parsePList(plistFileBuf);
|
||||||
new SwingWorker<Void, Void>() {
|
new SwingWorker<Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Exception {
|
protected Void doInBackground() {
|
||||||
setupTable(plist);
|
setupTable(plist);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -290,8 +287,10 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
||||||
|
} catch (IOException | PropertyListFormatException | ParseException | ParserConfigurationException | SAXException ex) {
|
||||||
|
LOGGER.log(Level.SEVERE, String.format("Error parsing plist for file (obj_id = %d)", plistFile.getId()), ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the columns in the display table
|
* Sets up the columns in the display table
|
||||||
@ -329,7 +328,6 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the given plist key/value
|
* Parses the given plist key/value
|
||||||
*/
|
*/
|
||||||
@ -342,17 +340,16 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
} else if (value instanceof NSNumber) {
|
} else if (value instanceof NSNumber) {
|
||||||
final NSNumber number = (NSNumber) value;
|
final NSNumber number = (NSNumber) value;
|
||||||
if (number.isInteger()) {
|
if (number.isInteger()) {
|
||||||
return new PropKeyValue(key, PropertyType.NUMBER, Long.valueOf(number.longValue()) );
|
return new PropKeyValue(key, PropertyType.NUMBER, number.longValue());
|
||||||
} else if (number.isBoolean()) {
|
} else if (number.isBoolean()) {
|
||||||
return new PropKeyValue(key, PropertyType.BOOLEAN, Boolean.valueOf(number.boolValue()) );
|
return new PropKeyValue(key, PropertyType.BOOLEAN, number.boolValue());
|
||||||
} else {
|
} else {
|
||||||
return new PropKeyValue(key, PropertyType.NUMBER, Float.valueOf(number.floatValue())) ;
|
return new PropKeyValue(key, PropertyType.NUMBER, number.floatValue());
|
||||||
}
|
}
|
||||||
} else if (value instanceof NSDate) {
|
} else if (value instanceof NSDate) {
|
||||||
final NSDate date = (NSDate) value;
|
final NSDate date = (NSDate) value;
|
||||||
return new PropKeyValue(key, PropertyType.DATE, date.toString());
|
return new PropKeyValue(key, PropertyType.DATE, date.toString());
|
||||||
}
|
} else if (value instanceof NSData) {
|
||||||
else if (value instanceof NSData ) {
|
|
||||||
return new PropKeyValue(key, PropertyType.DATA, Bundle.PListViewer_DataType_message());
|
return new PropKeyValue(key, PropertyType.DATA, Bundle.PListViewer_DataType_message());
|
||||||
} else if (value instanceof NSArray) {
|
} else if (value instanceof NSArray) {
|
||||||
final List<PropKeyValue> children = new ArrayList<>();
|
final List<PropKeyValue> children = new ArrayList<>();
|
||||||
@ -378,7 +375,7 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
pkv.setChildren(children.toArray(new PropKeyValue[children.size()]));
|
pkv.setChildren(children.toArray(new PropKeyValue[children.size()]));
|
||||||
return pkv;
|
return pkv;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.severe("Can't parse Plist for key = " + key + " value of type " + value.getClass());
|
LOGGER.log(Level.SEVERE, "Can''t parse Plist for key = {0} value of type {1}", new Object[]{key, value.getClass()});
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -391,10 +388,9 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
*
|
*
|
||||||
* @return list of PropKeyValue
|
* @return list of PropKeyValue
|
||||||
*/
|
*/
|
||||||
private List<PropKeyValue> parsePList(final byte[] plistbytes) {
|
private List<PropKeyValue> parsePList(final byte[] plistbytes) throws IOException, PropertyListFormatException, ParseException, ParserConfigurationException, SAXException {
|
||||||
|
|
||||||
final List<PropKeyValue> plist = new ArrayList<>();
|
final List<PropKeyValue> plist = new ArrayList<>();
|
||||||
try {
|
|
||||||
rootDict = (NSDictionary) PropertyListParser.parse(plistbytes);
|
rootDict = (NSDictionary) PropertyListParser.parse(plistbytes);
|
||||||
|
|
||||||
final String[] keys = rootDict.allKeys();
|
final String[] keys = rootDict.allKeys();
|
||||||
@ -404,10 +400,6 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
plist.add(pkv);
|
plist.add(pkv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (PropertyListFormatException | IOException | ParseException | ParserConfigurationException | SAXException ex) {
|
|
||||||
LOGGER.log(Level.SEVERE, "Failed to parse PList.", ex);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return plist;
|
return plist;
|
||||||
}
|
}
|
||||||
@ -434,7 +426,7 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
* Encapsulates a Plist property
|
* Encapsulates a Plist property
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class PropKeyValue {
|
final static class PropKeyValue {
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
private final PropertyType type;
|
private final PropertyType type;
|
||||||
@ -454,14 +446,13 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
* Copy constructor
|
* Copy constructor
|
||||||
*/
|
*/
|
||||||
PropKeyValue(PropKeyValue other) {
|
PropKeyValue(PropKeyValue other) {
|
||||||
this.key = other.key;
|
this.key = other.getKey();
|
||||||
this.type = other.type;
|
this.type = other.getType();
|
||||||
this.value = other.value;
|
this.value = other.getValue();
|
||||||
|
|
||||||
this.setChildren(other.getChildren());
|
this.setChildren(other.getChildren());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String getKey() {
|
String getKey() {
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
@ -476,6 +467,7 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of children, if any.
|
* Returns an array of children, if any.
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PropKeyValue[] getChildren() {
|
PropKeyValue[] getChildren() {
|
||||||
@ -490,10 +482,11 @@ public class PListViewer extends javax.swing.JPanel implements FileTypeViewer, E
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setChildren(final PropKeyValue... children) {
|
void setChildren(final PropKeyValue... children) {
|
||||||
this.children = children;
|
this.children = Arrays.stream(children)
|
||||||
|
.map(child -> new PropKeyValue(child))
|
||||||
|
.toArray(PropKeyValue[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
Loading…
x
Reference in New Issue
Block a user