Java Code Examples for org.openide.filesystems.FileUtil#preventFileChooserSymlinkTraversal()
The following examples show how to use
org.openide.filesystems.FileUtil#preventFileChooserSymlinkTraversal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: hostviewPanelVisual.java From visualvm with GNU General Public License v2.0 | 6 votes |
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed String command = evt.getActionCommand(); if ("BROWSE".equals(command)) { JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setDialogTitle("Select Project Location"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); String path = this.projectLocationTextField.getText(); if (path.length() > 0) { File f = new File(path); if (f.exists()) { chooser.setSelectedFile(f); } } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File projectDir = chooser.getSelectedFile(); projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); } panel.fireChangeEvent(); } }
Example 2
Source File: datasourcePanelVisual.java From visualvm with GNU General Public License v2.0 | 6 votes |
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed String command = evt.getActionCommand(); if ("BROWSE".equals(command)) { JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setDialogTitle("Select Project Location"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); String path = this.projectLocationTextField.getText(); if (path.length() > 0) { File f = new File(path); if (f.exists()) { chooser.setSelectedFile(f); } } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File projectDir = chooser.getSelectedFile(); projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); } panel.fireChangeEvent(); } }
Example 3
Source File: CustomizerSources.java From netbeans with Apache License 2.0 | 6 votes |
private void updateFolder(JTextField textField) { JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); File fileName = new File(textField.getText()); File folder = fileName.isAbsolute() ? fileName : new File(projectFld, fileName.getPath()); if (folder.exists()) { chooser.setSelectedFile(folder); } else { chooser.setSelectedFile(projectFld); } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File selected = FileUtil.normalizeFile(chooser.getSelectedFile()); String newFolder; if (CollocationQuery.areCollocated(projectFld, selected)) { newFolder = PropertyUtils.relativizeFile(projectFld, selected); } else { newFolder = selected.getPath(); } textField.setText(newFolder); } }
Example 4
Source File: OutputPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void javadocBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javadocBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES); chooser.setMultiSelectionEnabled(false); if (lastChosenFile != null) { chooser.setSelectedFile(lastChosenFile); } else if (javadoc.getText().length() > 0) { chooser.setSelectedFile(new File(javadoc.getText())); } else { File files[] = model.getBaseFolder().listFiles(); if (files != null && files.length > 0) { chooser.setSelectedFile(files[0]); } else { chooser.setSelectedFile(model.getBaseFolder()); } } chooser.setDialogTitle(NbBundle.getMessage(OutputPanel.class, "LBL_Browse_Javadoc")); // NOI18N if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = chooser.getSelectedFile(); file = FileUtil.normalizeFile(file); javadoc.setText(file.getAbsolutePath()); lastChosenFile = file; } }
Example 5
Source File: ProjectLocationPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void browseLocationAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLocationAction String command = evt.getActionCommand(); if ( "BROWSE".equals( command ) ) { // NOI18N JFileChooser chooser = new JFileChooser (); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setDialogTitle(NbBundle.getMessage(ProjectLocationPanel.class,"LBL_NWP1_SelectProjectLocation")); chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); String path = this.projectLocationTextField.getText(); if (path.length() > 0) { File f = new File (path); if (f.exists ()) { chooser.setSelectedFile(f); } } if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N File projectDir = chooser.getSelectedFile(); projectLocationTextField.setText( projectDir.getAbsolutePath() ); } wizard.fireChangeEvent(); } }
Example 6
Source File: pluggableViewDemoSuitePanelVisual.java From visualvm with GNU General Public License v2.0 | 6 votes |
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed String command = evt.getActionCommand(); if ("BROWSE".equals(command)) { JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setDialogTitle("Select Project Location"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); String path = this.projectLocationTextField.getText(); if (path.length() > 0) { File f = new File(path); if (f.exists()) { chooser.setSelectedFile(f); } } if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File projectDir = chooser.getSelectedFile(); projectLocationTextField.setText(FileUtil.normalizeFile(projectDir).getAbsolutePath()); } panel.fireChangeEvent(); } }
Example 7
Source File: CustomizerRun.java From netbeans with Apache License 2.0 | 6 votes |
private void jButtonWorkingDirectoryBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWorkingDirectoryBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); String workDir = jTextWorkingDirectory.getText(); if (workDir.equals("")) { workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(); } chooser.setSelectedFile(new File(workDir)); chooser.setDialogTitle(NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title")); // NOI18N if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N File file = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextWorkingDirectory.setText(file.getAbsolutePath()); } }
Example 8
Source File: CustomizerSources.java From netbeans with Apache License 2.0 | 6 votes |
private void configFilesFolderBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configFilesFolderBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); File fileName = new File(jTextFieldConfigFilesFolder.getText()); File configFiles = fileName.isAbsolute() ? fileName : new File(projectFld, fileName.getPath()); if (configFiles.isAbsolute()) { chooser.setSelectedFile(configFiles); } else { chooser.setSelectedFile(projectFld); } if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File selected = FileUtil.normalizeFile(chooser.getSelectedFile()); String newConfigFiles; if (CollocationQuery.areCollocated(projectFld, selected)) { newConfigFiles = PropertyUtils.relativizeFile(projectFld, selected); } else { newConfigFiles = selected.getPath(); } jTextFieldConfigFilesFolder.setText(newConfigFiles); } }
Example 9
Source File: TruststorePanel.java From netbeans with Apache License 2.0 | 6 votes |
private void storeLocationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_storeLocationButtonActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setDialogTitle(NbBundle.getMessage(TruststorePanel.class, "LBL_TruststoreBrowse_Title")); //NOI18N chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new StoreFileFilter()); File f = new File(storeLocationTextField.getText()); if ((f != null) && (f.exists())) { if (f.isDirectory()) { chooser.setCurrentDirectory(f); } else { chooser.setCurrentDirectory(f.getParentFile()); } } if (chooser.showOpenDialog(this)== JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); if (file != null) { setStoreLocation(file.getPath()); String extension = FileUtil.getExtension(file.getName()); storeType = StoreFileFilter.JKS_EXT.equals(extension) ? JKS : PKCS12; } } }
Example 10
Source File: CustomizerRun.java From netbeans with Apache License 2.0 | 6 votes |
private void jButtonWorkingDirectoryBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonWorkingDirectoryBrowseActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); String workDir = jTextWorkingDirectory.getText(); if (workDir.equals("")) { workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(); } chooser.setSelectedFile(new File(workDir)); chooser.setDialogTitle(NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title")); // NOI18N if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N File file = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextWorkingDirectory.setText(file.getAbsolutePath()); } }
Example 11
Source File: KeystorePanel.java From netbeans with Apache License 2.0 | 6 votes |
private void keystoreLocationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_keystoreLocationButtonActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setDialogTitle(NbBundle.getMessage(KeystorePanel.class, "LBL_KeystoreBrowse_Title")); //NOI18N chooser.setFileSelectionMode (JFileChooser.FILES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setFileFilter(new StoreFileFilter()); File f = new File(keystoreLocationTextField.getText()); if ((f != null) && (f.exists())) { if (f.isDirectory()) { chooser.setCurrentDirectory(f); } else { chooser.setCurrentDirectory(f.getParentFile()); } } if (chooser.showOpenDialog(this)== JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); if (file != null) { setKeystorePath(file.getPath()); String extension = FileUtil.getExtension(file.getName()); keystoreType = StoreFileFilter.JKS_EXT.equals(extension) ? JKS : PKCS12; } } }
Example 12
Source File: NbPlatformCustomizerHarness.java From netbeans with Apache License 2.0 | 6 votes |
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed JFileChooser jfc = new JFileChooser() { // Trick stolen from ProjectChooserAccessory.ProjectFileChooser: public void approveSelection() { File dir = FileUtil.normalizeFile(getSelectedFile()); if (NbPlatform.isHarness(dir)) { super.approveSelection(); } else { setCurrentDirectory(dir); } } }; FileUtil.preventFileChooserSymlinkTraversal(jfc, null); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setSelectedFile(plaf.getHarnessLocation()); if (jfc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try { plaf.setHarnessLocation(FileUtil.normalizeFile(jfc.getSelectedFile())); } catch (IOException e) { Exceptions.printStackTrace(e); } } update(); ApisupportAntUIUtils.setText(otherText, plaf.getHarnessLocation().getAbsolutePath()); }
Example 13
Source File: UpdateEclipseReferencePanel.java From netbeans with Apache License 2.0 | 5 votes |
private void browseWorkspaceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseWorkspaceButtonActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle(org.openide.util.NbBundle.getMessage(UpdateEclipseReferencePanel.class, "TITLE_Select_Eclipse_Workspace")); if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = FileUtil.normalizeFile(chooser.getSelectedFile()); eclipseWorkspaceTextField.setText(file.getAbsolutePath()); } }
Example 14
Source File: PanelSourceFolders.java From netbeans with Apache License 2.0 | 5 votes |
private void jButtonLibrariesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLibrariesActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); if (jTextFieldLibraries.getText().length() > 0 && getLibraries().exists()) { chooser.setSelectedFile(getLibraries()); } else { chooser.setCurrentDirectory((File) wizardDescriptor.getProperty(ProjectLocationWizardPanel.PROJECT_DIR)); } if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File configFilesDir = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextFieldLibraries.setText(configFilesDir.getAbsolutePath()); } }
Example 15
Source File: PanelSourceFolders.java From netbeans with Apache License 2.0 | 5 votes |
private void jButtonLibrariesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLibrariesActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (jTextFieldLibraries.getText().length() > 0 && getLibraries().exists()) { chooser.setSelectedFile(getLibraries()); } else { chooser.setCurrentDirectory((File) wizardDescriptor.getProperty(ProjectLocationWizardPanel.PROJECT_DIR)); } if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File configFilesDir = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextFieldLibraries.setText(configFilesDir.getAbsolutePath()); } }
Example 16
Source File: LibrariesNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { org.netbeans.api.project.ant.FileChooser chooser; if (helper.isSharableProject()) { chooser = new org.netbeans.api.project.ant.FileChooser(helper, true); } else { chooser = new org.netbeans.api.project.ant.FileChooser(FileUtil.toFile(helper.getProjectDirectory()), null); } chooser.enableVariableBasedSelection(true); chooser.setFileHidingEnabled(false); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES ); chooser.setMultiSelectionEnabled( true ); chooser.setDialogTitle( NbBundle.getMessage( LibrariesNode.class, "LBL_AddJar_DialogTitle" ) ); // NOI18N //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order. chooser.setAcceptAllFileFilterUsed( false ); FileFilter fileFilter = new SimpleFileFilter ( NbBundle.getMessage( LibrariesNode.class, "LBL_ZipJarFolderFilter" )); // NOI18N chooser.setFileFilter(fileFilter); File curDir = EditMediator.getLastUsedClassPathFolder(); chooser.setCurrentDirectory (curDir); int option = chooser.showOpenDialog( WindowManager.getDefault().getMainWindow() ); if ( option == JFileChooser.APPROVE_OPTION ) { String filePaths[]; try { filePaths = chooser.getSelectedPaths(); } catch (IOException ex) { Exceptions.printStackTrace(ex); return; } addJarOrFolder ( filePaths, chooser.getSelectedPathVariables(), fileFilter, FileUtil.toFile(helper.getProjectDirectory())); curDir = FileUtil.normalizeFile(chooser.getCurrentDirectory()); EditMediator.setLastUsedClassPathFolder(curDir); } }
Example 17
Source File: PanelSourceFolders.java From netbeans with Apache License 2.0 | 5 votes |
private void jButtonConfigFilesLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfigFilesLocationActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (jTextFieldConfigFiles.getText().length() > 0 && getConfigFiles().exists()) { chooser.setSelectedFile(getConfigFiles()); } else { chooser.setCurrentDirectory((File) wizardDescriptor.getProperty(ProjectLocationWizardPanel.PROJECT_DIR)); } if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File configFilesDir = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextFieldConfigFiles.setText(configFilesDir.getAbsolutePath()); } }
Example 18
Source File: PanelSourceFolders.java From netbeans with Apache License 2.0 | 5 votes |
private void jButtonConfigFilesLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfigFilesLocationActionPerformed JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); if (jTextFieldConfigFiles.getText().length() > 0 && getConfigFiles().exists()) { chooser.setSelectedFile(getConfigFiles()); } else { chooser.setCurrentDirectory((File) wizardDescriptor.getProperty(ProjectLocationWizardPanel.PROJECT_DIR)); } if ( JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File configFilesDir = FileUtil.normalizeFile(chooser.getSelectedFile()); jTextFieldConfigFiles.setText(configFilesDir.getAbsolutePath()); } }
Example 19
Source File: VariablePanel.java From netbeans with Apache License 2.0 | 5 votes |
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed JFileChooser chooser = new JFileChooser(); chooser.setFileHidingEnabled(false); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); chooser.setMultiSelectionEnabled(false); chooser.setDialogTitle(NbBundle.getBundle(VariablePanel.class).getString("MSG_Choose_Folder")); if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = FileUtil.normalizeFile(chooser.getSelectedFile()); locationTextField.setText(file.getAbsolutePath()); } }
Example 20
Source File: CustomizerSupport.java From netbeans with Apache License 2.0 | 4 votes |
private void addPathElement () { JFileChooser chooser = new JFileChooser(); FileUtil.preventFileChooserSymlinkTraversal(chooser, null); chooser.setMultiSelectionEnabled (true); String title = null; String message = null; String approveButtonName = null; String approveButtonNameMne = null; if (SOURCES.equals(this.type)) { title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources"); message = NbBundle.getMessage (CustomizerSupport.class,"TXT_FilterSources"); approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources"); approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenSources"); } else if (JAVADOC.equals(this.type)) { title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc"); message = NbBundle.getMessage (CustomizerSupport.class,"TXT_FilterJavadoc"); approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc"); approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenJavadoc"); } else { throw new IllegalStateException("Can't add element for classpath"); // NOI18N } chooser.setDialogTitle(title); chooser.setApproveButtonText(approveButtonName); chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0)); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order. chooser.setAcceptAllFileFilterUsed( false ); chooser.setFileFilter (new SimpleFileFilter(message,new String[] {"ZIP","JAR"})); //NOI18N if (this.currentDir != null && currentDir.exists()) { chooser.setCurrentDirectory(this.currentDir); } if (chooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) { File[] fs = chooser.getSelectedFiles(); PathModel model = (PathModel) this.resources.getModel(); boolean addingFailed = false; int firstIndex = this.resources.getModel().getSize(); for (int i = 0; i < fs.length; i++) { File f = fs[i]; //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file // E.g. for /foo/src it returns /foo/src/src // Try to convert it back by removing last invalid name component if (!f.exists()) { File parent = f.getParentFile(); if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) { f = parent; } } addingFailed|=!model.addPath (f); } if (addingFailed) { new NotifyDescriptor.Message (NbBundle.getMessage(CustomizerSupport.class,"TXT_CanNotAddResolve"), NotifyDescriptor.ERROR_MESSAGE); } int lastIndex = this.resources.getModel().getSize()-1; if (firstIndex<=lastIndex) { int[] toSelect = new int[lastIndex-firstIndex+1]; for (int i = 0; i < toSelect.length; i++) { toSelect[i] = firstIndex+i; } this.resources.setSelectedIndices(toSelect); } this.currentDir = FileUtil.normalizeFile(chooser.getCurrentDirectory()); } }