本文整理汇总了Java中org.openide.filesystems.FileObject.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.getAttributes方法的具体用法?Java FileObject.getAttributes怎么用?Java FileObject.getAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileObject
的用法示例。
在下文中一共展示了FileObject.getAttributes方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributes
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** Returns map of attributes for given FileObject. */ // XXX: copied from org.netbeans.modules.favorites.templates
private static Map<String, Object> getAttributes (FileObject fo) {
HashMap<String, Object> attributes = new HashMap<String, Object> ();
Enumeration<String> attributeNames = fo.getAttributes ();
while (attributeNames.hasMoreElements ()) {
String attrName = attributeNames.nextElement ();
if (attrName == null) {
continue;
}
Object attrValue = fo.getAttribute (attrName);
if (attrValue != null) {
attributes.put (attrName, attrValue);
}
}
return attributes;
}
示例2: testUserHasPreferenceOverFSs
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testUserHasPreferenceOverFSs() throws Exception {
FileObject global = FileUtil.createData(FileUtil.getConfigRoot(), "dir/file.txt");
global.setAttribute("global", 3);
write(global, "global");
FileObject fo1 = FileUtil.createData(fs1.getRoot(), "dir/file.txt");
fo1.setAttribute("one", 1);
write(fo1, "fileone");
FileObject fo2 = FileUtil.createData(fs2.getRoot(), "dir/file.txt");
fo2.setAttribute("two", 2);
write(fo2, "two");
events.clear();
MainLookup.register(fs1, this);
MainLookup.register(fs2, this);
Enumeration<String> en = global.getAttributes();
TreeSet<String> t = new TreeSet<String>();
while (en.hasMoreElements()) {
t.add(en.nextElement());
}
assertEquals("three elements: " + t, 3, t.size());
assertTrue(t.contains("two"));
assertTrue(t.contains("one"));
assertTrue(t.contains("global"));
assertEquals(1, global.getAttribute("one"));
assertEquals(2, global.getAttribute("two"));
assertEquals(3, global.getAttribute("global"));
assertEquals("contains global", 6, global.getSize());
assertEquals("global", read(global));
assertTrue("no events: " + events, events.isEmpty());
}
示例3: LazyMenu
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** Constructor. */
public LazyMenu(final DataFolder df, boolean icon) {
this.master = df;
this.icon = icon;
this.dynaModel = new DynaMenuModel();
this.slave = new MenuFolder();
setName(df.getName());
final FileObject pf = df.getPrimaryFile();
Object prefix = pf.getAttribute("property-prefix"); // NOI18N
if (prefix instanceof String) {
Enumeration<String> en = pf.getAttributes();
while (en.hasMoreElements()) {
String attrName = en.nextElement();
if (attrName.startsWith((String)prefix)) {
putClientProperty(
attrName.substring(((String)prefix).length()),
pf.getAttribute(attrName)
);
}
}
}
// Listen for changes in Node's DisplayName/Icon
Node n = master.getNodeDelegate ();
n.addNodeListener (org.openide.nodes.NodeOp.weakNodeListener (this, n));
Mutex.EVENT.readAccess(this);
getModel().addChangeListener(this);
}
示例4: readKeywordsFromNewAnnotation
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void readKeywordsFromNewAnnotation() {
FileObject keywordsFOs = FileUtil.getConfigRoot().getFileObject(CategoryModel.OD_LAYER_KEYWORDS_FOLDER_NAME);
for(FileObject keywordsFO : keywordsFOs.getChildren()) {
String location = keywordsFO.getAttribute("location").toString(); //NOI18N
String tabTitle = keywordsFO.getAttribute("tabTitle").toString(); //NOI18N
Set<String> keywords = new HashSet<String>();
Enumeration<String> attributes = keywordsFO.getAttributes();
while (attributes.hasMoreElements()) {
String attribute = attributes.nextElement();
if (attribute.startsWith("keywords")) {
String word = keywordsFO.getAttribute(attribute).toString();
for (String s : word.split(",")) {
keywords.add(s.trim());
}
}
}
String path = location.concat("/").concat(tabTitle);
Set<String> keywordsFromPath = path2keywords.get(path);
if(keywordsFromPath != null) {
for (String keyword : keywordsFromPath) {
if (!keywords.contains(keyword)) {
keywords.add(keyword);
}
}
}
path2keywords.put(path, keywords);
}
}
示例5: storeShortCuts
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void storeShortCuts(String profileName) {
FileObject root = FileUtil.getConfigRoot();
try {
FileObject actionsDir = FileUtil.createFolder(
root, STORAGE_DIR + profileName);
for (OutWinShortCutAction a : allActions) {
FileObject data = actionsDir.getFileObject(a.getId());
if (data == null) {
data = actionsDir.createData(a.getId());
} else if (data.isFolder()) {
throw new IOException(data + " is a folder."); //NOI18N
}
Enumeration<String> atts = data.getAttributes();
while (atts.hasMoreElements()) {
String attName = atts.nextElement();
data.setAttribute(attName, null);
}
int index = 1;
if (keymaps.get(profileName).get(a) == null) {
continue;
}
for (String shortCut : keymaps.get(profileName).get(a)) {
data.setAttribute(SHORTCUT_PREFIX + index++, shortCut);
}
}
} catch (IOException e) {
LOG.log(Level.WARNING, "Cannot create folder", e); //NOI18N
}
}
示例6: loadShortCuts
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void loadShortCuts() {
FileObject root = FileUtil.getConfigRoot();
FileObject actionsDir = root.getFileObject(STORAGE_DIR);
if (actionsDir == null) {
return;
}
for (FileObject profileDir : actionsDir.getChildren()) {
if (!profileDir.isFolder()) {
continue;
}
Map<ShortcutAction, Set<String>> keymap =
new HashMap<ShortcutAction, Set<String>>();
keymaps.put(profileDir.getName(), keymap);
for (OutWinShortCutAction a : allActions) {
FileObject actionFile = profileDir.getFileObject(a.getId());
if (actionFile == null || !actionFile.isData()) {
keymap.put(a, Collections.<String>emptySet());
continue;
}
Enumeration<String> atts = actionFile.getAttributes();
Set<String> strokes = new HashSet<String>();
while (atts.hasMoreElements()) {
String att = atts.nextElement();
if (att.startsWith(SHORTCUT_PREFIX)) {
strokes.add((String) actionFile.getAttribute(att));
}
}
keymap.put(a, strokes);
}
}
}
示例7: testUserHasPreferenceOverFSsButGeneratesAnEvent
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testUserHasPreferenceOverFSsButGeneratesAnEvent() throws Exception {
FileObject fo1 = FileUtil.createData(fs1.getRoot(), "dir/file.txt");
fo1.setAttribute("one", 1);
write(fo1, "fileone");
FileObject fo2 = FileUtil.createData(fs2.getRoot(), "dir/file.txt");
fo2.setAttribute("two", 2);
write(fo2, "two");
events.clear();
MainLookup.register(fs1, this);
MainLookup.register(fs2, this);
assertFalse("not empty", events.isEmpty());
events.clear();
FileObject global = FileUtil.createData(FileUtil.getConfigRoot(), "dir/file.txt");
global.setAttribute("global", 3);
write(global, "global");
assertFalse("yet another set", events.isEmpty());
Enumeration<String> en = global.getAttributes();
TreeSet<String> t = new TreeSet<String>();
while (en.hasMoreElements()) {
t.add(en.nextElement());
}
assertEquals("three elements: " + t, 3, t.size());
assertTrue(t.contains("two"));
assertTrue(t.contains("one"));
assertTrue(t.contains("global"));
assertEquals(1, global.getAttribute("one"));
assertEquals(2, global.getAttribute("two"));
assertEquals(3, global.getAttribute("global"));
assertEquals("contains global", 6, global.getSize());
assertEquals("global", read(global));
}
示例8: getClassName
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** get class name from specified file object*/
private static String getClassName(FileObject fo) {
// first of all try "instanceClass" property of the primary file
Object attr = fo.getAttribute ("instanceClass");
if (attr instanceof String) {
return BaseUtilities.translate((String) attr);
} else if (attr != null) {
LOG.warning(
"instanceClass was a " + attr.getClass().getName()); // NOI18N
}
attr = fo.getAttribute("instanceCreate");
if (attr != null) {
return attr.getClass().getName();
} else {
Enumeration<String> attributes = fo.getAttributes();
while (attributes.hasMoreElements()) {
if (attributes.nextElement().equals("instanceCreate")) {
// It was specified, just unloadable (usually a methodvalue).
return null;
}
}
}
// otherwise extract the name from the filename
String name = fo.getName ();
int first = name.indexOf('[') + 1;
if (first != 0) {
LOG.log(Level.WARNING, "Cannot understand {0}", fo);
}
int last = name.indexOf (']');
if (last < 0) {
last = name.length ();
}
// take only a part of the string
if (first < last) {
name = name.substring (first, last);
}
name = name.replace ('-', '.');
name = BaseUtilities.translate(name);
return name;
}
示例9: testAreAttributesFine
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testAreAttributesFine () {
List<String> errors = new ArrayList<String>();
FileObject root = FileUtil.getConfigRoot();
Enumeration<? extends FileObject> files = Enumerations.concat(Enumerations.singleton(root), root.getChildren(true));
while (files.hasMoreElements()) {
FileObject fo = files.nextElement();
if (
"Keymaps/NetBeans/D-BACK_QUOTE.shadow".equals(fo.getPath()) ||
"Keymaps/NetBeans55/D-BACK_QUOTE.shadow".equals(fo.getPath()) ||
"Keymaps/Emacs/D-BACK_QUOTE.shadow".equals(fo.getPath())
) {
// #46753
continue;
}
if (
"Services/Browsers/FirefoxBrowser.settings".equals(fo.getPath()) ||
"Services/Browsers/MozillaBrowser.settings".equals(fo.getPath()) ||
"Services/Browsers/NetscapeBrowser.settings".equals(fo.getPath())
) {
// #161784
continue;
}
Enumeration<String> attrs = fo.getAttributes();
while (attrs.hasMoreElements()) {
String name = attrs.nextElement();
if (isInstanceAttribute(name)) {
continue;
}
if (name.indexOf('\\') != -1) {
errors.add("File: " + fo.getPath() + " attribute name must not contain backslashes: " + name);
}
Object attr = fo.getAttribute(name);
if (attr == null) {
CharSequence warning = Log.enable("", Level.WARNING);
if (
fo.getAttribute("class:" + name) != null &&
fo.getAttribute(name) == null &&
warning.length() == 0
) {
// ok, factory method returned null
continue;
}
errors.add("File: " + fo.getPath() + " attribute name: " + name);
}
if (attr instanceof URL) {
URL u = (URL) attr;
int read = -1;
try {
read = u.openStream().read(new byte[4096]);
} catch (IOException ex) {
errors.add(fo.getPath() + ": " + ex.getMessage());
}
if (read <= 0) {
errors.add("URL resource does not exist: " + fo.getPath() + " attr: " + name + " value: " + attr);
}
}
}
}
assertNoErrors("Some attributes in files are unreadable", errors);
}
示例10: BindingEnumeration
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public BindingEnumeration(FileObject fo) {
this.fo = fo;
this.en = fo.getAttributes();
}
示例11: enableActionsOnExpand
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
static void enableActionsOnExpand(ServerRegistry registry) {
FileObject fo = FileUtil.getConfigFile(registry.getPath()+"/Actions"); // NOI18N
Enumeration<String> en;
if (fo != null) {
for (FileObject o : fo.getChildren()) {
en = o.getAttributes();
while (en.hasMoreElements()) {
String attr = en.nextElement();
boolean enable = false;
final String prefix = "property-"; // NOI18N
if (attr.startsWith(prefix)) {
attr = attr.substring(prefix.length());
if (System.getProperty(attr) != null) {
enable = true;
}
} else {
final String config = "config-"; // NOI18N
if (attr.startsWith(config)) {
attr = attr.substring(config.length());
FileObject configFile = FileUtil.getConfigFile(attr);
if (configFile != null) {
if (!configFile.isFolder() || configFile.getChildren().length > 0) {
enable = true;
}
}
}
}
if (enable) {
Lookup l = Lookups.forPath(registry.getPath()+"/Actions"); // NOI18N
for (Lookup.Item<Action> item : l.lookupResult(Action.class).allItems()) {
if (item.getId().contains(o.getName())) {
Action a = item.getInstance();
a.actionPerformed(new ActionEvent(getInstance(), 0, "noui")); // NOI18N
}
}
}
}
}
}
}
示例12: getClassName
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** get class name from specified file object*/
private static String getClassName(FileObject fo) {
// first of all try "instanceClass" property of the primary file
Object attr = fo.getAttribute ("instanceClass");
if (attr instanceof String) {
return BaseUtilities.translate((String) attr);
} else if (attr != null) {
LOG.warning(
"instanceClass was a " + attr.getClass().getName()); // NOI18N
}
attr = fo.getAttribute("instanceCreate");
if (attr != null) {
return attr.getClass().getName();
} else {
Enumeration<String> attributes = fo.getAttributes();
while (attributes.hasMoreElements()) {
if (attributes.nextElement().equals("instanceCreate")) {
// It was specified, just unloadable (usually a methodvalue).
return null;
}
}
}
// otherwise extract the name from the filename
String name = fo.getName ();
int first = name.indexOf('[') + 1;
if (first != 0) {
LOG.log(Level.WARNING, "Cannot understand {0}", fo);
}
int last = name.indexOf (']');
if (last < 0) {
last = name.length ();
}
// take only a part of the string
if (first < last) {
name = name.substring (first, last);
}
name = name.replace ('-', '.');
name = BaseUtilities.translate(name);
//System.out.println ("Original: " + getPrimaryFile ().getName () + " new one: " + name); // NOI18N
return name;
}
示例13: handlePanel
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void handlePanel(FileObject keywordsFO) {
String location = keywordsFO.getAttribute("location").toString(); //NOI18N
String tabTitle = keywordsFO.getAttribute("tabTitle").toString(); //NOI18N
JTabbedPane pane = categoryid2tabbedpane.get(location);
int tabIndex = pane == null ? -1 : pane.indexOfTab(tabTitle);
Set<String> keywords = new HashSet<String>();
keywords.add(location.toUpperCase());
keywords.add(tabTitle.toUpperCase());
Enumeration<String> attributes = keywordsFO.getAttributes();
while(attributes.hasMoreElements()) {
String attribute = attributes.nextElement();
if(attribute.startsWith("keywords")) {
String word = keywordsFO.getAttribute(attribute).toString();
keywords.add(word.toUpperCase());
}
}
ArrayList<String> words = categoryid2words.get(location);
if (words == null) {
words = new ArrayList<String>();
}
Set<String> newWords = new HashSet<String>();
for (String keyword : keywords) {
if (!words.contains(keyword)) {
newWords.add(keyword);
}
}
words.addAll(newWords);
categoryid2words.put(location, words);
if (!categoryid2tabs.containsKey(location)) {
categoryid2tabs.put(location, new HashMap<Integer, TabInfo>());
}
HashMap<Integer, TabInfo> categoryTabs = categoryid2tabs.get(location);
TabInfo tabInfo;
if (!categoryTabs.containsKey(tabIndex)) {
tabInfo = new TabInfo();
} else {
tabInfo = categoryTabs.get(tabIndex);
}
tabInfo.addWords(keywords);
categoryTabs.put(tabIndex, tabInfo);
categoryid2tabs.put(location, categoryTabs);
}