public static String getFreeFileName(FileObject folder, String filename, String nameExt) { String myfilename = filename.replaceAll("\\W", ""); return FileUtil.findFreeFileName(folder, myfilename, nameExt); } }
@Override public Transferable paste() throws IOException { FileObject fieldsFolder = getLookup().lookup(FileObject.class); String name = FileUtil.findFreeFileName(fieldsFolder, field.getName(), Field.EXT); LOGGER.log(Level.FINEST, "found free filename: {0}", name); FileObject fieldFile = fieldsFolder.createData(name, Field.EXT); FieldManager fieldManager = Lookup.getDefault().lookup(FieldManager.class); fieldManager.save(field, fieldFile); return null; } };
public void run () throws IOException { String fileName; if (name == null) { fileName = FileUtil.findFreeFileName( fo, className.replace ('.', '-'), INSTANCE); } else { fileName = escape(name); } fos[0] = fo.createData (fileName, INSTANCE); fos[0].setAttribute(EA_INSTANCE_CLASS, className); } });
public void run () throws IOException { FileObject fo = folder.getPrimaryFile (); String filename = name; if (filename == null) { filename = instance.getClass().getName().replace ('.', '-'); filename = FileUtil.findFreeFileName(fo, filename, XML_EXT); } else { String escapedFileName = escape(filename); // do not cut if such file already exist FileObject newFile = fo.getFileObject (escapedFileName, XML_EXT); if (newFile == null) { filename = escapeAndCut(filename); } else { filename = escapedFileName; } if (create /*|| (newFile == null && Utilities.isWindows()) */) { filename = FileUtil.findFreeFileName(fo, filename, XML_EXT); } } result = storeSettings(folder, filename, instance, mi); }
private synchronized void stop(int round) throws Exception { ActionListener ss = (ActionListener) profiler; profiler = null; if (!profiling) { return; } FileObject wd = FileUtil.toFileObject(getWorkDir()); String n = FileUtil.findFreeFileName(wd, "snapshot-" + round, "nps"); // NOI18N FileObject snapshot = wd.createData(n, "nps"); // NOI18N DataOutputStream dos = new DataOutputStream(snapshot.getOutputStream()); ss.actionPerformed(new ActionEvent(dos, 0, "write")); // NOI18N dos.close(); LOG.log( Level.WARNING, "Profiling snapshot taken into {0}", snapshot.getPath() ); }
/** Check if in specific folder exists fileobject with the same name. * If it exists user is asked for confirmation to rewrite, rename or cancel operation. * @param folder destination folder * @return the suffix which should be added to the name or null if operation is cancelled */ private String existInFolder(FileObject fo, FileObject folder) { // merge folders when neccessary if (fo.isFolder () && isMergingFolders ()) return ""; // NOI18N String orig = fo.getName (); String name = FileUtil.findFreeFileName( folder, orig, fo.getExt () ); if (name.length () <= orig.length ()) { return ""; // NOI18N } else { return name.substring (orig.length ()); } }
private synchronized void stop(int round) throws Exception { ActionListener ss = (ActionListener) profiler; profiler = null; if (!profiling) { return; } FileObject wd = FileUtil.toFileObject(getWorkDir()); String n = FileUtil.findFreeFileName(wd, "snapshot-" + round, "nps"); // NOI18N FileObject snapshot = wd.createData(n, "nps"); // NOI18N DataOutputStream dos = new DataOutputStream(snapshot.getOutputStream()); ss.actionPerformed(new ActionEvent(dos, 0, "write")); // NOI18N dos.close(); LOG.log( Level.WARNING, "Profiling snapshot taken into {0}", snapshot.getPath() ); }
public void actionPerformed(ActionEvent e) { try { final PageFlowController pfc = scene.getPageFlowView().getPageFlowController(); final FileObject webFileObject = pfc.getWebFolder(); String name = FileUtil.findFreeFileName(webFileObject, "page", "jsp"); name = JOptionPane.showInputDialog("Select Page Name", name); createIndexJSP(webFileObject, name); } catch (IOException ex) { Exceptions.printStackTrace(ex); } // } }
public void actionPerformed(ActionEvent e) { // This would work if we wanted to use the wizard. // Action newFileAction = CommonProjectActions.newFileAction(); // JOptionPane.showMessageDialog(null, "Source: " + e.getSource()); Object obj = e.getSource(); if (obj instanceof PageFlowScene) { try { scene = (PageFlowScene) obj; PageFlowController pfc = scene.getPageFlowView().getPageFlowController(); FileObject webFileObject = pfc.getWebFolder(); String name = FileUtil.findFreeFileName(webFileObject, "Templates/JSP_Servlet/JSP.jsp", "jsp"); name = JOptionPane.showInputDialog("Select Page Name", name); createIndexJSP(webFileObject, name); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
/** * Copy sourcefiles to import-folder * @param dataObject */ @Override public void importSources(DataObject dataObject) { FileObject importFolder = getImportFolder(true); Iterator<FileObject> files = dataObject.files().iterator(); while(files.hasNext()){ FileObject current = files.next(); try { String newFileName = FileUtil.findFreeFileName(importFolder, current.getName(), current.getExt()); FileUtil.copyFile(current, importFolder, newFileName); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
/** * Copies the specified fileObject to the specified targetFolder. Tries to * get a free filename for the file object * * @param targetFolder the folder the fileObject must be copied to * @param toCopy the file to be copied * @return the copied fileObject or null if it could not be copied */ private FileObject copy(FileObject targetFolder, FileObject toCopy) { try { String newFileName = FileUtil.findFreeFileName(targetFolder, toCopy.getName(), toCopy.getExt()); return FileUtil.copyFile(toCopy, targetFolder, newFileName); } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Could not copy file {0} with the exception {1}", new Object[]{toCopy.getName(), ex}); } return null; }
public Object run () throws IOException { FileObject fo; if (trg.isData ()) { fo = trg; } else { String n; if (name == null) { // #45810 - if obj is disk root then fix the filename String baseName = obj.getName().replace(':', '_').replace('/', '_'); // NOI18N n = FileUtil.findFreeFileName (trg, baseName, ext); } else { n = name; } fo = trg.createData (n, ext); } writeShadowFile(fo, obj.getPrimaryFile().getURL()); return fo; } });
/** * Copies the specified FileObject to the specified targetFolder. * * <p> * Tries to get a free filename for the file object</p> * * @param targetFolder the folder the fileObject must be copied to * @param toCopy the file to be copied * @return the copied fileObject or null if it could not be copied */ private FileObject copy(FileObject targetFolder, FileObject toCopy) { try { String newFileName = FileUtil.findFreeFileName(targetFolder, toCopy.getName(), toCopy.getExt()); return FileUtil.copyFile(toCopy, targetFolder, newFileName); } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Could not copy file {0} with the exception {1}", new Object[]{toCopy.getName(), ex}); } return null; }
private String getCurrentHeapDumpFilename(String targetFolder) { try { String fileName = ResultsManager.getDefault().getDefaultHeapDumpFileName(System.currentTimeMillis()); FileObject folder = (targetFolder == null) ? ProjectStorage.getSettingsFolder(NetBeansProfiler.getDefaultNB().getProfiledProject(), true) : FileUtil.toFileObject(FileUtil.normalizeFile(new File(targetFolder))); return FileUtil.toFile(folder).getAbsolutePath() + File.separator + FileUtil.findFreeFileName(folder, fileName, ResultsManager.HEAPDUMP_EXTENSION) + "." + ResultsManager.HEAPDUMP_EXTENSION; // NOI18N } catch (IOException e) { return null; } }
@Override public void importShapes(List<Shape> shapes) { FileObject fieldsFolder = getFieldsFolder(true); for (Shape shape : shapes) { // Create field from shape Field field = new Field(); field.setGeometry(shape.getGeometry()); field.setName(shape.getName()); try { String name = FileUtil.findFreeFileName(fieldsFolder, field.getName(), Field.EXT); LOGGER.log(Level.FINEST, "found free filename: {0}", name); FileObject fieldFile; fieldFile = fieldsFolder.createData(name, Field.EXT); FieldManager fieldManager = Lookup.getDefault().lookup(FieldManager.class); fieldManager.save(field, fieldFile); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
/** Creates shadow for this object in specified folder (overridable in subclasses). * <p>The default * implementation creates a reference data shadow and pastes it into * the specified folder. * * @param f the folder to create a shortcut in * @return the shadow */ protected DataShadow handleCreateShadow (DataFolder f) throws IOException { // #33871 - prevent creation of recursive folder structure testNesting(this, f); String name; if (getPrimaryFile ().isRoot ()) { name = FileUtil.findFreeFileName ( f.getPrimaryFile (), ROOT_SHADOW_NAME, DataShadow.SHADOW_EXTENSION ); } else { name = null; } return DataShadow.create (f, name, this); }
protected DataObject handleCreateFromTemplate ( DataFolder df, String name ) throws IOException { FileObject fo; if (name == null) { name = FileUtil.findFreeFileName( df.getPrimaryFile (), getPrimaryFile ().getName (), getPrimaryFile ().getExt () ); } fo = getPrimaryEntry().createFromTemplate (df.getPrimaryFile (), name); Iterator it = secondaryEntries().iterator(); while (it.hasNext ()) { ((Entry)it.next()).createFromTemplate (df.getPrimaryFile (), name); } try { return createMultiObject (fo); } catch (DataObjectExistsException ex) { return ex.getDataObject (); } }
public FileObject createFromTemplate (FileObject f, String name) throws IOException { if (name == null) { name = FileUtil.findFreeFileName( f, getFile ().getName (), getFile ().getExt () ); } FileObject fo = getFile().copy (f, name, getFile().getExt ()); // unmark template state DataObject.setTemplate (fo, false); return fo; }
/** Creates new folder and copies attributes, the template flag is cleared. * @param f the folder to create this entry in * @param name the new name to use * @return the copied <code>FileObject</code> or <code>null</code> if it cannot be copied * @exception IOException when the operation fails */ public FileObject createFromTemplate (FileObject f, String name) throws IOException { if (name == null) { name = FileUtil.findFreeFileName( f, getFile ().getName (), getFile ().getExt () ); } FileObject fo = FileUtil.createFolder (f, name); FileUtil.copyAttributes (getFile (), fo); DataObject.setTemplate (fo, false); return fo; }
private static void register(FileObject serverInstanceDir, String serverLocation, String domainLocation, String host, String port) throws IOException { String displayName = generateDisplayName(serverInstanceDir); String url = URI_PREFIX + host + ":" + port + "#default&" + serverLocation; // NOI18N String name = FileUtil.findFreeFileName(serverInstanceDir, "instance", null); // NOI18N FileObject instanceFO = serverInstanceDir.createData(name); instanceFO.setAttribute(InstanceProperties.URL_ATTR, url); instanceFO.setAttribute(InstanceProperties.USERNAME_ATTR, ""); instanceFO.setAttribute(InstanceProperties.PASSWORD_ATTR, ""); instanceFO.setAttribute(InstanceProperties.DISPLAY_NAME_ATTR, displayName); instanceFO.setAttribute(InstanceProperties.REMOVE_FORBIDDEN, "true"); instanceFO.setAttribute(JBPluginProperties.PROPERTY_SERVER, "default"); // NOI18N String deployDir = JBPluginUtils.getDeployDir(domainLocation); instanceFO.setAttribute(JBPluginProperties.PROPERTY_DEPLOY_DIR, deployDir); instanceFO.setAttribute(JBPluginProperties.PROPERTY_SERVER_DIR, domainLocation); instanceFO.setAttribute(JBPluginProperties.PROPERTY_ROOT_DIR, serverLocation); instanceFO.setAttribute(JBPluginProperties.PROPERTY_HOST, host); instanceFO.setAttribute(JBPluginProperties.PROPERTY_PORT, port); }