19 package org.turro.documentation;
22 import java.io.IOException;
23 import java.io.Writer;
24 import java.util.Collection;
25 import java.util.SortedSet;
26 import java.util.TreeSet;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.impl.util.FileUtil;
31 import org.turro.file.FileWatch;
32 import org.turro.lock.Initializer;
33 import org.turro.reflection.JSONSerializer;
42 return stream().filter(dd -> dd.getName().equals(name)).findFirst().orElse(
null);
45 public SortedSet<String>
names() {
46 return new TreeSet(stream().map(dd -> dd.getName()).toList());
59 private static final Initializer<DocumentDefinitions> INIT =
new Initializer<>();
60 private static final FileWatch watch =
new FileWatch(definitionsFile());
63 return INIT.
instance(() -> !watch.isNewer(), () ->
load());
70 private static final String DOCUMENTATION_FILE =
"/WEB-INF/elephant/conf/documentation.json";
74 if(watch.exists())
try {
76 JSONSerializer ser =
new JSONSerializer(
true);
78 }
catch (IOException ex) {
81 if(definitions ==
null) {
90 JSONSerializer ser =
new JSONSerializer(definitions,
true);
91 writer.write(ser.toJson());
92 }
catch (IOException ex) {
93 Logger.getLogger(
DocumentDefinitions.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
97 private static File definitionsFile() {
98 return new File(ElephantContext.getRealPath(DOCUMENTATION_FILE));
static DocumentDefinitions instance()
static DocumentDefinitions load()
DocumentDefinitions filtered(String root)
SortedSet< String > names()
static String logMsg(String msg)
static OutputStreamWriter getFileWriter(String folder, String file)
static String getContent(File file)