Java Code Examples for org.openide.filesystems.FileObject#getFileObject()

The following examples show how to use org.openide.filesystems.FileObject#getFileObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LayersBridge.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static DataFolder getRootFolder (String name1, String name2) {
    FileObject root = FileUtil.getConfigRoot ();
    FileObject fo1 = root.getFileObject (name1);
    try {
        if (fo1 == null) fo1 = root.createFolder (name1);
        if (fo1 == null) return null;
        if (name2 == null) return DataFolder.findFolder (fo1);
        FileObject fo2 = fo1.getFileObject (name2);
        if (fo2 == null) fo2 = fo1.createFolder (name2);
        if (fo2 == null) return null;
        return DataFolder.findFolder (fo2);
    } catch (IOException ex) {
        ErrorManager.getDefault ().notify (ex);
        return null;
    }
}
 
Example 2
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static FileObject getFileObject (String name, String ext, boolean create)
throws IOException {
    FileObject r = (FileObject) filesCache.get (name + '.' + ext);
    if (r != null) return r;
    FileObject optionsFolder = FileUtil.getConfigFile("Options");
    if (optionsFolder == null) {
        if (create) 
            optionsFolder = FileUtil.getConfigRoot().createFolder ("Options");
        else 
            return null;
    }
    FileObject fileObject = optionsFolder.getFileObject (name, ext);
    if (fileObject == null) {
        if (create)
            fileObject = optionsFolder.createData (name, ext);
        else
            return null;
    }
    filesCache.put (name + '.' + ext, fileObject);
    return fileObject;
}
 
Example 3
Source File: WildflyJ2eePlatformFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean containsService(LibraryImplementation library, String serviceName, String serviceImplName) {
    List roots = library.getContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH);
    for (Iterator it = roots.iterator(); it.hasNext();) {
        URL rootUrl = (URL) it.next();
        FileObject root = URLMapper.findFileObject(rootUrl);
        if (root != null && "jar".equals(rootUrl.getProtocol())) {  //NOI18N
            FileObject archiveRoot = FileUtil.getArchiveRoot(FileUtil.getArchiveFile(root));
            String serviceRelativePath = "META-INF/services/" + serviceName; //NOI18N
            FileObject serviceFO = archiveRoot.getFileObject(serviceRelativePath);
            if (serviceFO != null && containsService(serviceFO, serviceName, serviceImplName)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: TestUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static EditableProperties loadProjectProperties(
        final FileObject projectDir) throws IOException {
    FileObject propsFO = projectDir.getFileObject(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    InputStream propsIS = propsFO.getInputStream();
    EditableProperties props = new EditableProperties(true);
    try {
        props.load(propsIS);
    } finally {
        propsIS.close();
    }
    return props;
}
 
Example 5
Source File: EjbJarImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileObject getWebServicesDeploymentDescriptor() {
    FileObject metaInf = getMetaInf();
    if (metaInf != null) {
        return metaInf.getFileObject("webservices.xml"); //NOI18N
    }
    return null;
}
 
Example 6
Source File: CompletionContextTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void writeSourceFile() throws Exception {
    File f = new File(getWorkDir(), "source.fxml");
    FileObject dirFo = FileUtil.toFileObject(getWorkDir());
    OutputStream ostm = dirFo.createAndOpen("source.fxml");
    OutputStreamWriter wr = new OutputStreamWriter(ostm);
    wr.write(text);
    wr.flush();
    wr.close();
    
    sourceFO = dirFo.getFileObject("source.fxml");
}
 
Example 7
Source File: PDFOpenSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve stored custom command from System FileSystem.
 *
 * @return Stored command, or null if not available.
 */
private String getCustomCommand() {

    FileObject root = FileUtil.getConfigRoot();
    FileObject d = root.getFileObject(DATA_FOLDER
            + "/" + DATA_FILE);                                     //NOI18N
    if (d != null) {
        return (String) d.getAttribute(CMD_ATTR);
    } else {
        return null;
    }
}
 
Example 8
Source File: JsfAttributesCompletionHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void handleContracts(FileObject parent, String path, List<Source> result) {
    FileObject contractsFolder = parent.getFileObject("contracts"); //NOI18N
    if (contractsFolder != null) {
        for (FileObject child : contractsFolder.getChildren()) {
            FileObject contract = child.getFileObject(path);
            if (contract != null) {
                result.add(Source.create(contract));
            }
        }
    }
}
 
Example 9
Source File: TestLocatorImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static @CheckForNull FileObject findOpposite(FileObject rule, boolean toTest) {
    ClassPath cp = ClassPath.getClassPath(rule, ClassPath.SOURCE);
    String resourceName = cp != null ? cp.getResourceName(rule) : null;

    if (resourceName == null) {
        Logger.getLogger(TestLocatorImpl.class.getName()).log(Level.FINE, "cp==null or rule file cannot be found on its own source cp");
        return null;
    }

    String testFileName = resourceName.substring(0, resourceName.lastIndexOf('.')) + (toTest ? ".test" : ".hint");

    FileObject testFile = cp.findResource(testFileName);

    if (testFile == null) {
        URL[] sr;

        if (toTest) {
            sr = UnitTestForSourceQuery.findUnitTests(cp.findOwnerRoot(rule));
        } else {
            sr = UnitTestForSourceQuery.findSources(cp.findOwnerRoot(rule));
        }
        
        for (URL testRoot : sr) {
            FileObject testRootFO = URLMapper.findFileObject(testRoot);

            if (testRootFO != null) {
                testFile = testRootFO.getFileObject(testFileName);

                if (testFile != null) {
                    break;
                }
            }
        }
    }

    return testFile;
}
 
Example 10
Source File: ProfilerStorageProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void loadGlobalProperties(Properties properties, String filename) throws IOException {
    FileObject folder = getGlobalFolder(false);
    if (folder == null) return;

    FileObject fo = folder.getFileObject(filename, EXT);
    if (fo == null) return;

    loadProperties(properties, fo);
}
 
Example 11
Source File: WebProjectOperations.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void addFile(FileObject projectDirectory, String fileName, List<FileObject> result) {
    FileObject file = projectDirectory.getFileObject(fileName);
    
    if (file != null) {
        result.add(file);
    }
}
 
Example 12
Source File: BootClassPathImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private PathResourceImplementation createFxCPImpl(JavaPlatform pat) {
    for (FileObject fo : pat.getInstallFolders()) {
        FileObject jdk8 = fo.getFileObject("jre/lib/ext/jfxrt.jar"); // NOI18N
        if (jdk8 == null) {
            FileObject jdk7 = fo.getFileObject("jre/lib/jfxrt.jar"); // NOI18N
            if (jdk7 != null) {
                // jdk7 add the classes on bootclasspath
                if (FileUtil.isArchiveFile(jdk7)) {
                    return ClassPathSupport.createResource(FileUtil.getArchiveRoot(jdk7.toURL()));
                }
            }
        }
    }
    return null;
}
 
Example 13
Source File: SaasServicesModelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private FileObject setupLocalWadl() throws Exception {
    FileObject workDir = FileUtil.toFileObject(getWorkDir());
    FileObject wadl = workDir.getFileObject("application.wadl.xml");
    if (wadl == null) {
        wadl = workDir.createData("application.wadl.xml");
    }
    OutputStream out = wadl.getOutputStream();
    try {
        FileUtil.copy(getClass().getResourceAsStream("application.wadl"), out);
    } finally {
        out.close();
    }
    return wadl;
}
 
Example 14
Source File: FilePathParameter.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
private List<String> getCategoryElements(CakePHP3Module cakeModule, ModuleInfo info, String subpath, String filter, String pluginName, Category category) {
    Base base = info.getBase();
    if (StringUtils.isEmpty(pluginName)) {
        if (base == Base.PLUGIN) {
            pluginName = info.getPluginName();
        }
    } else {
        if (base != Base.PLUGIN) {
            base = Base.PLUGIN;
        }
    }
    // app or plugin
    List<FileObject> directories = cakeModule.getDirectories(base, category, pluginName);
    List<FileObject> coreDirectories;
    if (!StringUtils.isEmpty(pluginName)) {
        coreDirectories = Collections.emptyList();
    } else {
        coreDirectories = cakeModule.getDirectories(Base.CORE, category, null);
    }
    List<String> elements = new ArrayList<>();
    for (List<FileObject> targets : Arrays.asList(directories, coreDirectories)) {
        for (FileObject directory : targets) {
            FileObject baseDirectory = directory.getFileObject(subpath);
            if (baseDirectory != null) {
                for (FileObject child : baseDirectory.getChildren()) {
                    if (child.isFolder()) {
                        continue;
                    }
                    String name = child.getName();
                    name = ModuleUtils.toCommonName(name, category);
                    if (!elements.contains(name) && name.toLowerCase().startsWith(filter.toLowerCase())) {
                        elements.add(name);
                    }
                }
            }
        }
    }
    return elements;
}
 
Example 15
Source File: CakePHP3CustomizerValidator.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
public CakePHP3CustomizerValidator validateImg(FileObject baseDirectory, String path) {
    FileObject root = baseDirectory.getFileObject(path);
    if (root == null) {
        String error = String.format("Img %s ", path); // NOI18N
        addNotFoundError("img", error); // NOI18N
    }
    return this;
}
 
Example 16
Source File: RestClientPhpCodeGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FileObject getSaasFolder() throws IOException {
    if (saasFolder == null) {
        FileObject rootFolder = getSourceRootFolder();
        String folderName = SaasClientCodeGenerator.REST_CONNECTION_PACKAGE.replace(".", "_");
        saasFolder = rootFolder.getFileObject(folderName);
        if(saasFolder == null)
            saasFolder = FileUtil.createFolder(rootFolder, folderName);
    }
    return saasFolder;
}
 
Example 17
Source File: NewEarProjectWizardIterator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
FileObject getIndexJSPFO(FileObject webRoot, String indexJSP) {
    // XXX: ignore unvalid mainClass?
    return webRoot.getFileObject(indexJSP.replace('.', '/'), "jsp"); // NOI18N
}
 
Example 18
Source File: NbModuleProjectTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testThatModuleWithOverriddenSrcDirPropertyDoesNotThrowNPE() throws Exception {
    FileObject prjFO = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "module1");
    FileObject srcFO = prjFO.getFileObject("src");
    FileUtil.moveFile(srcFO, prjFO, "src2");
    ProjectManager.getDefault().findProject(prjFO);
}
 
Example 19
Source File: ConfigurationFiles.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<FileInfo> getFiles() {
    FileObject sourceDir = getSourceDirectory();
    if (sourceDir == null) {
        // broken project
        return Collections.emptyList();
    }
    List<FileInfo> files = new ArrayList<>();
    FileObject configDir = sourceDir.getFileObject(CONFIG_DIRECTORY);
    if (configDir != null
            && configDir.isFolder()
            && configDir.isValid()) {
        List<FileObject> fileObjects = getConfigFilesRecursively(configDir);
        Collections.sort(fileObjects, new Comparator<FileObject>() {
            @Override
            public int compare(FileObject o1, FileObject o2) {
                // php files go last
                boolean phpFile1 = FileUtils.isPhpFile(o1);
                boolean phpFile2 = FileUtils.isPhpFile(o2);
                if (phpFile1 && phpFile2) {
                    return o1.getNameExt().compareTo(o2.getNameExt());
                } else if (phpFile1) {
                    return 1;
                } else if (phpFile2) {
                    return -1;
                }

                // compare extensions, then full names
                String ext1 = o1.getExt();
                String ext2 = o2.getExt();
                if (ext1.equals(ext2)) {
                    return o1.getNameExt().compareToIgnoreCase(o2.getNameExt());
                }
                return ext1.compareToIgnoreCase(ext2);
            }
        });
        for (FileObject fo : fileObjects) {
            files.add(new FileInfo(fo));
        }
    }
    return files;
}
 
Example 20
Source File: ResourceLibraryIteratorPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Messages({
    "ResourceLibraryIteratorPanel.err.contract.name.empty=Contract name is empty",
    "ResourceLibraryIteratorPanel.err.contract.name.not.valid=Contract name is not valid folder name",
    "ResourceLibraryIteratorPanel.err.template.name.empty=Template name is empty",
    "ResourceLibraryIteratorPanel.err.template.name.not.valid=Template name is not valid file name",
    "ResourceLibraryIteratorPanel.err.contracts.parent.not.extists=Contracts parent folder doesn't exist",
    "ResourceLibraryIteratorPanel.err.contracts.parent.not.writeable=Contracts parent folder is not writeable",
    "ResourceLibraryIteratorPanel.err.contracts.folder.not.writeable=Contracts folder is not writeable",
    "ResourceLibraryIteratorPanel.err.contract.already.exists=Such contract folder already exists",
})
@Override
public boolean isValid() {
    getComponent();
    descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, " "); //NOI18N

    // folders permissions
    if (!contractsParent.isValid() || !contractsParent.isFolder()) {
        descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.ResourceLibraryIteratorPanel_err_contracts_parent_not_extists());
        return false;
    }
    FileObject contractsFolder = contractsParent.getFileObject(ResourceLibraryIterator.CONTRACTS);
    if (contractsFolder == null) {
        if (!contractsParent.canWrite()) {
            descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.ResourceLibraryIteratorPanel_err_contracts_parent_not_writeable());
            return false;
        }
    } else {
        if (!contractsFolder.canWrite()) {
            descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.ResourceLibraryIteratorPanel_err_contracts_folder_not_writeable());
            return false;
        }
        if (contractsFolder.getFileObject(gui.getContractName()) != null) {
            descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.ResourceLibraryIteratorPanel_err_contract_already_exists());
            return false;
        }
    }

    // contact naming
    if (gui.getContractName().isEmpty()) {
        descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.ResourceLibraryIteratorPanel_err_contract_name_empty());
        return false;
    }
    if (!isValidFileName(gui.getContractName())) {
        descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.ResourceLibraryIteratorPanel_err_contract_name_not_valid());
        return false;
    }

    // initial template naming
    if (gui.isCreateInitialTemplate()) {
        if (gui.getTemplateName().isEmpty()) {
            descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.ResourceLibraryIteratorPanel_err_template_name_empty());
            return false;
        }
        if (!isValidFileName(gui.getTemplateName())) {
            descriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, Bundle.ResourceLibraryIteratorPanel_err_template_name_not_valid());
            return false;
        }
    }
    return true;
}