From 3a1be13443b9a6b5f50dbec4a70f7f31a4cd2f0a Mon Sep 17 00:00:00 2001 From: nedlir Date: Fri, 25 Feb 2022 23:44:56 +0200 Subject: [PATCH] working Version --- .gitignore | 3 ++- XMLParser.java | 6 ++++- ZipFileManipulator.java | 53 ----------------------------------------- 3 files changed, 7 insertions(+), 55 deletions(-) delete mode 100644 ZipFileManipulator.java diff --git a/.gitignore b/.gitignore index 2e83dcf..08962db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ test.xml Tester.java Testing.java -tempCodeRunnerFile.java \ No newline at end of file +tempCodeRunnerFile.java +makefile \ No newline at end of file diff --git a/XMLParser.java b/XMLParser.java index 207145f..fcbf074 100644 --- a/XMLParser.java +++ b/XMLParser.java @@ -35,7 +35,11 @@ public class XMLParser { Element element = (Element) document.getElementsByTagName(TARGET_ELEMENT).item(0); // remove the node: - element.getParentNode().removeChild(element); + if (element != null) // if element == null it means there is no hashed pass + { + element.getParentNode().removeChild(element); + } + } public void writeToXMLFile(String newFilePath) throws Exception { diff --git a/ZipFileManipulator.java b/ZipFileManipulator.java deleted file mode 100644 index 8c817b3..0000000 --- a/ZipFileManipulator.java +++ /dev/null @@ -1,53 +0,0 @@ -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Enumeration; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public class ZipFileManipulator { - - private String fileName; // file which will be extracted from - private String extractionPath; // temporary path where the file will be extracted to - - public ZipFileManipulator(String fileName, String extractionPath) { - this.fileName = fileName; - this.extractionPath = extractionPath; - } - - public void extractFile(String targetFile) throws Exception { - File outputLocation = new File(extractionPath, targetFile); - - // path to the file the file will be extracted from - Path zipFile = Paths.get(fileName); - - // load zip file as filesystem - FileSystem fileSystem = FileSystems.newFileSystem(zipFile, null); - - Path source = fileSystem.getPath("ppt/" + targetFile); // location of targetFile inside the zip file - - Files.copy(source, outputLocation.toPath()); - } - - public void insertFile(String targetFile) throws Exception { - Path myFilePath = Paths.get(targetFile); - - Path zipFilePath = Paths.get(this.fileName); - try( FileSystem fs = FileSystems.newFileSystem(zipFilePath, null) ){ - Path fileInsideZipPath = fs.getPath("/ppt/" + targetFile); - Files.delete(fileInsideZipPath); - Files.copy(myFilePath, fileInsideZipPath); - - } catch (IOException e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file