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 java.io.IOException;
036: import java.io.Writer;
037: import java.net.URI;
038:
039: import org.libresource.Libresource;
040: import org.libresource.LibresourceResourceValue;
041: import org.libresource.kernel.KernelConstants;
042: import org.libresource.kernel.comparator.util.CountStructure;
043: import org.libresource.kernel.comparator.util.FlatStructure;
044: import org.libresource.kernel.comparator.util.ListStructure;
045: import org.libresource.kernel.comparator.util.TreeStructure;
046: import org.libresource.kernel.filter.Filter;
047: import org.libresource.kernel.filter.FilterBuilder;
048: import org.libresource.kernel.interfaces.KernelService;
049: import org.libresource.web.wiki.LibresourceRenderContext;
050: import org.radeox.macro.BaseMacro;
051: import org.radeox.macro.parameter.MacroParameter;
052:
053: public class SubResourcesMacro extends BaseMacro {
054: private KernelService kernelService = null;
055:
056: private static final String CREATION = "creation";
057:
058: private static final String OWNER = "owner";
059:
060: private static final String UPDATE = "update";
061:
062: private static final String TYPE = "type";
063:
064: private static final String VIEW = "view";
065:
066: private static final String GROUP_BY = "groupby";
067:
068: private static final String LIMIT = "limit";
069:
070: private static final String SORT = "sort";
071:
072: private static final String DEPTH = "depth";
073:
074: private static final String URI = "uri";
075:
076: public SubResourcesMacro() throws Exception {
077: kernelService = (KernelService) Libresource
078: .getService(KernelConstants.SERVICE);
079: }
080:
081: public String getName() {
082: return "children";
083: }
084:
085: public void execute(Writer writer, MacroParameter params)
086: throws IllegalArgumentException, IOException {
087: try {
088: // Get params
089: URI currentUri = ((LibresourceRenderContext) params
090: .getContext()).getUri();
091: String uri = (String) params.getParams().get(URI);
092: // Set the right URI
093: URI uriToList = null;
094: if (uri == null) {
095: uriToList = Libresource.getAbsoluteURI(currentUri, ".");
096: } else {
097: uriToList = Libresource.getAbsoluteURI(currentUri, uri);
098: }
099: String sort = params.get(SORT);
100: String groupby = params.get(GROUP_BY);
101: String view = params.get(VIEW);
102: int depth = (params.get(DEPTH) != null) ? Integer
103: .parseInt(params.get(DEPTH)) : 1;
104: int limit = (params.get(LIMIT) != null) ? Integer
105: .parseInt(params.get(LIMIT)) : Integer.MAX_VALUE;
106: String creationFilter = params.get(CREATION);
107: String updateFilter = params.get(UPDATE);
108: String typeFilter = params.get(TYPE);
109: String ownerFilter = params.get(OWNER);
110:
111: // Get the Data
112: ListStructure data = null;
113: if (view == null || view.equalsIgnoreCase("flat")) {
114: // flat
115: data = new FlatStructure();
116: } else if (view.equalsIgnoreCase("count")) {
117: // count
118: data = new CountStructure();
119: } else if (view.equalsIgnoreCase("tree")) {
120: // tree
121: data = new TreeStructure();
122: } else if (view.equalsIgnoreCase("tree-secu")) {
123: // tree
124: data = new TreeStructure(true);
125: }
126: data.setLimit(limit);
127: data.setGroupBy(groupby);
128: data.setSort(sort);
129: // Build comparator and filter
130: Filter filter = FilterBuilder.getFilter(creationFilter,
131: updateFilter, typeFilter, ownerFilter);
132: fillData(data, filter, uriToList, depth);
133:
134: // Show the data
135: data.print(writer);
136: } catch (IOException e) {
137: throw e;
138: } catch (IllegalArgumentException e) {
139: throw e;
140: } catch (Exception e) {
141: e.printStackTrace();
142: }
143:
144: }
145:
146: public void fillData(ListStructure data, Filter filter,
147: URI currentURI, int currentDepth) {
148: if (currentDepth > 0) {
149: try {
150: LibresourceResourceValue[] lsData = kernelService
151: .listResourcesAt(currentURI);
152: for (int i = 0; i < lsData.length; i++) {
153: if (filter.keep(lsData[i])) {
154: data.addItem(lsData[i]);
155: }
156: fillData(data, filter, lsData[i].getUri(),
157: currentDepth - 1);
158: }
159: } catch (Exception e) {
160: e.printStackTrace();
161: }
162: }
163: }
164:
165: public String getDescription() {
166: // "Display the current children list. ex:
167: // children:uri=/projects/demoFile|groupby=creation|sort=type|creation+12/05/2007|update=+12/04/2007|owner=root|limit=5|depth=2|view=tree
168: // ";
169: return "Display the current children list.";
170:
171: }
172:
173: public String[] getParamDescription() {
174: return new String[] {
175: "1. uri= ...(optional) where you list the resources, the default uri is the current ",
176: "2. groupby=... (optional) to group resources.The following value are available : type or owner or uri or creation or update or name",
177: "3. sort=... (optional) to sort resources. The values available are : type or owner or uri or creation or update or name ",
178: "4. creation=...(optional) allows you to filter on the creation date. The values available are: Date (dd/MM/yyyy) or '+'/'-'/'!' followed by a Date(dd/MM/yyyy): allows to keep superior/inferior/exclude date",
179: "5. update=...(optional) allows you to filter on the modification date. The values available are: Date (dd/MM/yyyy) or '+'/'-'/'!' followed by a Date(dd/MM/yyyy): allows to keep superior/inferior/exclude date",
180: "6. type=...(optional) :allows you to filter resources with its type. The values available are : Project, Template, Timeline, Page, Repository, File, Forum, Thread, Message, Group, Synchronizer, BugTracker, Issue, Site, Survey, Form, DropBox ",
181: "7. owner=...(optional):allows you to show only resources belonging to one user or many users. ",
182: "8. limit=...(optional): allows you to limit the displayed resources",
183: "9. depth=...(optional): allows you to fix the depth of listed ressources",
184: "10. view=...(optional): to fix the view of displayed resources. The view available are : flat (default view) or count(to display the number of listed ressources) or tree(display resource following tree viewer)" };
185: }
186:
187: }
|