BrightSide Workbench Full Report + Source Code
DocumentationParser.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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;
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.icon.IconSet;
28 import org.turro.indicator.IElephantIndicator;
29 import org.turro.indicator.Indicators;
30 import org.turro.marker.ElephantMarker;
31 import org.turro.reflection.Instances;
32 import org.turro.security.Permissions;
33 import org.turro.security.SecurityGroups;
34 
39 @ExternalParser
40 public class DocumentationParser extends AbstractParser {
41 
42  @Override
43  public String getParserName() {
44  return "Documentation";
45  }
46 
47  @Override
48  protected boolean doExecute() {
49  boolean done = false;
50  if("provider-macros".equals(getMacroName())) {
52  marker.put("providers", ContentProviders.getProviders());
53  prepareProperties(marker, getToken(1));
54  marker.process(getToken(2), getToken(3));
55  } else if("social-groups".equals(getMacroName())) {
57  marker.put("socialGroups", SecurityGroups.getAll().stream().sorted().toList());
58  marker.put("roles", Permissions.permissionStringMap());
59  prepareProperties(marker, getToken(1));
60  marker.process(getToken(2), getToken(3));
61  } else if("elephant-macros".equals(getMacroName())) {
63  marker.put("elephantParsers",
64  Instances.cached().byAnnotation(ExternalParser.class, IParser.class)
65  .stream().filter((p) -> {
66  return "all".equals(getToken(1)) ||
67  ((p instanceof AbstractParser) &&
68  ((AbstractParser) p).getParserName().equals(getToken(1)));
69  }).collect(Collectors.toList()));
70  marker.put("headers", "true".equals(getToken(2)));
71  prepareProperties(marker, getToken(3));
72  marker.process(getToken(4), getToken(5));
73  } else if("elephant-emojis".equals(getMacroName())) {
75  marker.put("emojimap", EmojiMap.getInstance());
76  marker.process(getToken(1), getToken(2));
77  } else if("elephant-icons".equals(getMacroName())) {
79  marker.put("iconset", IconSet.getInstance());
80  marker.process(getToken(1), getToken(2));
81  } else if("elephant-indicators".equals(getMacroName())) {
83  marker.put("elephantIndicators", Indicators.getIndicators().stream().filter((i) -> {
84  return "all".equals(getToken(1)) ||
85  ((i instanceof IElephantIndicator) &&
86  ((IElephantIndicator) i).getRoot().equals(getToken(1)));
87  }).collect(Collectors.toList()));
88  marker.put("headers", "true".equals(getToken(2)));
89  prepareProperties(marker, getToken(3));
90  marker.process(getToken(4), getToken(5));
91  } else if("notice".equals(getMacroName())) {
93  marker.put("notice", Secrets.<List<String>>getObject("key=notice;show=false"));
94  marker.process("widgets/licenses", "notice");
95  } else if("licenses".equals(getMacroName())) {
97  marker.put("licenses", Secrets.<List<String>>getObject("key=licenses;show=false"));
98  marker.process("widgets/licenses", "licenses");
99  } else if("libraries".equals(getMacroName())) {
101  marker.put("libraries", Secrets.<List<String>>getObject("key=libraries;show=false"));
102  marker.process("widgets/licenses", "libraries");
103  }
104  return done;
105  }
106 
107  @Override
108  protected void explainMacros(ParserMacroSet macros) {
109  macros.addMacro("provider-macros")
110  .addParameter("doc-properties", true, "*/documentation")
111  .addParameter("tmpl-root", true, "documentation")
112  .addParameter("template", true, "providerMacros");
113  macros.addMacro("social-groups")
114  .addParameter("doc-properties", true, "*/documentation")
115  .addParameter("tmpl-root", true, "documentation")
116  .addParameter("template", true, "socialGroups");
117  macros.addMacro("elephant-macros")
118  .addParameter("parser", false, "all")
119  .addParameter("headers", true, "true")
120  .addParameter("doc-properties", true, "*/documentation")
121  .addParameter("tmpl-root", true, "documentation")
122  .addParameter("template", true, "elephantMacros");
123  macros.addMacro("elephant-emojis")
124  .addParameter("tmpl-root", true, "documentation")
125  .addParameter("template", true, "providerEmojis");
126  macros.addMacro("elephant-icons")
127  .addParameter("tmpl-root", true, "documentation")
128  .addParameter("template", true, "providerIcons");
129  macros.addMacro("elephant-indicators")
130  .addParameter("indicator", false, "all")
131  .addParameter("headers", true, "true")
132  .addParameter("doc-properties", true, "*/documentation")
133  .addParameter("tmpl-root", true, "documentation")
134  .addParameter("template", true, "elephantIndicators");
135  }
136 
137 }
138 
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)
void explainMacros(ParserMacroSet macros)
ParserMacro addMacro(String macroName)
ParserMacro addParameter(String name, boolean optional)
static SortedMap< String, SortedSet< String > > permissionStringMap()
static Collection< SecurityGroup > getAll()