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.wiki.macros;
034:
035: import org.libresource.Libresource;
036:
037: import org.libresource.kernel.KernelConstants;
038: import org.libresource.kernel.interfaces.KernelService;
039:
040: import org.libresource.so6.server.ls.LibresourceSynchronizerConstants;
041: import org.libresource.so6.server.ls.interfaces.LibresourceSynchronizerService;
042:
043: import org.libresource.web.taglibs.JspFunctions;
044:
045: import org.radeox.macro.BaseMacro;
046: import org.radeox.macro.parameter.MacroParameter;
047:
048: import java.io.IOException;
049: import java.io.Writer;
050:
051: import java.net.URI;
052:
053: import java.util.Iterator;
054: import java.util.Vector;
055:
056: public class WorkspacesMacro extends BaseMacro {
057: KernelService kernelService = null;
058: LibresourceSynchronizerService synchronizerService = null;
059:
060: public WorkspacesMacro() throws Exception {
061: kernelService = (KernelService) Libresource
062: .getService(KernelConstants.SERVICE);
063: synchronizerService = (LibresourceSynchronizerService) Libresource
064: .getService(LibresourceSynchronizerConstants.SERVICE);
065: }
066:
067: public String getName() {
068: return "workspaces";
069: }
070:
071: public void execute(Writer writer, MacroParameter params)
072: throws IllegalArgumentException, IOException {
073: try {
074: URI userUri = kernelService.getConnectedResource();
075: Vector wcs = synchronizerService
076: .listManagerWsConnection(userUri.getPath());
077:
078: StringBuffer wcsContent = new StringBuffer();
079:
080: if (!wcs.isEmpty()) {
081: writer
082: .write("<div class=\"workspaces\"><h3>My workspaces :</h3>");
083:
084: for (Iterator i = wcs.iterator(); i.hasNext();) {
085: Object[] o = (Object[]) i.next();
086: wcsContent.append(" - {html} ["
087: + ((URI) o[0]).getPath() + "|");
088: wcsContent.append(o[1] + "@" + o[2] + "] ");
089:
090: if (((Boolean) o[3]).booleanValue()) {
091: wcsContent
092: .append(" <span style=\"color:red;\">(need update)</span>");
093: } else {
094: wcsContent
095: .append("<span>(__up-to-date__)</span>");
096: }
097:
098: wcsContent.append("{html}\n");
099: }
100:
101: writer.write(JspFunctions.render(userUri, wcsContent
102: .toString()));
103: writer.write("</div>");
104: }
105: } catch (IOException e) {
106: throw e;
107: } catch (IllegalArgumentException e) {
108: throw e;
109: } catch (Exception e) {
110: throw new IllegalArgumentException(e.getMessage());
111: }
112: }
113:
114: public String getDescription() {
115: return "Display the user workspaces.";
116: }
117:
118: public String[] getParamDescription() {
119: return new String[0];
120: }
121: }
|