diff --git a/sample_file.chp b/sample_file.chp
new file mode 100644
index 0000000..7bfba25
--- /dev/null
+++ b/sample_file.chp
@@ -0,0 +1,5 @@
+
+
+
+ 10
+
\ No newline at end of file
diff --git a/src/eu/steffo/cleaver/errors/ChpFileError.java b/src/eu/steffo/cleaver/errors/ChpFileError.java
new file mode 100644
index 0000000..6b55adb
--- /dev/null
+++ b/src/eu/steffo/cleaver/errors/ChpFileError.java
@@ -0,0 +1,4 @@
+package eu.steffo.cleaver.errors;
+
+public class ChpFileError extends Exception {
+}
diff --git a/src/eu/steffo/cleaver/errors/ProgrammingError.java b/src/eu/steffo/cleaver/errors/ProgrammingError.java
new file mode 100644
index 0000000..9483252
--- /dev/null
+++ b/src/eu/steffo/cleaver/errors/ProgrammingError.java
@@ -0,0 +1,4 @@
+package eu.steffo.cleaver.errors;
+
+public class ProgrammingError extends Exception {
+}
diff --git a/src/eu/steffo/cleaver/gui/panels/ChopPanel.java b/src/eu/steffo/cleaver/gui/panels/ChopPanel.java
index efffb5a..e23f58e 100644
--- a/src/eu/steffo/cleaver/gui/panels/ChopPanel.java
+++ b/src/eu/steffo/cleaver/gui/panels/ChopPanel.java
@@ -1,11 +1,26 @@
package eu.steffo.cleaver.gui.panels;
+import eu.steffo.cleaver.gui.rows.CreateJobButtonRow;
+import eu.steffo.cleaver.gui.rows.option.CompressRow;
+import eu.steffo.cleaver.gui.rows.option.CryptRow;
+import eu.steffo.cleaver.gui.rows.option.SplitRow;
import eu.steffo.cleaver.logic.ChopJob;
import eu.steffo.cleaver.logic.Job;
+import eu.steffo.cleaver.logic.compress.CompressConfig;
+import eu.steffo.cleaver.logic.crypt.CryptConfig;
+import eu.steffo.cleaver.logic.split.SplitConfig;
+import javax.swing.*;
import java.awt.event.ActionListener;
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
public class ChopPanel extends CreateJobPanel {
+ protected final SplitRow splitOptionPanel;
+ protected final CryptRow cryptOptionPanel;
+ protected final CompressRow compressOptionPanel;
+ protected final CreateJobButtonRow createJobButtonPanel;
@Override
protected String getPanelText() {
@@ -19,5 +34,55 @@ public class ChopPanel extends CreateJobPanel {
public ChopPanel(ActionListener onCreateJobClick) {
super(onCreateJobClick);
+
+ this.add(Box.createVerticalStrut(8));
+
+ splitOptionPanel = new SplitRow();
+ this.add(splitOptionPanel);
+
+ this.add(Box.createVerticalStrut(8));
+
+ cryptOptionPanel = new CryptRow();
+ this.add(cryptOptionPanel);
+
+ this.add(Box.createVerticalStrut(8));
+
+ compressOptionPanel = new CompressRow();
+ this.add(compressOptionPanel);
+
+ this.add(Box.createVerticalStrut(8));
+
+ createJobButtonPanel = new CreateJobButtonRow(onCreateJobClick);
+ this.add(createJobButtonPanel);
+
+ this.add(Box.createVerticalStrut(8));
+ }
+
+ public void createAndAddJobs(ArrayList jobs) {
+ if(fileSelectPanel.getSelectedFiles().length == 0) {
+ JOptionPane.showMessageDialog(null, "No files selected.", "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ for(File file : fileSelectPanel.getSelectedFiles()) {
+
+ SplitConfig sc;
+ try {
+ sc = splitOptionPanel.getSplitConfig();
+ } catch (NumberFormatException exc) {
+ JOptionPane.showMessageDialog(null, "Invalid value in the Split fields.", "Error", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+
+ CryptConfig cc = cryptOptionPanel.getCryptConfig();
+
+ CompressConfig zc = compressOptionPanel.getCompressConfig();
+
+ try {
+ Job job = getJobClass().getConstructor(File.class, SplitConfig.class, CryptConfig.class, CompressConfig.class).newInstance(file, sc, cc, zc);
+ jobs.add(job);
+ } catch (InstantiationException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
+ JOptionPane.showMessageDialog(null, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ fileSelectPanel.clearSelectedFiles();
}
}
diff --git a/src/eu/steffo/cleaver/gui/panels/CreateJobPanel.java b/src/eu/steffo/cleaver/gui/panels/CreateJobPanel.java
index c9f0ef0..83ff717 100644
--- a/src/eu/steffo/cleaver/gui/panels/CreateJobPanel.java
+++ b/src/eu/steffo/cleaver/gui/panels/CreateJobPanel.java
@@ -1,27 +1,15 @@
package eu.steffo.cleaver.gui.panels;
-import eu.steffo.cleaver.gui.rows.CreateJobButtonRow;
import eu.steffo.cleaver.gui.rows.FileSelectRow;
import eu.steffo.cleaver.gui.rows.TitleRow;
-import eu.steffo.cleaver.gui.rows.option.*;
import eu.steffo.cleaver.logic.Job;
-import eu.steffo.cleaver.logic.compress.CompressConfig;
-import eu.steffo.cleaver.logic.crypt.CryptConfig;
-import eu.steffo.cleaver.logic.split.SplitConfig;
import javax.swing.*;
import java.awt.event.ActionListener;
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
public abstract class CreateJobPanel extends JPanel {
protected final TitleRow titlePanel;
protected final FileSelectRow fileSelectPanel;
- protected final SplitRow splitOptionPanel;
- protected final CryptRow cryptOptionPanel;
- protected final CompressRow compressOptionPanel;
- protected final CreateJobButtonRow createJobButtonPanel;
protected abstract String getPanelText();
@@ -42,55 +30,5 @@ public abstract class CreateJobPanel extends JPanel {
fileSelectPanel = new FileSelectRow();
this.add(fileSelectPanel);
-
- this.add(Box.createVerticalStrut(8));
-
- splitOptionPanel = new SplitRow();
- this.add(splitOptionPanel);
-
- this.add(Box.createVerticalStrut(8));
-
- cryptOptionPanel = new CryptRow();
- this.add(cryptOptionPanel);
-
- this.add(Box.createVerticalStrut(8));
-
- compressOptionPanel = new CompressRow();
- this.add(compressOptionPanel);
-
- this.add(Box.createVerticalStrut(8));
-
- createJobButtonPanel = new CreateJobButtonRow(onCreateJobClick);
- this.add(createJobButtonPanel);
-
- this.add(Box.createVerticalStrut(8));
- }
-
- public void createAndAddJobs(ArrayList jobs) {
- if(fileSelectPanel.getSelectedFiles().length == 0) {
- JOptionPane.showMessageDialog(null, "No files selected.", "Error", JOptionPane.ERROR_MESSAGE);
- }
- for(File file : fileSelectPanel.getSelectedFiles()) {
-
- SplitConfig sc;
- try {
- sc = splitOptionPanel.getSplitConfig();
- } catch (NumberFormatException exc) {
- JOptionPane.showMessageDialog(null, "Invalid value in the Split fields.", "Error", JOptionPane.ERROR_MESSAGE);
- return;
- }
-
- CryptConfig cc = cryptOptionPanel.getCryptConfig();
-
- CompressConfig zc = compressOptionPanel.getCompressConfig();
-
- try {
- Job job = getJobClass().getConstructor(File.class, SplitConfig.class, CryptConfig.class, CompressConfig.class).newInstance(file, sc, cc, zc);
- jobs.add(job);
- } catch (InstantiationException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
- JOptionPane.showMessageDialog(null, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- fileSelectPanel.clearSelectedFiles();
}
}
diff --git a/src/eu/steffo/cleaver/gui/panels/StitchPanel.java b/src/eu/steffo/cleaver/gui/panels/StitchPanel.java
index 5141d6f..04a2cc7 100644
--- a/src/eu/steffo/cleaver/gui/panels/StitchPanel.java
+++ b/src/eu/steffo/cleaver/gui/panels/StitchPanel.java
@@ -1,11 +1,19 @@
package eu.steffo.cleaver.gui.panels;
+import eu.steffo.cleaver.gui.rows.CreateJobButtonRow;
+import eu.steffo.cleaver.gui.rows.option.CryptRow;
import eu.steffo.cleaver.logic.Job;
import eu.steffo.cleaver.logic.StitchJob;
+import javax.swing.*;
+import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.ArrayList;
public class StitchPanel extends CreateJobPanel {
+ protected final CreateJobButtonRow createJobButtonPanel;
+ protected final CryptRow cryptOptionPanel;
@Override
protected String getPanelText() {
@@ -19,8 +27,30 @@ public class StitchPanel extends CreateJobPanel {
public StitchPanel(ActionListener onCreateJobClick) {
super(onCreateJobClick);
- this.splitOptionPanel.setEditable(false);
- this.cryptOptionPanel.setEditable(false);
- this.compressOptionPanel.setEditable(false);
+
+ this.add(Box.createVerticalStrut(8));
+ this.add(Box.createVerticalStrut(24));
+ this.add(Box.createVerticalStrut(8));
+
+ cryptOptionPanel = new CryptRow();
+ this.add(cryptOptionPanel);
+
+ this.add(Box.createVerticalStrut(8));
+ this.add(Box.createVerticalStrut(24));
+ this.add(Box.createVerticalStrut(8));
+
+ createJobButtonPanel = new CreateJobButtonRow(onCreateJobClick);
+ this.add(createJobButtonPanel);
+
+ this.add(Box.createVerticalStrut(8));
+
+ fileSelectPanel.setFileFilter(new FileNameExtensionFilter("Cleaver Metadata (*.chp)", "chp"));
+ }
+
+ public void createAndAddJobs(ArrayList jobs) {
+ File[] files = fileSelectPanel.getSelectedFiles();
+ for(File file : files) {
+ job
+ }
}
}
diff --git a/src/eu/steffo/cleaver/gui/rows/FileSelectRow.java b/src/eu/steffo/cleaver/gui/rows/FileSelectRow.java
index fa2fc35..b2b8261 100644
--- a/src/eu/steffo/cleaver/gui/rows/FileSelectRow.java
+++ b/src/eu/steffo/cleaver/gui/rows/FileSelectRow.java
@@ -4,6 +4,7 @@ import eu.steffo.cleaver.gui.rows.Row;
import java.awt.*;
import javax.swing.*;
+import javax.swing.filechooser.FileFilter;
import java.io.File;
public class FileSelectRow extends Row {
@@ -56,4 +57,8 @@ public class FileSelectRow extends Row {
fileChooser.setSelectedFiles(new File[0]);
update();
}
+
+ public void setFileFilter(FileFilter filter) {
+ fileChooser.setFileFilter(filter);
+ }
}
diff --git a/src/eu/steffo/cleaver/logic/ChopJob.java b/src/eu/steffo/cleaver/logic/ChopJob.java
index b6b8340..b5610d3 100644
--- a/src/eu/steffo/cleaver/logic/ChopJob.java
+++ b/src/eu/steffo/cleaver/logic/ChopJob.java
@@ -11,9 +11,15 @@ import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
public class ChopJob extends Job {
+ protected final SplitConfig splitConfig;
+ protected final CryptConfig cryptConfig;
+ protected final CompressConfig compressConfig;
public ChopJob(File file, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) {
- super(file, splitConfig, cryptConfig, compressConfig);
+ super(file);
+ this.splitConfig = splitConfig;
+ this.cryptConfig = cryptConfig;
+ this.compressConfig = compressConfig;
}
@Override
@@ -37,4 +43,16 @@ public class ChopJob extends Job {
// TODO: end with inputStream.transferTo(outputStream);
}
+
+ public SplitConfig getSplitConfig() {
+ return splitConfig;
+ }
+
+ public CryptConfig getCryptConfig() {
+ return cryptConfig;
+ }
+
+ public CompressConfig getCompressConfig() {
+ return compressConfig;
+ }
}
diff --git a/src/eu/steffo/cleaver/logic/Job.java b/src/eu/steffo/cleaver/logic/Job.java
index 6c38b54..04ded10 100644
--- a/src/eu/steffo/cleaver/logic/Job.java
+++ b/src/eu/steffo/cleaver/logic/Job.java
@@ -10,16 +10,10 @@ import eu.steffo.cleaver.logic.split.SplitConfig;
public abstract class Job extends Thread {
protected final File file;
- protected final SplitConfig splitConfig;
- protected final CryptConfig cryptConfig;
- protected final CompressConfig compressConfig;
protected Progress progress;
- public Job(File file, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) {
+ public Job(File file) {
this.file = file;
- this.splitConfig = splitConfig;
- this.cryptConfig = cryptConfig;
- this.compressConfig = compressConfig;
this.progress = new NotStartedProgress();
}
@@ -29,18 +23,6 @@ public abstract class Job extends Thread {
return file;
}
- public SplitConfig getSplitConfig() {
- return splitConfig;
- }
-
- public CryptConfig getCryptConfig() {
- return cryptConfig;
- }
-
- public CompressConfig getCompressConfig() {
- return compressConfig;
- }
-
public Progress getProgress() {
return progress;
}
diff --git a/src/eu/steffo/cleaver/logic/StitchJob.java b/src/eu/steffo/cleaver/logic/StitchJob.java
index b3c20bd..161ac5d 100644
--- a/src/eu/steffo/cleaver/logic/StitchJob.java
+++ b/src/eu/steffo/cleaver/logic/StitchJob.java
@@ -1,15 +1,82 @@
package eu.steffo.cleaver.logic;
+import eu.steffo.cleaver.errors.ChpFileError;
+import eu.steffo.cleaver.errors.ProgrammingError;
import eu.steffo.cleaver.logic.compress.CompressConfig;
import eu.steffo.cleaver.logic.crypt.CryptConfig;
+import eu.steffo.cleaver.logic.split.SplitByPartsConfig;
+import eu.steffo.cleaver.logic.split.SplitBySizeConfig;
import eu.steffo.cleaver.logic.split.SplitConfig;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
public class StitchJob extends Job {
+ protected final SplitConfig splitConfig;
+ protected final CryptConfig cryptConfig;
+ protected final CompressConfig compressConfig;
- public StitchJob(File file, SplitConfig splitConfig, CryptConfig cryptConfig, CompressConfig compressConfig) {
- super(file, splitConfig, cryptConfig, compressConfig);
+ public StitchJob(File file, String cryptKey) throws ChpFileError, ProgrammingError {
+ super(file);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = null;
+ try {
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ throw new ProgrammingError();
+ }
+ Document doc = null;
+ try {
+ doc = builder.parse(file);
+ } catch (SAXException | IOException e) {
+ throw new ProgrammingError();
+ }
+ Element root = doc.getDocumentElement();
+ NodeList splits = root.getElementsByTagName("Split");
+ NodeList crypts = root.getElementsByTagName("Crypt");
+ NodeList compresses = root.getElementsByTagName("Compress");
+ Node splitNode = splits.item(0);
+ Node cryptNode = crypts.item(0);
+ Node compressNode = compresses.item(0);
+ if(splitNode == null) {
+ splitConfig = null;
+ }
+ else {
+ Element split = (Element)splitNode;
+ String splitMode = split.getAttribute("mode");
+ if(splitMode.equals("by-parts")) {
+ splitConfig = new SplitByPartsConfig(Integer.parseInt(split.getTextContent()));
+ }
+ else if(splitMode.equals("by-size")) {
+ splitConfig = new SplitBySizeConfig(Integer.parseInt(split.getTextContent()));
+ }
+ else {
+ throw new ChpFileError();
+ }
+ }
+ if(cryptNode == null) {
+ cryptConfig = null;
+ }
+ else {
+ cryptConfig = new CryptConfig(cryptKey);
+ }
+ if(compressNode == null) {
+ compressConfig = null;
+ }
+ else {
+ compressConfig = new CompressConfig();
+ }
}
@Override
@@ -21,4 +88,16 @@ public class StitchJob extends Job {
public void run() {
}
+
+ public SplitConfig getSplitConfig() {
+ return splitConfig;
+ }
+
+ public CryptConfig getCryptConfig() {
+ return cryptConfig;
+ }
+
+ public CompressConfig getCompressConfig() {
+ return compressConfig;
+ }
}