org.openide.filesystems.FileUtil.getConfigFile()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(146)

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

FileUtil.getConfigFile介绍

[英]Returns FileObject from the NetBeans default (system, configuration) filesystem or null if does not exist. If you wish to create the file/folder when it does not already exist, start with #getConfigRoot and use #createData(FileObject,String)or #createFolder(FileObject,String) methods.
[中]从NetBeans默认(系统、配置)文件系统返回FileObject,如果不存在则返回null。如果希望在文件/文件夹不存在时创建它,请从#getConfigRoot开始,并使用#createData(FileObject,String)或#createFolder(FileObject,String)方法。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/**
 * Returns the root of the NetBeans default (system, configuration)
 * filesystem.
 * @return a {@code FileObject} for the root of the NetBeans default (system, configuration)
 * filesystem
 * @since org.openide.filesystems 7.19
 */
public static FileObject getConfigRoot() {
  return getConfigFile("");  //NOI18N
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/** Lists registered MIMEResolver instances in reverse order,
 * i.e. first are ones with lower priority (position attribute higher)
 * and last are ones with highest prority (position attribute lower).
 * @return list of all registered MIMEResolver instances in reverse order
 */
public static Collection<? extends FileObject> getOrderedResolvers() {
  // scan resolvers and order them to be able to assign extension to mime type from resolver with the lowest position
  FileObject[] resolvers = FileUtil.getConfigFile(MIME_RESOLVERS_PATH).getChildren();
  TreeMap<Integer, FileObject> orderedResolvers = new TreeMap<Integer, FileObject>(Collections.reverseOrder());
  for (FileObject mimeResolverFO : resolvers) {
    Integer position = (Integer) mimeResolverFO.getAttribute("position");  //NOI18N
    if (position == null) {
      position = Integer.MAX_VALUE;
    }
    while (orderedResolvers.containsKey(position)) {
      position--;
    }
    orderedResolvers.put(position, mimeResolverFO);
  }
  return orderedResolvers.values();
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

@Override
public <T> T lookupObject(String path, Class<T> type) {
  FileObject fo = FileUtil.getConfigFile(path);
  if (fo != null && fo.isData()) {
    return FOItem.createInstanceFor(fo, type);
  }
  return null;
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/** Returns FileObject representing declarative user defined MIME resolver
 * or null if not yet created.
 * @return FileObject representing declarative user defined MIME resolver
 * or null if not yet created.
 */
public static FileObject getUserDefinedResolver() {
  FileObject resolversFolder = FileUtil.getConfigFile(MIME_RESOLVERS_PATH);
  if (resolversFolder != null) {
    FileObject[] resolvers = resolversFolder.getChildren();
    for (FileObject resolverFO : resolvers) {
      if (resolverFO.getAttribute(USER_DEFINED_MIME_RESOLVER) != null) {
        return resolverFO;
      }
    }
  }
  return null;
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/** Finds a config object under given path. The path contains the extension
 * of a file e.g.:
 * <pre>
 * Actions/Edit/org-openide-actions-CopyAction.instance
 * Services/Browsers/swing-browser.settings
 * </pre>
 * @param filePath path to .instance or .settings file
 * @param type the requested type for given object
 * @return either null or instance of requrested type
 * @since 7.49 
 */
public static <T> T getConfigObject(String path, Class<T> type) {
  FileObject fo = getConfigFile(path);
  if (fo == null || fo.isFolder()) {
    return null;
  }
  return NamedServicesProvider.getConfigObject(path, type);
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

public static List<FileFilter> findRegisteredFileFilters() {
  List<FileFilter> filters = new LinkedList<FileFilter>();
  FileObject root = FileUtil.getConfigFile(
      "Services/MIMEResolver");                               //NOI18N
  Map<String, Set<FileObject>> filterNameToResolversMap =
      new HashMap<String, Set<FileObject>>();
  for (FileObject child : root.getChildren()) {
    if (child.isFolder()) {
      continue;
    }
    int i = 0;
    String f;
    while ((f = (String) child.getAttribute("fileChooser." + i))//NOI18N
        != null) {
      Set<FileObject> set = filterNameToResolversMap.get(f);
      if (set == null) {
        set = new HashSet<FileObject>();
        filterNameToResolversMap.put(f, set);
      }
      set.add(child);
      i++;
    }
  }
  for (Map.Entry<String, Set<FileObject>> e :
      filterNameToResolversMap.entrySet()) {
    filters.add(createFilter(e.getKey(), e.getValue()));
  }
  return sortFiltersByDescription(filters);
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

private static Lookup[] computeDelegates(String p, List<FOItem> items, Lookup lkp) {
  FileObject fo = FileUtil.getConfigFile(p);
  List<Lookup> delegates = new LinkedList<Lookup>();
  delegates.add(lkp);
          Object real = f.getAttribute("originalFile"); // NOI18N
          if (real instanceof String) {
            f = FileUtil.getConfigFile((String)real);

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

private static synchronized List<MIMEResolver> declarativeResolvers() {
  List<MIMEResolver> declmimes = new ArrayList<MIMEResolver>();
  if (declarativeFolder == null) {
    declarativeFolder = FileUtil.getConfigFile("Services/MIMEResolver"); // NOI18N
  }
  if (declarativeFolder != null) {
    for (FileObject f : Ordering.getOrder(Arrays.asList(declarativeFolder.getChildren()), true)) {
      if (f.hasExt("xml")) { // NOI18N
        try {
          // For now, just assume it has the right DTD. Could check this if desired.
          declmimes.add(MIMEResolverImpl.forDescriptor(f)); // NOI18N
        } catch (IOException ex) {
          Exceptions.printStackTrace(ex);
        }
      }
    }
    declarativeFolder.removeFileChangeListener(weakDeclarativeFolderListener);
    declarativeFolder.addFileChangeListener(weakDeclarativeFolderListener);
  }
  return declmimes;
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

FileObject newUserDefinedFO = null;
try {
  FileObject resolversFolder = FileUtil.getConfigFile(MIME_RESOLVERS_PATH);
  if (resolversFolder == null) {
    resolversFolder = FileUtil.createFolder(FileUtil.getConfigRoot(), MIME_RESOLVERS_PATH);

代码示例来源:origin: org.netbeans.api/org-openide-awt

return null;
FileObject def = FileUtil.getConfigFile(path);
if (def != null) {
  AcceleratorBinding.setAccelerator(a, def);

代码示例来源:origin: dcaoyuan/nbscala

/**
 * Creates/acquires an instance of InstallerRegistry
 */
public static InstallerRegistry getDefault() {
  InstallerRegistry regs = defaultInstance.get();
  if (regs != null)
    return regs;
  regs = new InstallerRegistry(FileUtil.getConfigFile(
    INSTALLER_REGISTRY_FOLDER));
  defaultInstance = new WeakReference<InstallerRegistry>(regs);
  return regs;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-core

private void listenToDeclarativeResolvers() {
  declarativeResolvers = FileUtil.getConfigFile("Services/MIMEResolver"); // NOI18N
  if (declarativeResolvers != null) { // might be inside test which overrides SFS?
    declarativeResolvers.addFileChangeListener(listener);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf

private void initSelectionHints() {
  DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
  //suggestionsTreeModel = new DefaultTreeModel( rootNode );
  FileObject folder = FileUtil.getConfigFile( RULES_FOLDER + mimeType + SELECTION ); // NOI18N
  List<Pair<Rule,FileObject>> rules = readRules(folder);
  categorizeSelectionRules(rules, selectionHints, folder, rootNode);
  selectionsRoot = rootNode;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-core

private static FileObject getLoaderPoolStorage(boolean create) throws IOException {
  FileObject fo = FileUtil.getConfigFile(LOADER_POOL_NAME);
  if (fo == null && create) {
    fo = FileUtil.getConfigRoot().createData(LOADER_POOL_NAME);
  }
  return fo;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-project

private static FileObject createWelcomeFile(FileObject webFolder, Profile profile) throws IOException {
  FileObject template = profile != null && profile.isAtLeast(Profile.JAVA_EE_7_WEB) ?
      FileUtil.getConfigFile( "Templates/JSP_Servlet/Html.html" ) :
      FileUtil.getConfigFile( "Templates/JSP_Servlet/JSP.jsp" ); // NOI18N
  
  if (template == null) {
    return null; // Don't know the template
  }
  
  DataObject mt = DataObject.find(template);
  DataFolder webDf = DataFolder.findFolder(webFolder);
  return mt.createFromTemplate(webDf, "index").getPrimaryFile(); // NOI18N
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-editor-settings-lib

public StorageImpl(StorageDescription<K, V> sd, Callable<Void> callback) {
  this.storageDescription = sd;
  this.dataChangedCallback = callback;
  this.baseFolder = FileUtil.getConfigFile("Editors"); //NOI18N
  try {
    this.tracker = new FilesystemTracker(FileUtil.getConfigRoot().getFileSystem());
  } catch (FileStateInvalidException ex) {
    // something is terribly wrong, because we can't access SystemFileSystem
    throw new IllegalStateException(ex);
  }
  Filters.registerCallback(this);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf-navigation

private void createIndexJSP(FileObject targetFolder, String name ) throws IOException {
    
    final FileObject jspTemplate = FileUtil.getConfigFile( "Templates/JSP_Servlet/JSP.jsp" ); // NOI18N
    
    if (jspTemplate == null) {
      return; // Don't know the template
    }
    
    final DataObject mt = DataObject.find(jspTemplate);
    final DataFolder webDf = DataFolder.findFolder(targetFolder);
    mt.createFromTemplate(webDf, name); // NOI18N
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2

public void read(Reader reader) throws IOException {
final FileObject fo = FileUtil.getConfigFile(fullPath());
if (fo == null) {
  // not an error
  return;
}
InputStream inputStream = fo.getInputStream();
reader.readFrom(inputStream);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils

private Manager() {
  configFolder = FileUtil.getConfigFile("CND/Extensions"); // NOI18N
  if (configFolder != null) {
    listener = new L();
    configFolder.addFileChangeListener(FileUtil.weakFileChangeListener(listener, configFolder));
    initialize(configFolder);
  } else {
    listener = null;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor

static IntroduceClassFix getInstance(String className, Model model, ClassInstanceCreation instanceCreation) {
  FileObject currentFile = model.getFileScope().getFileObject();
  FileObject folder = currentFile == null ? null : currentFile.getParent();
  String templatePath = "Templates/Scripting/PHPClass.php"; //NOI18N
  FileObject template = FileUtil.getConfigFile(templatePath);
  return (template != null && folder != null && folder.canWrite())
      ? new IntroduceClassFix(className, template, folder, instanceCreation) : null;
}

相关文章