001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.webengine.ui.tree.directory;
021
022import org.nuxeo.ecm.directory.Directory;
023import org.nuxeo.ecm.directory.DirectoryException;
024import org.nuxeo.ecm.directory.api.DirectoryService;
025import org.nuxeo.ecm.webengine.WebException;
026import org.nuxeo.ecm.webengine.model.WebContext;
027import org.nuxeo.ecm.webengine.ui.tree.ContentProvider;
028import org.nuxeo.ecm.webengine.ui.tree.JSonTree;
029import org.nuxeo.ecm.webengine.ui.tree.JSonTreeSerializer;
030import org.nuxeo.runtime.api.Framework;
031
032/**
033 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
034 */
035public abstract class DirectoryTree extends JSonTree {
036
037    protected Directory dir;
038
039    protected DirectoryTree() {
040    }
041
042    protected DirectoryTree(Directory dir) {
043        this.dir = dir;
044    }
045
046    protected DirectoryTree(String directory) throws DirectoryException {
047        this(Framework.getService(DirectoryService.class).getDirectory(directory));
048    }
049
050    @Override
051    protected Object getInput(WebContext ctx) {
052        return dir;
053    }
054
055    @Override
056    protected ContentProvider getProvider(WebContext ctx) {
057        try {
058            return new DirectoryContentProvider(dir.getSession());
059        } catch (DirectoryException e) {
060            throw WebException.wrap(e);
061        }
062    }
063
064    @Override
065    protected JSonTreeSerializer getSerializer(WebContext ctx) {
066        return new JSonTreeSerializer();
067    }
068
069}