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

The following are Jave code examples for showing how to use getAttribute() 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: InterceptorTest.java   Source Code and License Vote up 6 votes
public void testGetAttributeClonedOnlyPush() throws HgException, IOException {
    File folder = createFolder("folder");
    File file = createFile(folder, "file");

    commit(folder);
    File cloned = clone(getWorkTreeDir());

    String defaultPush = "http://a.repository.far.far/away";
    new HgConfigFiles(cloned).removeProperty(HgConfigFiles.HG_PATHS_SECTION, HgConfigFiles.HG_DEFAULT_PULL);
    new HgConfigFiles(cloned).removeProperty(HgConfigFiles.HG_PATHS_SECTION, HgConfigFiles.HG_DEFAULT_PULL_VALUE);
    new HgConfigFiles(cloned).setProperty(HgConfigFiles.HG_DEFAULT_PUSH, defaultPush);
    HgRepositoryContextCache.getInstance().reset();

    FileObject fo = FileUtil.toFileObject(new File(new File(cloned, folder.getName()), file.getName()));
    String attr = (String) fo.getAttribute("ProvidedExtensions.RemoteLocation");
    assertNotNull(attr);
    assertEquals(defaultPush, attr);
}
 
Example 2
Project: incubator-netbeans   File: ContextActionTest.java   Source Code and License Vote up 6 votes
public void testBasicUsageWithEnablerFromLayer() throws Exception {
    FileObject folder;
    folder = FileUtil.getConfigFile("actions/support/test");
    assertNotNull("testing layer is loaded: ", folder);

    FileObject fo = folder.getFileObject("testContextEnabler.instance");
    
    Object obj = fo.getAttribute("instanceCreate");
    if (!(obj instanceof ContextAwareAction)) {
        fail("Shall create an action: " + obj);
    }
    ContextAwareAction caa = (ContextAwareAction)obj;
    Action action = caa.createContextAwareInstance(lookupProxy);
    
    
    doBasicUsageWithEnabler(action);
}
 
Example 3
Project: incubator-netbeans   File: PlainTokenList.java   Source Code and License Vote up 6 votes
public void setStartOffset(int offset) {
    currentWord = null;
    currentStartOffset = (-1);
    CharSequence content = DocumentUtilities.getText(doc);

    while (offset > 0 && offset < content.length()) {
        if (!Character.isLetter(content.charAt(offset))) {
            break;
        }
        
        offset--;
    }
    
    this.nextSearchOffset = offset;
    FileObject fileObject = FileUtil.getConfigFile ("Spellcheckers/Plain");
    Boolean b = (Boolean) fileObject.getAttribute ("Hidden");
    hidden = Boolean.TRUE.equals (b);
}
 
Example 4
Project: incubator-netbeans   File: ContextActionInjectTest.java   Source Code and License Vote up 6 votes
public void testContextAction() throws Exception {
    Context.cnt = 0;
    
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testInjectContext.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is context aware action", obj instanceof ContextAwareAction);
    ContextAwareAction a = (ContextAwareAction)obj;

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(10);

    assertEquals("Number lover!", clone.getValue(Action.NAME));
    clone.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Global Action not called", 10, Context.cnt);

    ic.remove(10);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Global Action stays same", 10, Context.cnt);
}
 
Example 5
Project: incubator-netbeans   File: XMLPropertiesConvertor.java   Source Code and License Vote up 6 votes
public void write(java.io.Writer w, Object inst) throws IOException {
    w.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"+XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    w.write("<!DOCTYPE properties PUBLIC \""); // NOI18N
    
    FileObject foEntity = Env.findEntityRegistration(providerFO);
    if (foEntity == null) foEntity = providerFO;
    Object publicId = foEntity.getAttribute(Env.EA_PUBLICID);
    if (publicId == null || !(publicId instanceof String)) {
        throw new IOException("missing or invalid attribute: " + //NOI18N
            Env.EA_PUBLICID + ", provider: " + foEntity); //NOI18N
    }
    
    w.write((String) publicId);
    w.write("\" \"http://www.netbeans.org/dtds/properties-1_0.dtd\">"+XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    w.write("<properties>"+XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
    Properties p = getProperties(inst);
    if (p != null && !p.isEmpty()) writeProperties(w, p);
    w.write("</properties>"+XMLSettingsSupport.LINE_SEPARATOR); // NOI18N
}
 
Example 6
Project: incubator-netbeans   File: DelegatingVCS.java   Source Code and License Vote up 6 votes
private DelegatingVCS(VersioningSystem delegate) {
    this.delegate = delegate;
    String serviceName = "Services/VersioningSystem/"+delegate.getClass().getName().replace('.', '-')+".instance"; // NOI18N
    FileObject serviceFO = FileUtil.getConfigFile(serviceName); // NOI18N
    metadataFolderNames = new HashSet<String>();
    int i = 0;
    while(true) {
        String name = (String) serviceFO.getAttribute("metadataFolderName" + i++); // NOI18N
        if(name == null) {
            break;
        }
        name = parseName(name);
        if(name == null) {
            continue;
        }
        metadataFolderNames.add(name);
    }
    HashMap<String,String> aMap = new HashMap<String,String>();
    aMap.put("actionsCategory", (String) serviceFO.getAttribute("actionsCategory")); // NOI18N
    map = aMap;
    this.displayName = (String) serviceFO.getAttribute("displayName"); // NOI18N
    this.menuLabel = (String) serviceFO.getAttribute("menuLabel"); // NOI18N
    this.isLocalHistory = false;
    VersioningManager.LOG.log(Level.FINE, "Created DelegatingVCS for : {0}", displayName); // NOI18N
}
 
Example 7
Project: incubator-netbeans   File: FilesystemInterceptorTest.java   Source Code and License Vote up 5 votes
public void testGetRemoteLocationAttribute () throws Exception {
        File file = new File(repositoryLocation, "attrfile");
        file.createNewFile();
        FileObject fo = FileUtil.toFileObject(file);

        String str = (String) fo.getAttribute(PROVIDED_EXTENSIONS_REMOTE_LOCATION);
        // TODO implement getRemoteRepositoryURL
//        assertNotNull(str);
//        assertEquals(repositoryLocation.getAbsolutePath().toString(), str);
    }
 
Example 8
Project: incubator-netbeans   File: LayersBridge.java   Source Code and License Vote up 5 votes
public String getCurrentProfile() {
    if (cachedProfile == null) {
        FileObject fo = FileUtil.getConfigFile (KEYMAPS_FOLDER);
        if (fo != null) {
            Object o = fo.getAttribute (FATTR_CURRENT_KEYMAP_PROFILE);
            if (o instanceof String) {
                cachedProfile = (String) o;
            }
        }
        if (cachedProfile == null) {
            cachedProfile = DEFAULT_PROFILE;
        }
    }
    return cachedProfile;
}
 
Example 9
Project: incubator-netbeans   File: Hinter.java   Source Code and License Vote up 5 votes
/**
 * Tries to find the instance associated with a file.
 * If it is a folder, or not a {@code *.instance} file, null is returned.
 * If it has an {@code instanceCreate} attribute, that is used, else
 * {@code instanceClass}, and finally the class implied by the filename.
 * @param file any file
 * @return a methodvalue or newvalue attribute, or null
 * @see #findAndModifyDeclaration
 */
public @CheckForNull Object instanceAttribute(FileObject file) {
    if (!file.isData() || !file.hasExt("instance")) {
        return null; // not supporting *.settings etc. for now
    }
    Object instanceCreate = file.getAttribute("literal:instanceCreate");
    if (instanceCreate != null) {
        return instanceCreate;
    }
    Object clazz = file.getAttribute("instanceClass");
    if (clazz != null) {
        return "new:" + clazz;
    }
    return "new:" + file.getName().replace('-', '.');
}
 
Example 10
Project: incubator-netbeans   File: OpenLayerFilesAction.java   Source Code and License Vote up 5 votes
private void openLayersForFile(FileObject f) {
    URL[] location = (URL[]) f.getAttribute("layers"); // NOI18N
    if (location != null) {
        for (URL u : location) {
            FileObject layer = URLMapper.findFileObject(u);
            if (layer != null) {
                try {
                    openLayerFileAndFind(DataObject.find(layer), f);
                } catch (DataObjectNotFoundException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}
 
Example 11
Project: incubator-netbeans   File: ContextActionInjectTest.java   Source Code and License Vote up 5 votes
public void testMultiContextActionLookup() throws Exception {
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testInjectContextLookup.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is context aware action", obj instanceof ContextAwareAction);
    ContextAwareAction a = (ContextAwareAction)obj;

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(10);
    ic.add(3L);

    assertEquals("Number lover!", clone.getValue(Action.NAME));
    clone.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Global Action not called", 13, LookupContext.cnt);

    ic.remove(10);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Adds 3", 16, LookupContext.cnt);

    ic.remove(3L);
    assertFalse("It is disabled", clone.isEnabled());
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("No change", 16, LookupContext.cnt);
}
 
Example 12
Project: incubator-netbeans   File: ParsingErrorsFilter.java   Source Code and License Vote up 5 votes
/**
 * Checks if the parsing errors are filtered for this file or any of its
 * parent folders.
 *
 * @param file
 * @return
 */
private static SetFilterAction getDisableFilterAction(@NonNull FileObject file) {
    FileObject source = file;
    for (; file != null && FileOwnerQuery.getOwner(file) != null; file = file.getParent()) {
        if (file.getAttribute(DISABLE_ERROR_CHECKS_KEY) != null) {
            return new SetFileFilterAction(source, file, false);
        }
    }
    return null;
}
 
Example 13
Project: incubator-netbeans   File: NbEditorKit.java   Source Code and License Vote up 5 votes
private static String getLocalizedName(FileObject f) {
    Object displayName = f.getAttribute("displayName"); //NOI18N
    if (displayName instanceof String) {
        return (String) displayName;
    } else {
        try {
            return f.getFileSystem().getDecorator().annotateName(
                f.getNameExt(),
                Collections.singleton(f));
        } catch (FileStateInvalidException e) {
            return f.getNameExt();
        }
    }
}
 
Example 14
Project: incubator-netbeans   File: SearchBar.java   Source Code and License Vote up 5 votes
public static String getCurrentKeyMapProfile() {
    String currentKeyMapProfile = null;
    FileObject fo = FileUtil.getConfigFile(KEYMAPS_FOLDER);
    if (fo != null) {
        Object o = fo.getAttribute(FATTR_CURRENT_KEYMAP_PROFILE);
        if (o instanceof String) {
            currentKeyMapProfile = (String) o;
        }
    }
    if (currentKeyMapProfile == null) {
        currentKeyMapProfile = DEFAULT_PROFILE;
    }
    return currentKeyMapProfile;
}
 
Example 15
Project: incubator-netbeans   File: EditorActionUtilities.java   Source Code and License Vote up 5 votes
/**
 * Get single-key accelerator for a given declared action.
 * Only a single-key accelerators are supported.
 */
public static KeyStroke getAccelerator(FileObject fo) {
    if (fo == null) {
        throw new IllegalArgumentException("Must be called with non-null fileObject"); // NOI18N
    }
    boolean fineLoggable = LOG.isLoggable(Level.FINE);
    String path = fo.getParent().getPath();
    String actionName = (String) fo.getAttribute(Action.NAME);
    KeyStroke ks = null;
    if (path.startsWith("Editors/")) {
        path = path.substring(7); // Leave ending '/' to support "Editors/Actions"
        if (path.endsWith("/Actions")) {
            path = path.substring(0, path.length() - 8);
            if (path.startsWith("/")) {
                path = path.substring(1);
            }
            String mimeType = path;
            if (!MimePath.validate(mimeType)) {
                LOG.info("Invalid mime-type='" + mimeType + "' of action's fileObject=" + fo); // NOI18N
            }
            ks = getAccelerator(mimeType, actionName);
        } else if (fineLoggable) {
            LOG.fine("No \"/Actions\" at end of mime-type='" + path +
                "' of action's fileObject=" + fo); // NOI18N
        }
    } else if (fineLoggable) {
        LOG.fine("No \"Editors/\" at begining of mime-type='" + path + // NOI18N
                "' of action's fileObject=" + fo); // NOI18N
    }

    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("Accelerator for action \"" + actionName + "\" is " + ks);
    }
    return ks;
}
 
Example 16
Project: incubator-netbeans   File: GeneralActionTest.java   Source Code and License Vote up 5 votes
private Action readAction(String fileName) throws Exception {
    FileObject fo = this.folder.getFileObject(fileName);
    assertNotNull("file " + fileName, fo);
    
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("File object has not null instanceCreate attribute", obj);
    
    if (!(obj instanceof Action)) {
        fail("Object needs to be action: " + obj);
    }
    
    return (Action)obj;
}
 
Example 17
Project: incubator-netbeans   File: CategoryNode.java   Source Code and License Vote up 5 votes
@Override
public String getDisplayName() {

    String retValue = null;
    DataFolder folder = (DataFolder)getCookie( DataFolder.class );
    if( null != folder ) {
        FileObject fob = folder.getPrimaryFile();
        Object catName = fob.getAttribute( CAT_NAME );
        if (catName instanceof String)
            retValue = catName.toString();
    } 
    if( null == retValue ) {
        retValue = super.getDisplayName();
    }
    // XXX poor impl; should not depend on org.openide.loaders.Bundle#FMT_shadowName:
    if( null != retValue && retValue.indexOf("\u2192") > 0 ) {
        DataShadow shadow = (DataShadow)getCookie( DataShadow.class );
        if( null != shadow ) {
            DataObject dobj = shadow.getOriginal();
            if( null != dobj ) {
                Node origNode = dobj.getNodeDelegate();
                if( null != origNode && null != origNode.getDisplayName() ) {
                    retValue = origNode.getDisplayName();
                }
            }
        }
    }
    return retValue;
}
 
Example 18
Project: incubator-netbeans   File: ConvertorResolver.java   Source Code and License Vote up 4 votes
/** extract convertor from file attributes */
private Convertor getConvertor(FileObject fo) {
    Object attrb = fo.getAttribute(org.netbeans.modules.settings.Env.EA_CONVERTOR);
    return (attrb == null || !(attrb instanceof Convertor))? null: (Convertor) attrb;
}
 
Example 19
Project: incubator-netbeans   File: ValidateLayerConsistencyTest.java   Source Code and License Vote up 4 votes
public void testInstantiateAllInstances () {
    List<String> errors = new ArrayList<String>();
    
    Enumeration<? extends FileObject> files = FileUtil.getConfigRoot().getChildren(true);
    while (files.hasMoreElements()) {
        FileObject fo = files.nextElement();
        
        if (skipFile(fo)) {
            continue;
        }
        
        try {
            DataObject obj = DataObject.find (fo);
            InstanceCookie ic = obj.getLookup().lookup(InstanceCookie.class);
            if (ic != null) {
                Object o = ic.instanceCreate ();
                if (fo.getPath().matches("Services/.+[.]instance")) {
                    String instanceOf = (String) fo.getAttribute("instanceOf");
                    if (instanceOf == null) {
                        errors.add("File " + fo.getPath() + " should declare instanceOf");
                    } else if (o != null) {
                        for (String piece : instanceOf.split(", ?")) {
                            if (!Class.forName(piece, true, Lookup.getDefault().lookup(ClassLoader.class)).isInstance(o)) {
                                errors.add("File " + fo.getPath() + " claims to be a " + piece + " but is not (instance of " + o.getClass() + ")");
                            }
                        }
                    }
                } else if (fo.getPath().matches("Services/.+[.]settings")) {
                    if (!fo.asText().contains("<instanceof")) {
                        errors.add("File " + fo.getPath() + " should declare <instanceof class=\"...\"/>");
                    }
                    // XXX test assignability here too, perhaps (but only used in legacy code)
                }
            }
        } catch (Exception ex) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(baos);
            ex.printStackTrace(ps);
            ps.flush();
            errors.add(
                "File " + fo.getPath() +
                "\nRead from: " + Arrays.toString((Object[])fo.getAttribute("layers")) +
                "\nthrew: " + baos);
        }
    }
    
    assertNoErrors("Some instances cannot be created", errors);
}
 
Example 20
Project: incubator-netbeans   File: OQLQueryRepository.java   Source Code and License Vote up 4 votes
@NonNull
private String getDisplayName(@NonNull FileObject fo) {
    String dName = (String)fo.getAttribute("displayName"); // NOI18N
    return dName != null ? dName : fo.getName();
}