Package unibg.overencrypt.domain

Source Code of unibg.overencrypt.domain.OverEncryptedRootFolder

/**
* OverEncrypt project hosted by Università degli Studi di Bergamo
*   -> for PrimeLife project {@link http://www.primelife.eu/}
*/
package unibg.overencrypt.domain;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.swing.JOptionPane;

import org.apache.log4j.Logger;

import com.bradmcevoy.http.LockInfo;
import com.bradmcevoy.http.LockTimeout;
import com.bradmcevoy.http.LockToken;
import com.bradmcevoy.http.Resource;
import com.bradmcevoy.http.exceptions.NotAuthorizedException;

import unibg.overencrypt.server.ResourcesManager;
import unibg.overencrypt.server.ServerConfiguration;

/**
*
* @author Flavio Giovarruscio & Riccardo Tribbia
* @version 1.0
*/
public class OverEncryptedRootFolder extends OverEncryptedFolderResource {

  /** Logger for this class. */
  private static final Logger LOGGER = Logger.getLogger( OverEncryptedRootFolder.class );


  public OverEncryptedRootFolder(String host, OverEncryptResourceFactory factory, int ownerid){
    super(host, factory, new File(ServerConfiguration.getWebDAVrootPath() + "/" + ownerid), ownerid, true);

  }

  @Override
  public Resource child(String name) {
    JOptionPane.showMessageDialog(null, "RootFolder child: " + name);
    JOptionPane.showMessageDialog(null, "\"shared\".equalsIgnoreCase(name): " + "shared".equalsIgnoreCase(name));
    if("shared".equalsIgnoreCase(name)){
      JOptionPane.showMessageDialog(null, "1");
      return new OverEncryptedSharedFolder(factory, ownerId);
    }else{
      JOptionPane.showMessageDialog(null, "2");
      return super.child(name);
    }
  }
 
  @Override
  public List<? extends Resource> getChildren() {
    ArrayList<Resource> list = new ArrayList<Resource>();
    File[] files = this.realFile.listFiles();
    if( files != null ) {
      for( File fchild : files ) {
        Resource res = factory.resolveFile( this.host, fchild );
        if( res != null ) {
          list.add( res );
        } else {
          LOGGER.error("Couldn't resolve file - " + fchild.getAbsolutePath());
        }
      }
    }
    //Check if owner has got shared file form other users
    LOGGER.debug("Start check if this user have some sharing folders from other users");
    ResourcesManager resMan = (ResourcesManager) factory;
    HashMap<Integer,ArrayList<String>> permissions = resMan.getUserPermissions(ownerId);
    if(permissions != null && permissions.size() > 1){
      Set<Integer> keys = permissions.keySet();
      for (Iterator<Integer> iterator = keys.iterator(); iterator.hasNext();) {
        Integer user = (Integer) iterator.next();
        if(user != ownerId){
          LOGGER.debug("Yes, he have.");
          list.add(new OverEncryptedSharedFolder(factory, ownerId));
          break;
        }
      }
    }
    return list;
  }
 
 
  @Override
  public Resource createNew(String name, InputStream in, Long length,
      String contentType) throws IOException {
    Resource res = null;
    if(".tokens".equals(name) || ".request".equals(name) || ".response".equals(name)){
      res = super.createNew(name, in, length, contentType);
    }
    return res;
  }
 
  @Override
  protected void doCopy(File dest) {
    //Do nothing
  }
 
  @Override
  public LockToken createAndLock(String name, LockTimeout timeout,
      LockInfo lockInfo) throws NotAuthorizedException {
    return null;
  }
}
TOP

Related Classes of unibg.overencrypt.domain.OverEncryptedRootFolder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.