BrightSide Workbench Full Report + Source Code
elephant-plugins/src/main/java/org/turro/plugin/command/TimelinePlugin.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.plugin.command;
20 
21 import java.util.Collection;
22 import java.util.TreeSet;
23 import org.turro.command.Command;
24 import org.turro.command.Context;
25 import org.turro.elephant.context.Application;
26 import org.turro.plugin.contacts.IContact;
27 
32 public abstract class TimelinePlugin implements IPlugin, Command {
33 
34  protected IContact contact;
35  protected Collection<TimelineEvent> result;
36 
37  @Override
38  public String getName() {
39  return "Timeline";
40  }
41 
42  @Override
43  public boolean stopsPropagating() {
44  return false;
45  }
46 
47  @Override
48  public void setParams(Object params) {
49  if(params instanceof IContact) {
51  }
52  }
53 
54  @Override
55  public Object execute(Context context) {
56 // if(getName().equals(context.get(CommandFactory.COMMAND_PARS))) {
57 // setParams(context.get(CommandFactory.DATA));
58 // result = (Collection<TimelineEvent>) context.get(CommandFactory.RESULT);
59 // executePlugin(context);
60 // context.put(CommandFactory.RESULT, result);
61 // if(stopsPropagating()) {
62 // return PROCESSING_COMPLETE;
63 // }
64 // }
65 // return CONTINUE_PROCESSING;
66  return null;
67  };
68 
69  protected void addToResult(Object data) {
70  if(result == null) {
71  result = new TreeSet<TimelineEvent>();
72  }
73  if(data instanceof TimelineEvent) {
74  result.add((TimelineEvent) data);
75  }
76  }
77 
78  protected abstract void executePlugin(Context context) throws Exception;
79 
80  public static String getTimelineFor(Application app, IContact contact) {
81 // Collection<TimelineEvent> list = (Collection<TimelineEvent>) CommandFactory
82 // .executePlugins(app, contact, "Timeline");
83 // if(list != null) {
84 // return generateXML(app, list);
85 // }
86  return null;
87  }
88 
89  public static String generateXML(Application app, Collection<TimelineEvent> result) {
90  StringBuilder sb = new StringBuilder("<data>\n");
91  for(TimelineEvent tle : result) {
92  sb.append(tle.getEvent(app));
93  }
94  sb.append("\n</data>");
95  return sb.toString();
96  }
97 
98 }
99 
Map< String, Object > params
abstract void executePlugin(Context context)
static String generateXML(Application app, Collection< TimelineEvent > result)