BrightSide Workbench Full Report + Source Code
AttachParser.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.annotation.ExternalParser;
22 import org.turro.attach.www.AttachCtrl;
23 import org.turro.entities.Entities;
24 import org.turro.plugin.contacts.IContact;
25 
30 @ExternalParser
31 public class AttachParser extends AbstractParser {
32 
33  @Override
34  public String getParserName() {
35  return "Attachments";
36  }
37 
38  @Override
39  protected boolean doExecute() {
40  boolean done = false;
41  if("attachment".equals(getMacroName()) ||
42  "attachment-ro".equals(getMacroName()) ||
43  "attachment-rot".equals(getMacroName())) {
45  IContact contact = (IContact) constructor.findAttribute("loggedIContact");
46  Entities.getController(getToken(1)).configureCtrl(ac, contact);
47  ac.setPublicOnly(true);
48  ac.setLastOnly(true);
49  ac.setEntityPath(getToken(1));
51  ac.setReadOnly(!"attachment".equals(getMacroName()));
52  ac.renderAttachments();
53  done = true;
54  } else if("self-attachments".equals(getMacroName()) ||
55  "self-attachments-ro".equals(getMacroName()) ||
56  "self-attachments-rot".equals(getMacroName())) {
57  IContact contact = (IContact) constructor.findAttribute("loggedIContact");
58  if(contact != null && contact.isValid()) {
60  ac.setPublicOnly(true);
61  ac.setLastOnly(true);
62  ac.setEntityPath("/contact/" + contact.getId());
63  ac.setReadOnly(!"self-attachments".equals(getMacroName()));
64  ac.renderAttachments();
65  done = true;
66  }
67  }
68  return done;
69  }
70 
71  @Override
72  protected void explainMacros(ParserMacroSet macros) {
73  macros.addMacro("attachment")
74  .addParameter("entityPath", false)
75  .addParameter("template", true, "tree")
76  .addPossibleValue("editableTree");
77  macros.addMacro("attachment-ro")
78  .addParameter("entityPath", false)
79  .addParameter("template", true, "tree-ro");
80  macros.addMacro("attachment-rot")
81  .addParameter("entityPath", false)
82  .addParameter("template", true, "tree-rot");
83  macros.addMacro("self-attachments")
84  .addParameter("template", true, "tree");
85  macros.addMacro("self-attachments-ro")
86  .addParameter("template", true, "tree-ro");
87  macros.addMacro("self-attachments-rot")
88  .addParameter("template", true, "tree-rot");
89  }
90 
91 }
void setLastOnly(boolean lastOnly)
Definition: AttachCtrl.java:86
void setPublicOnly(boolean publicOnly)
Definition: AttachCtrl.java:77
void setEntityPath(String entityPath)
Definition: AttachCtrl.java:45
void setReadOnly(boolean readOnly)
Definition: AttachCtrl.java:95
void setTreeTemplate(String treeTemplate)
Definition: AttachCtrl.java:55
static IElephantEntity getController(String path)
Definition: Entities.java:78
void explainMacros(ParserMacroSet macros)
ParserMacro addMacro(String macroName)
ParserMacro addPossibleValue(String value)
ParserMacro addParameter(String name, boolean optional)