net.sf.okapi.common.Util.getDirectoryName()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(201)

本文整理了Java中net.sf.okapi.common.Util.getDirectoryName()方法的一些代码示例,展示了Util.getDirectoryName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getDirectoryName()方法的具体详情如下:
包路径:net.sf.okapi.common.Util
类名称:Util
方法名:getDirectoryName

Util.getDirectoryName介绍

[英]Gets the directory name of a full path.
[中]获取完整路径的目录名。

代码示例

代码示例来源:origin: net.sf.okapi.tm/okapi-tm-simpletm

  1. private void deleteFiles (String pathAndPattern) {
  2. class WildcharFilenameFilter implements FilenameFilter {
  3. public boolean accept(File dir, String name) {
  4. return Pattern.matches(".*?\\..*?\\.db", name);
  5. }
  6. }
  7. String dir = Util.getDirectoryName(pathAndPattern);
  8. File d = new File(dir);
  9. File[] list = d.listFiles(new WildcharFilenameFilter());
  10. for ( File f : list ) {
  11. f.delete();
  12. }
  13. }

代码示例来源:origin: net.sf.okapi/okapi-core

  1. /**
  2. * Gets the directory location of a given class. The value returned can be the directory
  3. * where the .class file is located, or, if the class in a JAR file, the directory
  4. * where the .jar file is located.
  5. * @param theClass the class to query.
  6. * @return the directory location of the given class, or null if an error occurs.
  7. */
  8. public static String getClassLocation (Class<?> theClass) {
  9. String res = null;
  10. File file = new File(theClass.getProtectionDomain().getCodeSource().getLocation().getFile());
  11. res = URLDecodeUTF8(file.getAbsolutePath());
  12. // Remove the JAR file if necessary
  13. if ( res.endsWith(".jar") ) {
  14. res = getDirectoryName(res);
  15. }
  16. return res;
  17. }

代码示例来源:origin: net.sf.okapi/okapi-core

  1. /**
  2. * Creates a new FilterConfigurationMapper object with no mappings and the
  3. * custom configuration directory set to the current directory.
  4. */
  5. public FilterConfigurationMapper () {
  6. super();
  7. configMap = new LinkedHashMap<String, FilterConfiguration>();
  8. filters = new ArrayList<FilterInfo>();
  9. String customDir;
  10. try {
  11. customDir = Util.getDirectoryName((new File(".")).getAbsolutePath());
  12. } catch (SecurityException ex) {
  13. // Resolving "." will try to read the user.dir system property,
  14. // which is restricted in some scenarios so we fall back to
  15. // something safe in that case. See "Forbidden System Properties":
  16. // https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/properties.html
  17. customDir = "/";
  18. }
  19. setCustomConfigurationsDirectory(customDir);
  20. }

代码示例来源:origin: net.sf.okapi/okapi-core

  1. int i = 0;
  2. while ( newLow.indexOf(tmp) != 0 ) {
  3. tmp = Util.getDirectoryName(tmp);
  4. i++;
  5. if ( tmp.length() == 0 ) {
  6. tmp = Util.getDirectoryName(tmp);

代码示例来源:origin: net.sf.okapi.lib/okapi-lib-segmentation-ui

  1. private String makeNonHtmlOutputPath (String inputPath) {
  2. if ( inputPath.length() == 0 ) return ""; //$NON-NLS-1$
  3. String ext = Util.getExtension(inputPath);
  4. String filename = Util.getFilename(inputPath, false);
  5. return Util.getDirectoryName(inputPath) + File.separator +
  6. filename + Res.getString("testFileDlg.outputExtension") + ext; //$NON-NLS-1$
  7. }

代码示例来源:origin: net.sf.okapi.lib/okapi-lib-verification-ui

  1. private void openContainingFolder () {
  2. try {
  3. String path = cbDocument.getText();
  4. if ( Util.isEmpty(path) ) return;
  5. path = (new File(path)).getPath();
  6. Program.launch(Util.getDirectoryName(path));
  7. }
  8. catch ( Exception e ) {
  9. Dialogs.showError(shell, e.getMessage(), null);
  10. }
  11. }

代码示例来源:origin: net.sf.okapi/okapi-core

  1. this.outputURI = outputURI;
  2. if ( getInputURI() != null ) {
  3. String dir = Util.getDirectoryName(outputURI.getPath());

代码示例来源:origin: net.sf.okapi.steps/okapi-step-leveraging

  1. private XMLWriter startTemporaryFiles () {
  2. // Create the HTML source file
  3. XMLWriter htmlWriter = new XMLWriter(htmlSourceFile.getPath());
  4. // Start building the source file
  5. htmlWriter.writeStartElement("html");
  6. htmlWriter.writeStartElement("meta");
  7. htmlWriter.writeAttributeString("http-equiv", "Content-Type");
  8. htmlWriter.writeAttributeString("content", "text/html; charset=UTF-8");
  9. htmlWriter.writeEndElementLineBreak();
  10. // Set the output name and make sure it's deleted
  11. String path = htmlSourceFile.getAbsolutePath();
  12. path = Util.getDirectoryName(path) + File.separator + Util.getFilename(path, false) + ".trg.html";
  13. htmlTargetFile = new File(path);
  14. if ( htmlTargetFile.exists() ) {
  15. htmlTargetFile.delete();
  16. }
  17. // Create the store for the original source
  18. path = htmlSourceFile.getAbsolutePath();
  19. path = Util.getDirectoryName(path) + File.separator + Util.getFilename(path, false) + ".ori.bin";
  20. originalStoreFile = new File(path);
  21. store.create(originalStoreFile);
  22. return htmlWriter;
  23. }

代码示例来源:origin: net.sf.okapi/okapi-core

  1. if (!Util.getDirectoryName(outFilename).isEmpty()) {
  2. Util.createDirectories(f.getAbsolutePath());

代码示例来源:origin: net.sf.okapi/okapi-core

  1. /**
  2. * Detects if a given string matches a given pattern (not necessarily a regex), possibly containing wildcards
  3. * @param string the given string (no-wildcards)
  4. * @param pattern the pattern containing wildcards to match against
  5. * @param filenameMode indicates if the given string should be considered a file name
  6. * @return true if the given string matches the given pattern
  7. */
  8. public static boolean matchesWildcard(String string, String pattern, boolean filenameMode) {
  9. if (filenameMode) {
  10. String filename = Util.getFilename(string, true);
  11. String patternFilename = Util.getFilename(pattern, true);
  12. String filePath = Util.getDirectoryName(string);
  13. String patternFilePath = Util.getDirectoryName(pattern);
  14. boolean pathMatches;
  15. if (Util.isEmpty(patternFilePath))
  16. pathMatches = true; // word/settings/filename.ext matches *.ext
  17. else
  18. pathMatches = Pattern.matches(normalizeWildcards(patternFilePath), filePath); // word/settings/filename.ext matches word/*/*.ext
  19. boolean filenameMatches = Pattern.matches(normalizeWildcards(patternFilename), filename);
  20. return pathMatches && filenameMatches;
  21. }
  22. return Pattern.matches(normalizeWildcards(pattern), string);
  23. }

代码示例来源:origin: net.sf.okapi.lib/okapi-lib-segmentation-ui

  1. public void widgetSelected(SelectionEvent e) {
  2. String[] paths = Dialogs.browseFilenames(shell, Res.getString("testFileDlg.getInputCaption"), false, //$NON-NLS-1$
  3. Util.getDirectoryName(edInput.getText()), Res.getString("testFileDlg.getInputFileTypes"), Res.getString("testFileDlg.getInputFilter")); //$NON-NLS-1$ //$NON-NLS-2$
  4. if ( paths == null ) return;
  5. edInput.setText(paths[0]);
  6. edInput.selectAll();
  7. edInput.setFocus();
  8. updateOutputPath();
  9. }
  10. });

代码示例来源:origin: net.sf.okapi.steps/okapi-step-ttxsplitter

  1. String newPath = Util.getDirectoryName(path) + File.separatorChar + fname
  2. + params.getSuffix() + Util.getExtension(path);

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-mosestext

  1. trgOutputPath = Util.getDirectoryName(srcOutputPath)
  2. + File.separator
  3. + Util.getFilename(srcOutputPath, false)

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-pensieve

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public void open (RawDocument input,
  4. boolean generateSkeleton)
  5. {
  6. this.input = input;
  7. srcLoc = input.getSourceLocale();
  8. trgLoc = input.getTargetLocale();
  9. if ( input.getInputURI() == null ) {
  10. throw new OkapiBadFilterInputException("Only input URI is supported for this filter.");
  11. }
  12. docName = Util.getDirectoryName(input.getInputURI().getPath());
  13. ITmSeeker seeker = TmSeekerFactory.createFileBasedTmSeeker(docName);
  14. //TODO: Not very clean way to get the iterator, maybe ITmSeeker should just includes Iterable methods
  15. iterator = ((Iterable<TranslationUnit>)seeker).iterator();
  16. state = 1;
  17. }

代码示例来源:origin: net.sf.okapi/okapi-core

  1. /**
  2. * Adds to a given {@link FilterConfigurationMapper} object the custom configuration
  3. * defined in the fprm file denoted by a given URL.
  4. * @param fcMapper the given {@link FilterConfigurationMapper}.
  5. * @param customConfig the URL of a fprm file defining the custom configuration
  6. * the filter should be loaded from. The file extension should be .fprm.
  7. * The file name should follow the pattern of custom filter configurations,
  8. * i.e. contain a filter name like "okf_xmlstream@custom_config.fprm".
  9. * @return the configuration identifier or null if the configuration was not added.
  10. */
  11. public static String addCustomConfig(FilterConfigurationMapper fcMapper,
  12. URL customConfig) {
  13. String configId = null;
  14. try {
  15. String path = customConfig.toURI().getPath();
  16. String root = Util.getDirectoryName(path) + File.separator;
  17. configId = Util.getFilename(path, false);
  18. fcMapper.setCustomConfigurationsDirectory(root);
  19. fcMapper.addCustomConfiguration(configId);
  20. fcMapper.updateCustomConfigurations();
  21. } catch (URISyntaxException e) {
  22. throw new OkapiIOException(e);
  23. }
  24. return configId;
  25. }

代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit

  1. String origDir = Util.getDirectoryName(origin);
  2. File dir = new File(Util.getDirectoryName(origin));
  3. File[] files = dir.listFiles(new DefaultFilenameFilter(pattern, false));
  4. if ( files == null ) {
  5. destFn = origFn;
  6. String destDir = Util.getDirectoryName(destination);
  7. String destPath = manifest.getTempPackageRoot() + (destDir.isEmpty() ? "" : destDir+"/") + destFn;

代码示例来源:origin: net.sf.okapi.lib/okapi-lib-verification-ui

  1. private void generateReport () {
  2. try {
  3. startWaiting("Generating report...");
  4. String rootDir = (qcsPath==null ? null : Util.getDirectoryName(qcsPath));
  5. session.generateReport(rootDir);
  6. String finalPath = Util.fillRootDirectoryVariable(session.getParameters().getOutputPath(), rootDir);
  7. if ( session.getParameters().getAutoOpen() ) {
  8. Util.openURL((new File(finalPath)).getAbsolutePath());
  9. }
  10. }
  11. catch ( Throwable e ) {
  12. Dialogs.showError(shell, "Error while generating report.\n"+e.getMessage(), null);
  13. }
  14. finally {
  15. stopWaiting();
  16. }
  17. }

代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit

  1. private String makeTargetPath (MergingInfo item) {
  2. String ex = Util.getExtension(item.getRelativeInputPath());
  3. String sd = Util.getDirectoryName(item.getRelativeInputPath());
  4. String fn = Util.getFilename(item.getRelativeInputPath(), false);
  5. return manifest.getTempSourceDirectory()
  6. + ( sd.isEmpty() ? "" : sd + "/" )
  7. + fn + "_" + manifest.getTargetLocale().toPOSIXLocaleId()
  8. + ex + ".po";
  9. }

代码示例来源:origin: net.sf.okapi.lib/okapi-lib-verification-ui

  1. outEncoding = rawDoc.getEncoding();
  2. outPath = new File(rawDoc.getInputURI()).getPath();
  3. outPath = Util.getDirectoryName(outPath) + File.separator + Util.getFilename(outPath, false) + ".out" + Util.getExtension(outPath);
  4. writer = sd.getFilterWriter();
  5. writer.setOptions(trgLoc, outEncoding);

代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit

  1. String subdir = Util.getDirectoryName(info.getRelativeInputPath());
  2. if ( !subdir.isEmpty() ) {
  3. resourceFile = Util.makeId(subdir) + "_" + resourceFile;

相关文章