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.LibresourceResourceValue;
037:
038: import org.libresource.kernel.KernelConstants;
039: import org.libresource.kernel.interfaces.KernelService;
040:
041: import org.libresource.web.Controller;
042: import org.libresource.web.taglibs.JspFunctions;
043:
044: import java.net.URI;
045:
046: import javax.servlet.http.HttpServletRequest;
047: import javax.servlet.http.HttpServletResponse;
048:
049: public class ChildrenTreeController implements Controller {
050: private static KernelService kernel;
051:
052: public Object process(URI uri, HttpServletRequest request,
053: HttpServletResponse response) throws Exception {
054: String depth = request.getParameter("depth");
055: int max = 1;
056:
057: if (depth != null) {
058: max = Integer.parseInt(depth);
059: }
060:
061: request.setAttribute("depth", new Integer(max));
062:
063: StringBuffer buffer = new StringBuffer();
064:
065: LibresourceResourceValue[] resourceValues = getKernel()
066: .listResourcesAt(uri);
067:
068: for (int i = 0; i < resourceValues.length; i++) {
069: listRecursively(resourceValues[i], buffer, 0, max - 1);
070: }
071:
072: request.setAttribute("content", buffer.toString());
073:
074: return "/pages/childrenTree.jsp";
075: }
076:
077: public static void listRecursively(LibresourceResourceValue node,
078: StringBuffer buffer, int currentLevel, int max)
079: throws Exception {
080: if (currentLevel > max) {
081: return;
082: }
083:
084: buffer.append("<ul>\n");
085: buffer.append("<li><span class=\"miniResource"
086: + JspFunctions.typeName(node)
087: + "\">\n<a href=\""
088: + node.getUri().getPath().substring(1)
089: + "\" title=\""
090: + node.getUri()
091: + "\">"
092: + ((node.getShortResourceName().length() > 0) ? node
093: .getShortResourceName() : "(Empty)")
094: + "</a></span></li>\n");
095:
096: LibresourceResourceValue[] resourceValues = getKernel()
097: .listResourcesAt(node.getUri());
098:
099: for (int i = 0; i < resourceValues.length; i++) {
100: listRecursively(resourceValues[i], buffer,
101: currentLevel + 1, max);
102: }
103:
104: buffer.append("</ul>\n");
105: }
106:
107: private static KernelService getKernel() throws Exception {
108: if (kernel == null) {
109: kernel = (KernelService) Libresource
110: .getService(KernelConstants.SERVICE);
111: }
112:
113: return kernel;
114: }
115: }
|