List of usage examples for org.apache.commons.vfs FileObject getName
public FileName getName();
From source file:com.panet.imeta.trans.steps.getxmldata.GetXMLData.java
private boolean ReadNextString() { try {//from w w w.ja va 2 s . com data.readrow = getRow(); // Grab another row ... if (data.readrow == null) // finished processing! { if (log.isDetailed()) logDetailed(Messages.getString("GetXMLData.Log.FinishedProcessing")); return false; } if (first) { first = false; if (meta.getIsInFields()) { data.inputRowMeta = getInputRowMeta(); data.outputRowMeta = data.inputRowMeta.clone(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this); // Get total previous fields data.totalpreviousfields = data.inputRowMeta.size(); // Create convert meta-data objects that will contain Date & // Number formatters data.convertRowMeta = data.outputRowMeta.clone(); for (int i = 0; i < data.convertRowMeta.size(); i++) data.convertRowMeta.getValueMeta(i).setType(ValueMetaInterface.TYPE_STRING); // For String to <type> conversions, we allocate a // conversion meta data row as well... // data.convertRowMeta = data.outputRowMeta.clone(); for (int i = 0; i < data.convertRowMeta.size(); i++) { data.convertRowMeta.getValueMeta(i).setType(ValueMetaInterface.TYPE_STRING); } // Check is XML field is provided if (Const.isEmpty(meta.getXMLField())) { logError(Messages.getString("GetXMLData.Log.NoField")); throw new KettleException(Messages.getString("GetXMLData.Log.NoField")); } // cache the position of the field if (data.indexOfXmlField < 0) { data.indexOfXmlField = getInputRowMeta().indexOfValue(meta.getXMLField()); if (data.indexOfXmlField < 0) { // The field is unreachable ! logError(Messages.getString("GetXMLData.Log.ErrorFindingField") + "[" //$NON-NLS-1$//$NON-NLS-2$ + meta.getXMLField() + "]"); throw new KettleException(Messages.getString("GetXMLData.Exception.CouldnotFindField", //$NON-NLS-1$ meta.getXMLField())); //$NON-NLS-2$ } } } } if (meta.getIsInFields()) { // get XML field value String Fieldvalue = getInputRowMeta().getString(data.readrow, data.indexOfXmlField); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("GetXMLData.Log.XMLStream", meta.getXMLField(), Fieldvalue)); if (meta.getIsAFile()) { FileObject file = null; try { // XML source is a file. file = KettleVFS.getFileObject(Fieldvalue); // Open the XML document if (!setDocument(null, file, false, false)) { throw new KettleException(Messages.getString("GetXMLData.Log.UnableCreateDocument")); } if (!applyXPath()) { throw new KettleException(Messages.getString("GetXMLData.Log.UnableApplyXPath")); } addFileToResultFilesname(file); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("GetXMLData.Log.LoopFileOccurences", "" + data.nodesize, file.getName().getBaseName())); } catch (Exception e) { throw new KettleException(e); } finally { try { if (file != null) file.close(); } catch (Exception e) { } } } else { boolean url = false; boolean xmltring = true; if (meta.isReadUrl()) { url = true; xmltring = false; } // Open the XML document if (!setDocument(Fieldvalue, null, xmltring, url)) { throw new KettleException(Messages.getString("GetXMLData.Log.UnableCreateDocument")); } // Apply XPath and set node list if (!applyXPath()) { throw new KettleException(Messages.getString("GetXMLData.Log.UnableApplyXPath")); } if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("GetXMLData.Log.LoopFileOccurences", "" + data.nodesize)); } } } catch (Exception e) { logError(Messages.getString("GetXMLData.Log.UnexpectedError", e.toString())); stopAll(); logError(Const.getStackTracker(e)); setErrors(1); return false; } return true; }
From source file:com.panet.imeta.job.entries.movefiles.JobEntryMoveFiles.java
private boolean CreateDestinationFolder(FileObject filefolder) { LogWriter log = LogWriter.getInstance(); FileObject folder = null; try {// w w w .j a v a 2 s . c o m if (destination_is_a_file) folder = filefolder.getParent(); else folder = filefolder; if (!folder.exists()) { if (create_destination_folder) { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FolderNotExist", folder.getName().toString())); folder.createFolder(); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FolderWasCreated", folder.getName().toString())); } else { log.logError(toString(), Messages.getString("JobMoveFiles.Log.FolderNotExist", folder.getName().toString())); return false; } } return true; } catch (Exception e) { log.logError(toString(), Messages.getString("JobMoveFiles.Log.CanNotCreateParentFolder", folder.getName().toString())); } finally { if (folder != null) { try { folder.close(); } catch (Exception ex) { } ; } } return false; }
From source file:com.panet.imeta.job.entries.ssh2put.JobEntrySSH2PUT.java
private boolean deleteOrMoveFiles(FileObject file, String destinationFolder) throws KettleException { try {/*www .j a v a 2 s . com*/ boolean retval = false; // Delete the file if this is needed! // if (afterFtpPut.equals("delete_file")) { file.delete(); retval = true; if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobSSH2PUT.Log.DeletedFile", file.toString())); } else if (afterFtpPut.equals("move_file")) { // Move File FileObject destination = null; FileObject source = null; try { destination = KettleVFS .getFileObject(destinationFolder + Const.FILE_SEPARATOR + file.getName().getBaseName()); file.moveTo(destination); retval = true; } catch (Exception e) { log.logError(toString(), Messages.getString("JobSSH2PUT.Cant_Move_File.Label", file.toString(), destinationFolder, e.getMessage())); } finally { if (destination != null) { try { destination.close(); } catch (Exception ex) { } ; } if (source != null) { try { source.close(); } catch (Exception ex) { } ; } } if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobSSH2PUT.Log.MovedFile", file.toString(), ftpDirectory)); } return retval; } catch (Exception e) { throw new KettleException(e); } }
From source file:com.panet.imeta.job.entries.movefiles.JobEntryMoveFiles.java
private boolean MoveOneFile(FileObject Currentfile, FileObject sourcefilefolder, String realDestinationFilefoldername, String realWildcard, LogWriter log, Job parentJob, Result result, FileObject movetofolderfolder) { boolean entrystatus = false; FileObject file_name = null;//from ww w. java 2s .c o m try { if (!Currentfile.toString().equals(sourcefilefolder.toString())) { // Pass over the Base folder itself // return destination short filename String sourceshortfilename = Currentfile.getName().getBaseName(); String shortfilename = sourceshortfilename; try { shortfilename = getDestinationFilename(sourceshortfilename); } catch (Exception e) { log.logError(toString(), Messages.getString(Messages.getString("JobMoveFiles.Error.GettingFilename", Currentfile.getName().getBaseName(), e.toString()))); return entrystatus; } int lenCurrent = sourceshortfilename.length(); String short_filename_from_basefolder = shortfilename; if (!isDoNotKeepFolderStructure()) short_filename_from_basefolder = Currentfile.toString() .substring(sourcefilefolder.toString().length(), Currentfile.toString().length()); short_filename_from_basefolder = short_filename_from_basefolder.substring(0, short_filename_from_basefolder.length() - lenCurrent) + shortfilename; // Built destination filename file_name = KettleVFS.getFileObject( realDestinationFilefoldername + Const.FILE_SEPARATOR + short_filename_from_basefolder); if (!Currentfile.getParent().toString().equals(sourcefilefolder.toString())) { // Not in the Base Folder..Only if include sub folders if (include_subfolders) { // Folders..only if include subfolders if (Currentfile.getType() == FileType.FOLDER) { if (include_subfolders && move_empty_folders && Const.isEmpty(wildcard)) { entrystatus = MoveFile(shortfilename, Currentfile, file_name, movetofolderfolder, log, parentJob, result); } } else { if (GetFileWildcard(sourceshortfilename, realWildcard)) { entrystatus = MoveFile(shortfilename, Currentfile, file_name, movetofolderfolder, log, parentJob, result); } } } } else { // In the Base Folder... // Folders..only if include subfolders if (Currentfile.getType() == FileType.FOLDER) { if (include_subfolders && move_empty_folders && Const.isEmpty(wildcard)) { entrystatus = MoveFile(shortfilename, Currentfile, file_name, movetofolderfolder, log, parentJob, result); } } else { // file...Check if exists if (GetFileWildcard(sourceshortfilename, realWildcard)) { entrystatus = MoveFile(shortfilename, Currentfile, file_name, movetofolderfolder, log, parentJob, result); } } } } entrystatus = true; } catch (Exception e) { log.logError(toString(), Messages.getString("JobMoveFiles.Log.Error", e.toString())); } finally { if (file_name != null) { try { file_name.close(); } catch (IOException ex) { } ; } } return entrystatus; }
From source file:net.sf.vfsjfilechooser.plaf.metal.MetalVFSFileChooserUI.java
private String fileNameString(FileObject fileObject) { if (fileObject == null) { return null; } else {/* w w w. ja v a 2 s . c om*/ VFSJFileChooser fc = getFileChooser(); if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) || (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystemRoot(fileObject))) { String url = null; try { url = fileObject.getURL().toExternalForm(); } catch (FileSystemException ex) { ex.printStackTrace(); } return url; } else { return fileObject.getName().getBaseName(); } } }
From source file:com.panet.imeta.job.entries.unzip.JobEntryUnZip.java
private boolean unzipFile(LogWriter log, FileObject sourceFileObject, String realTargetdirectory, String realWildcard, String realWildcardExclude, Result result, Job parentJob, FileObject fileObject, FileObject movetodir, String realMovetodirectory) { boolean retval = false; try {//from w ww. j av a2 s . c o m if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.Log.ProcessingFile", sourceFileObject.toString())); // Do you create a root folder? // if (rootzip) { String shortSourceFilename = sourceFileObject.getName().getBaseName(); int lenstring = shortSourceFilename.length(); int lastindexOfDot = shortSourceFilename.lastIndexOf('.'); if (lastindexOfDot == -1) lastindexOfDot = lenstring; String foldername = realTargetdirectory + "/" + shortSourceFilename.substring(0, lastindexOfDot); FileObject rootfolder = KettleVFS.getFileObject(foldername); if (!rootfolder.exists()) { try { rootfolder.createFolder(); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.Log.RootFolderCreated", foldername)); } catch (Exception e) { throw new Exception(Messages.getString("JobUnZip.Error.CanNotCreateRootFolder", foldername), e); } } } // Try to read the entries from the VFS object... // String zipFilename = "zip:" + sourceFileObject.getName().getFriendlyURI(); FileObject zipFile = KettleVFS.getFileObject(zipFilename); FileObject[] items = zipFile.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return true; } public boolean includeFile(FileSelectInfo info) { // Never return the parent directory of a file list. if (info.getDepth() == 0) { return false; } FileObject fileObject = info.getFile(); return fileObject != null; } }); Pattern pattern = null; if (!Const.isEmpty(realWildcard)) { pattern = Pattern.compile(realWildcard); } Pattern patternexclude = null; if (!Const.isEmpty(realWildcardExclude)) { patternexclude = Pattern.compile(realWildcardExclude); } for (FileObject item : items) { if (successConditionBroken) { if (!successConditionBrokenExit) { log.logError(toString(), Messages.getString("JobUnZip.Error.SuccessConditionbroken", "" + NrErrors)); successConditionBrokenExit = true; } return false; } try { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.Log.ProcessingZipEntry", item.getName().getURI(), sourceFileObject.toString())); // get real destination filename // String newFileName = realTargetdirectory + Const.FILE_SEPARATOR + getTargetFilename(item.getName().getPath()); FileObject newFileObject = KettleVFS.getFileObject(newFileName); if (item.getType().equals(FileType.FOLDER)) { // Directory // if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.CreatingDirectory.Label", newFileName)); // Create Directory if necessary ... // if (!newFileObject.exists()) newFileObject.createFolder(); } else { // File // boolean getIt = true; boolean getItexclude = false; // First see if the file matches the regular expression! // if (pattern != null) { Matcher matcher = pattern.matcher(item.getName().getURI()); getIt = matcher.matches(); } if (patternexclude != null) { Matcher matcherexclude = patternexclude.matcher(item.getName().getURI()); getItexclude = matcherexclude.matches(); } boolean take = takeThisFile(log, item, newFileName); if (getIt && !getItexclude && take) { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.ExtractingEntry.Label", item.getName().getURI(), newFileName)); if (iffileexist == IF_FILE_EXISTS_UNIQ) { // Create file with unique name int lenstring = newFileName.length(); int lastindexOfDot = newFileName.lastIndexOf('.'); if (lastindexOfDot == -1) lastindexOfDot = lenstring; newFileName = newFileName.substring(0, lastindexOfDot) + StringUtil.getFormattedDateTimeNow(true) + newFileName.substring(lastindexOfDot, lenstring); if (log.isDebug()) log.logDebug(toString(), Messages.getString("JobUnZip.Log.CreatingUniqFile", newFileName)); } // See if the folder to the target file exists... // if (!newFileObject.getParent().exists()) { newFileObject.getParent().createFolder(); // creates // the // whole // path. } InputStream is = null; OutputStream os = null; try { is = KettleVFS.getInputStream(item); os = KettleVFS.getOutputStream(newFileObject, false); if (is != null) { byte[] buff = new byte[2048]; int len; while ((len = is.read(buff)) > 0) { os.write(buff, 0, len); } // Add filename to result filenames addFilenameToResultFilenames(result, parentJob, newFileName); } } finally { if (is != null) is.close(); if (os != null) os.close(); } } // end if take } } catch (Exception e) { updateErrors(); log.logError(toString(), Messages.getString("JobUnZip.Error.CanNotProcessZipEntry", item.getName().getURI(), sourceFileObject.toString()), e); } } // End while // Here gc() is explicitly called if e.g. createfile is used in the // same // job for the same file. The problem is that after creating the // file the // file object is not properly garbaged collected and thus the file // cannot // be deleted anymore. This is a known problem in the JVM. // System.gc(); // Unzip done... if (afterunzip == 1) { // delete zip file boolean deleted = fileObject.delete(); if (!deleted) { updateErrors(); log.logError(toString(), Messages.getString("JobUnZip.Cant_Delete_File.Label", sourceFileObject.toString())); } // File deleted if (log.isDebug()) log.logDebug(toString(), Messages.getString("JobUnZip.File_Deleted.Label", sourceFileObject.toString())); } else if (afterunzip == 2) { FileObject destFile = null; // Move File try { String destinationFilename = movetodir + Const.FILE_SEPARATOR + fileObject.getName().getBaseName(); destFile = KettleVFS.getFileObject(destinationFilename); fileObject.moveTo(destFile); // File moved if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobUnZip.Log.FileMovedTo", sourceFileObject.toString(), realMovetodirectory)); } catch (Exception e) { updateErrors(); log.logError(toString(), Messages.getString("JobUnZip.Cant_Move_File.Label", sourceFileObject.toString(), realMovetodirectory, e.getMessage())); } finally { if (destFile != null) { try { destFile.close(); } catch (IOException ex) { } ; } } } retval = true; } catch (Exception e) { updateErrors(); log.logError(Messages.getString("JobUnZip.Error.Label"), Messages.getString("JobUnZip.ErrorUnzip.Label", sourceFileObject.toString(), e.getMessage()), e); } return retval; }
From source file:com.panet.imeta.job.entries.copymoveresultfilenames.JobEntryCopyMoveResultFilenames.java
public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) { LogWriter log = LogWriter.getInstance(); Result result = previousResult; result.setNrErrors(1);/*from w ww . j ava 2s. com*/ result.setResult(false); String realdestinationFolder = environmentSubstitute(getDestinationFolder()); if (!CreateDestinationFolder(realdestinationFolder, log)) { return result; } if (previousResult != null) { NrErrors = 0; limitFiles = Const.toInt(environmentSubstitute(getNrErrorsLessThan()), 10); NrErrors = 0; NrSuccess = 0; successConditionBroken = false; successConditionBrokenExit = false; FileObject file = null; try { int size = result.getResultFiles().size(); if (log.isBasic()) log.logBasic(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.log.FilesFound", "" + size)); List<ResultFile> resultFiles = result.getResultFilesList(); if (resultFiles != null && resultFiles.size() > 0) { for (Iterator<ResultFile> it = resultFiles.iterator(); it.hasNext() && !parentJob.isStopped();) { if (successConditionBroken) { log.logError(toString(), Messages.getString( "JobEntryCopyMoveResultFilenames.Error.SuccessConditionbroken", "" + NrErrors)); throw new Exception(Messages.getString( "JobEntryCopyMoveResultFilenames.Error.SuccessConditionbroken", "" + NrErrors)); } ResultFile resultFile = (ResultFile) it.next(); file = resultFile.getFile(); if (file != null && file.exists()) { if (!specifywildcard || (CheckFileWildcard(file.getName().getBaseName(), environmentSubstitute(wildcard), true) && !CheckFileWildcard(file.getName().getBaseName(), environmentSubstitute(wildcardexclude), false) && specifywildcard)) { // Copy or Move file if (!ProcessFile(file, realdestinationFolder, log, result, parentJob)) { // Update Errors updateErrors(); } } } else { log.logError(toString(), Messages.getString( "JobEntryCopyMoveResultFilenames.log.ErrorCanNotFindFile", file.toString())); // Update Errors updateErrors(); } } // end for } } catch (Exception e) { log.logError(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.Error", e.toString())); } finally { if (file != null) { try { file.close(); } catch (Exception ex) { } ; } } } // Success Condition result.setNrErrors(NrErrors); result.setNrLinesWritten(NrSuccess); if (getSuccessStatus()) result.setResult(true); return result; }
From source file:com.panet.imeta.job.entries.movefiles.JobEntryMoveFiles.java
private boolean MoveFile(String shortfilename, FileObject sourcefilename, FileObject destinationfilename, FileObject movetofolderfolder, LogWriter log, Job parentJob, Result result) { FileObject destinationfile = null; boolean retval = false; try {/*from ww w . ja v a 2 s.c o m*/ if (!destinationfilename.exists()) { if (!simulate) sourcefilename.moveTo(destinationfilename); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileMoved", sourcefilename.getName().toString(), destinationfilename.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfilename.toString(), log, result, parentJob); updateSuccess(); } else { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileExists", destinationfilename.toString())); if (iffileexists.equals("overwrite_file")) { if (!simulate) sourcefilename.moveTo(destinationfilename); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileOverwrite", destinationfilename.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfilename.toString(), log, result, parentJob); updateSuccess(); } else if (iffileexists.equals("unique_name")) { String short_filename = shortfilename; // return destination short filename try { short_filename = getMoveDestinationFilename(short_filename, "ddMMyyyy_HHmmssSSS"); } catch (Exception e) { log.logError(toString(), Messages.getString( Messages.getString("JobMoveFiles.Error.GettingFilename", short_filename))); return retval; } String movetofilenamefull = destinationfilename.getParent().toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(movetofilenamefull); if (!simulate) sourcefilename.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileMoved", sourcefilename.getName().toString(), destinationfile.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfile.toString(), log, result, parentJob); updateSuccess(); } else if (iffileexists.equals("delete_file")) { if (!simulate) destinationfilename.delete(); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileDeleted", destinationfilename.getName().toString())); } else if (iffileexists.equals("move_file")) { String short_filename = shortfilename; // return destination short filename try { short_filename = getMoveDestinationFilename(short_filename, null); } catch (Exception e) { log.logError(toString(), Messages.getString( Messages.getString("JobMoveFiles.Error.GettingFilename", short_filename))); return retval; } String movetofilenamefull = movetofolderfolder.toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(movetofilenamefull); if (!destinationfile.exists()) { if (!simulate) sourcefilename.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileMoved", sourcefilename.getName().toString(), destinationfile.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfile.toString(), log, result, parentJob); } else { if (ifmovedfileexists.equals("overwrite_file")) { if (!simulate) sourcefilename.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileOverwrite", destinationfile.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfile.toString(), log, result, parentJob); updateSuccess(); } else if (ifmovedfileexists.equals("unique_name")) { SimpleDateFormat daf = new SimpleDateFormat(); Date now = new Date(); daf.applyPattern("ddMMyyyy_HHmmssSSS"); String dt = daf.format(now); short_filename += "_" + dt; String destinationfilenamefull = movetofolderfolder.toString() + Const.FILE_SEPARATOR + short_filename; destinationfile = KettleVFS.getFileObject(destinationfilenamefull); if (!simulate) sourcefilename.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FileMoved", destinationfile.getName().toString())); // add filename to result filename if (add_result_filesname && !iffileexists.equals("fail") && !iffileexists.equals("do_nothing")) addFileToResultFilenames(destinationfile.toString(), log, result, parentJob); updateSuccess(); } else if (ifmovedfileexists.equals("fail")) { // Update Errors updateErrors(); } } } else if (iffileexists.equals("fail")) { // Update Errors updateErrors(); } } } catch (Exception e) { log.logError(toString(), Messages.getString("JobMoveFiles.Error.Exception.MoveProcessError", sourcefilename.toString(), destinationfilename.toString(), e.getMessage())); } finally { if (destinationfile != null) { try { destinationfile.close(); } catch (IOException ex) { } ; } } return retval; }
From source file:be.ibridge.kettle.job.JobMeta.java
/** * This method sets various internal kettle variables that can be used by the transformation. *//* w w w . j a v a2 s . c o m*/ public void setInternalKettleVariables() { KettleVariables variables = KettleVariables.getInstance(); if (filename != null) // we have a finename that's defined. { try { FileSystemManager fsManager = VFS.getManager(); FileObject fileObject = fsManager.resolveFile(filename); FileName fileName = fileObject.getName(); // The filename of the transformation variables.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName()); // The directory of the transformation FileName fileDir = fileName.getParent(); variables.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI()); } catch (IOException e) { variables.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, ""); variables.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, ""); } } else { variables.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, ""); //$NON-NLS-1$ variables.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, ""); //$NON-NLS-1$ } // The name of the job variables.setVariable(Const.INTERNAL_VARIABLE_JOB_NAME, Const.NVL(name, "")); //$NON-NLS-1$ // The name of the directory in the repository variables.setVariable(Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, directory != null ? directory.getPath() : ""); //$NON-NLS-1$ }
From source file:brainflow.app.presentation.controls.FileObjectGroupSelector.java
public FileObjectGroupSelector(FileObject root) throws FileSystemException { if (root.getType() != FileType.FOLDER) { throw new IllegalArgumentException("root file must be a directory"); }/*from w w w .java 2s . c o m*/ rootFolder = root; explorer = new FileExplorer(rootFolder); explorer.getJTree().setRootVisible(false); explorer.getJTree().getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); setLayout(new BorderLayout()); Box topPanel = new Box(BoxLayout.X_AXIS); topPanel.setBorder(BorderFactory.createEmptyBorder(8, 12, 8, 8)); topPanel.add(regexLabel); topPanel.add(regexField); topPanel.add(Box.createHorizontalStrut(4)); topPanel.add(searchType); add(topPanel, BorderLayout.NORTH); //JPanel mainPanel = new JPanel(); //MigLayout layout = new MigLayout(""); // mainPanel.setLayout(layout); //add(regexLabel); //add(regexField, "gap left 0, growx"); //add(findButton, "align right, wrap"); //add(searchType, "wrap"); //add(createSplitPane(), "span 3, grow, wrap"); add(createSplitPane(), BorderLayout.CENTER); depthSpinner.setMaximumSize(new Dimension(50, 200)); depthSpinner.setModel(new SpinnerNumberModel(recursiveDepth, 0, 5, 1)); JPanel bottomPanel = new JPanel(); MigLayout layout = new MigLayout("", "[][grow]", "[][]"); bottomPanel.setLayout(layout); //bottomPanel.setBorder(BorderFactory.createEmptyBorder(4,12,8,8)); bottomPanel.add(new JLabel("Root Folder: ")); rootField.setEditable(false); rootField.setText(root.getName().getBaseName()); bottomPanel.add(rootField, "wrap, width 150:150:150"); bottomPanel.add(new JLabel("Search Depth: "), "gap top 8"); bottomPanel.add(depthSpinner, "width 35:45:55, wrap"); add(bottomPanel, BorderLayout.SOUTH); explorer.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getPath(); Object[] obj = path.getPath(); Object lastNode = obj[obj.length - 1]; if (lastNode instanceof FileExplorer.FileObjectNode) { FileExplorer.FileObjectNode fnode = (FileExplorer.FileObjectNode) lastNode; try { if (fnode.getFileObject().getType() == FileType.FOLDER) { rootField.setText(fnode.getFileObject().getName().getBaseName()); rootFolder = fnode.getFileObject(); updateFileList(); } } catch (FileSystemException ex) { throw new RuntimeException(ex); } } } }); depthSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { recursiveDepth = ((Number) depthSpinner.getValue()).intValue(); updateFileList(); } }); regexField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateFileList(); System.out.println(Arrays.toString(explorer.getSelectedNodes().toArray())); } }); }