001: /*
002: * $Id:TaskFeed.java 847 2007-02-08 20:03:35Z hengels $
003: * (c) Copyright 2004 - 2007 osbl development team.
004: *
005: * This file is part of the osbl (http://osbl.wilken.de).
006: *
007: * the osbl is free software; you can redistribute it and/or modify
008: * it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2.1
010: * of the License, or (at your option) any later version.
011: *
012: * Please see COPYING for the complete licence.
013: */
014: package org.osbl.client.feeder;
015:
016: import org.concern.Worklist;
017: import org.concern.Work;
018: import org.concern.*;
019: import org.conform.format.FormatFactory;
020: import org.osbl.client.wings.shell.Client;
021: import org.wings.plaf.css.Utils;
022: import org.wings.io.StringBuilderDevice;
023:
024: import javax.servlet.ServletException;
025: import javax.servlet.http.*;
026: import java.io.IOException;
027: import java.io.PrintWriter;
028: import java.util.*;
029:
030: /**
031: * @author hengels
032: * @version $Revision:847 $
033: */
034: public class TaskFeed extends Feed {
035: protected Worklist worklist;
036:
037: protected void initialize() {
038: worklist = ControllerLookup.getInstance().getWorklist();
039: }
040:
041: public void doGet(HttpServletRequest request,
042: HttpServletResponse response) throws ServletException,
043: IOException, java.net.MalformedURLException {
044: String user = request.getParameter("user");
045: String localeString = request.getParameter("locale");
046: Locale locale;
047: int pos = localeString.indexOf('_');
048: if (pos != -1)
049: locale = new Locale(localeString.substring(0, pos),
050: localeString.substring(pos + 1));
051: else
052: locale = new Locale(localeString.substring(0, pos));
053:
054: FormatFactory.getInstance().setLocale(locale);
055:
056: response.setContentType("text/html; charset=UTF-8");
057: PrintWriter out = response.getWriter();
058:
059: out
060: .print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
061: + "<rss>\n"
062: + "<channel>\n"
063: + " <title>con:cern Task Feed</title>\n"
064: + " <link><![CDATA["
065: + channelURL
066: + "]]></link>\n"
067: + " <description>Serves tasks assignments</description>\n");
068:
069: List works = worklist.listWork(new String[] { "*", user },
070: null, null, null,
071: new String[] { "-enlistment.timeout" }, locale
072: .toString(), 10);
073: for (Iterator iterator = works.iterator(); iterator.hasNext();) {
074: Work work = (Work) iterator.next();
075: out.print("<item>\n" + " <title>"
076: + formatTask(locale, work) + "</title>\n"
077: + " <description>\n" + message(locale, "process")
078: + ": " + work.getProcess() + "\n"
079: + message(locale, "activity") + ": "
080: + work.getActivity() + "\n"
081: + message(locale, "subjectLine") + ": "
082: + work.getSubjectLine() + "\n"
083: + message(locale, "originator") + ": "
084: + work.getOriginator() + "\n"
085: + message(locale, "due") + ": " + work.getDue()
086: + "\n" + " </description>\n" + " <link><![CDATA["
087: + format(work) + "]]></link>\n" + "</item>");
088: }
089:
090: out.print("</channel>\n" + "</rss>\n");
091: out.close();
092:
093: FormatFactory.getInstance().setLocale(null);
094: }
095:
096: private String message(Locale locale, String property) {
097: return getResourceProvider().getMessage(locale,
098: "org.concern.Work." + property);
099: }
100:
101: private String format(final Work work) {
102: StringTemplate template = new StringTemplate(itemURL);
103: template.setMap(new AbstractMap() {
104: public Set entrySet() {
105: return null;
106: }
107:
108: public Object get(Object key) {
109: if ("process".equals(key))
110: return work.getProcess();
111: if ("activity".equals(key))
112: return work.getActivity();
113: if ("subject".equals(key))
114: return work.getSubjectId();
115: if ("originator".equals(key))
116: return work.getOriginator();
117: if ("due".equals(key))
118: return work.getDue();
119: return null;
120: }
121: });
122: return template.toString();
123: }
124:
125: private StringBuilderDevice device = new StringBuilderDevice();
126:
127: private String formatSubject(Subject subject) {
128: try {
129: device.reset();
130: device.print("<html><b>");
131: Utils.writeQuoted(device, Client.getInstance()
132: .getResourceProvider().getMessage(
133: "process." + subject.getProcess()), true);
134: device.print("</b><br/>");
135: device.print(subject.getSubjectLine());
136: return device.toString();
137: } catch (IOException e) {
138: throw new RuntimeException(e);
139: }
140: }
141:
142: private String formatTask(Locale locale, Work work) {
143: try {
144: device.reset();
145: Utils.writeQuoted(device, getResourceProvider().getMessage(
146: locale,
147: "process." + work.getProcess() + "."
148: + work.getActivity()), true);
149: Utils.writeQuoted(device, work.getProcess() + " "
150: + work.getActivity(), true);
151: device.print(" - ");
152: device.print(work.getSubjectLine());
153: return device.toString();
154: } catch (IOException e) {
155: throw new RuntimeException(e);
156: }
157: }
158:
159: public String getServletInfo() {
160: return "TaskFeed - serving con:cern task assignments";
161: }
162: }
|