本文整理了Java中net.sf.okapi.common.Util.getDirectoryName()
方法的一些代码示例,展示了Util.getDirectoryName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getDirectoryName()
方法的具体详情如下:
包路径:net.sf.okapi.common.Util
类名称:Util
方法名:getDirectoryName
[英]Gets the directory name of a full path.
[中]获取完整路径的目录名。
代码示例来源:origin: net.sf.okapi.tm/okapi-tm-simpletm
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();
}
}
代码示例来源:origin: net.sf.okapi/okapi-core
/**
* 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;
}
代码示例来源:origin: net.sf.okapi/okapi-core
/**
* 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);
}
代码示例来源:origin: net.sf.okapi/okapi-core
int i = 0;
while ( newLow.indexOf(tmp) != 0 ) {
tmp = Util.getDirectoryName(tmp);
i++;
if ( tmp.length() == 0 ) {
tmp = Util.getDirectoryName(tmp);
代码示例来源:origin: net.sf.okapi.lib/okapi-lib-segmentation-ui
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$
}
代码示例来源:origin: net.sf.okapi.lib/okapi-lib-verification-ui
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);
}
}
代码示例来源:origin: net.sf.okapi/okapi-core
this.outputURI = outputURI;
if ( getInputURI() != null ) {
String dir = Util.getDirectoryName(outputURI.getPath());
代码示例来源:origin: net.sf.okapi.steps/okapi-step-leveraging
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;
}
代码示例来源:origin: net.sf.okapi/okapi-core
if (!Util.getDirectoryName(outFilename).isEmpty()) {
Util.createDirectories(f.getAbsolutePath());
代码示例来源:origin: net.sf.okapi/okapi-core
/**
* 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);
}
代码示例来源:origin: net.sf.okapi.lib/okapi-lib-segmentation-ui
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();
}
});
代码示例来源:origin: net.sf.okapi.steps/okapi-step-ttxsplitter
String newPath = Util.getDirectoryName(path) + File.separatorChar + fname
+ params.getSuffix() + Util.getExtension(path);
代码示例来源:origin: net.sf.okapi.filters/okapi-filter-mosestext
trgOutputPath = Util.getDirectoryName(srcOutputPath)
+ File.separator
+ Util.getFilename(srcOutputPath, false)
代码示例来源:origin: net.sf.okapi.filters/okapi-filter-pensieve
@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;
}
代码示例来源:origin: net.sf.okapi/okapi-core
/**
* 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;
}
代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit
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;
代码示例来源:origin: net.sf.okapi.lib/okapi-lib-verification-ui
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();
}
}
代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit
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";
}
代码示例来源:origin: net.sf.okapi.lib/okapi-lib-verification-ui
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);
代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit
String subdir = Util.getDirectoryName(info.getRelativeInputPath());
if ( !subdir.isEmpty() ) {
resourceFile = Util.makeId(subdir) + "_" + resourceFile;
内容来源于网络,如有侵权,请联系作者删除!