Java Code Examples for org.openide.filesystems.FileObject.getName()

The following are Jave code examples for showing how to use getName() of the org.openide.filesystems.FileObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: SourceUtils.java   Source Code and License Vote up 6 votes
/**
 * Finds the first public top-level type in the compilation unit given by the
 * given <code>CompilationController</code>.
 *
 * This method assumes the restriction that there is at most a public
 * top-level type declaration in a compilation unit, as described in the
 * section 7.6 of the JLS.
 *
 * @param  controller a {@link CompilationController}.
 * @return the <code>TypeElement</code> encapsulating the public top-level type
 *         in the compilation unit given by <code>controller</code> or null
 *         if no such type is found.
 * @throws IllegalStateException when the controller was created with no file
 *         objects.
 */
public static TypeElement getPublicTopLevelElement(CompilationController controller) {
    Parameters.notNull("controller", controller); // NOI18N

    FileObject mainFileObject = controller.getFileObject();
    if (mainFileObject == null) {
        throw new IllegalStateException();
    }
    String mainElementName = mainFileObject.getName();
    List<? extends TypeElement> elements = controller.getTopLevelElements();
    if (elements != null) {
        for (TypeElement element : elements) {
            if (element.getModifiers().contains(Modifier.PUBLIC) && element.getSimpleName().contentEquals(mainElementName)) {
                return element;
            }
        }
    }
    return null;
}
 
Example 2
Project: incubator-netbeans   File: DBSchemaFileList.java   Source Code and License Vote up 6 votes
private void searchRoot(FileObject root, String rootDisplayName) {
    Enumeration ch = root.getChildren(true);
    while (ch.hasMoreElements()) {
        FileObject f = (FileObject) ch.nextElement();
        if (f.getExt().equals(DBSchemaManager.DBSCHEMA_EXT) && !f.isFolder()) {
            if (!dbschema2DisplayName.containsKey(f)) {
                String relativeParent = FileUtil.getRelativePath(root, f.getParent()) + File.separator;
                if (relativeParent.startsWith("/")) { // NOI18N
                    relativeParent = relativeParent.substring(1);
                }
                String relative = relativeParent + f.getName();
                String displayName = NbBundle.getMessage(DBSchemaFileList.class,
                        "LBL_SchemaLocation", rootDisplayName, relative);
                dbschema2DisplayName.put(f, displayName);
            }
        }
    }
}
 
Example 3
Project: incubator-netbeans   File: DBSchemaManager.java   Source Code and License Vote up 6 votes
/**
 * Overwrites <code>dbschemaFile</code> with the contents of
 * <code>schemaElement</code>.
 */
private static void overwriteDBSchema(SchemaElement schemaElement, FileObject dbschemaFile, DBIdentifier dbschemaName) throws IOException {
    try {
        schemaElement.setName(dbschemaName);
    } catch (DBException e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.initCause(e);
        throw ioe;
    }

    // cannot just overwrite the file, DBSchemaDataObject would not
    // notice the file has changed.
    FileObject parent = dbschemaFile.getParent();
    String fileName = dbschemaFile.getName();
    String fileExt = dbschemaFile.getExt();
    dbschemaFile.delete();
    FileObject newDBSchemaFile = parent.createData(fileName, fileExt);

    writeSchemaElement(schemaElement, newDBSchemaFile);
}
 
Example 4
Project: incubator-netbeans   File: SpellcheckerOptionsPanel.java   Source Code and License Vote up 6 votes
private static List<String> loadCategories () {
    //Repository.getDefault ().findResource ("Spellcheckers");
    List<String> result = new ArrayList<String> ();
    FileObject root = FileUtil.getConfigFile ("Spellcheckers");
    if (root != null) {
        FileObject[] children = root.getChildren ();
        for (FileObject fileObject : children) {
            String name = null;
            try {
                name = fileObject.getFileSystem ().getDecorator ().annotateName (fileObject.getName (), Collections.singleton (fileObject));
            } catch (FileStateInvalidException ex) {
                name = fileObject.getName ();
            }
            Boolean b = (Boolean) fileObject.getAttribute ("Hidden");
            if (b != null && b) {
                result.add ("-" + name); // hidden
            } else {
                result.add ("+" + name);
            }
        }
    }
    Collections.sort (result, CategoryComparator);
    return result;
}
 
Example 5
Project: incubator-netbeans   File: TestProject.java   Source Code and License Vote up 6 votes
@Override
public Result isProject(@NonNull final FileObject projectDirectory) {
    if (projectDirectory.getFileObject(CONVERTOR_MARKER) != null) {
        try {
            return new Result(
                LOOKUP_FACTORY.call(),
                new Callable<Project>() {
                    @Override
                    public Project call() throws Exception {
                        projectDirectory.createFolder(PROJECT_MARKER);
                        final Runnable action = CALLBACK;
                        if (action != null) {
                            action.run();
                        }
                        return ProjectManager.getDefault().findProject(projectDirectory);
                    }
                },
                projectDirectory.getName(),
                null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return null;
}
 
Example 6
Project: incubator-netbeans   File: CreatedModifiedFilesProvider.java   Source Code and License Vote up 5 votes
/**
 * returns archive name or temporarily null cause there is no zip support
 * for file protocol
 */
private static String addArchiveToCopy(CreatedModifiedFiles fileSupport, NewLibraryDescriptor.DataModel data, URL originalURL, String pathPrefix) {
    String retval = null;

    URL archivURL = FileUtil.getArchiveFile(originalURL);
    if (archivURL != null && FileUtil.isArchiveFile(archivURL)) {
        FileObject archiv = URLMapper.findFileObject(archivURL);
        if (archiv == null) {
            // #129617: broken library entry, just skip it.
            return null;
        }
        retval = archiv.getNameExt();
        fileSupport.add(fileSupport.createFile(pathPrefix + retval, archiv));
    } else {
        if ("file".equals(originalURL.getProtocol())) {//NOI18N
            FileObject folderToZip;
            folderToZip = URLMapper.findFileObject(originalURL);
            if (folderToZip != null) {
                retval = data.getLibraryName() + "-" + folderToZip.getName() + ".zip"; // NOI18N
                pathPrefix += retval;
                fileSupport.add(new ZipAndCopyOperation(data.getProject(),
                        folderToZip, pathPrefix));
            }
        }
    }
    return retval;
}
 
Example 7
Project: incubator-netbeans   File: CopyClassesUI.java   Source Code and License Vote up 5 votes
private static String getDOPackageName(FileObject f) {
    ClassPath cp = ClassPath.getClassPath(f, ClassPath.SOURCE);
    if (cp != null) {
        return cp.getResourceName(f, '.', false);
    } else {
        Logger.getLogger("org.netbeans.modules.refactoring.java").info("Cannot find classpath for " + f.getPath()); //NOI18N
        return f.getName();
    }
}
 
Example 8
Project: incubator-netbeans   File: HtmlBrowser.java   Source Code and License Vote up 5 votes
public java.lang.String[] getTags () {
    ArrayList<String> list = new ArrayList<String> (6);
    Lookup.Result<org.openide.awt.HtmlBrowser.Factory> r = Lookup.getDefault().lookupResult(org.openide.awt.HtmlBrowser.Factory.class);
    for (Lookup.Item<org.openide.awt.HtmlBrowser.Factory> i: r.allItems()) {
        list.add(i.getDisplayName());
    }
    
    // PENDING need to get rid of this filtering
    FileObject fo = FileUtil.getConfigFile (BROWSER_FOLDER);
    if (fo != null) {
        DataFolder folder = DataFolder.findFolder (fo);
        DataObject [] dobjs = folder.getChildren ();
        for (int i = 0; i<dobjs.length; i++) {
            // Must not be hidden and have to provide instances (we assume instance is HtmlBrowser.Factory)
            if (Boolean.TRUE.equals(dobjs[i].getPrimaryFile().getAttribute(EA_HIDDEN)) ||
                    dobjs[i].getCookie(InstanceCookie.class) == null) {
                FileObject fo2 = dobjs[i].getPrimaryFile();
                String n = fo2.getName();
                try {
                    n = fo2.getFileSystem().getDecorator().annotateName(n, dobjs[i].files());
                } catch (FileStateInvalidException e) {
                    // Never mind.
                }
                list.remove(n);
            }
        }
    }
    String[] retValue = new String[list.size ()];
    
    list.toArray (retValue);
    return retValue;
}
 
Example 9
Project: incubator-netbeans   File: Saas.java   Source Code and License Vote up 5 votes
public FileObject getSaasFile() throws IOException {
    if (saasFile == null) {
        FileObject folder = getSaasFolder();
        String filename = folder.getName() + "-saas.xml"; //NOI18N

        saasFile = folder.getFileObject(filename);
        if (saasFile == null) {
            saasFile = getSaasFolder().createData(filename);
        }
    }
    return saasFile;
}
 
Example 10
Project: incubator-netbeans   File: PropertiesDataNode.java   Source Code and License Vote up 5 votes
private static boolean containsLocale(PropertiesDataObject propertiesDataObject, Locale locale) {
        FileObject file = propertiesDataObject.getBundleStructure().getNthEntry(0).getFile();
//        FileObject file = propertiesDataObject.getPrimaryFile();
        String newName = file.getName() + PropertiesDataLoader.PRB_SEPARATOR_CHAR + locale;
        BundleStructure structure = propertiesDataObject.getBundleStructure();
        for (int i = 0; i<structure.getEntryCount();i++) {
            FileObject f = structure.getNthEntry(i).getFile();
            if (newName.startsWith(f.getName()) && f.getName().length() > file.getName().length())
                file = f;
        }
        return file.getName().equals(newName);
    }
 
Example 11
Project: incubator-netbeans   File: TestUtil.java   Source Code and License Vote up 5 votes
@Override
    public ProjectManager.Result isProject2(FileObject dir) {
        FileObject testproject = dir.getFileObject("testproject");
        if(testproject != null && testproject.isFolder() && testproject.getFileObject("broken") != null) {
            return new ProjectManager.Result(TEST_PROJECT_ICON);
}
        if(testproject != null && testproject.isFolder()) {
            return new ProjectManager.Result(
                        dir.getName(), 
                        TEST_PROJECT_TYPE, 
                        TEST_PROJECT_ICON);
        }
        return null;
    }
 
Example 12
Project: incubator-netbeans   File: SourceMapsScanner.java   Source Code and License Vote up 5 votes
private static FileObject findCompiledFile(FileObject sourceMapFile) {
    String name = sourceMapFile.getName();
    FileObject parent = sourceMapFile.getParent();
    FileObject compiledFO = parent.getFileObject(name);
    if (compiledFO != null) {
        return compiledFO;
    }
    compiledFO = parent.getFileObject(name, "js");
    if (compiledFO != null) {
        return compiledFO;
    }
    return null;
}
 
Example 13
Project: incubator-netbeans   File: VisibilityQueryImpl.java   Source Code and License Vote up 4 votes
@Override
public boolean isVisible(FileObject file) {
    final String name = file.getName();
    return !name.endsWith(INVISIBLE_SUFFIX);
}
 
Example 14
Project: incubator-netbeans   File: ConfigureFXMLPanelVisual.java   Source Code and License Vote up 4 votes
public void initValues(FileObject template, FileObject preselectedFolder) {
    if (template == null) {
            throw new IllegalArgumentException(
                    NbBundle.getMessage(ConfigureFXMLPanelVisual.class,
                        "MSG_ConfigureFXMLPanel_Template_Error")); // NOI18N
    }

    // Show name of the project
    projectTextField.setText(ProjectUtils.getInformation(project).getDisplayName());
    
    String displayName;
    try {
        DataObject templateDo = DataObject.find(template);
        displayName = templateDo.getNodeDelegate().getDisplayName();
    } catch (DataObjectNotFoundException ex) {
        displayName = template.getName();
    }
    putClientProperty("NewFileWizard_Title", displayName); // NOI18N        

    // Setup comboboxes 
    locationComboBox.setModel(new DefaultComboBoxModel(support.getSourceGroups().toArray()));
    SourceGroupProxy preselectedGroup = SourceGroupSupport.getContainingSourceGroup(support, preselectedFolder);
    ignoreRootCombo = true;
    locationComboBox.setSelectedItem(preselectedGroup);
    ignoreRootCombo = false;
    FileObject targetFolder = preselectedFolder;
    if(isMaven && support.getType().equals(JavaProjectConstants.SOURCES_TYPE_RESOURCES)) {
        packageComboBox.getEditor().setItem(FXMLTemplateWizardIterator.defaultMavenFXMLPackage);
        targetFolder = null;
        if(preselectedGroup.isReal()) {
            File f = new File(preselectedGroup.getRootFolder().getPath() + File.separator + FXMLTemplateWizardIterator.defaultMavenFXMLPackage);
            if(f.exists()) {
                targetFolder = FileUtil.toFileObject(f);
            }
        }
    } else {
        Object preselectedPackage = FXMLTemplateWizardIterator.getPreselectedPackage(preselectedGroup, preselectedFolder);
        if (preselectedPackage != null) {
            packageComboBox.getEditor().setItem(preselectedPackage);
        }
    }
    if (template != null) {
        if (fxmlNameTextField.getText().trim().length() == 0) { // To preserve the fxml name on back in the wiazard
            final String baseName = template.getName();
            String activeName = baseName;
            if (targetFolder != null) {
                int index = 0;
                while (true) {
                    FileObject fo = targetFolder.getFileObject(activeName, JFXProjectProperties.FXML_EXTENSION);
                    if (fo == null) {
                        break;
                    }
                    activeName = baseName + ++index;
                }
            }
            fxmlNameTextField.setText(activeName);
            fxmlNameTextField.selectAll();
        }
    }
    
    updatePackages();
    updateText();
}
 
Example 15
Project: incubator-netbeans   File: FolderPathLookup.java   Source Code and License Vote up 4 votes
/** 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;
}
 
Example 16
Project: incubator-netbeans   File: SourceUtils.java   Source Code and License Vote up 4 votes
final boolean apply(final FileObject fo) {
    final String foName = fo.getName();
    return match(foName,name) && isJava(fo);
}
 
Example 17
Project: incubator-netbeans   File: RenameRefactoringUI.java   Source Code and License Vote up 4 votes
public RenameRefactoringUI(FileObject file) {
this.file = file;
       this.newName = file.getName();
this.refactoring = new RenameRefactoring(Lookups.fixed(file));
   }
 
Example 18
Project: incubator-netbeans   File: SpringBinaryIndexer.java   Source Code and License Vote up 4 votes
private String findXsdVersion(FileObject file) {
    String v = file.getName();
    v = v.substring(v.lastIndexOf("-")+1);
    return v;
}
 
Example 19
Project: incubator-netbeans   File: CategoryNode.java   Source Code and License Vote up 4 votes
/** Converts category name to name that can be used as name of folder
 * for the category (restricted even to package name).
 */ 
static String convertCategoryToFolderName( FileObject paletteFO, 
                                                   String name,
                                                   String currentName)
{
    if (name == null || "".equals(name)) // NOI18N
        return null;

    int i;
    int n = name.length();
    StringBuffer nameBuff = new StringBuffer(n);

    char ch = name.charAt(0);
    if (Character.isJavaIdentifierStart(ch)) {
        nameBuff.append(ch);
        i = 1;
    }
    else {
        nameBuff.append('_');
        i = 0;
    }

    while (i < n) {
        ch = name.charAt(i);
        if (Character.isJavaIdentifierPart(ch))
            nameBuff.append(ch);
        i++;
    }

    String fName = nameBuff.toString();
    if ("_".equals(fName)) // NOI18N
        fName = "Category"; // NOI18N
    if (fName.equals(currentName))
        return fName;

    // having the base name, make sure it is not used yet
    String freeName = null;
    boolean nameOK = false;

    for (i=0; !nameOK; i++) {
        freeName = i > 0 ? fName + "_" + i : fName; // NOI18N

        if (Utilities.isWindows()) {
            nameOK = true;
            java.util.Enumeration en = paletteFO.getChildren(false);
            while (en.hasMoreElements()) {
                FileObject fo = (FileObject)en.nextElement();
                String fn = fo.getName();
                String fe = fo.getExt();

                // case-insensitive on Windows
                if ((fe == null || "".equals(fe)) && fn.equalsIgnoreCase(freeName)) { // NOI18N
                    nameOK = false;
                    break;
                }
            }
        }
        else nameOK = paletteFO.getFileObject(freeName) == null;
    }
    return freeName;
}
 
Example 20
Project: incubator-netbeans   File: Util.java   Source Code and License Vote up 3 votes
/**
 * Returns a locale specification suffix of a given
 * <code>MultiDataObject</code> entry.
 * <p>
 * Examples:<br />
 * <pre>    </pre>Bundle.properties       -&gt; &quot;&quot;<br />
 * <pre>    </pre>Bundle_en_CA.properties -&gt; &quot;_en_CA&quot;
 * 
 * @param  fe  <code>DataObject</code> entry, representing a single bundle
 * @return  locale specification suffix of a given entry;
 *          or an empty string if the given entry has no locale suffix
 * @see  #getLanguage
 * @see  #getCountry
 * @see  #getVariant
 */
public static String getLocaleSuffix(MultiDataObject.Entry fe) {
    FileObject fo = fe.getFile();
    String fName = fo.getName();
    String baseName = getBaseName(fName);
    if (fName.equals(baseName))
        return "";
    else
        return fName.substring(baseName.length());
}