/** * Indicates if this object has at least standoff item. * @return true if this object has at least standoff item, false otherwise. */ public boolean hasStandoff () { return !Util.isEmpty(standoff); }
/** * Expand all supported variables and canonicalize (resolve ".." and ".") * a path. If the input path has no variables, it is returned unchanged. * rootDir and inputRootDir can be null. * @param path The path to expand * @param rootDir The directory to expand ${rootDir} into * @param inputRootDir The directory to expand ${inputRootDir} into * @return The expanded path * @throws IOException If canonicalizing fails */ public static String expandPath (String path, String rootDir, String inputRootDir) throws IOException { if (!path.contains("${")) return path; path = Util.fillSystemEnvars(path); path = Util.fillRootDirectoryVariable(path, rootDir); path = Util.fillInputRootDirectoryVariable(path, inputRootDir); path = new File(path).getCanonicalPath(); return path; }
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$ }
/** * 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; }
protected void copySupportMaterial () { if ( Util.isEmpty(data) ) return; List<String> list = params.convertSupportFilesToList(data); origin = Util.fillRootDirectoryVariable(origin, rootDir); origin = Util.fillInputRootDirectoryVariable(origin, inputRootDir); origin = LocaleId.replaceVariables(origin, manifest.getSourceLocale(), manifest.getTargetLocale()); String pattern = Util.getFilename(origin, true); String origDir = Util.getDirectoryName(origin); File dir = new File(Util.getDirectoryName(origin)); File[] files = dir.listFiles(new DefaultFilenameFilter(pattern, false)); if ( files == null ) { String origFn = Util.getFilename(file.getAbsolutePath(), true); String destFn = Util.getFilename(destination, true); if ( destFn.equalsIgnoreCase(Parameters.SUPPORTFILE_SAMENAME) ) { destFn = origFn; String destDir = Util.getDirectoryName(destination); String destPath = manifest.getTempPackageRoot() + (destDir.isEmpty() ? "" : destDir+"/") + destFn;
/** * 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); }
private void initialize () { if ( params.getMakeTMX() ) { String tmxOutputPath = Util.fillRootDirectoryVariable(params.getTmxPath(), rootDir); tmxOutputPath = Util.fillInputRootDirectoryVariable(tmxOutputPath, inputRootDir); tmxOutputPath = LocaleId.replaceVariables(tmxOutputPath, srcLoc, trgLoc); attributes.put("creationid", Util.MTFLAG); if ( !Util.isEmpty(params.getOrigin()) ) { attributes.put("Txt::Origin", params.getOrigin()); String existingTMPath = Util.fillRootDirectoryVariable(params.getExistingTm(), rootDir); existingTMPath = Util.fillInputRootDirectoryVariable(existingTMPath, inputRootDir); existingTMPath = LocaleId.replaceVariables(existingTMPath, srcLoc, trgLoc); existingTm = TmSeekerFactory.createFileBasedTmSeeker(existingTMPath); if ( params.getSegment() ) { SRXDocument srxDoc = new SRXDocument(); String srxPath = Util.fillRootDirectoryVariable(params.getSrxPath(), rootDir); srxPath = Util.fillInputRootDirectoryVariable(srxPath, inputRootDir); srxPath = LocaleId.replaceVariables(srxPath, srcLoc, trgLoc); srxDoc.loadRules(srxPath);
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); } }
/** * Copies an {@link InputStream} to a File. * @param in the input stream. * @param outputFile the output {@link File}. * @throws OkapiIOException if an error occurs. */ public static void copy(InputStream in, File outputFile) { try { if (!outputFile.exists()) { Util.createDirectories(outputFile.getAbsolutePath()); outputFile.createNewFile(); } Files.copy(in, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new OkapiIOException(e); } }
Util.createDirectories(srcOutputPath); output = new BufferedOutputStream(new FileOutputStream(srcOutputPath)); String ext = Util.getExtension(srcOutputPath); if ( ext.equals("."+srcLCode) ) { trgOutputPath = Util.getDirectoryName(srcOutputPath) + File.separator + Util.getFilename(srcOutputPath, false) + "." + trgLoc.toString();
private void generateReport (String text) { // Output the report PrintWriter writer = null; try { String finalPath = Util.fillRootDirectoryVariable(params.getLogPath(), rootDir); finalPath = Util.fillInputRootDirectoryVariable(finalPath, inputRootDir); Util.createDirectories(finalPath); writer = new PrintWriter(finalPath, "UTF-8"); writer.println(text); } catch ( IOException e ) { throw new OkapiException("Error when writing output file.", e); } finally { if ( writer != null ) { writer.close(); writer = null; } } }
this.outputURI = outputURI; if ( getInputURI() != null ) { String dir = Util.getDirectoryName(outputURI.getPath()); Util.createDirectories(workFile.getAbsolutePath()); return workFile;
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 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; }
String resolvedPath = Util.fillRootDirectoryVariable(params.getTmxPath(), rootDir); resolvedPath = Util.fillInputRootDirectoryVariable(resolvedPath, inputRootDir); resolvedPath = LocaleId.replaceVariables(resolvedPath, sourceLocale, targetLocale); tmx = new TMXWriter(resolvedPath);
@Override protected Event handleStartDocument(Event event) { close(); // For concurrent pipelines tmDir = String.format("%s~okapi-step-repetitionanalysis-%s/", Util.ensureSeparator(Util.getTempDirectory(), true), UUID.randomUUID().toString()); Util.createDirectories(tmDir); searchExact = params.getFuzzyThreshold() >= 100; tuCounter = 0; groupCounter = 1; tmWriter = (PensieveWriter) TmWriterFactory.createFileBasedTmWriter(tmDir, true); currentTm = new PensieveSeeker(tmWriter.getIndexWriter()); return super.handleStartDocument(event); }
@Override public void prepareForMerge(String dir) { movedFiles = new HashMap<String, String>(); if (!dir.endsWith(File.separator)) dir = dir + File.separator; String tmDir = dir + "tm" + File.separator; Util.createDirectories(tmDir); String projSave = dir + "omegat" + File.separator + "project_save.tmx"; if (new File(projSave).isFile()) { String moveTo = uniqueName(tmDir + "project_save.tmx", "-orig"); StreamUtil.copy(projSave, moveTo, true); movedFiles.put(projSave, moveTo); } for (String file : RENAME_FILES) { if (! new File(dir + file).isFile()) continue; String moveFrom = dir + file; String moveTo = uniqueName(dir + file, "-orig"); StreamUtil.copy(moveFrom, moveTo, true); movedFiles.put(moveFrom, moveTo); } File manifest = new File(dir + "manifest.rkm"); if (manifest.isFile()) manifest.delete(); Util.deleteDirectory(dir + "original", false); Util.deleteDirectory(dir + "source", false); Util.deleteDirectory(dir + "target", false); }
try { Util.createDirectories(zipPath); os = new ZipOutputStream(new FileOutputStream(zipPath)); for (String name : filenames) { File file = new File(Util.ensureSeparator(sourceDir, true) + name); addFileToZip(file, os);
protected String updateCaption_getFileName(String srxPath) { return Util.getFilename(srxPath, true); }
@Override protected Event handleEndBatch (Event event) { extractor.completeExtraction(); String finalPath = Util.fillRootDirectoryVariable(params.getOutputPath(), rootDir); LOGGER.info("Output: {}", finalPath); LOGGER.info("Candidate terms found = {}", extractor.getTerms().size()); if ( params.getAutoOpen() ) { Util.openURL((new File(finalPath)).getAbsolutePath()); } return event; }