Also extract html files
(cherry picked from commit 2933b79)
This commit is contained in:
@ -2,13 +2,18 @@ package org.owasp.webgoat.plugins;
|
||||
|
||||
import org.owasp.webgoat.lessons.AbstractLesson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Plugin {
|
||||
|
||||
private final Class<AbstractLesson> lesson;
|
||||
private final String lessonPlanHtml;
|
||||
private final String lessonSolutionHtml;
|
||||
private final Path pluginDirectory;
|
||||
|
||||
public static class Builder {
|
||||
|
||||
@ -36,19 +41,23 @@ public class Plugin {
|
||||
}
|
||||
|
||||
public Plugin build() {
|
||||
return new Plugin(this.lesson, null, null);
|
||||
return new Plugin(this.lesson, pluginDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
public Plugin(Class<AbstractLesson> lesson, String lessonPlanHtml, String lessonSolutionHtml) {
|
||||
public Plugin(Class<AbstractLesson> lesson, Path pluginDirectory) {
|
||||
this.lesson = lesson;
|
||||
this.lessonPlanHtml = lessonPlanHtml;
|
||||
this.lessonSolutionHtml = lessonSolutionHtml;
|
||||
this.pluginDirectory = pluginDirectory;
|
||||
}
|
||||
|
||||
|
||||
public String getLessonPlanHtml() {
|
||||
return lessonPlanHtml;
|
||||
Path lesson_plans = this.pluginDirectory.resolve("lesson_plans");
|
||||
try {
|
||||
Files.readAllLines(lesson_plans.resolve(this.lesson.getSimpleName() + ".html"), Charset.defaultCharset());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return lesson_plans.resolve(this.lesson.getSimpleName() + ".html").toFile().toString();
|
||||
}
|
||||
|
||||
public Class<AbstractLesson> getLesson() {
|
||||
@ -56,6 +65,17 @@ public class Plugin {
|
||||
}
|
||||
|
||||
public String getLessonSolutionHtml() {
|
||||
return lessonSolutionHtml;
|
||||
return null;
|
||||
//return lessonSolutionHtml;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Path tempDir = Files.createTempDirectory("tempfiles");
|
||||
|
||||
Path tempFile = Files.createTempFile(tempDir, "tempfiles", ".tmp");
|
||||
List<String> lines = Arrays.asList("Line1", "Line2");
|
||||
Files.write(tempFile, lines, Charset.defaultCharset(), StandardOpenOption.WRITE);
|
||||
|
||||
System.out.printf("Wrote text to temporary file %s%n", tempFile.toString());
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,15 @@ import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Extract the zip file and place the files in a temp directory
|
||||
*
|
||||
* TODO: should only do the extraction of the zip file return should be the base directory of the extracted
|
||||
* plugin. The PluginLoader should take care of the loading
|
||||
*
|
||||
*/
|
||||
public class PluginExtractor {
|
||||
|
||||
@ -46,7 +49,7 @@ public class PluginExtractor {
|
||||
Files.copy(file, bos);
|
||||
pluginBuilder.loadClass(file.toString(), bos.toByteArray());
|
||||
}
|
||||
Files.copy(file, tempDirectory, StandardCopyOption.REPLACE_EXISTING);
|
||||
// Files.copy(file, tempDirectory.resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user