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 ChildrenExpandableController implements Controller {
050: private static KernelService kernel;
051:
052: public Object process(URI uri, HttpServletRequest request,
053: HttpServletResponse response) throws Exception {
054: String expandNode = request.getParameter("expand");
055:
056: StringBuffer buffer = new StringBuffer();
057: LibresourceResourceValue[] resourceValues = getKernel()
058: .listResourcesAt(uri);
059:
060: if (expandNode == null) {
061: expandNode = uri.getPath();
062: }
063:
064: for (int i = 0; i < resourceValues.length; i++) {
065: listRecursively(uri, resourceValues[i], buffer, expandNode
066: + "/");
067: }
068:
069: request.setAttribute("content", buffer.toString());
070:
071: return "/pages/childrenEx.jsp";
072: }
073:
074: private void listRecursively(URI currentNode,
075: LibresourceResourceValue node, StringBuffer buffer,
076: String expandPath) throws Exception {
077: buffer.append("<ul>\n");
078:
079: if ((expandPath).startsWith(node.getUri().getPath() + "/")) {
080: buffer
081: .append("<li><a href=\""
082: + currentNode.getPath()
083: + "?action=children&expand="
084: + node.getUri().getPath().substring(
085: 0,
086: node.getUri().getPath()
087: .lastIndexOf("/"))
088: + "\">"
089: + "<img src=\"/static/images/node-open.png\" alt=\"Collapse\"/></a>\n"
090: + "<span class=\"miniResource"
091: + JspFunctions.typeName(node)
092: + "\">\n"
093: + "<a href=\""
094: + node.getUri().getPath().substring(1)
095: + "\" title=\""
096: + node.getUri()
097: + "\">"
098: + ((node.getShortResourceName().length() > 0) ? node
099: .getShortResourceName()
100: : "(Empty)") + "</a></span></li>\n");
101:
102: LibresourceResourceValue[] resourceValues = getKernel()
103: .listResourcesAt(node.getUri());
104:
105: for (int i = 0; i < resourceValues.length; i++) {
106: listRecursively(currentNode, resourceValues[i], buffer,
107: expandPath);
108: }
109: } else {
110: buffer
111: .append("<li><a href=\""
112: + currentNode.getPath()
113: + "?action=children&expand="
114: + node.getUri().getPath()
115: + "\">"
116: + "<img src=\"/static/images/node-close.png\" alt=\"Expand\"/></a>\n"
117: + "<span class=\"miniResource"
118: + JspFunctions.typeName(node)
119: + "\">\n"
120: + "<a href=\""
121: + node.getUri().getPath().substring(1)
122: + "\" title=\""
123: + node.getUri()
124: + "\">"
125: + ((node.getShortResourceName().length() > 0) ? node
126: .getShortResourceName()
127: : "(Empty)") + "</a></span></li>\n");
128: }
129:
130: buffer.append("</ul>\n");
131: }
132:
133: private static KernelService getKernel() throws Exception {
134: if (kernel == null) {
135: kernel = (KernelService) Libresource
136: .getService(KernelConstants.SERVICE);
137: }
138:
139: return kernel;
140: }
141: }
|