BrightSide Workbench Full Report + Source Code
PublicationContentProvider.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.publication.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("publications");
44  mc.addParameter("context", "", true);
45  mc.addParameter("categoryId", Long.valueOf(0), true);
46  mc.addParameter("groupId", Long.valueOf(0), true);
47  mc.addParameter("count", Integer.valueOf(10), true);
48  mc.addParameter("template", "summary", true);
49  mc.addParameter("notSent", Boolean.FALSE, true);
50  mc.addParameter("lang", "", true);
51  mc.addParameter("asBlogger", Boolean.FALSE, true);
52  mc.addParameter("future", Boolean.FALSE, true);
53  commands.add(mc);
54  }
55 
56  @Override
57  public ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext) {
58  if(macroCommand.itsMe("publications(")) {
59  StringWriter sw = new StringWriter();
62  sw, contact, true,
63  macroCommand.getParameterValue(String.class, "context"));
64  pi.setGroupId(macroCommand.getParameterValue(Long.class, "groupId"));
65  pi.setCategoryId(macroCommand.getParameterValue(Long.class, "categoryId"));
66  pi.setPage(macroCommand.getParameterValue(Integer.class, "count"));
67  pi.setAllowAttachments(true);
68  pi.setAllowFiles(true);
69  pi.setAllowDescriptions(true);
70  pi.setAllowInterest(true);
71  pi.setAllowVotes(true);
72  pi.setAllowComments(true);
73  pi.setAllowPolls(true);
74  pi.setSummaryTemplate(macroCommand.getParameterValue(String.class, "template"));
75  pi.setLang(macroCommand.getParameterValue(String.class, "lang"));
76  pi.setNotSent(macroCommand.getParameterValue(Boolean.class, "notSent"));
77  pi.setBlogger(macroCommand.getParameterValue(Boolean.class, "asBlogger"));
78  pi.setFuture(macroCommand.getParameterValue(Boolean.class, "future"));
79  pi.setNavigatorTop(false);
80  pi.setNavigatorBottom(false);
81  pi.setSearchOption(false);
82  pi.load();
83  return new ContentRenderer(macroCommand, pi, sw, (IContentIterator iterator, Writer writer) -> {
84  iterator.render();
85  return writer.toString();
86  });
87  }
88  return null;
89  }
90 
91 }
92 
void setAllowAttachments(boolean allowAttachments)
void setAllowInterest(boolean allowInterest)
void setAllowDescriptions(boolean allowDescriptions)
void setAllowComments(boolean allowComments)
void setNavigatorBottom(boolean navigatorBottom)
void setSearchOption(boolean searchOption)
void setSummaryTemplate(String summaryTemplate)
void setNavigatorTop(boolean navigatorTop)
ContentRenderer loadCommand(MacroCommand macroCommand, IContact contact, String idContext)