001/* 002 * (C) Copyright 2012 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 * Antoine Taillefer <ataillefer@nuxeo.com> 018 */ 019package org.nuxeo.drive.adapter.impl; 020 021import java.security.Principal; 022import java.util.Calendar; 023import java.util.List; 024 025import org.nuxeo.drive.adapter.FileItem; 026import org.nuxeo.drive.adapter.FileSystemItem; 027import org.nuxeo.drive.adapter.FolderItem; 028import org.nuxeo.drive.service.impl.NuxeoDriveManagerImpl; 029import org.nuxeo.ecm.core.api.Blob; 030 031/** 032 * Base implementation of a virtual {@link FolderItem}. 033 * 034 * @author Antoine Taillefer 035 */ 036public abstract class AbstractVirtualFolderItem extends AbstractFileSystemItem implements FolderItem { 037 038 private static final long serialVersionUID = 1L; 039 040 protected boolean canCreateChild; 041 042 public AbstractVirtualFolderItem(String factoryName, Principal principal, String parentId, String parentPath, 043 String folderName) { 044 super(factoryName, principal, false); 045 this.parentId = parentId; 046 name = folderName; 047 folder = true; 048 creator = "system"; 049 lastContributor = "system"; 050 // The Fixed Origin of (Unix) Time 051 creationDate = Calendar.getInstance(NuxeoDriveManagerImpl.UTC); 052 creationDate.set(1970, 0, 1, 0, 0, 0); 053 lastModificationDate = this.creationDate; 054 canRename = false; 055 canDelete = false; 056 canCreateChild = false; 057 path = "/" + getId(); 058 if (parentPath != null) { 059 path = parentPath + path; 060 } 061 } 062 063 protected AbstractVirtualFolderItem() { 064 // Needed for JSON deserialization 065 } 066 067 /*----------------------- FolderItem -----------------------*/ 068 @Override 069 public abstract List<FileSystemItem> getChildren(); 070 071 /*--------------------- FileSystemItem ---------------------*/ 072 @Override 073 public void rename(String name) { 074 throw new UnsupportedOperationException("Cannot rename a virtual folder item."); 075 } 076 077 @Override 078 public void delete() { 079 throw new UnsupportedOperationException("Cannot delete a virtual folder item."); 080 } 081 082 @Override 083 public boolean canMove(FolderItem dest) { 084 return false; 085 } 086 087 @Override 088 public FileSystemItem move(FolderItem dest) { 089 throw new UnsupportedOperationException("Cannot move a virtual folder item."); 090 } 091 092 /*--------------------- FolderItem -----------------*/ 093 @Override 094 public boolean getCanCreateChild() { 095 return canCreateChild; 096 } 097 098 @Override 099 public FolderItem createFolder(String name) { 100 throw new UnsupportedOperationException("Cannot create a folder in a virtual folder item."); 101 } 102 103 @Override 104 public FileItem createFile(Blob blob) { 105 throw new UnsupportedOperationException("Cannot create a file in a virtual folder item."); 106 } 107 108 /*---------- Needed for JSON deserialization ----------*/ 109 protected void setCanCreateChild(boolean canCreateChild) { 110 this.canCreateChild = canCreateChild; 111 } 112 113}