001/*
002 * (C) Copyright 2012 Nuxeo SA (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 *     Antoine Taillefer <ataillefer@nuxeo.com>
016 */
017package org.nuxeo.drive.service.impl;
018
019import java.security.Principal;
020
021import org.nuxeo.drive.adapter.FileSystemItem;
022import org.nuxeo.drive.adapter.FolderItem;
023import org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem;
024import org.nuxeo.drive.service.FileSystemItemFactory;
025import org.nuxeo.drive.service.FileSystemItemManager;
026import org.nuxeo.ecm.core.api.DocumentModel;
027import org.nuxeo.runtime.api.Framework;
028
029/**
030 * Default {@link FileSystemItemFactory} for a synchronization root {@link FolderItem}.
031 *
032 * @author Antoine Taillefer
033 */
034public class DefaultSyncRootFolderItemFactory extends AbstractSyncRootFolderItemFactory {
035
036    /*------------------- AbstractFileSystemItemFactory ---------------------*/
037    @Override
038    protected FileSystemItem adaptDocument(DocumentModel doc, boolean forceParentItem, FolderItem parentItem,
039            boolean relaxSyncRootConstraint) {
040        return new DefaultSyncRootFolderItem(name, parentItem, doc, relaxSyncRootConstraint);
041    }
042
043    /*------------------ AbstractSyncRootFolderItemFactory ------------------*/
044    @Override
045    protected FolderItem getParentItem(DocumentModel doc) {
046        FileSystemItemManager fileSystemItemManager = Framework.getLocalService(FileSystemItemManager.class);
047        Principal principal = doc.getCoreSession().getPrincipal();
048        return fileSystemItemManager.getTopLevelFolder(principal);
049    }
050
051}