19 package org.turro.elephant.web.context;
22 import java.io.FileReader;
23 import java.io.FileWriter;
24 import java.io.IOException;
25 import java.io.Reader;
26 import java.io.Writer;
27 import java.nio.file.Path;
30 import java.util.TreeMap;
31 import java.util.TreeSet;
32 import java.util.logging.Level;
33 import java.util.logging.Logger;
34 import org.turro.string.Strings;
35 import org.turro.configuration.JsonConfiguration;
36 import org.turro.elephant.context.ElephantContext;
37 import org.turro.elephant.context.IElement;
38 import org.turro.i18n.I_;
56 private Set<String> langs =
new TreeSet<>();
57 private Map<String, String> names =
new TreeMap<>();
58 private String i18nKey, order, role, redirect, target, image, webTag;
65 return showInNavigators;
69 this.showInNavigators = showInNavigators;
77 this.showAlways = showAlways;
81 return traversalNavigation;
85 this.traversalNavigation = traversalNavigation;
93 this.noIndex = noIndex;
101 this.noFollow = noFollow;
109 this.printContext = printContext;
117 this.printVersion = printVersion;
121 return controlVersion;
125 this.controlVersion = controlVersion;
145 if(!Strings.isBlank(i18nKey)) {
146 return I_.
get(i18nKey);
150 "_" +
I_.
api().used().getLanguage(),
151 getNames().values().iterator().next());
169 this.i18nKey = i18nKey;
193 this.redirect = redirect;
201 this.target = target;
217 this.webTag = webTag;
225 this.layout = layout;
235 this.element = element;
255 return Strings.listToCvs(
getLangs());
260 this.langs.addAll(Strings.csvToList(langs));
267 private void prepareSaving() {
268 getLangs().removeIf(l -> Strings.isBlank(l));
269 getNames().entrySet().removeIf(entry ->
270 (Strings.isBlank(entry.getValue()) || Strings.isBlank(entry.getKey())));
272 (Strings.isBlank(entry.getValue()) || Strings.isBlank(entry.getKey())));
277 private transient boolean dynamic;
284 this.dynamic = dynamic;
289 public static final String
291 CONTEXT_REPOSITORY =
"repository",
292 CONTEXT_FILE =
"context.el";
309 return Path.of(
"/",
CONTEXT_FOLDER, CONTEXT_REPOSITORY).toString();
319 return real.toFile().exists();
325 return real.toFile().delete();
331 try(Reader reader =
new FileReader(real.toFile())) {
332 return JsonConfiguration.read(reader,
WebContext.class);
333 }
catch (IOException ex) {
342 try(Writer writer =
new FileWriter(real.toFile())) {
343 context.prepareSaving();
344 JsonConfiguration.write(writer, context);
345 }
catch (IOException ex) {
352 if(!folder.exists()) {
354 folder.toPath().resolve(
CONTEXT_FOLDER).resolve(CONTEXT_REPOSITORY).toFile().mkdirs();
static String getRealPath(String path)
static boolean createFolders(Path relativePath)
void setPrintContext(boolean printContext)
void setElement(WebElement element)
static boolean existsConf(Path path)
void setLangs(Set< String > langs)
void setNoIndex(boolean noIndex)
boolean isControlVersion()
static boolean removeFrom(Path path)
static String relativeRepository()
void setTraversalNavigation(boolean traversalNavigation)
static WebContext inheritFrom(WebContext webContext)
void setPrintVersion(boolean printVersion)
static void saveTo(Path path, WebContext context)
void setNoFollow(boolean noFollow)
void setLangsStr(String langs)
Map< String, String > getNames()
void setLayout(WebLayout layout)
IElement getElementInstance()
void setNames(Map< String, String > names)
void setShowAlways(boolean showAlways)
void setRedirect(String redirect)
void setImage(String image)
void setDynamic(boolean dynamic)
void setI18nKey(String i18nKey)
static WebContext loadFrom(Path path)
static Path repository(Path path)
void setOrder(String order)
void setTarget(String target)
boolean isTraversalNavigation()
void setPage(WebPage page)
void setWebTag(String webTag)
void setControlVersion(boolean controlVersion)
boolean isShowInNavigators()
static final String CONTEXT_FOLDER
void setRole(String role)
void setIcon(boolean icon)
void setShowInNavigators(boolean showInNavigators)
Map< String, String > getAttributes()
IElement getInstance(WebContext context)
static String get(String msg)
static I18nApiWrapper api()