01 /*
02 * Twitter.java
03 * Copyright (c) 1998-2008, The University of Sheffield.
04 *
05 * This code is from the GATE project (http://gate.ac.uk/) and is free
06 * software licenced under the GNU General Public License version 3. It is
07 * distributed without any warranty. For more details see COPYING.txt in the
08 * top level directory (or at http://gatewiki.sf.net/COPYING.txt).
09 *
10 * Hamish Cunningham, 24th August 2009
11 */
12
13 package gate.yam.plugins;
14
15 import java.util.*;
16 import java.io.*;
17 import gate.yam.YamPlugin;
18 import gate.yam.translate.AbstractTranslator;
19 import gate.util.Files;
20
21 /**
22 * Twitter plugin for YAM.
23 * @author Hamish Cunningham
24 */
25 public class Twitter implements YamPlugin {
26 /**
27 * Translate Twitter updates in YAM pages.
28 *
29 * @param m a map of arguments from the YAM source
30 * @param t the translator that is converting the YAM document
31 * @param target the target output language
32 * @return the translation for insertion at the plugin call location
33 *
34 * An example call:
35 * %twitter(title=GATE News, account=GateAcUk, name=GATE, count=5)
36 */
37 public String translate(Map m, AbstractTranslator t, String target) {
38
39 if(target.equals("Html")) { // html output
40 String bodyTemplate = null;
41 String footTemplate = null;
42 try {
43 bodyTemplate =
44 Files.getResourceAsString("/gate/yam/plugins/twitter-body.html");
45 footTemplate =
46 Files.getResourceAsString("/gate/yam/plugins/twitter-foot.html");
47 } catch(IOException e) {
48 return "YAM Twitter plugin resource file(s) not found";
49 }
50 for(String key : (Set<String>) m.keySet()) {
51 String theKey = "__" + key + "__";
52 bodyTemplate = bodyTemplate.replaceAll(theKey, (String) m.get(key));
53 footTemplate = footTemplate.replaceAll(theKey, (String) m.get(key));
54 }
55
56 t.addToFooter(footTemplate);
57 return bodyTemplate;
58
59 } else if(target.equals("LaTeX")) { // latex output
60
61 //TODO
62 return m.toString();
63 }
64
65 // catchall for other output types
66 return m.toString();
67 } // String translate(Map, AbstractTranslator, String)
68
69 } // Twitter
|