BrightSide Workbench Full Report + Source Code
EditingContext.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.elephant.web;
20 
21 import java.io.File;
22 import org.turro.string.Strings;
23 import org.turro.elephant.util.Images;
24 import org.turro.elephant.web.context.WebContext;
25 import org.turro.plugin.contacts.IContact;
26 
31 public class EditingContext {
32 
33  private ElContext context;
34 
35  public String getPath() {
36  String path = context == null ? null : context.getPath();
37  if(Strings.isBlank(path)) path = "/";
38  return path;
39  }
40 
41  public ElContext getContext() {
42  return context;
43  }
44 
45  public void setContext(ElContext context) {
46  this.context = context;
47  }
48 
49  public WebContext getAttr() {
50  return context == null ? new WebContext() : context.getWebContext();
51  }
52 
53  public String getSocialImage() {
54  SocialImage si = context != null ? context.getSocialImage() : null;
55  return si != null ? Images.removeAppContext(si.getUrl()) : null;
56  }
57 
58  public boolean isEditable(String base, String lang) {
59  if(context == null) return false;
60  if(!getAttr().isWikiPage()) return false; // DefaultElement
61  if(!context.getResources().globalResourceNames().isEmpty()) return false; // Normal HTML page
62  if(Strings.isBlank(lang)) return false; // No lang selected
63  return true;
64  }
65 
66  public void saveContent(IContact contact, String base, String lang, String wiki, String html, boolean autoremove) {
67  context.getResources().saveContent(context.getFile().toPath(), contact, base, lang, wiki, html, autoremove);
68  }
69 
70  public void removeVersion(String base, String lang, String version) {
71  File file = context.getResources().getEditable(base, lang, version);
72  if(file != null) {
73  file.delete();
74  }
75  }
76 
77 }
static String removeAppContext(String path)
Definition: Images.java:64
void saveContent(IContact contact, String base, String lang, String wiki, String html, boolean autoremove)
boolean isEditable(String base, String lang)
void removeVersion(String base, String lang, String version)
void saveContent(Path folder, IContact contact, String base, String lang, String wiki, String html, boolean autoremove)
File getEditable(String base, String lang, String version)