From a66f0ec7589be843600699c6a332bf6abcb8e484 Mon Sep 17 00:00:00 2001 From: hmm Date: Wed, 27 Aug 2014 10:16:20 +0800 Subject: [PATCH] read record falg html from file --- .../config/httpCaptureConfig/maxq.properties | 6 +- .../config/httpCaptureConfig/recordFlag.html | 1 + .../bench4q/recorder/httpcapture/Config.java | 7 +- .../generator/HtmlDocumentParser.java | 65 +++++++++++++------ 4 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 Bench4Q-Master/src/main/resources/org/bench4q/master/config/httpCaptureConfig/recordFlag.html diff --git a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/httpCaptureConfig/maxq.properties b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/httpCaptureConfig/maxq.properties index 8b23e25a..6f37461a 100644 --- a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/httpCaptureConfig/maxq.properties +++ b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/httpCaptureConfig/maxq.properties @@ -51,4 +51,8 @@ generator.isac.timer=ConstantTimer #extra properties for a negative exponential law distribution #generator.isac.timer.random.dist=negexpo -#generator.isac.timer.random.delta=10 \ No newline at end of file +#generator.isac.timer.random.delta=10 +########################################## +#file append to record html +########################################## +record.flag.file=recordFlag.html \ No newline at end of file diff --git a/Bench4Q-Master/src/main/resources/org/bench4q/master/config/httpCaptureConfig/recordFlag.html b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/httpCaptureConfig/recordFlag.html new file mode 100644 index 00000000..94f29c88 --- /dev/null +++ b/Bench4Q-Master/src/main/resources/org/bench4q/master/config/httpCaptureConfig/recordFlag.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/Config.java b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/Config.java index 6c426e6f..55f3b182 100644 --- a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/Config.java +++ b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/Config.java @@ -54,10 +54,9 @@ public class Config { String maxqDir = System.getProperty("maxq.dir"); String pathSep = System.getProperty("file.separator"); // "\\src\\main\\resources\\org\\bench4q\\master\\config\\httpCaptureConfig\\maxq.properties"; - String propertiesFileName = System.getProperty("user.dir") + "src" - + pathSep + "main" + pathSep + "resources" + pathSep + "org" - + pathSep + "bench4q" + pathSep + "master" + pathSep + "config" - + pathSep + "httpCaptureConfig" + pathSep + "maxq.properties"; + String propertiesFileName = "org" + pathSep + "bench4q" + pathSep + + "master" + pathSep + "config" + pathSep + "httpCaptureConfig" + + pathSep + "maxq.properties"; InputStream propertiesStream = Config.class.getClassLoader() .getResourceAsStream(propertiesFileName); diff --git a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/generator/HtmlDocumentParser.java b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/generator/HtmlDocumentParser.java index e6bef172..83a529de 100644 --- a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/generator/HtmlDocumentParser.java +++ b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/generator/HtmlDocumentParser.java @@ -1,9 +1,12 @@ package org.bench4q.recorder.httpcapture.generator; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; +import org.bench4q.recorder.httpcapture.Config; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -12,24 +15,39 @@ import org.jsoup.select.Elements; public class HtmlDocumentParser { private Document document; private static Logger logger = Logger.getLogger(HtmlDocumentParser.class); - private static String recordFlagHtml = "
"; + private static String recordFlagHtml = null; + + private static void initRecordFlagHtml() { + String pathSep = System.getProperty("file.separator"); + String recordFlagFilePath = "org" + pathSep + "bench4q" + pathSep + + "master" + pathSep + "config" + pathSep + "httpCaptureConfig" + + pathSep + Config.getConfig().getProperty("record.flag.file"); + + InputStream is = HtmlDocumentParser.class.getClassLoader() + .getResourceAsStream(recordFlagFilePath); + if (is == null) + return; + StringBuffer out = new StringBuffer(); + byte[] b = new byte[4096]; + int n; + try { + while ((n = is.read(b)) != -1) { + out.append(new String(b, 0, n)); + } + recordFlagHtml = out.toString(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private static String getRecordFlagHtml() { + if (recordFlagHtml == null) { + initRecordFlagHtml(); + } + return recordFlagHtml; + } private Document getDocument() { return document; @@ -43,18 +61,23 @@ public class HtmlDocumentParser { this.setDocument(Jsoup.parse(htmlContent, baseUrl)); } - public String toString(){ + public String toString() { return this.getDocument().toString(); } + public void beginParse() { } + /** * */ - public void appendRecordFlag(){ - this.getDocument().body().append(recordFlagHtml); + public void appendRecordFlag() { + String recordFlagHtml = getRecordFlagHtml(); + if (recordFlagHtml != null) + this.getDocument().body().append(recordFlagHtml); } + public List buildParentChildrenRelationship(int parentBatchId) { List result = new ArrayList(); if (parentBatchId == -1) {