private void deleteFiles (String pathAndPattern) { class WildcharFilenameFilter implements FilenameFilter { public boolean accept(File dir, String name) { return Pattern.matches(".*?\\..*?\\.db", name); } } String dir = Util.getDirectoryName(pathAndPattern); File d = new File(dir); File[] list = d.listFiles(new WildcharFilenameFilter()); for ( File f : list ) { f.delete(); } }
/** * Gets the directory location of a given class. The value returned can be the directory * where the .class file is located, or, if the class in a JAR file, the directory * where the .jar file is located. * @param theClass the class to query. * @return the directory location of the given class, or null if an error occurs. */ public static String getClassLocation (Class<?> theClass) { String res = null; File file = new File(theClass.getProtectionDomain().getCodeSource().getLocation().getFile()); res = URLDecodeUTF8(file.getAbsolutePath()); // Remove the JAR file if necessary if ( res.endsWith(".jar") ) { res = getDirectoryName(res); } return res; }
/** * Creates a new FilterConfigurationMapper object with no mappings and the * custom configuration directory set to the current directory. */ public FilterConfigurationMapper () { super(); configMap = new LinkedHashMap<String, FilterConfiguration>(); filters = new ArrayList<FilterInfo>(); String customDir; try { customDir = Util.getDirectoryName((new File(".")).getAbsolutePath()); } catch (SecurityException ex) { // Resolving "." will try to read the user.dir system property, // which is restricted in some scenarios so we fall back to // something safe in that case. See "Forbidden System Properties": // https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/properties.html customDir = "/"; } setCustomConfigurationsDirectory(customDir); }
int i = 0; while ( newLow.indexOf(tmp) != 0 ) { tmp = Util.getDirectoryName(tmp); i++; if ( tmp.length() == 0 ) { tmp = Util.getDirectoryName(tmp);
private String makeNonHtmlOutputPath (String inputPath) { if ( inputPath.length() == 0 ) return ""; //$NON-NLS-1$ String ext = Util.getExtension(inputPath); String filename = Util.getFilename(inputPath, false); return Util.getDirectoryName(inputPath) + File.separator + filename + Res.getString("testFileDlg.outputExtension") + ext; //$NON-NLS-1$ }
private void openContainingFolder () { try { String path = cbDocument.getText(); if ( Util.isEmpty(path) ) return; path = (new File(path)).getPath(); Program.launch(Util.getDirectoryName(path)); } catch ( Exception e ) { Dialogs.showError(shell, e.getMessage(), null); } }
this.outputURI = outputURI; if ( getInputURI() != null ) { String dir = Util.getDirectoryName(outputURI.getPath());
private XMLWriter startTemporaryFiles () { // Create the HTML source file XMLWriter htmlWriter = new XMLWriter(htmlSourceFile.getPath()); // Start building the source file htmlWriter.writeStartElement("html"); htmlWriter.writeStartElement("meta"); htmlWriter.writeAttributeString("http-equiv", "Content-Type"); htmlWriter.writeAttributeString("content", "text/html; charset=UTF-8"); htmlWriter.writeEndElementLineBreak(); // Set the output name and make sure it's deleted String path = htmlSourceFile.getAbsolutePath(); path = Util.getDirectoryName(path) + File.separator + Util.getFilename(path, false) + ".trg.html"; htmlTargetFile = new File(path); if ( htmlTargetFile.exists() ) { htmlTargetFile.delete(); } // Create the store for the original source path = htmlSourceFile.getAbsolutePath(); path = Util.getDirectoryName(path) + File.separator + Util.getFilename(path, false) + ".ori.bin"; originalStoreFile = new File(path); store.create(originalStoreFile); return htmlWriter; }
if (!Util.getDirectoryName(outFilename).isEmpty()) { Util.createDirectories(f.getAbsolutePath());
/** * Detects if a given string matches a given pattern (not necessarily a regex), possibly containing wildcards * @param string the given string (no-wildcards) * @param pattern the pattern containing wildcards to match against * @param filenameMode indicates if the given string should be considered a file name * @return true if the given string matches the given pattern */ public static boolean matchesWildcard(String string, String pattern, boolean filenameMode) { if (filenameMode) { String filename = Util.getFilename(string, true); String patternFilename = Util.getFilename(pattern, true); String filePath = Util.getDirectoryName(string); String patternFilePath = Util.getDirectoryName(pattern); boolean pathMatches; if (Util.isEmpty(patternFilePath)) pathMatches = true; // word/settings/filename.ext matches *.ext else pathMatches = Pattern.matches(normalizeWildcards(patternFilePath), filePath); // word/settings/filename.ext matches word/*/*.ext boolean filenameMatches = Pattern.matches(normalizeWildcards(patternFilename), filename); return pathMatches && filenameMatches; } return Pattern.matches(normalizeWildcards(pattern), string); }
public void widgetSelected(SelectionEvent e) { String[] paths = Dialogs.browseFilenames(shell, Res.getString("testFileDlg.getInputCaption"), false, //$NON-NLS-1$ Util.getDirectoryName(edInput.getText()), Res.getString("testFileDlg.getInputFileTypes"), Res.getString("testFileDlg.getInputFilter")); //$NON-NLS-1$ //$NON-NLS-2$ if ( paths == null ) return; edInput.setText(paths[0]); edInput.selectAll(); edInput.setFocus(); updateOutputPath(); } });
String newPath = Util.getDirectoryName(path) + File.separatorChar + fname + params.getSuffix() + Util.getExtension(path);
trgOutputPath = Util.getDirectoryName(srcOutputPath) + File.separator + Util.getFilename(srcOutputPath, false)
@SuppressWarnings("unchecked") @Override public void open (RawDocument input, boolean generateSkeleton) { this.input = input; srcLoc = input.getSourceLocale(); trgLoc = input.getTargetLocale(); if ( input.getInputURI() == null ) { throw new OkapiBadFilterInputException("Only input URI is supported for this filter."); } docName = Util.getDirectoryName(input.getInputURI().getPath()); ITmSeeker seeker = TmSeekerFactory.createFileBasedTmSeeker(docName); //TODO: Not very clean way to get the iterator, maybe ITmSeeker should just includes Iterable methods iterator = ((Iterable<TranslationUnit>)seeker).iterator(); state = 1; }
/** * Adds to a given {@link FilterConfigurationMapper} object the custom configuration * defined in the fprm file denoted by a given URL. * @param fcMapper the given {@link FilterConfigurationMapper}. * @param customConfig the URL of a fprm file defining the custom configuration * the filter should be loaded from. The file extension should be .fprm. * The file name should follow the pattern of custom filter configurations, * i.e. contain a filter name like "okf_xmlstream@custom_config.fprm". * @return the configuration identifier or null if the configuration was not added. */ public static String addCustomConfig(FilterConfigurationMapper fcMapper, URL customConfig) { String configId = null; try { String path = customConfig.toURI().getPath(); String root = Util.getDirectoryName(path) + File.separator; configId = Util.getFilename(path, false); fcMapper.setCustomConfigurationsDirectory(root); fcMapper.addCustomConfiguration(configId); fcMapper.updateCustomConfigurations(); } catch (URISyntaxException e) { throw new OkapiIOException(e); } return configId; }
String origDir = Util.getDirectoryName(origin); File dir = new File(Util.getDirectoryName(origin)); File[] files = dir.listFiles(new DefaultFilenameFilter(pattern, false)); if ( files == null ) { destFn = origFn; String destDir = Util.getDirectoryName(destination); String destPath = manifest.getTempPackageRoot() + (destDir.isEmpty() ? "" : destDir+"/") + destFn;
private void generateReport () { try { startWaiting("Generating report..."); String rootDir = (qcsPath==null ? null : Util.getDirectoryName(qcsPath)); session.generateReport(rootDir); String finalPath = Util.fillRootDirectoryVariable(session.getParameters().getOutputPath(), rootDir); if ( session.getParameters().getAutoOpen() ) { Util.openURL((new File(finalPath)).getAbsolutePath()); } } catch ( Throwable e ) { Dialogs.showError(shell, "Error while generating report.\n"+e.getMessage(), null); } finally { stopWaiting(); } }
private String makeTargetPath (MergingInfo item) { String ex = Util.getExtension(item.getRelativeInputPath()); String sd = Util.getDirectoryName(item.getRelativeInputPath()); String fn = Util.getFilename(item.getRelativeInputPath(), false); return manifest.getTempSourceDirectory() + ( sd.isEmpty() ? "" : sd + "/" ) + fn + "_" + manifest.getTargetLocale().toPOSIXLocaleId() + ex + ".po"; }
outEncoding = rawDoc.getEncoding(); outPath = new File(rawDoc.getInputURI()).getPath(); outPath = Util.getDirectoryName(outPath) + File.separator + Util.getFilename(outPath, false) + ".out" + Util.getExtension(outPath); writer = sd.getFilterWriter(); writer.setOptions(trgLoc, outEncoding);
String subdir = Util.getDirectoryName(info.getRelativeInputPath()); if ( !subdir.isEmpty() ) { resourceFile = Util.makeId(subdir) + "_" + resourceFile;