BrightSide Workbench Full Report + Source Code
MacroProcessorContext.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.parser.processor;
20
21
import
java.io.IOException;
22
import
java.io.Writer;
23
import
java.util.Optional;
24
import
org.turro.elephant.context.ElephantContext;
25
import
org.turro.elephant.context.IConstructor;
26
import
org.turro.log.WebLoggers;
27
import
org.turro.marker.ElephantMarker;
28
import
org.turro.plugin.contacts.IContact;
29
34
public
class
MacroProcessorContext
{
35
36
private
final
IConstructor
constructor;
37
private
final
Writer writer;
38
private
final
IContact
contact;
39
private
final
MacroAdapter
macro;
40
41
private
ElephantMarker
marker;
42
43
public
MacroProcessorContext
(
IConstructor
constructor, Writer writer,
IContact
contact,
MacroAdapter
macro) {
44
this.constructor = constructor;
45
this.writer = writer;
46
this.contact = contact;
47
this.macro = macro;
48
}
49
50
public
IConstructor
getConstructor
() {
51
return
constructor;
52
}
53
54
public
Writer
getWriter
() {
55
return
writer;
56
}
57
58
public
IContact
getContact
() {
59
if
(contact !=
null
) {
60
return
contact;
61
}
else
if
(constructor !=
null
) {
62
return
constructor.
getUser
();
63
}
else
{
64
return
null
;
65
}
66
}
67
68
public
MacroAdapter
getMacro
() {
69
return
macro;
70
}
71
72
public
ElephantMarker
getMarker
() {
73
if
(marker ==
null
) {
74
marker =
new
ElephantMarker
(constructor);
75
}
76
return
marker;
77
}
78
79
public
void
write
(String value) {
80
try
{
81
writer.write(value);
82
}
catch
(IOException ex) {
83
WebLoggers
.
info
(
this
).
exception
(ex).
log
();
84
}
85
}
86
87
public
String
getContextPath
(
boolean
full) {
88
return
(full ?
ElephantContext
.
getRootWebPath
() :
""
) +
89
Optional.ofNullable(macro.
get
(
"context"
))
90
.orElse(getCurrentContextPath());
91
}
92
93
public
String
getTemplateRoot
() {
94
return
macro.
get
(
"tmpl-root"
);
95
}
96
97
public
String
getTemplate
() {
98
return
macro.
get
(
"template"
);
99
}
100
101
public
boolean
isNavigation
() {
102
return
macro.
get
(Boolean.class,
"navigation"
,
true
);
103
}
104
105
public
int
getPage
() {
106
return
macro.
get
(Integer.class,
"count"
);
107
}
108
109
public
boolean
isRestricted
() {
110
return
macro.
get
(Boolean.class,
"restricted"
,
false
);
111
}
112
113
public
boolean
isRanking
() {
114
return
macro.
get
(Boolean.class,
"ranking"
,
false
);
115
}
116
117
public
boolean
isMatching
() {
118
return
macro.
get
(Boolean.class,
"matching"
,
false
);
119
}
120
121
private
String getCurrentContextPath() {
122
return
Optional.ofNullable(constructor)
123
.map(c -> c.getCurrentContext())
124
.map(c -> c.getPath())
125
.orElse(
""
);
126
}
127
128
}
org.turro.elephant.context.ElephantContext
Definition:
ElephantContext.java:59
org.turro.elephant.context.ElephantContext.getRootWebPath
static String getRootWebPath()
Definition:
ElephantContext.java:137
org.turro.log.WebLoggers
Definition:
WebLoggers.java:27
org.turro.log.WebLoggers.log
void log()
Definition:
WebLoggers.java:39
org.turro.log.WebLoggers.exception
WebLoggers exception(Throwable throwable)
Definition:
WebLoggers.java:29
org.turro.log.WebLoggers.info
static WebLoggers info(Object entity)
Definition:
WebLoggers.java:43
org.turro.marker.ElephantMarker
Definition:
ElephantMarker.java:49
org.turro.parser.processor.MacroAdapter
Definition:
MacroAdapter.java:30
org.turro.parser.processor.MacroAdapter.get
String get(String name)
Definition:
MacroAdapter.java:48
org.turro.parser.processor.MacroProcessorContext
Definition:
MacroProcessorContext.java:34
org.turro.parser.processor.MacroProcessorContext.isNavigation
boolean isNavigation()
Definition:
MacroProcessorContext.java:101
org.turro.parser.processor.MacroProcessorContext.getMarker
ElephantMarker getMarker()
Definition:
MacroProcessorContext.java:72
org.turro.parser.processor.MacroProcessorContext.isRestricted
boolean isRestricted()
Definition:
MacroProcessorContext.java:109
org.turro.parser.processor.MacroProcessorContext.getConstructor
IConstructor getConstructor()
Definition:
MacroProcessorContext.java:50
org.turro.parser.processor.MacroProcessorContext.isMatching
boolean isMatching()
Definition:
MacroProcessorContext.java:117
org.turro.parser.processor.MacroProcessorContext.write
void write(String value)
Definition:
MacroProcessorContext.java:79
org.turro.parser.processor.MacroProcessorContext.getTemplateRoot
String getTemplateRoot()
Definition:
MacroProcessorContext.java:93
org.turro.parser.processor.MacroProcessorContext.getContextPath
String getContextPath(boolean full)
Definition:
MacroProcessorContext.java:87
org.turro.parser.processor.MacroProcessorContext.getContact
IContact getContact()
Definition:
MacroProcessorContext.java:58
org.turro.parser.processor.MacroProcessorContext.getMacro
MacroAdapter getMacro()
Definition:
MacroProcessorContext.java:68
org.turro.parser.processor.MacroProcessorContext.getWriter
Writer getWriter()
Definition:
MacroProcessorContext.java:54
org.turro.parser.processor.MacroProcessorContext.isRanking
boolean isRanking()
Definition:
MacroProcessorContext.java:113
org.turro.parser.processor.MacroProcessorContext.MacroProcessorContext
MacroProcessorContext(IConstructor constructor, Writer writer, IContact contact, MacroAdapter macro)
Definition:
MacroProcessorContext.java:43
org.turro.parser.processor.MacroProcessorContext.getPage
int getPage()
Definition:
MacroProcessorContext.java:105
org.turro.parser.processor.MacroProcessorContext.getTemplate
String getTemplate()
Definition:
MacroProcessorContext.java:97
org.turro.elephant.context.IConstructor
Definition:
IConstructor.java:42
org.turro.elephant.context.IConstructor.getUser
IContact getUser()
org.turro.plugin.contacts.IContact
Definition:
elephant/src/main/java/org/turro/plugin/contacts/IContact.java:33
TurroProjects
Public
Elephant
elephant
src
main
java
org
turro
parser
processor
MacroProcessorContext.java
Generated on Tue Mar 12 2024 07:01:19 for BrightSide by
1.9.1