コード例 #1
0
  public void updateParentFileCombo(FileObject selectedItem) {
    try {
      List<FileObject> parentChain = new ArrayList<FileObject>();
      // are we a directory?
      try {
        if (selectedItem.getType() == FileType.FOLDER && selectedItem.getType().hasChildren()) {
          // we have real children....
          parentChain.add(selectedItem);
        }
      } catch (Exception e) {
        // we are not a folder
      }
      FileObject parentFileObject;
      parentFileObject = selectedItem.getParent();
      while (parentFileObject != null) {
        parentChain.add(parentFileObject);
        parentFileObject = parentFileObject.getParent();
      }

      File roots[] = File.listRoots();
      if (currentPanel != null) {
        for (int i = 0; i < roots.length; i++) {
          parentChain.add(currentPanel.resolveFile(roots[i].getAbsolutePath()));
        }
      }

      String items[] = new String[parentChain.size()];
      int idx = 0;
      for (int i = parentChain.size() - 1; i >= 0; i--) {
        items[idx++] = ((FileObject) parentChain.get(i)).getName().getURI();
      }

      openFileCombo.setItems(items);
      openFileCombo.select(items.length - 1);
    } catch (Exception e) {
      e.printStackTrace();
      // then let's not update the GUI
    }
  }
コード例 #2
0
  @Override
  public boolean backupAgentConfigurations(boolean remove) {
    try {
      super.backupAgentConfigurations(remove);
      // backup jaas.conf
      FileObject jaasConfigFile = targetConfDir.resolveFile("jaas.conf");
      if (jaasConfigFile.exists()) {
        // backup file in the same folder it is installed
        backupFile(jaasConfigFile, jaasConfigFile.getParent());
        if (remove) {
          jaasConfigFile.delete();
        }
      }
      // backup setenv.sh and setenv.bat
      FileObject[] libs = targetBinDir.getChildren();
      for (int i = 0; i < libs.length; i++) {
        FileObject cfgFile = libs[i];

        if (!cfgFile.getType().getName().equals(FileType.FILE.getName())) {
          // ignore folders
          continue;
        }
        if (cfgFile.getName().getBaseName().startsWith("setenv")
            && (cfgFile.getName().getBaseName().endsWith(".sh")
                || cfgFile.getName().getBaseName().endsWith(".bat"))) {
          // backup files in the same folder they're installed in
          backupFile(cfgFile, cfgFile.getParent());
          if (remove) {
            cfgFile.delete();
          }
        }
      }
    } catch (Exception e) {
      getPrinter().printErrStatus("BackupAgentConfigurations", e.getMessage());
      return false;
    }
    return true;
  }
コード例 #3
0
 @Override
 public boolean backupAgentConfigurations(boolean remove) {
   try {
     // backup portal-ext.properties
     FileObject portalConfFile = targetConfDir.resolveFile("portal-ext.properties");
     if (portalConfFile.exists()) {
       // backup file in the same folder it is installed
       backupFile(portalConfFile, portalConfFile.getParent());
       if (remove) {
         portalConfFile.delete();
       }
     }
   } catch (Exception e) {
     getPrinter().printErrStatus("BackupAgentConfigurations", e.getMessage());
     return false;
   }
   return true;
 }
コード例 #4
0
ファイル: ZipLister.java プロジェクト: shrekwang/jvifm
  public void upOneDir() {
    try {
      // if the currentFileObject is the root of the archive file, do
      // nothing.
      if (currentFileObject.getName().getPath().equals("/")) return;
      FileObject parentFO = currentFileObject.getParent();
      if (parentFO != null) {
        if (table.getItemCount() > 0) {
          TableItem item = table.getItem(currentRow);
          FileObject selectFO = (FileObject) item.getData("fileObject");
          historyManager.setSelectedItem(
              currentFileObject.getName().getPath(), selectFO.getName().getBaseName());
        }

        currentFileObject = parentFO;
        changeCurrentNode();
        textLocation.setText(currentFileObject.getName().getPath());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #5
0
  /**
   * Since the exported transformation that runs this will reside in a ZIP file, we can't reference
   * files relatively. So what this does is turn the name of files into absolute paths OR it simply
   * includes the resource in the ZIP file. For now, we'll simply turn it into an absolute path and
   * pray that the file is on a shared drive or something like that.
   *
   * <p>TODO: create options to configure this behavior
   */
  public String exportResources(
      VariableSpace space,
      Map<String, ResourceDefinition> definitions,
      ResourceNamingInterface resourceNamingInterface,
      Repository repository)
      throws KettleException {
    try {
      // The object that we're modifying here is a copy of the original!
      // So let's change the filename from relative to absolute by grabbing the file object...
      // In case the name of the file comes from previous steps, forget about this!
      //
      if (Const.isEmpty(filenameField)) {
        // From : ${Internal.Transformation.Filename.Directory}/../foo/bar.csv
        // To   : /home/matt/test/files/foo/bar.csv
        //
        FileObject fileObject = KettleVFS.getFileObject(space.environmentSubstitute(filename));

        // If the file doesn't exist, forget about this effort too!
        //
        if (fileObject.exists()) {
          // Convert to an absolute path...
          //
          filename =
              resourceNamingInterface.nameResource(
                  fileObject.getName().getBaseName(),
                  fileObject.getParent().getName().getPath(),
                  space.toString(),
                  FileNamingType.DATA_FILE);

          return filename;
        }
      }
      return null;
    } catch (Exception e) {
      throw new KettleException(e); // $NON-NLS-1$
    }
  }
コード例 #6
0
  public FileObject open(
      Shell applicationShell,
      String[] schemeRestrictions,
      String initialScheme,
      boolean showFileScheme,
      String fileName,
      String[] fileFilters,
      String[] fileFilterNames,
      boolean returnUserAuthenticatedFile,
      int fileDialogMode,
      boolean showLocation,
      boolean showCustomUI) {

    this.fileDialogMode = fileDialogMode;
    this.fileFilters = fileFilters;
    this.fileFilterNames = fileFilterNames;
    this.applicationShell = applicationShell;
    this.showFileScheme = showFileScheme;
    this.initialScheme = initialScheme;
    this.schemeRestrictions = schemeRestrictions;
    this.showLocation = showLocation;
    this.showCustomUI = showCustomUI;

    FileObject tmpInitialFile = initialFile;

    if (defaultInitialFile != null && rootFile == null) {
      try {
        rootFile = defaultInitialFile.getFileSystem().getRoot();
        initialFile = defaultInitialFile;
      } catch (FileSystemException ignored) {
        // well we tried
      }
    }

    createDialog(applicationShell);

    if (!showLocation) {
      comboPanel.setParent(fakeShell);
    } else {
      comboPanel.setParent(customUIPanel);
    }

    if (!showCustomUI) {
      customUIPanel.setParent(fakeShell);
    } else {
      customUIPanel.setParent(dialog);
    }

    // create our file chooser tool bar, contains parent folder combo and various controls
    createToolbarPanel(dialog);
    // create our vfs browser component
    createVfsBrowser(dialog);
    populateCustomUIPanel(dialog);
    if (fileDialogMode == VFS_DIALOG_SAVEAS) {
      createFileNamePanel(dialog, fileName);
    } else {
      // create file filter panel
      createFileFilterPanel(dialog);
    }
    // create our ok/cancel buttons
    createButtonPanel(dialog);

    initialFile = tmpInitialFile;
    // set the initial file selection
    try {
      if (initialFile != null || rootFile != null) {
        vfsBrowser.selectTreeItemByFileObject(initialFile != null ? initialFile : rootFile, true);
        updateParentFileCombo(initialFile != null ? initialFile : rootFile);
        setSelectedFile(initialFile != null ? initialFile : rootFile);
        openFileCombo.setText(
            initialFile != null ? initialFile.getName().getURI() : rootFile.getName().getURI());
      }
    } catch (FileSystemException e) {
      MessageBox box = new MessageBox(dialog.getShell());
      box.setText(Messages.getString("VfsFileChooserDialog.error")); // $NON-NLS-1$
      box.setMessage(e.getMessage());
      box.open();
    }

    // set the size and show the dialog
    int height = 550;
    int width = 800;
    dialog.setSize(width, height);
    Rectangle bounds = dialog.getDisplay().getPrimaryMonitor().getClientArea();
    int x = (bounds.width - width) / 2;
    int y = (bounds.height - height) / 2;
    dialog.setLocation(x, y);
    dialog.open();

    if (rootFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) {
      if (!rootFile.getFileSystem().hasCapability(Capability.WRITE_CONTENT)) {
        MessageBox messageDialog = new MessageBox(dialog.getShell(), SWT.OK);
        messageDialog.setText(Messages.getString("VfsFileChooserDialog.warning")); // $NON-NLS-1$
        messageDialog.setMessage(
            Messages.getString("VfsFileChooserDialog.noWriteSupport")); // $NON-NLS-1$
        messageDialog.open();
      }
    }

    vfsBrowser.fileSystemTree.forceFocus();
    while (!dialog.isDisposed()) {
      if (!dialog.getDisplay().readAndDispatch()) dialog.getDisplay().sleep();
    }

    // we just woke up, we are probably disposed already..
    if (!dialog.isDisposed()) {
      hideCustomPanelChildren();
      dialog.dispose();
    }
    if (okPressed) {
      FileObject returnFile = vfsBrowser.getSelectedFileObject();
      if (returnFile != null && fileDialogMode == VFS_DIALOG_SAVEAS) {
        try {
          if (returnFile.getType().equals(FileType.FILE)) {
            returnFile = returnFile.getParent();
          }
          returnFile = returnFile.resolveFile(enteredFileName);
        } catch (FileSystemException e) {
          e.printStackTrace();
        }
      }

      // put user/pass on the filename so it comes out in the getUri call.
      if (!returnUserAuthenticatedFile) {
        // make sure to put the user/pass on the url if it's not there
        if (returnFile != null && returnFile.getName() instanceof URLFileName) {
          URLFileName urlFileName = (URLFileName) returnFile.getName();
          if (urlFileName.getUserName() == null || urlFileName.getPassword() == null) {
            // set it
            String user = "";
            String pass = "";

            UserAuthenticator userAuthenticator =
                DefaultFileSystemConfigBuilder.getInstance()
                    .getUserAuthenticator(returnFile.getFileSystem().getFileSystemOptions());

            if (userAuthenticator != null) {
              UserAuthenticationData data =
                  userAuthenticator.requestAuthentication(AUTHENTICATOR_TYPES);
              user = String.valueOf(data.getData(UserAuthenticationData.USERNAME));
              pass = String.valueOf(data.getData(UserAuthenticationData.PASSWORD));
              try {
                user = URLEncoder.encode(user, "UTF-8");
                pass = URLEncoder.encode(pass, "UTF-8");
              } catch (UnsupportedEncodingException e) {
                // ignore, just use the un encoded values
              }
            }

            // build up the url with user/pass on it
            int port = urlFileName.getPort();
            String portString = (port < 1) ? "" : (":" + port);
            String urlWithUserPass =
                urlFileName.getScheme()
                    + "://"
                    + user
                    + ":"
                    + pass
                    + "@"
                    + urlFileName.getHostName()
                    + portString
                    + urlFileName.getPath();

            try {
              returnFile = currentPanel.resolveFile(urlWithUserPass);
            } catch (FileSystemException e) {
              // couldn't resolve with user/pass on url??? interesting
              e.printStackTrace();
            }
          }
        }
      }
      return returnFile;
    } else {
      return null;
    }
  }
コード例 #7
0
  /**
   * Retrieves the output files produced by the job having the id given as argument. If the transfer
   * finishes successfully it deletes the temporary folders (at push_url and pull_url location) and
   * send notification to the listeners. Otherwise it notifies the listeners of the failure.
   *
   * <p>The transfer data operation is executed by a fixed thread pool executor (see {@link
   * DataTransferProcessor})
   *
   * @param awaitedjob
   * @return
   * @throws FileSystemException
   */
  protected void pullData(AwaitedJob awaitedjob) {
    String localOutFolderPath = awaitedjob.getLocalOutputFolder();
    if (localOutFolderPath == null) {
      logger.warn(
          "The job "
              + awaitedjob.getJobId()
              + " does not define an output folder on local machine. No output data will be retrieved");
      return;
    }

    String jobId = awaitedjob.getJobId();
    String pull_URL = awaitedjob.getPullURL();
    String pushUrl = awaitedjob.getPushURL();

    FileObject remotePullFolder = null;
    FileObject remotePushFolder = null;
    FileObject localfolder = null;

    Set<FileObject> foldersToDelete = new HashSet<FileObject>();

    try {
      remotePullFolder = fsManager.resolveFile(pull_URL);
      remotePushFolder = fsManager.resolveFile(pushUrl);
      localfolder = fsManager.resolveFile(localOutFolderPath);
    } catch (Exception e) {
      logger.error("Could not retrieve data for job " + jobId, e);
      logger.info(
          "Job  "
              + jobId
              + " will be removed from the known job list. The system will not attempt again to retrieve data for this job. You couyld try to manually copy the data from the location  "
              + pull_URL);
      removeAwaitedJob(jobId);
      return;
    }

    try {
      foldersToDelete.add(remotePullFolder.getParent());
      if (!remotePullFolder.getParent().equals(remotePushFolder.getParent()))
        foldersToDelete.add(remotePushFolder.getParent());
    } catch (FileSystemException e) {
      logger.warn(
          "Data in folders "
              + pull_URL
              + " and "
              + pushUrl
              + " cannot be deleted due to an unexpected error ",
          e);
      e.printStackTrace();
    }

    FileSelector fileSelector = Selectors.SELECT_ALL;
    // The code bellow has been commented:
    // We do not need to build a file selector because the files in the temporary folder
    // have been copied by the data space layer which already used a FastFileSelector
    // configured with includes and excludes patterns

    //         DSFileSelector fileSelector  = new DSFileSelector();
    //          try{
    //            JobState jobstate = uischeduler.getJobState(jobId);
    //            for (TaskState ts : jobstate.getTasks() )
    //     	   {
    //         	 List<OutputSelector> of =  ts.getOutputFilesList();
    //         	 for (OutputSelector outputSelector : of) {
    //         		 org.ow2.proactive.scheduler.common.task.dataspaces.FileSelector fs =
    // outputSelector.getOutputFiles();
    //
    //         		fileSelector.addIncludes(fs.getIncludes());
    //         		fileSelector.addExcludes(fs.getExcludes());
    //     		}
    //     	   }
    //          }catch (Exception e)
    //     	   {
    //     		 logger_util.error("An exception occured while computing which output files to download
    // for job "+ jobId+". All available files will be downloaded for this job");
    //         	 e.printStackTrace();
    //     	   }

    DataTransferProcessor dtp =
        new DataTransferProcessor(
            remotePullFolder, localfolder, jobId, foldersToDelete, fileSelector);
    tpe.submit(dtp);
  }