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.core.CoreConstants;
038: import org.libresource.core.ejb.model.ProjectResourceValue;
039: import org.libresource.core.interfaces.LibresourceCoreService;
040:
041: import org.libresource.web.wiki.LibresourceRenderContext;
042:
043: import org.radeox.engine.BaseRenderEngine;
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: public class SubProjectsMacro extends BaseMacro {
054: public String getName() {
055: return "subProjects";
056: }
057:
058: public void execute(Writer writer, MacroParameter params)
059: throws IllegalArgumentException, IOException {
060: try {
061: if ((params.getLength() != 0) && (params.getLength() != 1)) {
062: throw new IllegalArgumentException(
063: "syntax : subProjects or subProjects:Libresource://...");
064: }
065:
066: URI uri = null;
067:
068: if (params.getLength() == 0) {
069: uri = ((LibresourceRenderContext) params.getContext())
070: .getUri();
071: } else {
072: uri = new URI(params.get(0));
073: }
074:
075: LibresourceCoreService libresourceCoreService = (LibresourceCoreService) Libresource
076: .getService(CoreConstants.SERVICE);
077: ProjectResourceValue[] projects = libresourceCoreService
078: .listProjectAt(uri);
079:
080: writer
081: .write("<div class=\"subProjects\"><table class=\"lsList\">");
082:
083: for (int i = 0; i < projects.length; i++) {
084: writer.write("<tr class=\""
085: + (((i % 2) == 0) ? "odd" : "even") + "\">");
086: writer.write("<td class=\"label\"><a href=\""
087: + projects[i].getUri().getPath().substring(1)
088: + "\">");
089: writer.write(projects[i].getName());
090: writer.write("</a></td>");
091: writer.write("<td class=\"value\">");
092: writer
093: .write(new BaseRenderEngine().render(
094: projects[i].getDescription(),
095: new LibresourceRenderContext(new URI(
096: projects[i].getUri().getPath()
097: + "/"))));
098: writer.write("</td>");
099: writer.write("</tr>");
100: }
101:
102: writer.write("</table></div>");
103: } catch (IOException e) {
104: throw e;
105: } catch (IllegalArgumentException e) {
106: throw e;
107: } catch (Exception e) {
108: throw new IllegalArgumentException(
109: "error in subProjects : " + e.getMessage());
110: }
111: }
112:
113: public String getDescription() {
114: return "Display the current subProjects list.";
115: }
116:
117: public String[] getParamDescription() {
118: return new String[0];
119: }
120: }
|