BrightSide Workbench Full Report + Source Code
DocumentationProcessor.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.util.List;
22 import java.util.stream.Collectors;
23 import org.turro.action.Secrets;
24 import org.turro.action.content.ContentProviders;
25 import org.turro.annotation.ExternalParser;
26 import org.turro.emoji.EmojiMap;
27 import org.turro.html.Colors;
28 import org.turro.icon.IconSet;
29 import org.turro.indicator.IElephantIndicator;
30 import org.turro.indicator.Indicators;
31 import org.turro.marker.ElephantMarker;
32 import org.turro.parser.AbstractParser;
33 import org.turro.parser.IParser;
34 import org.turro.parser.MacroMap;
35 import org.turro.parser.MacroParameter;
36 import org.turro.reflection.Instances;
37 import org.turro.security.Permissions;
38 import org.turro.security.SecurityGroups;
39 
45 
46  @Override
47  public String getName() {
48  return "Documentation";
49  }
50 
51  @Override
52  protected void doProcess(MacroProcessorContext context) {
53  final MacroAdapter macro = context.getMacro();
54  switch(macro.getName()) {
55  case "provider-macros" -> {
56  ElephantMarker marker = context.getMarker();
57  marker.put("providers", ContentProviders.getProviders());
58  prepareProperties(marker, macro.get("doc-properties"));
59  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
60  }
61  case "social-groups" -> {
62  ElephantMarker marker = context.getMarker();
63  marker.put("socialGroups", SecurityGroups.getAll().stream().sorted().toList());
64  marker.put("roles", Permissions.permissionStringMap());
65  prepareProperties(marker, macro.get("doc-properties"));
66  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
67  }
68  case "elephant-macros" -> {
69  ElephantMarker marker = context.getMarker();
70  marker.put("elephantParsers",
71  Instances.cached().byAnnotation(ExternalParser.class, IParser.class)
72  .stream().filter((p) -> {
73  return "all".equals(macro.get("parser")) ||
74  ((p instanceof AbstractParser) &&
75  ((AbstractParser) p).getParserName().equals(macro.get("parser")));
76  }).collect(Collectors.toList()));
77  marker.put("headers", "true".equals(macro.get("headers")));
78  prepareProperties(marker, macro.get("doc-properties"));
79  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
80  }
81  case "elephant-macro-processors" -> {
82  ElephantMarker marker = context.getMarker();
83  marker.put("elephantProcessors",
84  Instances.cached().bySuper(AbstractMacroProcessor.class, IMacroProcessor.class)
85  .stream().filter((p) -> {
86  return "all".equals(macro.get("processor")) ||
87  ((p instanceof AbstractMacroProcessor) &&
88  ((AbstractMacroProcessor) p).getName().equals(macro.get("processor")));
89  }).collect(Collectors.toList()));
90  marker.put("headers", "true".equals(macro.get("headers")));
91  prepareProperties(marker, macro.get("doc-properties"));
92  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
93  }
94  case "elephant-emojis" -> {
95  ElephantMarker marker = context.getMarker();
96  marker.put("emojimap", EmojiMap.getInstance());
97  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
98  }
99  case "elephant-icons" -> {
100  ElephantMarker marker = context.getMarker();
101  marker.put("iconset", IconSet.getInstance());
102  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
103  }
104  case "elephant-colors" -> {
105  ElephantMarker marker = context.getMarker();
106  marker.put("colors", Colors.getHueList());
107  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
108  }
109  case "elephant-indicators" -> {
110  ElephantMarker marker = context.getMarker();
111  marker.put("elephantIndicators", Indicators.getIndicators().stream().filter((i) -> {
112  return "all".equals(macro.get("indicator")) ||
113  ((i instanceof IElephantIndicator) &&
114  ((IElephantIndicator) i).getRoot().equals(macro.get("indicator")));
115  }).toList());
116  marker.put("headers", "true".equals(macro.get("headers")));
117  prepareProperties(marker, macro.get("doc-properties"));
118  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
119  }
120  case "notice" -> {
121  ElephantMarker marker = context.getMarker();
122  marker.put("notice", Secrets.<List<String>>getObject("key=notice;show=false"));
123  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
124  }
125  case "licenses" -> {
126  ElephantMarker marker = context.getMarker();
127  marker.put("licenses", Secrets.<List<String>>getObject("key=licenses;show=false"));
128  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
129  }
130  case "libraries" -> {
131  ElephantMarker marker = context.getMarker();
132  marker.put("libraries", Secrets.<List<String>>getObject("key=libraries;show=false"));
133  marker.process(context.getTemplateRoot(), context.getTemplate(), context.getWriter());
134  }
135  }
136  }
137 
138  @Override
139  protected void explainMacros(MacroMap macros) {
140  macros.addSecret("provider-macros")
141  .addParameter(MacroParameter.optional("doc-properties", "*/documentation"))
142  .addTemplate("documentation", "providerMacros");
143  macros.addSecret("social-groups")
144  .addParameter(MacroParameter.optional("doc-properties", "*/documentation"))
145  .addTemplate("documentation", "socialGroups");
146  macros.addSecret("elephant-macros")
147  .addParameter(MacroParameter.optional("parser", "all"))
148  .addParameter(MacroParameter.optional("headers", "true"))
149  .addParameter(MacroParameter.optional("doc-properties", "*/documentation"))
150  .addTemplate("documentation", "elephantMacros");
151  macros.addSecret("elephant-macro-processors")
152  .addParameter(MacroParameter.optional("processor", "all"))
153  .addParameter(MacroParameter.optional("headers", "true"))
154  .addParameter(MacroParameter.optional("doc-properties", "*/documentation"))
155  .addTemplate("documentation", "elephantMacroProcessors");
156  macros.addSecret("elephant-emojis")
157  .addParameter(MacroParameter.optional("tmpl-root", "documentation"))
158  .addTemplate("documentation", "providerEmojis");
159  macros.addSecret("elephant-icons")
160  .addTemplate("documentation", "providerIcons");
161  macros.addSecret("elephant-colors")
162  .addTemplate("documentation", "elephantColors");
163  macros.addSecret("elephant-indicators")
164  .addParameter(MacroParameter.optional("indicator", "all"))
165  .addParameter(MacroParameter.optional("headers", "true"))
166  .addParameter(MacroParameter.optional("doc-properties", "*/documentation"))
167  .addTemplate("documentation", "elephantIndicators");
168  macros.addSecret("notice")
169  .addTemplate("widgets/licenses", "notice");
170  macros.addSecret("licenses")
171  .addTemplate("widgets/licenses", "licenses");
172  macros.addSecret("libraries")
173  .addTemplate("widgets/licenses", "libraries");
174  }
175 
176 }
static List< IContentProvider > getProviders()
static List< IElephantIndicator > getIndicators()
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
void prepareProperties(ElephantMarker marker, String properties)
static SortedMap< String, SortedSet< String > > permissionStringMap()
static Collection< SecurityGroup > getAll()