BrightSide Workbench Full Report + Source Code
WebPage.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.context;
20 
21 import java.util.HashSet;
22 import java.util.Set;
23 import org.turro.string.Strings;
24 import org.turro.elephant.context.IConstructor;
25 
30 public class WebPage {
31 
32  private Set<String> metas, headers, onLoaded;
33 
34  public void setMetas(Set<String> metas) {
35  this.metas = metas;
36  }
37 
38  public void setHeaders(Set<String> headers) {
39  this.headers = headers;
40  }
41 
42  public void setOnLoaded(Set<String> onLoaded) {
43  this.onLoaded = onLoaded;
44  }
45 
46  public void setMetasStr(String meta) {
47  metas = new HashSet<>();
48  metas.addAll(Strings.toList(meta, "[,;\\n]"));
49  }
50 
51  public void setHeadersStr(String header) {
52  headers = new HashSet<>();
53  headers.addAll(Strings.toList(header, "[,;\\n]"));
54  }
55 
56  public void setOnLoadedStr(String script) {
57  onLoaded = new HashSet<>();
58  onLoaded.add(script);
59  }
60 
61  public boolean hasMetas() {
62  return metas != null && !metas.isEmpty();
63  }
64 
65  public boolean hasHeaders() {
66  return headers != null && !headers.isEmpty();
67  }
68 
69  public boolean hasOnLoaded() {
70  return onLoaded != null && !onLoaded.isEmpty();
71  }
72 
73  public Set<String> getMetas() {
74  return metas;
75  }
76 
77  public Set<String> getHeaders() {
78  return headers;
79  }
80 
81  public Set<String> getOnLoaded() {
82  return onLoaded;
83  }
84 
85  public String getMetasStr() {
86  return hasMetas() ? Strings.listToCvs(metas) : "";
87  }
88 
89  public String getHeadersStr() {
90  return hasHeaders() ? Strings.listToCvs(headers) : "";
91  }
92 
93  public String getOnLoadedStr() {
94  return hasOnLoaded() ? Strings.listToCvs(onLoaded) : "";
95  }
96 
97  public void initiate(IConstructor constructor) {
98  if(hasMetas()) {
99  getMetas().forEach(meta -> constructor.addMeta(meta));
100  }
101  if(hasHeaders()) {
102  getHeaders().forEach(header -> constructor.addHeader(header));
103  }
104  if(hasOnLoaded()) {
105  getOnLoaded().forEach(onLoad -> constructor.addOnLoadedJavaScript(onLoad));
106  }
107  }
108 
109 }
void setOnLoaded(Set< String > onLoaded)
Definition: WebPage.java:42
void setOnLoadedStr(String script)
Definition: WebPage.java:56
void setMetas(Set< String > metas)
Definition: WebPage.java:34
void setHeadersStr(String header)
Definition: WebPage.java:51
void setHeaders(Set< String > headers)
Definition: WebPage.java:38
void initiate(IConstructor constructor)
Definition: WebPage.java:97
void addOnLoadedJavaScript(String script)