19 package org.turro.elephant.web.context;
22 import java.io.IOException;
23 import java.nio.file.Path;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
29 import java.util.TreeMap;
30 import java.util.TreeSet;
31 import java.util.logging.Level;
32 import java.util.logging.Logger;
33 import org.turro.string.Strings;
34 import org.turro.elephant.context.ElephantContext;
35 import org.turro.elephant.impl.util.FileUtil;
36 import org.turro.elephant.web.ElContext;
37 import org.turro.plugin.contacts.IContact;
45 private final Path folder;
48 private Map<String, WebLocaleResource> resources =
new TreeMap<>();
60 List<String> names =
new ArrayList<>();
61 resources.values().forEach(wlr -> {
62 String name = wlr.resourceNameForLang(lang);
63 if(!Strings.isBlank(name)) names.add(name);
69 return resources.keySet();
73 Set<String> langs =
new TreeSet<>();
74 resources.values().forEach(v -> langs.addAll(v.getLangs()));
85 return wr !=
null ?
new TreeSet(wr.
getEditables().keySet()).descendingSet() : Collections.EMPTY_SET;
88 public File
getEditable(String base, String lang, String version) {
89 if(!Strings.isBlank(version)) {
91 return wr !=
null ? wr.
getEditables().get(version) :
null;
97 resources.putIfAbsent(base, resource);
98 return resources.get(base);
101 public void saveContent(Path folder,
IContact contact, String base, String lang, String wiki, String html,
boolean autoremove) {
112 }
catch (IOException ex) {
117 private void populate() {
118 for(File file : folder.toFile().listFiles()) {
132 private WebResource webResource(String base, String lang) {
133 if(!Strings.isBlank(base) && !Strings.isBlank(lang)) {
134 WebLocaleResource wlr = resources.get(base);
static String logMsg(String msg)
static void setContent(File file, String value)
static boolean isInternal(File file)
WebResource getWebResource(String lang)
WebResource addWebResource(String lang, WebResource resource)
File getEditableFile(Path folder, IContact contact)
static WebResourceParts editable(IContact contact, String base, String locale)
File getResourceFile(Path folder)
static WebResourceParts decompose(File file)
void addFile(WebResourceParts wrp, File file)
Map< String, File > getEditables()
void cleanEditables(String current)
List< String > globalResourceNames()
Set< String > getBaseNames()
File getResource(String base, String lang)
void saveContent(Path folder, IContact contact, String base, String lang, String wiki, String html, boolean autoremove)
File getEditable(String base, String lang, String version)
WebResources(Path folder)
List< String > resourceNamesForLang(String lang)
Set< String > getVersions(String base, String lang)
WebLocaleResource addWebLocaleResource(String base, WebLocaleResource resource)