BrightSide Workbench Full Report + Source Code
PublicationParser.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 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 org.turro.string.ObjectString;
22 import org.turro.string.Strings;
23 import org.turro.annotation.ExternalParser;
24 import org.turro.elephant.context.ElephantContext;
25 import org.turro.i18n.I_;
26 import org.turro.publication.www.PublicationIterator;
27 import org.turro.util.IdGenerator;
28 
33 @ExternalParser
34 public class PublicationParser extends AbstractParser {
35 
36  @Override
37  public String getParserName() {
38  return "Publications";
39  }
40 
41  @Override
42  protected boolean doExecute() {
43  boolean done = false;
44  if("publication".equals(getMacroName()) || "publication-summary".equals(getMacroName())) {
46  Strings.isBlank(tokens[1]) ? null : ElephantContext.getRootWebPath() + tokens[1],
47  IdGenerator.generate());
48  pi.setGroupId((Integer) ObjectString.parseNativeString(getToken(2), Integer.class, true));
49  pi.setCategoryId((Integer) ObjectString.parseNativeString(getToken(3), Integer.class, true));
50  pi.setPage((Integer) ObjectString.parseNativeString(getToken(4), Integer.class, true));
52  String lang = getToken(6);
53  pi.setLang(Strings.isBlank(lang, "_" + I_.api().used().getLanguage()));
54  if("publication-summary".equals(getMacroName())) {
55  pi.setNavigatorTop(false);
56  pi.setNavigatorBottom(false);
57  pi.setSearchOption(false);
58  }
59  pi.load();
60  pi.render();
61  done = true;
62  } else if("single-publication".equals(getMacroName())) { //{@single-publication:publicationId[:full]}
64  null,
65  IdGenerator.generate());
67  pi.forceItem(Long.parseLong(getToken(1)));
68  pi.render();
69  done = true;
70  }
71  return done;
72  }
73 
74  @Override
75  protected void explainMacros(ParserMacroSet macros) {
76  macros.addMacro("publication")
77  .addParameter("context", false)
78  .addParameter("groupId", true, "0")
79  .addParameter("categoryId", true, "0")
80  .addParameter("count", true, "10")
81  .addParameter("template", true, "summary")
82  .addPossibleValue("entry")
83  .addPossibleValue("entryTitle")
84  .addPossibleValue("entryTitleImage")
85  .addPossibleValue("event")
86  .addPossibleValue("eventTitle")
87  .addPossibleValue("eventTitleImage")
88  .addPossibleValue("grid")
89  .addParameter("lang", true, null);
90  macros.addMacro("publication-summary")
91  .copyParametersFrom("publication", macros);
92  macros.addMacro("single-publication")
93  .addParameter("id", false)
94  .addParameter("template", true, "full");
95  }
96 
97 }
static I18nApiWrapper api()
Definition: I_.java:65
void setFullTemplate(String fullTemplate)
void setNavigatorBottom(boolean navigatorBottom)
void setSearchOption(boolean searchOption)
void setSummaryTemplate(String summaryTemplate)
void setNavigatorTop(boolean navigatorTop)
ParserMacro addMacro(String macroName)
ParserMacro addPossibleValue(String value)
void copyParametersFrom(String macroName, ParserMacroSet macros)
ParserMacro addParameter(String name, boolean optional)
void explainMacros(ParserMacroSet macros)