001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.web.controllers;
034:
035: import org.libresource.Libresource;
036: import org.libresource.LibresourceResourceIdentifier;
037:
038: import org.libresource.core.CoreConstants;
039: import org.libresource.core.interfaces.LibresourceCoreService;
040:
041: import org.libresource.kernel.KernelConstants;
042: import org.libresource.kernel.interfaces.KernelService;
043:
044: import org.libresource.so6.core.net.LibresourceDataflowUriResolver;
045:
046: import org.libresource.web.Controller;
047:
048: import java.net.URI;
049:
050: import javax.servlet.http.HttpServletRequest;
051: import javax.servlet.http.HttpServletResponse;
052:
053: public class WatchController implements Controller {
054: public Object process(URI uri, HttpServletRequest request,
055: HttpServletResponse response) throws Exception {
056: if (request.getParameter("cancel") != null) {
057: return uri;
058: }
059:
060: KernelService kernelService = (KernelService) Libresource
061: .getService(KernelConstants.SERVICE);
062: String[] events = request.getParameterValues("events");
063:
064: if (events == null) {
065: LibresourceResourceIdentifier resourceIdentifier = kernelService
066: .lookup(uri);
067:
068: String[] kernelEvents = kernelService.listKernelEvents();
069: String[] resourceEvents = Libresource
070: .listAvailablesEvents(resourceIdentifier);
071: request.setAttribute("kernelEvents", kernelEvents);
072: request.setAttribute("resourceEvents", resourceEvents);
073:
074: String notificationType = Libresource
075: .getLibresourceConfiguration("notification.default.type");
076:
077: if (notificationType == null) {
078: notificationType = "mail,jabber";
079: }
080:
081: if (notificationType.indexOf("mail") != -1) {
082: request.setAttribute("mail", "true");
083: }
084:
085: if (notificationType.indexOf("jabber") != -1) {
086: request.setAttribute("jabber", "true");
087: }
088:
089: return "/pages/watch.jsp";
090: } else {
091: for (int i = 0; i < events.length; i++) {
092: StringBuffer name = new StringBuffer();
093: name.append("Watch ");
094:
095: if ("*".equals(events[i])) {
096: name.append("All ");
097: } else {
098: name.append(events[i].substring(events[i]
099: .lastIndexOf(".") + 1, events[i].length())
100: + " ");
101: }
102:
103: name.append("events on node : [" + uri + "|"
104: + Libresource.getShortName(uri) + "]");
105:
106: String uriFilter = uri.getPath();
107: String argsFilter = "*";
108:
109: StringBuffer notificationType = new StringBuffer();
110:
111: if (request.getParameter("mail") != null) {
112: notificationType.append("mail");
113: }
114:
115: if (request.getParameter("jabber") != null) {
116: if (notificationType.length() > 0) {
117: notificationType.append(",");
118: }
119:
120: notificationType.append("jabber");
121: }
122:
123: LibresourceCoreService libresourceCoreService = (LibresourceCoreService) Libresource
124: .getService(CoreConstants.SERVICE);
125: libresourceCoreService.addEventFilter(name.toString(),
126: kernelService.getConnectedResource(),
127: uriFilter, events[i], argsFilter,
128: notificationType.toString());
129: }
130: }
131:
132: return uri;
133: }
134: }
|