Skip to content

Commit b61b6dc

Browse files
committed
added report ID suggestions
1 parent b6fb47d commit b61b6dc

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

root/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<extension version="1">
22
<name>ReportFTP</name>
33
<description>Can be configured to send scheduled reports to an FTP server.</description>
4-
<version>0.1.0</version>
4+
<version>0.1.1</version>
55
<vendor>Automatic Controls Equipment Systems, Inc.</vendor>
66
</extension>

src/aces/webctrl/ftp/core/ConfigReader.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ public class ConfigReader {
1010
private char[] arr;
1111
private int i = 0;
1212
private int len;
13+
public ConfigReader(StringBuilder sb, char[] arr){
14+
this.arr = arr;
15+
len = arr.length;
16+
skipUntil("label");
17+
String ID = nextToken();
18+
if (ID.length()>0){
19+
sb.append("<option value=\"").append(Utility.escapeHTML(ID)).append("\">\n");
20+
}
21+
}
1322
public ConfigReader(char[] arr){
1423
String ID, local, remote;
1524
this.arr = arr;

src/aces/webctrl/ftp/core/Servers.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,22 @@ public class Servers {
2525
private volatile static Path dataFile;
2626
/** Contains a list of {@code Server} objects. */
2727
private final static ArrayList<Server> servers = new ArrayList<Server>();
28+
/** Controls access to report config files. */
29+
public final static Object configReadLock = new Object();
2830
/**
2931
* Analyzes current scheduled reports, and sends them to the appropriate servers.
3032
*/
3133
public static void run(){
3234
if (servers.size()>0 && ftp.compareAndSet(false,true)){
3335
try{
34-
try(
35-
DirectoryStream<Path> stream = Files.newDirectoryStream(Initializer.configs);
36-
){
37-
for (Path config:stream){
38-
if (Files.isReadable(config)){
39-
new ConfigReader(java.nio.charset.StandardCharsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(config))).array());
36+
synchronized (configReadLock){
37+
try(
38+
DirectoryStream<Path> stream = Files.newDirectoryStream(Initializer.configs);
39+
){
40+
for (Path config:stream){
41+
if (Files.isReadable(config)){
42+
new ConfigReader(java.nio.charset.StandardCharsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(config))).array());
43+
}
4044
}
4145
}
4246
}

src/aces/webctrl/ftp/web/ReportPage.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ <h1>Report List For __SERVER__</h1>
129129
<th>Actions</th>
130130
</tr>
131131
<tr id="newRow">
132-
<td><input id="newLabel" type="text" class="e c" oninput="resize(this)"></td>
132+
<td><input id="newLabel" list="reportIDs" class="e c" oninput="resize(this)"></td>
133133
<td><input id="newFolder" type="text" class="e c" oninput="resize(this)"></td>
134134
<td><button class="e" onclick="submitNew(this)">Add New Report</button></td>
135135
</tr>
@@ -142,6 +142,9 @@ <h3 class="e">Status: <span id="statusText" style="color:red">Idle</span></h3>
142142
<br>
143143
<a href="https://github.com/automatic-controls/report-ftp-addon/blob/main/README.md" target="_blank">Documentation</a>
144144
<span id="hiddenSpan" style="min-width:14em;color:black;display:inline-block;position:absolute;left:-100000px"></span>
145+
<datalist id="reportIDs">
146+
<!--__REPORTS__-->
147+
</datalist>
145148
</div>
146149
<script>
147150
resize(newLabel);

src/aces/webctrl/ftp/web/ReportPage.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.io.*;
99
import javax.servlet.*;
1010
import javax.servlet.http.*;
11+
import java.nio.*;
12+
import java.nio.file.*;
1113
public class ReportPage extends HttpServlet {
1214
private volatile static String html = null;
1315
@Override public void init() throws ServletException {
@@ -53,8 +55,22 @@ public boolean test(Report r){
5355
return false;
5456
}
5557
});
58+
String str = html.replace("__ID__", ID).replace("__SERVER__", s.getHost()).replace("//__INIT_SCRIPT__", sb.toString());
59+
sb.setLength(0);
60+
synchronized (Servers.configReadLock){
61+
try(
62+
DirectoryStream<Path> stream = Files.newDirectoryStream(Initializer.configs);
63+
){
64+
for (Path config:stream){
65+
if (Files.isReadable(config)){
66+
new ConfigReader(sb, java.nio.charset.StandardCharsets.UTF_8.decode(ByteBuffer.wrap(Files.readAllBytes(config))).array());
67+
}
68+
}
69+
}catch(Throwable t){}
70+
}
71+
str = str.replace("<!--__REPORTS__-->", sb.toString());
5672
res.setContentType("text/html");
57-
res.getWriter().print(html.replace("__ID__", ID).replace("__SERVER__", s.getHost()).replace("//__INIT_SCRIPT__", sb.toString()));
73+
res.getWriter().print(str);
5874
}else{
5975
switch (type){
6076
case "clear":{

0 commit comments

Comments
 (0)