Skip to content

Commit c7f85a4

Browse files
author
DABURON Vincent
committed
Version 1.4 Add Table Of Contents and new property add_toc (default value : true)
1 parent cf814a7 commit c7f85a4

4 files changed

Lines changed: 97 additions & 19 deletions

File tree

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,37 @@ The types of files searched are:
88
* gz
99
* zip
1010
* log
11+
* xlsx
12+
* xls
1113
* gif
1214
* png
1315
* bmp
1416
* jpg
1517
* jpeg
1618
* html
1719

18-
The link is "<a ref=" relative for files of type: csv, jtl, xml, gz, zip, log (to download it)
20+
The link is "<a ref=" relative for files of type: csv, jtl, xml, gz, zip, log, xlsx, xls (to download it)
1921

2022
The link is "<img src=" relative for files of type: gif, png, bmp, jpg, jpeg (to view it)
2123

22-
For html files, the content is read and directly included in the generated html page (blocks of html tables created with the csv-report-to-html tool from csv file)
24+
For html files, the content is read and directly included in the generated html page (blocks of html tables created with the csv-report-to-html tool from csv file). This HTML include file must not have elements &lt;html&gt; and &lt;/html&gt;.
2325

24-
sorting algorithm : Filenames with less directory deep are before file this directory
26+
Sorting algorithm : Ascending alphabetical sorting but filenames with less directory deep are before file this directory
2527
<pre>
2628
Example : z.img < dir/x.img < dir/y.img < aa/bb/c.img < aa/bb/d.img
2729
Deep : no dir, dir 1 deep level, dir 2 deep level
2830
</pre>
2931

32+
## Default values
33+
- image_width = 1024 (pixels)
34+
- add_toc = true (add Table Of Contents)
35+
36+
And the charset to read could be set with -Dfile.encoding=&lt;charset encoding&gt; (e.g: UFT-8)
37+
38+
Change this values with system properties :
39+
- -Dimage_width=new_int_value (e.g: 1280)
40+
- -Dadd_toc=false (e.g: true or false)
41+
3042
## License
3143
See the LICENSE file Apache 2 [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
3244

@@ -42,22 +54,23 @@ The maven groupId, artifactId and version, this plugin is in the **Maven Central
4254
```xml
4355
<groupId>io.github.vdaburon</groupId>
4456
<artifactId>create-html-for-files-in-directory</artifactId>
45-
<version>1.2</version>
57+
<version>1.4</version>
4658
```
4759
Just include the plugin in your `pom.xml` and execute `mvn verify` <br>
48-
or individual launch `mvn -Dgraph_width=950 exec:java@create_html_page_for_files_in_directory`
60+
or individual launch `mvn -Dimage_width=950 -Dadd_toc=false exec:java@create_html_page_for_files_in_directory`
4961

5062
```xml
5163
<project>
5264
<properties>
53-
<graph_width>1024</graph_width>
65+
<image_width>1024</image_width>
66+
<add_toc>true</add_toc>
5467
</properties>
5568

5669
<dependencies>
5770
<dependency>
5871
<groupId>io.github.vdaburon</groupId>
5972
<artifactId>create-html-for-files-in-directory</artifactId>
60-
<version>1.2</version>
73+
<version>1.4</version>
6174
</dependency>
6275
</dependencies>
6376

@@ -83,7 +96,11 @@ or individual launch `mvn -Dgraph_width=950 exec:java@create_html_page_for_files
8396
<systemProperties>
8497
<systemProperty>
8598
<key>image_width</key>
86-
<value>${graph_width}</value>
99+
<value>${image_width}</value>
100+
</systemProperty>
101+
<systemProperty>
102+
<key>add_toc</key>
103+
<value>${add_toc}</value>
87104
</systemProperty>
88105
</systemProperties>
89106
</configuration>
@@ -98,19 +115,23 @@ or individual launch `mvn -Dgraph_width=950 exec:java@create_html_page_for_files
98115
## Simple jar tool
99116
This tool is a java jar, so it's could be use as simple jar (look at [Release](https://github.com/vdaburon/CreateHtmlForFilesInDirectory/releases) to download jar file)
100117
<pre>
101-
java -Dimage_width=900 -cp create-html-for-files-in-directory-&lt;version&gt;.jar io.github.vdaburon.jmeter.utils.HtmlGraphVisualizationGenerator jmeter/results index.html
118+
java -Dimage_width=900 -Dadd_toc=true -cp create-html-for-files-in-directory-&lt;version&gt;.jar io.github.vdaburon.jmeter.utils.HtmlGraphVisualizationGenerator jmeter/results index.html
102119
or
103-
java -Dimage_width=900 -jar create-html-for-files-in-directory-&lt;version&gt;-jar-with-dependencies.jar jmeter/results index.html
120+
java -Dimage_width=900 -Dadd_toc=true -jar create-html-for-files-in-directory-&lt;version&gt;-jar-with-dependencies.jar jmeter/results index.html
104121
</pre>
105122

106123
## Link to others projects
107-
Usally this plugin is use with [jmeter-graph-tool-maven-plugin](https://github.com/vdaburon/jmeter-graph-tool-maven-plugin)<br>
124+
Usually this plugin is use with [jmeter-graph-tool-maven-plugin](https://github.com/vdaburon/jmeter-graph-tool-maven-plugin)<br>
108125
and this plugin [csv-report-to-html](https://github.com/vdaburon/JMReportCsvToHtml)
109126
1) The **jmeter-graph-tool-maven-plugin** create the report csv files and graphs
110127
2) The **csv-report-to-html** create the **html table report** from the csv file
111128
3) The **create-html-for-files-in-directory** create a page html this links to images and files in a directory to show and add links
112129

113130
## Versions
131+
Version 1.4 date 2025-04-26, add Table Of Contents and new property add_toc (default value : true)
132+
133+
Version 1.3 date 2023-05-10, Add extensions xlsx and xls (Excel file)
134+
114135
Version 1.2 add the file size after the "&lt;a ref=" link
115136

116137
Version 1.1 add link (a href) to jtl and xml files

doc/images/html_extract.png

89.1 KB
Loading

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.vdaburon</groupId>
88
<artifactId>create-html-for-files-in-directory</artifactId>
9-
<version>1.2</version>
9+
<version>1.4</version>
1010
<packaging>jar</packaging>
1111
<name>Create html page for files in directory</name>
1212
<description>A tool that creates an html page for files in the directory to display graphics and link files</description>
@@ -143,7 +143,7 @@
143143
<plugin>
144144
<groupId>org.sonatype.plugins</groupId>
145145
<artifactId>nexus-staging-maven-plugin</artifactId>
146-
<version>1.6.13</version>
146+
<version>1.7.0</version>
147147
<extensions>true</extensions>
148148
<configuration>
149149
<serverId>ossrh</serverId>

src/main/java/io/github/vdaburon/jmeter/utils/HtmlGraphVisualizationGenerator.java

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.github.vdaburon.jmeter.utils;
22

3+
import java.io.BufferedReader;
34
import java.io.BufferedWriter;
45
import java.io.File;
6+
import java.io.FileReader;
57
import java.io.FileWriter;
68
import java.io.IOException;
79
import java.nio.file.Files;
@@ -22,12 +24,14 @@
2224
public class HtmlGraphVisualizationGenerator {
2325
// CRLF ou LF ou CR
2426
public static final String LINE_SEP = System.getProperty("line.separator");
27+
28+
public static final String K_TABLE_CONTENTS = "@@TABLE_OF_CONTENTS@@";
2529

2630
public static void main(String[] args) {
2731

2832
if (args.length != 2) {
2933
System.err.println("Usage HtmlGraphVisualizationGenerator dirWithFiles fileOutHtml");
30-
System.err.println("E.g. java -Dimage_width=1024 -jar create-html-for-files-in-directory-<version>.jar c:/jmeter/dir_results index.html");
34+
System.err.println("E.g. java -Dimage_width=1024-Dadd_toc=true -jar create-html-for-files-in-directory-<version>.jar c:/jmeter/dir_results index.html");
3135
System.exit(1);
3236
}
3337
String dirWithFiles = args[0];
@@ -44,6 +48,12 @@ public static void main(String[] args) {
4448
}
4549
}
4650

51+
String sIsAddToc = System.getProperty("add_toc");
52+
boolean isAddToc = true;
53+
if (sIsAddToc != null) {
54+
isAddToc = Boolean.parseBoolean(sIsAddToc);
55+
}
56+
4757
File fDirWithFiles = new File(dirWithFiles);
4858
File fileIndex = new File(dirWithFiles + "/" + fileOutHtml);
4959
if (fileIndex.exists()) {
@@ -52,6 +62,7 @@ public static void main(String[] args) {
5262
}
5363

5464
Object[] tabFiles = listFileOrderByName(fDirWithFiles);
65+
ArrayList listTitles = new ArrayList<>();
5566

5667
BufferedWriter out = null;
5768
try {
@@ -78,21 +89,32 @@ public static void main(String[] args) {
7889

7990
out.write("<h1> Generated date " + sDate + "</h1><br/>");
8091
out.write(LINE_SEP);
81-
92+
93+
if (isAddToc) {
94+
out.write(K_TABLE_CONTENTS + "<br/>");
95+
out.write(LINE_SEP);
96+
System.out.println("With a Table Of Contents");
97+
}
98+
8299
for (int i = 0; i < tabFiles.length; i++) {
83100
File f = (File) tabFiles[i];
84101

85102
String name = f.getName().toLowerCase();
86103
if (name.endsWith("csv") || name.endsWith("jtl") || name.endsWith("xml") ||name.endsWith("gz") || name.endsWith("zip") || name.endsWith("log")
87-
|| name.endsWith("gif") || name.endsWith("png") || name.endsWith("bmp") || name.endsWith("jpg") || name.endsWith("jpeg") || name.endsWith("html")) {
104+
|| name.endsWith("xlsx") || name.endsWith("xls")
105+
|| name.endsWith("gif") || name.endsWith("png") || name.endsWith("bmp") || name.endsWith("jpg") || name.endsWith("jpeg")
106+
|| name.endsWith("html")) {
88107

89108
// folderRead = c:\dir1\dir2\dirIn, f = c:\dir1\dir2\dirIn\logo.gif => nameRelative = logo.gif (remove the folderRead path)
90109
String nameRelative = f.getCanonicalPath().substring(fDirWithFiles.getCanonicalPath().length() + 1);
91-
110+
out.write("<p><a name=\"" + i + "\"></a></p>");
111+
out.write(LINE_SEP);
92112
out.write("<h2>" + nameRelative + "</h2><br/>");
93113
out.write(LINE_SEP);
114+
listTitles.add(nameRelative);
94115

95-
if (name.endsWith("csv") || name.endsWith("jtl") || name.endsWith("xml") ||name.endsWith("gz") || name.endsWith("zip") || name.endsWith("log")) {
116+
if (name.endsWith("csv") || name.endsWith("jtl") || name.endsWith("xml") ||name.endsWith("gz") || name.endsWith("zip") || name.endsWith("log") ||
117+
name.endsWith("xlsx") || name.endsWith("xls")) {
96118
long lengthBytes = f.length();
97119
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
98120
symbols.setGroupingSeparator(' ');
@@ -136,7 +158,15 @@ public static void main(String[] args) {
136158
}
137159
}
138160
}
139-
}
161+
162+
if (isAddToc) {
163+
try {
164+
replaceTableOfContentsByTitle(fileIndex, listTitles);
165+
} catch (IOException e) {
166+
System.out.println(e.getMessage());
167+
}
168+
}
169+
}
140170

141171
@SuppressWarnings("unchecked")
142172
public static Object[] listFileOrderByName(File folderRead) {
@@ -174,5 +204,32 @@ public static void findAllFilesInDirectory(File directory, List<File> files) {
174204
}
175205
}
176206
}
207+
208+
public static void replaceTableOfContentsByTitle(File fileIndex, ArrayList <String> listTitles) throws IOException {
209+
String allIndex = readAllFileToString(fileIndex.getCanonicalPath());
210+
StringBuffer sbTitles = new StringBuffer(2048);
211+
sbTitles.append("<h2>Table Of Contents</h2>" + LINE_SEP);
212+
sbTitles.append("<h4>" + LINE_SEP);
213+
for (int i = 0; i < listTitles.size(); i++) {
214+
sbTitles.append("<a href=\"#" + i + "\">");
215+
sbTitles.append(listTitles.get(i));
216+
sbTitles.append("</a></br>" + LINE_SEP);
217+
}
218+
int position = allIndex.indexOf(K_TABLE_CONTENTS);
219+
StringBuffer sbNewIndex = new StringBuffer(128 * 1024);
220+
if (position > 1) {
221+
sbNewIndex.append(allIndex.substring(0,position));
222+
sbNewIndex.append(sbTitles.toString());
223+
sbNewIndex.append(allIndex.substring((position + K_TABLE_CONTENTS.length()), allIndex.length()));
224+
}
225+
sbTitles.append("</h4>" + LINE_SEP);
226+
227+
if (fileIndex.exists()) {
228+
fileIndex.delete();
229+
}
230+
BufferedWriter out = new BufferedWriter(new FileWriter(fileIndex));
231+
out.write(sbNewIndex.toString());
232+
out.close();
233+
}
177234
}
178235

0 commit comments

Comments
 (0)