@Override
  public NetworkFile openFile(SrvSession sess, TreeConnection tree, FileOpenParams param)
      throws IOException {
    String path = param.getPath();

    boolean truncate = param.isOverwrite();

    if (logger.isDebugEnabled()) {
      int sharedAccess = param.getSharedAccess();
      String strSharedAccess = SharingMode.getSharingModeAsString(sharedAccess);

      logger.debug(
          "openFile:"
              + path
              + ", isDirectory: "
              + param.isDirectory()
              + ", isStream: "
              + param.isStream()
              + ", readOnlyAccess: "
              + param.isReadOnlyAccess()
              + ", readWriteAccess: "
              + param.isReadWriteAccess()
              + ", writeOnlyAccess:"
              + param.isWriteOnlyAccess()
              + ", attributesOnlyAccess:"
              + param.isAttributesOnlyAccess()
              + ", sequentialAccessOnly:"
              + param.isSequentialAccessOnly()
              + ", writeThrough:"
              + param.isWriteThrough()
              + ", truncate:"
              + truncate
              + ", requestBatchOpLock:"
              + param.requestBatchOpLock()
              + ", requestExclusiveOpLock:"
              + param.requestExclusiveOpLock()
              + ", isDeleteOnClose:"
              + param.isDeleteOnClose()
              + ", allocationSize:"
              + param.getAllocationSize()
              + ", sharedAccess: "
              + strSharedAccess
              + ", openAction: "
              + param.getOpenAction()
              + param);
    }

    ContentContext tctx = (ContentContext) tree.getContext();
    NodeRef rootNode = tctx.getRootNode();

    DriverState driverState = getDriverState(sess);

    String[] paths = FileName.splitPath(path);
    String folder = paths[0];
    String file = paths[1];

    EvaluatorContext ctx = getEvaluatorContext(driverState, folder);

    OpenFileMode openMode = OpenFileMode.READ_ONLY;

    if (param.isAttributesOnlyAccess()) {
      openMode = OpenFileMode.ATTRIBUTES_ONLY;
    } else if (param.isReadWriteAccess()) {
      openMode = OpenFileMode.READ_WRITE;
    } else if (param.isWriteOnlyAccess()) {
      openMode = OpenFileMode.WRITE_ONLY;
    } else if (param.isReadOnlyAccess()) {
      openMode = OpenFileMode.READ_ONLY;
    } else if (param.isDeleteOnClose()) {
      if (logger.isDebugEnabled()) {
        logger.debug("open file has delete on close");
      }
      openMode = OpenFileMode.DELETE;
    }

    try {
      Operation o = new OpenFileOperation(file, openMode, truncate, rootNode, path);
      Command c = ruleEvaluator.evaluate(ctx, o);
      Object ret = commandExecutor.execute(sess, tree, c);

      if (ret != null && ret instanceof NetworkFile) {
        NetworkFile x = (NetworkFile) ret;

        if (logger.isDebugEnabled()) {
          logger.debug("returning open file: for path:" + path + ", ret:" + ret);
        }
        return x;
      } else {
        // Error - contact broken
        logger.error(
            "contract broken - NetworkFile not returned. " + ret == null
                ? "Return value is null"
                : ret);
        return null;
      }
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
      throw new AccessDeniedException("Unable to open file " + param.getPath(), ade);
    }

    // return diskInterface.openFile(sess, tree, params);
  } // End of OpenFile
예제 #2
0
  @Override
  public NetworkFile openFile(SrvSession sess, TreeConnection tree, FileOpenParams params)
      throws IOException {
    ContentContext tctx = (ContentContext) tree.getContext();
    String path = params.getPath();

    FileAccessToken token = null;

    if (tctx.hasStateCache()) {
      if (!params.isDirectory()) {
        FileStateCache cache = tctx.getStateCache();
        FileState fstate = tctx.getStateCache().findFileState(params.getPath(), true);
        token = cache.grantFileAccess(params, fstate, FileStatus.Unknown);
        if (logger.isDebugEnabled()) {
          logger.debug("open file created lock token:" + token);
        }
      }
    }

    try {
      NetworkFile openFile = diskInterface.openFile(sess, tree, params);

      if (openFile instanceof ContentNetworkFile) {
        ContentNetworkFile x = (ContentNetworkFile) openFile;
        x.setProcessId(params.getProcessId());
        x.setAccessToken(token);
        if (tctx.hasStateCache()) {
          FileState fstate = tctx.getStateCache().findFileState(path, true);
          x.setFileState(fstate);
          fstate.setProcessId(params.getProcessId());
          fstate.setSharedAccess(params.getSharedAccess());
          fstate.setFileStatus(FileStatus.FileExists);
        }
      }

      if (openFile instanceof TempNetworkFile) {
        TempNetworkFile x = (TempNetworkFile) openFile;
        x.setAccessToken(token);
        // x.setProcessId( params.getProcessId());
        if (tctx.hasStateCache()) {
          FileState fstate = tctx.getStateCache().findFileState(path, true);
          x.setFileState(fstate);
          fstate.setFileStatus(FileStatus.FileExists);
          fstate.setProcessId(params.getProcessId());
          fstate.setSharedAccess(params.getSharedAccess());
        }
      }

      if (openFile instanceof AlfrescoFolder) {
        AlfrescoFolder x = (AlfrescoFolder) openFile;
        // x.setProcessId( param.getProcessId());
        if (tctx.hasStateCache()) {
          FileState fstate = tctx.getStateCache().findFileState(path, true);
          x.setFileState(fstate);
          fstate.setFileStatus(FileStatus.DirectoryExists);
          fstate.setProcessId(params.getProcessId());
          fstate.setSharedAccess(params.getSharedAccess());
        }
      }

      return openFile;
    } catch (IOException ie) {
      if (logger.isDebugEnabled()) {
        logger.debug("open file exception caught", ie);
      }
      if (tctx.hasStateCache() && token != null) {
        FileStateCache cache = tctx.getStateCache();
        FileState fstate = tctx.getStateCache().findFileState(params.getPath(), false);
        if (fstate != null) {
          if (logger.isDebugEnabled()) {
            logger.debug("open file release lock token:" + token);
          }
          cache.releaseFileAccess(fstate, token);
        }
      }
      throw ie;
    }
  }
  @Override
  public NetworkFile createFile(SrvSession sess, TreeConnection tree, FileOpenParams params)
      throws IOException {
    try {
      int attr = params.getAttributes();
      if (logger.isDebugEnabled()) {
        int sharedAccess = params.getSharedAccess();
        String strSharedAccess = SharingMode.getSharingModeAsString(sharedAccess);

        logger.debug(
            "createFile:"
                + params.getPath()
                + ", isDirectory: "
                + params.isDirectory()
                + ", isStream: "
                + params.isStream()
                + ", readOnlyAccess: "
                + params.isReadOnlyAccess()
                + ", readWriteAccess: "
                + params.isReadWriteAccess()
                + ", writeOnlyAccess:"
                + params.isWriteOnlyAccess()
                + ", attributesOnlyAccess:"
                + params.isAttributesOnlyAccess()
                + ", sequentialAccessOnly:"
                + params.isSequentialAccessOnly()
                + ", requestBatchOpLock:"
                + params.requestBatchOpLock()
                + ", requestExclusiveOpLock:"
                + params.requestExclusiveOpLock()
                + ", isDeleteOnClose:"
                + params.isDeleteOnClose()
                + ", sharedAccess: "
                + strSharedAccess
                + ", allocationSize: "
                + params.getAllocationSize()
                + ", isHidden:"
                + FileAttribute.isHidden(attr)
                + ", isSystem:"
                + FileAttribute.isSystem(attr));
      }

      long creationDateTime = params.getCreationDateTime();
      if (creationDateTime != 0) {
        logger.debug("creationDateTime is set:" + new Date(creationDateTime));
      }

      ContentContext tctx = (ContentContext) tree.getContext();
      NodeRef rootNode = tctx.getRootNode();

      String[] paths = FileName.splitPath(params.getPath());
      String folder = paths[0];
      String file = paths[1];

      DriverState driverState = getDriverState(sess);
      EvaluatorContext ctx = getEvaluatorContext(driverState, folder);

      Operation o =
          new CreateFileOperation(
              file,
              rootNode,
              params.getPath(),
              params.getAllocationSize(),
              FileAttribute.isHidden(attr));
      Command c = ruleEvaluator.evaluate(ctx, o);

      Object ret = commandExecutor.execute(sess, tree, c);

      if (ret != null && ret instanceof NetworkFile) {
        return (NetworkFile) ret;
      } else {
        // Error - contact broken
        logger.error(
            "contract broken - NetworkFile not returned. " + ret == null
                ? "Return value is null"
                : ret);
        return null;
      }
    } catch (org.alfresco.repo.security.permissions.AccessDeniedException ade) {
      throw new AccessDeniedException("Unable to create file " + params.getPath(), ade);
    }
  }