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

The following examples show how to use org.openide.filesystems.FileObject#getAttribute() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Messages({
    "# {0} - file attribute name", "DataObjectHinter_unrecognized_attr=Unrecognized DataObject attribute: {0}",
    "DataObjectRegistrationHinter.use.displayName=Please convert to displayName to be able to use Loader hinter"
})
private boolean checkAttributes(FileObject file, Context ctx) {
    boolean attributesCompatible = true;
    for (String attr : NbCollections.iterable(file.getAttributes())) {
        if (!attr.matches("mimeType|position|displayName|iconBase|dataObjectClass|instanceCreate|SystemFileSystem.localizingBundle")) {
            ctx.addHint(Severity.WARNING, DataObjectHinter_unrecognized_attr(attr));
            attributesCompatible = false;
        }
    }
    if (file.getAttribute("literal:SystemFileSystem.localizingBundle") != null) {
        attributesCompatible = false;
        ctx.addHint(Severity.HINT, DataObjectRegistrationHinter_use_displayName());
    }
    return attributesCompatible;
}
 
Example 2
Source Project: netbeans   File: JspServletDataLoader.java    License: Apache License 2.0 6 votes vote down vote up
/** For a given file finds a primary file.
* @param fo the file to find primary file for
* @return the primary file for the file or null if the file is not
*   recognized by this loader
*/
protected FileObject findPrimaryFile (FileObject fo) {
    // detects  *_jsp*.java
    FileObject javaPrim;
    // never recognize folders.
    if (fo.isFolder())
        javaPrim = null;
    else if (fo.getExt().equals(JAVA_EXTENSION))
        javaPrim = fo;
    else
        javaPrim = null;
    
    if (javaPrim == null)
        return null;
    
    // if there is a source JSP set then this is generated from a JSP
    if (javaPrim.getAttribute(JspServletDataObject.EA_ORIGIN_JSP_PAGE) != null) {
        return javaPrim;
    }

    // PENDING: old way of recognition was by name, need to remove this later
    //if (javaPrim.getName().lastIndexOf(JSP_MARK) != -1)
    //    return javaPrim;
        
    return null;
}
 
Example 3
Source Project: netbeans   File: InterceptorTest.java    License: Apache License 2.0 6 votes vote down vote up
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 4
public static WWLayerDescriptor createWWLayerDescriptor(final FileObject fileObject) {
    final String id = fileObject.getName();
    final String showInWorldMapToolView = (String) fileObject.getAttribute("showInWorldMapToolView");
    final String showIn3DToolView = (String) fileObject.getAttribute("showIn3DToolView");
    final Class<? extends WWLayer> WWLayerClass = getClassAttribute(fileObject, "WWLayerClass", WWLayer.class, false);

    Assert.argument(showInWorldMapToolView != null &&
                            (showInWorldMapToolView.equalsIgnoreCase("true") || showInWorldMapToolView.equalsIgnoreCase("false")),
                    "Missing attribute 'showInWorldMapToolView'");
    Assert.argument(showIn3DToolView != null &&
                            (showIn3DToolView.equalsIgnoreCase("true") || showIn3DToolView.equalsIgnoreCase("false")),
                    "Missing attribute 'showIn3DToolView'");
    Assert.argument(WWLayerClass != null, "Attribute 'class' must be provided");

    return new DefaultWWLayerDescriptor(id, Boolean.parseBoolean(showInWorldMapToolView),
                                        Boolean.parseBoolean(showIn3DToolView), WWLayerClass);
}
 
Example 5
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 6
Source Project: netbeans   File: ConvertorResolver.java    License: Apache License 2.0 5 votes vote down vote up
String getPublicID(Class clazz) {
    try {
        FileObject fo = org.netbeans.modules.settings.Env.findProvider(clazz);
        if (fo == null) {
            fo = org.netbeans.modules.settings.Env.findProvider(Object.class);
        }
        
        fo = org.netbeans.modules.settings.Env.findEntityRegistration(fo);
        Object attrib = fo.getAttribute(org.netbeans.modules.settings.Env.EA_PUBLICID);
        return (attrib == null || !(attrib instanceof String))? null: (String) attrib;
    } catch (IOException ex) {
        Logger.getLogger(ConvertorResolver.class.getName()).log(Level.WARNING, null, ex);
        return null;
    }
}
 
Example 7
Source Project: netbeans   File: LayersBridge.java    License: Apache License 2.0 5 votes vote down vote up
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 8
Source Project: netbeans   File: WebExecSupport.java    License: Apache License 2.0 5 votes vote down vote up
public static String getQueryString(FileObject fo) {
    try {
        String qStr = (String)fo.getAttribute (EA_REQPARAMS);
        if (qStr != null) {
            if ((qStr.length() > 0) && (!qStr.startsWith("?"))) // NOI18N
                qStr = "?" + qStr; // NOI18N
            return qStr;
        }
    } catch (Exception ex) {
        LOG.log(Level.FINE, "error", ex);
    }
    return ""; // NOI18N
}
 
Example 9
Source Project: netbeans   File: ColorsManager.java    License: Apache License 2.0 5 votes vote down vote up
private static String getBundleName(Language l) {
    FileSystem fs = Repository.getDefault().getDefaultFileSystem();
    FileObject root = fs.findResource("Editors/" + l.getMimeType()); // NOI18N
    Object attrValue = root.getAttribute("SystemFileSystem.localizingBundle"); //NOI18N
    // [PENDING] if (bundleName == null) ... check for bundle name in nbs file
    return (String) attrValue;
}
 
Example 10
Source Project: netbeans   File: PropertiesTokenList.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setStartOffset(int offset) {
    super.setStartOffset (offset);
    FileObject fileObject = FileUtil.getConfigFile ("Spellcheckers/Properties");
    Boolean b = (Boolean) fileObject.getAttribute ("Hidden");
    hidden = Boolean.TRUE.equals (b);
}
 
Example 11
Source Project: netbeans   File: OpenProjectList.java    License: Apache License 2.0 5 votes vote down vote up
static boolean isRecommended(@NullAllowed Project project, @NonNull String[] recommendedTypes, @NonNull FileObject primaryFile) {
    if (project != null) {
        return isRecommended(recommendedTypes, primaryFile);
    }

    if (primaryFile.isFolder()) {
        // folders of templates do not require a project for display
        return true;
    }

    Object requireProject = primaryFile.getAttribute("requireProject");
    return Boolean.FALSE.equals(requireProject);
}
 
Example 12
Source Project: netbeans   File: EditorTestLookup.java    License: Apache License 2.0 5 votes vote down vote up
public String annotateName (String name, java.util.Set files) {
            for(Object o : files) {
                FileObject fo = (FileObject) o;
                String bundleName = (String)fo.getAttribute ("SystemFileSystem.localizingBundle"); // NOI18N
                if (bundleName != null) {
                    bundleName = org.openide.util.Utilities.translate(bundleName);
//                    System.out.println("~~~ looking up annotateName for '" + fo.getPath() + "', localizingBundle='" + bundleName + "'");
                    
                    try {
                        ResourceBundle b = NbBundle.getBundle(bundleName);
                        return b.getString (fo.getPath());
                    } catch (MissingResourceException ex) {
                        // ignore--normal

//                        System.out.println("~~~ No annotateName for '" + fo.getPath() + "', localizingBundle='" + bundleName + "'");
//                        ex.printStackTrace();
//
//                        ClassLoader c = Lookup.getDefault().lookup(ClassLoader.class);
//                        if (c == null) {
//                            c = ClassLoader.getSystemClassLoader();
//                        }
//                        try {
//                            String s = bundleName.replace('.', '/') + ".properties";
//                            URL r = c.getResource(s);
//                            System.out.println("~~~ '" + s + "' -> " + r);
//
//                            Enumeration<URL> e = c.getResources(s);
//                            while (e.hasMoreElements()) {
//                                URL url = e.nextElement();
//                                System.out.println("  -> " + url);
//                            }
//                        } catch (IOException ioe) {
//                            ioe.printStackTrace();
//                        }
                    }
                }
            }

            return name;
        }
 
Example 13
Source Project: netbeans   File: SetExecutionUriAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected boolean enable (Node[] activatedNodes) {
    if ((activatedNodes != null) && (activatedNodes.length == 1)) {
        if (activatedNodes[0] != null) {
            DataObject data = (DataObject)activatedNodes[0].getLookup().lookup(DataObject.class);
            if (data != null) {
                FileObject javaClass = data.getPrimaryFile();
                WebModule webModule = WebModule.getWebModule(javaClass);
                if ( servletFilesScanning( webModule, javaClass ) ){
                    return false;
                }
                String mimetype = javaClass.getMIMEType();
                if ( !"text/x-java".equals(mimetype) ){     // NOI18N
                    return false;
                }
                Boolean servletAttr = (Boolean)javaClass.getAttribute(IS_SERVLET_FILE);
                if (!Boolean.TRUE.equals(servletAttr)) {
                    boolean isServletFile = isServletFile(webModule, 
                            javaClass, false );
                    if (isServletFile) {
                        try {
                            javaClass.setAttribute(IS_SERVLET_FILE, Boolean.TRUE); 
                        } catch (java.io.IOException ex) {
                            //we tried
                        }
                    }
                    servletAttr = Boolean.valueOf(isServletFile);
                }
                return Boolean.TRUE.equals(servletAttr);
            }
        }
    }
    return false;
}
 
Example 14
public void testCommentIsFirst() throws Exception {
    String HEADER =
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<!--\n" +
            "text\n" +
            "-->\n" +
            "<!DOCTYPE filesystem PUBLIC \"-//NetBeans//DTD Filesystem 1.1//EN\" \"http://www.netbeans.org/dtds/filesystem-1_1.dtd\">\n" +
            "<filesystem>\n";
    String FOOTER =
            "</filesystem>\n";

    Layer l = new Layer(
        HEADER +
        "    <file name=\"x\">\n" +
        "    </file>\n" +
        FOOTER,
        false
    );
    FileSystem fs = l.read();
    FileObject x = fs.findResource("x");
    assertNotNull("File x found", x);
    x.setAttribute("bv", "bundlevalue:org.netbeans.modules.apisupport.project.layers#AHOJ");
    assertEquals("special attrs written to XML",
            "    <file name=\"x\">\n" +
            "        <attr name=\"bv\" bundlevalue=\"org.netbeans.modules.apisupport.project.layers#AHOJ\"/>\n" +
            "    </file>\n",
            l.write(HEADER, FOOTER));

    Object lit = x.getAttribute("literal:bv");
    assertEquals("Literal value is returned prefixed with bundle", "bundle:org.netbeans.modules.apisupport.project.layers#AHOJ", lit);

    Object value = x.getAttribute("bv");
    // not working, localized attrs implemented only in merged layer FS, see BadgingSupport:
    //assertEquals("value is returned localized", "Hello", value);
    // currently returns null:
    assertNull("Current behaviour. Improve. XXX", value);

    String  txt = l.f.asText("UTF-8");
    if (txt.indexOf("-//NetBeans//DTD Filesystem 1.2//EN") == -1) {
        fail("Wrong DTD: " + txt);
    }

    if (txt.indexOf("http://www.netbeans.org/dtds/filesystem-1_2.dtd") == -1) {
        fail("Wrong DTD2: " + txt);
    }
}
 
Example 15
Source Project: netbeans   File: BinaryUsagesTest.java    License: Apache License 2.0 4 votes vote down vote up
private static File findFileInRepository(FileObject fo) {
    File f = (File) fo.getAttribute("java.io.File"); // NOI18N

    return (f != null) ? FileUtil.normalizeFile(f) : null;
}
 
Example 16
Source Project: netbeans   File: CompilationUnitTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected boolean accept(FileObject orig) {
    return orig.getAttribute("verbatim-create-from-template") != null;
}
 
Example 17
private String getDescription(FileObject fo) {
    return (String)fo.getAttribute("desc"); // NOI18N
}
 
Example 18
Source Project: netbeans   File: OQLQueryRepository.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
private String getDisplayName(@NonNull FileObject fo) {
    String dName = (String)fo.getAttribute("displayName"); // NOI18N
    return dName != null ? dName : fo.getName();
}
 
Example 19
Source Project: netbeans   File: ValidateNbinstTest.java    License: Apache License 2.0 4 votes vote down vote up
private void implNbinstHost(TestHandler handler) throws ParserConfigurationException, IOException, IllegalArgumentException, SAXException {
        FileObject libs = FileUtil.getConfigFile("org-netbeans-api-project-libraries/Libraries");                
        if (libs != null) {
            final List<FileObject> schemas = new ArrayList<FileObject>(3);
            schemas.add(null);
            final FileObject schema2 = FileUtil.getConfigFile("ProjectXMLCatalog/library-declaration/2.xsd");
            if (schema2 != null) {
                schemas.add(schema2);
            }
            final FileObject schema3 = FileUtil.getConfigFile("ProjectXMLCatalog/library-declaration/3.xsd");
            if (schema3 != null) {
                schemas.add(schema3);
            }
next:       for (FileObject lib : libs.getChildren()) {
                SAXException lastException = null;
                for (FileObject schema : schemas) {
                    lastException = null;
                    try {
                        final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                        docBuilderFactory.setValidating(true);
                        if (schema != null) {
                            docBuilderFactory.setNamespaceAware(true);
                            docBuilderFactory.setAttribute(
                                "http://java.sun.com/xml/jaxp/properties/schemaLanguage",   //NOI18N
                                "http://www.w3.org/2001/XMLSchema");                        //NOI18N
                            docBuilderFactory.setAttribute(
                                "http://java.sun.com/xml/jaxp/properties/schemaSource",     //NOI18N
                                schema.toURI().toString());
                        }
                        final DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
                        builder.setErrorHandler(XMLUtil.defaultErrorHandler());
                        builder.setEntityResolver(EntityCatalog.getDefault());
                        Document doc = builder.parse(new InputSource(lib.toURL().toString()));
                        NodeList nl = doc.getElementsByTagName("resource");
                        for (int i = 0; i < nl.getLength(); i++) {
                            Element resource = (Element) nl.item(i);
                            validateNbinstURL(new URL(XMLUtil.findText(resource)), handler, lib);
                        }
                        continue next;
                    } catch (SAXException e) {
                        lastException = e;
                    }
                }
                throw lastException;
            }
        }
        for (FileObject f : NbCollections.iterable(FileUtil.getConfigRoot().getChildren(true))) {
            for (String attr : NbCollections.iterable(f.getAttributes())) {
                if (attr.equals("instanceCreate")) {
                    continue; // e.g. on Services/Hidden/org-netbeans-lib-jakarta_oro-antlibrary.instance prints stack trace
                }
                Object val = f.getAttribute(attr);
                if (val instanceof URL) {
                    validateNbinstURL((URL) val, handler, f);
                }
            }
        }
        assertNoErrors("No improper nbinst URLs", handler.errors());
    }
 
Example 20
Source Project: netbeans   File: Source.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Find an existing Source instance for the given FileObject.
 * Currently, this method returns sources only for non-file sources.
 * @param fo
 * @return a Source, or <code>null</code>.
 *
public static Source get(JPDADebugger debugger, FileObject fo) {
    URI uri = fo.toURI();
    if (!URL_PROTOCOL.equals(uri.getScheme())) {
        return null;
    }
    String path = uri.getPath();
    int hashEnd = path.indexOf('/');
    String hashStr = path.substring(0, hashEnd);
    long id = Long.parseUnsignedLong(hashStr, 16);
    return getExistingSource(debugger, id);
}*/

public static URI getTruffleInternalURI(FileObject fo) {
    return (URI) fo.getAttribute(ATTR_URI);
}