001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.webengine.ui.tree.directory; 023 024import org.nuxeo.ecm.directory.Directory; 025import org.nuxeo.ecm.directory.DirectoryException; 026import org.nuxeo.ecm.directory.api.DirectoryService; 027import org.nuxeo.ecm.webengine.WebException; 028import org.nuxeo.ecm.webengine.model.WebContext; 029import org.nuxeo.ecm.webengine.ui.tree.ContentProvider; 030import org.nuxeo.ecm.webengine.ui.tree.JSonTree; 031import org.nuxeo.ecm.webengine.ui.tree.JSonTreeSerializer; 032import org.nuxeo.runtime.api.Framework; 033 034/** 035 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 036 */ 037public abstract class DirectoryTree extends JSonTree { 038 039 protected Directory dir; 040 041 protected DirectoryTree() { 042 } 043 044 protected DirectoryTree(Directory dir) { 045 this.dir = dir; 046 } 047 048 protected DirectoryTree(String directory) throws DirectoryException { 049 this(Framework.getService(DirectoryService.class).getDirectory(directory)); 050 } 051 052 @Override 053 protected Object getInput(WebContext ctx) { 054 return dir; 055 } 056 057 @Override 058 protected ContentProvider getProvider(WebContext ctx) { 059 try { 060 return new DirectoryContentProvider(dir.getSession()); 061 } catch (DirectoryException e) { 062 throw WebException.wrap(e); 063 } 064 } 065 066 @Override 067 protected JSonTreeSerializer getSerializer(WebContext ctx) { 068 return new JSonTreeSerializer(); 069 } 070 071}