EOS 2  1.1.0
Einfache Objektbasierte Sprache
Help.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.config;
2 
3 import java.text.MessageFormat;
4 import java.util.Collection;
5 import java.util.TreeMap;
6 
7 public class Help {
8  private TreeMap<String, HelpPage> pages = new TreeMap<>();
9  public Help(String id, String label, String tooltip, String description, Collection<LangModule> modules, TreeMap<String, LangClass> classes, Collection<LangHelp> helpEntries) {
10  HelpPage page = new HelpPage();
11  page.id = id;
12  page.pid = null;
13  page.title = label;
14  page.tooltip = tooltip;
15  page.html = MessageFormat.format(BODY, label, description);
16  pages.put(page.id, page);
17  for(LangModule lm: modules) {
18  HelpPage pagem = new HelpPage();
19  pagem.id = lm.id;
20  pagem.title = lm.label;
21  pagem.tooltip = lm.tooltip;
22  pagem.pid = id;
23  pagem.html = MessageFormat.format(BODY, lm.label, lm.description);
24  pages.put(pagem.id, pagem);
25  }
26  for (LangHelp lh: helpEntries) {
27  HelpPage pageh = new HelpPage();
28  pageh.id = lh.id;
29  pageh.title = lh.title;
30  pageh.tooltip = lh.tooltip;
31  pageh.pid = lh.pid;
32  pageh.html = MessageFormat.format(BODY, lh.title, lh.description);
33  pages.put(pageh.id, pageh);
34 
35  }
36  for (LangClass lc : classes.values()) {
37  HelpPage pagec = new HelpPage();
38  pagec.id = lc.id;
39  pagec.pid = id;
40  pagec.title = lc.label;
41  pagec.tooltip = lc.tooltip;
42  StringBuilder usage= new StringBuilder();
43  for (LangClass lcu : classes.values()) {
44  for(LangMethod lm:lcu.methods.values()) {
45  if (lm.uses(lc.id)) {
46  usage.append(MessageFormat.format(USAGE, lcu.id, lm.getFullSignature()));
47  }
48 
49  }
50  for(LangProperty lp:lcu.properties.values()) {
51  if (lp.uses(lc.id)) {
52  usage.append(MessageFormat.format(USAGE, lcu.id, lp.getFullSignature()));
53  }
54  }
55  }
56  String pcls = lc.pid;
57  StringBuilder inherited = new StringBuilder();
58  while (lc.pid != null && !lc.pid.isEmpty()) {
59  if (!inherited.isEmpty()) {
60  inherited.append(", ");
61  }
62  inherited.append(MessageFormat.format(LINK, pcls, classes.get(pcls).label));
63  }
64  StringBuilder methods = new StringBuilder();
65  for(LangMethod lm:lc.methods.values()) {
66  methods.append(MessageFormat.format(METHOD,lm.getFullSignature(), lm.description));
67  for(LangParameter lpa:lm.parameters) {
68  methods.append(MessageFormat.format(PARAMETER, lpa.name, lpa.type, classes.get(lpa.type).label, lpa.description));
69  }
70  }
71  StringBuilder properties = new StringBuilder();
72  for(LangProperty lp:lc.properties.values()) {
73  properties.append(MessageFormat.format(PROPERTY, lp.label, lp.type, classes.get(lp.type).label, lp.description));
74  }
75  pagec.html = MessageFormat.format(CLASS_BODY,
76  lc.label,
77  MessageFormat.format(INHERITED, inherited),
78  lc.description,
79  MessageFormat.format(METHODS, methods),
80  MessageFormat.format(PROPERTIES, properties),
81  MessageFormat.format(USAGES, lc.label, usage.toString())
82  );
83 
84  }
85 
86  }
87  public TreeMap<String, HelpPage> getHelpPages() {
88  return pages;
89  }
90  public HelpPage getHelpPage(String id) {
91  return pages.get(id);
92  }
93  public static class HelpPage {
94  public String html;
95  public String tooltip;
96  public String id;
97  public String title;
98  public String pid;
99  }
100  private final static String BODY = "<html><head>{0}</head><body><h1>{0}</h1>{1}</body></html>";
101  private final static String CLASS_BODY = "<html><head>{0}</head><body><h1>{0}</h1>{1}{2}{3}{4}</body></html>";
102  private final static String INHERITED = "<p>Die Klasse {0} besitzt alle Methoden und Attribute der Klassen {1}.</p>";
103  private final static String USAGES = "<p>{0} wird verwendet von </p><p><ul>{1}</ul></p>";
104  private final static String METHODS = "<h2>Methoden</h2><p>{0}</p>";
105  private final static String METHOD = "<h3>{0}</h3><p>{1}</p>";
106  private final static String PARAMETER = "<h4>{0}:<a href=\"{1}\">{2}</a></h4><p>{3}</p>";
107  private final static String PROPERTIES = "<h2>Attribute</h2><p>{0}</p>";
108  private final static String PROPERTY = "<h3>{0}:<a href=\"{1}\">{2}</a></h3><p>{3}</p>";
109  private final static String USAGE = "<li><a href=\"{0}\">{1}</a></li>";
110  private final static String LINK = "<a href=\"{0}\">{1}</a>";
111 }
Help(String id, String label, String tooltip, String description, Collection< LangModule > modules, TreeMap< String, LangClass > classes, Collection< LangHelp > helpEntries)
Definition: Help.java:9
TreeMap< String, HelpPage > getHelpPages()
Definition: Help.java:87
HelpPage getHelpPage(String id)
Definition: Help.java:90
Impressum