本文整理了Java中org.openide.util.Utilities.translate()
方法的一些代码示例,展示了Utilities.translate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.translate()
方法的具体详情如下:
包路径:org.openide.util.Utilities
类名称:Utilities
方法名:translate
[英]Provides support for parts of the system that deal with classnames (use Class.forName
, NbObjectInputStream
, etc.) or filenames in layers.
Often class names (especially package names) changes during lifecycle of a module. When some piece of the system stores the name of a class in certain point of a time and wants to find the correct Class
later it needs to count with the possibility of rename.
For such purposes this method has been created. It allows modules to register their classes that changed names and other parts of system that deal with class names to find the correct names.
To register a mapping from old class names to new ones create a file META-INF/netbeans/translate.names
in your module and fill it with your mapping:
#
# Mapping of legacy classes to new ones
#
org.oldpackage.MyClass=org.newpackage.MyClass # rename of package for one class
org.mypackage.OldClass=org.mypackage.NewClass # rename of class in a package
# rename of class and package
org.oldpackage.OldClass=org.newpackage.NewClass
# rename of whole package
org.someoldpackage=org.my.new.package.structure
# class was removed without replacement
org.mypackage.OldClass=
Btw. one can use spaces instead of =
sign. For a real world example check the xml module.
For purposes of org.openide.util.io.NbObjectInputStream there is a following special convention: If the className is not listed as one that is to be renamed, the returned string == className, if the className is registered to be renamed than the className != returned value, even in a case when className.equals (retValue)
Similar behaviour applies to filenames provided by layers (system filesystem). Filenames can be also translated to adapt to location changes e.g. in action registrations. Note that no spaces or special characters are allowed in both translated filenames or translation results. Filenames must conform to regexp ^[/a-zA-Z0-9$_.+-]+$. Keys and values are treated as paths from fs root.
Example of file path translation (action registration file has moved):
# registration ID has changed
Actions/Refactoring/RefactoringWhereUsed.instance=Actions/Refactoring/org-netbeans-modules-refactoring-api-ui-WhereUsedAction.instance
[中]为系统中处理类名(使用Class.forName
、NbObjectInputStream
等)或层中文件名的部分提供支持。
在模块的生命周期中,类名(尤其是包名)通常会发生变化。当系统的某个部分在某个时间点存储了一个类的名称,并希望在以后找到正确的Class
时,它需要进行计数,并可能进行重命名。
为此,创建了此方法。它允许模块注册更改名称的类,以及系统中处理类名的其他部分,以找到正确的名称。
要注册从旧类名到新类名的映射,请在模块中创建一个文件META-INF/netbeans/translate.names
,并用映射填充它:
#
# Mapping of legacy classes to new ones
#
org.oldpackage.MyClass=org.newpackage.MyClass # rename of package for one class
org.mypackage.OldClass=org.mypackage.NewClass # rename of class in a package
# rename of class and package
org.oldpackage.OldClass=org.newpackage.NewClass
# rename of whole package
org.someoldpackage=org.my.new.package.structure
# class was removed without replacement
org.mypackage.OldClass=
顺便说一句,你可以用空格代替=
符号。对于一个真实的例子,请检查xml module。
为了组织的目的。openide。util。伊奥。NbObjectInputStream有一个特殊约定:如果类名未被列为要重命名的类名,则返回的字符串==类名,如果注册要重命名的类名大于类名!=返回值,即使在className出现的情况下也是如此。等于(retValue)
类似的行为也适用于层(系统文件系统)提供的文件名。文件名也可以进行翻译,以适应位置变化,例如在用注册。请注意,翻译后的文件名或翻译结果中不允许使用空格或特殊字符。文件名必须符合regexp^[/a-zA-Z0-9$551;+-]+$。键和值被视为来自fs根的路径。
文件路径转换示例(操作注册文件已移动):
# registration ID has changed
Actions/Refactoring/RefactoringWhereUsed.instance=Actions/Refactoring/org-netbeans-modules-refactoring-api-ui-WhereUsedAction.instance
代码示例来源:origin: org.netbeans.api/org-openide-util
/** Old compatibility version.
*/
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
name = (String) ois.readObject();
String clazz = (String) ois.readObject();
className = (clazz == null) ? null : org.openide.util.Utilities.translate(clazz);
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
return Utilities.translate((String) attr);
} else if (attr != null) {
LOG.warning(
name = Utilities.translate(name);
代码示例来源:origin: org.netbeans.api/org-openide-util
String newN = Utilities.translate(name);
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
return URL.class;
case 12:
return ExternalUtil.findClass(Utilities.translate(value));
case 13:
return String.class;
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
case 12:
Class cls = ExternalUtil.findClass(Utilities.translate(value));
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
private final String annotateName(FileObject fo) {
String bundleName = (String) fo.getAttribute("SystemFileSystem.localizingBundle"); // NOI18N
if (bundleName != null) {
try {
bundleName = Utilities.translate(bundleName);
ResourceBundle b = NbBundle.getBundle(bundleName);
try {
return b.getString(fo.getPath());
} catch (MissingResourceException ex) {
// ignore--normal
}
} catch (MissingResourceException ex) {
Exceptions.attachMessage(ex, warningMessage(bundleName, fo));
LOG.log(Level.INFO, null, ex);
// ignore
}
}
return (String) fo.getAttribute("displayName"); // NOI18N
}
代码示例来源:origin: org.netbeans.api/org-openide-util-ui
/** Old compatibility version.
*/
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
name = (String) ois.readObject();
String clazz = (String) ois.readObject();
className = (clazz == null) ? null : org.openide.util.Utilities.translate(clazz);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
/** Old compatibility version.
*/
private void readObject (ObjectInputStream ois) throws IOException, ClassNotFoundException {
name = (String)ois.readObject ();
String clazz = (String)ois.readObject ();
className = (clazz==null)? null: org.openide.util.Utilities.translate (clazz);
}
代码示例来源:origin: uk.gov.nationalarchives.thirdparty.netbeans/org-openide-util
/** Old compatibility version.
*/
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
name = (String) ois.readObject();
String clazz = (String) ois.readObject();
className = (clazz == null) ? null : org.openide.util.Utilities.translate(clazz);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/** Old compatibility version.
*/
private void readObject (ObjectInputStream ois) throws IOException, ClassNotFoundException {
name = (String)ois.readObject ();
String clazz = (String)ois.readObject ();
className = (clazz==null)? null: org.openide.util.Utilities.translate (clazz);
}
代码示例来源:origin: in.jlibs/org-openide-util
/** Old compatibility version.
*/
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
name = (String) ois.readObject();
String clazz = (String) ois.readObject();
className = (clazz == null) ? null : org.openide.util.Utilities.translate(clazz);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders
return org.openide.util.Utilities.translate((String) attr);
} else if (attr != null) {
err.log(ErrorManager.WARNING,
name = org.openide.util.Utilities.translate(name);
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
Class cls = ExternalUtil.findClass (Utilities.translate (value));
if (SharedClassObject.class.isAssignableFrom(cls)) {
return SharedClassObject.findObject(cls, true);
代码示例来源:origin: uk.gov.nationalarchives.thirdparty.netbeans/org-openide-util
String newN = Utilities.translate(name);
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
Class cls = ExternalUtil.findClass (Utilities.translate (value));
if (SharedClassObject.class.isAssignableFrom(cls)) {
return SharedClassObject.findObject(cls, true);
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
String newN = Utilities.translate (name);
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf
public static String getLocalizedName(FileObject fo) {
String name = fo.getNameExt();
String bundleName = (String) fo.getAttribute(LOCALIZING_BUNDLE);
if (bundleName != null) {
try {
bundleName = org.openide.util.Utilities.translate(bundleName);
ResourceBundle b = NbBundle.getBundle(bundleName);
String localizedName = b.getString(fo.getPath());
if (localizedName != null) {
name = localizedName;
}
} catch (MissingResourceException ex) {
// ignore
}
}
return name;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
String newN = Utilities.translate (name);
代码示例来源:origin: in.jlibs/org-openide-util
String newN = Utilities.translate(name);
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-toolchain
if (bundleName != null) {
try {
bundleName = Utilities.translate(bundleName);
ResourceBundle bundle = NbBundle.getBundle(bundleName);
if (bundle != null) {
内容来源于网络,如有侵权,请联系作者删除!