BrightSide Workbench Full Report + Source Code
ContextConstructor.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.IOException;
22 import javax.servlet.ServletException;
23 import org.turro.elephant.context.ElephantContext;
24 import org.turro.elephant.context.IConstructor;
25 import org.turro.elephant.context.IElement;
26 import org.turro.elephant.impl.context.vc.FileVersionWrapper;
27 import org.turro.elephant.impl.navigation.Navigator;
28 import org.turro.elephant.impl.navigation.WebMap;
29 import org.turro.elephant.web.context.WebContext;
30 import org.turro.elephant.web.tags.SessionTags;
31 import org.turro.marker.ElephantMarker;
32 
37 public class ContextConstructor {
38 
39  private final IConstructor constructor;
40  private final ElContext context;
41 
42  public ContextConstructor(IConstructor constructor, ElContext context) {
43  this.constructor = constructor;
44  this.context = context;
45  }
46 
47  public void start() throws ServletException, IOException {
48  final IElement iel = context.getWebContext().getElementInstance();
49 
50  if(iel == null) return;
51 
52  iel.setConfiguration(constructor, context);
53 
54  String template = context.getTemplate();
55  WebContext webContext = context.getWebContext();
56 
57  webContext.getPage().initiate(constructor);
58 
59  SessionTags.get(constructor).add(webContext);
60 
61  ElephantMarker em = new ElephantMarker(constructor);
62  if(webContext.isControlVersion() ||
63  constructor.isInRole("control-version:admin") ||
64  constructor.isWebAdministering()) {
65  em.put("fileVersion", new FileVersionWrapper(iel, 20, 3));
66  }
67  // Desactivat fins no tenir les plantilles carregades
68  if(webContext.isPrintVersion() && context.canPrint()) {
69  String printPath = ElephantContext.getRootWebPath() + "/print_" + context.getPath();
70  em.put("printPath", printPath);
71  }
72  Navigator navigator = new Navigator(context);
73  navigator.setDynamicLoad("dynamic".equals(ElephantContext.getContextLoad()));
74  em.put("nav", navigator);
75  em.put("traversal", webContext.isTraversalNavigation());
76  em.put("body", iel);
77  em.put("webmap", new WebMap(constructor));
78  iel.loadData();
79  iel.getMetas().forEach(meta -> constructor.addMeta(meta));
80  context.setTitle(iel.getTitle());
81  constructor.getOut();
82  em.process("layout", template);
83  }
84 
85 }
void setDynamicLoad(boolean dynamicLoad)
Definition: Navigator.java:340
ContextConstructor(IConstructor constructor, ElContext context)
void initiate(IConstructor constructor)
Definition: WebPage.java:97
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
void setConfiguration(IConstructor constructor, ElContext context)
Collection< String > getMetas()