BrightSide Workbench Full Report + Source Code
ElephantContentProvider.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.content;
20 
21 import java.io.StringWriter;
22 import java.io.Writer;
23 import org.turro.action.content.AbstractContentProvider;
24 import org.turro.action.content.ContentRenderer;
25 import org.turro.action.content.IContentIterator;
26 import org.turro.annotation.ContentProvider;
27 import org.turro.command.MacroCommand;
28 import org.turro.elephant.context.HeadlessApplication;
29 import org.turro.plugin.contacts.IContact;
30 
35 @ContentProvider
37 
39  addCommands();
40  }
41 
42  private void addCommands() {
43  MacroCommand mc = new MacroCommand("polls");
44  mc.addParameter("context", "", true);
45  mc.addParameter("count", Integer.valueOf(10), true);
46  mc.addParameter("restricted", Boolean.TRUE, true);
47  mc.addParameter("active", Boolean.FALSE, true);
48  mc.addParameter("template", "summary", true);
49  commands.add(mc);
50  }
51 
52  @Override
53  public ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext) {
54  if(macroCommand.itsMe("polls(")) {
55  StringWriter sw = new StringWriter();
58  sw, contact,
59  macroCommand.getParameterValue(Boolean.class, "active"),
60  macroCommand.getParameterValue(Boolean.class, "restricted"),
61  macroCommand.getParameterValue(Integer.class, "count"),
62  true,
63  macroCommand.getParameterValue(String.class, "context"));
64  di.setPublicOnly(true);
65  di.setSummaryTemplate(macroCommand.getParameterValue(String.class, "template"));
66  di.setNavigatorTop(false);
67  di.setNavigatorBottom(false);
68  di.load();
69  return new ContentRenderer(macroCommand, di, sw, (IContentIterator iterator, Writer writer) -> {
70  iterator.render();
71  return writer.toString();
72  });
73  }
74  return null;
75  }
76 
77 }
ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext)