当前位置: 首页>>代码示例>>Java>>正文


Java FileObject.setAttribute方法代码示例

本文整理汇总了Java中org.openide.filesystems.FileObject.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.setAttribute方法的具体用法?Java FileObject.setAttribute怎么用?Java FileObject.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.filesystems.FileObject的用法示例。


在下文中一共展示了FileObject.setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateFromTemplateUsingFreemarker

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testCreateFromTemplateUsingFreemarker() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    String txt = "<html><h1>${title}</h1></html>";
    os.write(txt.getBytes());
    os.close();
    fo.setAttribute("javax.script.ScriptEngine", "freemarker");
    
    
    DataObject obj = DataObject.find(fo);
    
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
    
    Map<String,String> parameters = Collections.singletonMap("title", "Nazdar");
    DataObject n = obj.createFromTemplate(folder, "complex", parameters);
    
    assertEquals("Created in right place", folder, n.getFolder());
    assertEquals("Created with right name", "complex.txt", n.getName());
    
    String exp = ">lmth/<>1h/<radzaN>1h<>lmth<";
    assertEquals(exp, readFile(n.getPrimaryFile()));
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:IndentEngineIntTest.java

示例2: testCreateFromTemplateEncodingProperty

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testCreateFromTemplateEncodingProperty() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    os.write("${encoding}".getBytes());
    os.close();
    assertEquals("content/unknown", fo.getMIMEType());
    fo.setAttribute ("template", Boolean.TRUE);
    assertEquals("content/unknown", fo.getMIMEType());
    fo.setAttribute("javax.script.ScriptEngine", "freemarker");
    assertEquals("text/x-freemarker", fo.getMIMEType());
    
    DataObject obj = DataObject.find(fo);
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
    
    Map<String,String> parameters = Collections.emptyMap();
    DataObject inst = obj.createFromTemplate(folder, "complex", parameters);
    FileObject instFO = inst.getPrimaryFile();
    
    Charset targetEnc = FileEncodingQuery.getEncoding(instFO);
    assertNotNull("Template encoding is null", targetEnc);
    assertEquals("Encoding in template doesn't match", targetEnc.name(), instFO.asText());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ScriptingCreateFromTemplateTest.java

示例3: testFilesHiddenByAttribute

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testFilesHiddenByAttribute() throws Exception {
    String fileName1 = "file-on-layer-A.instance";
    String fileName2 = "file-on-layer-B.instance";
    TestUtilities.createFile(getWorkDir(), "Tmp/A/B/C/D/" + fileName1);
    TestUtilities.createFile(getWorkDir(), "Tmp/A/B/" + fileName2);
    TestUtilities.createFile(getWorkDir(), "Tmp/A/" + fileName2);

    // Check precondition
    FileObject f = FileUtil.getConfigFile("Tmp/A/B/" + fileName2);
    assertNotNull("The hidden file on the second layer does not exist", f);

    // Mark the file as hidden, which should hide both this file and
    // the same one on the third layer.
    f.setAttribute("hidden", Boolean.TRUE);
    
    f = FileUtil.getConfigFile("Tmp/A/" + fileName2);
    assertNotNull("The original file on the third layer that should be hidden does not exist", f);
    
    // Test compound children
    CompoundFolderChildren cfch = new CompoundFolderChildren(new String [] { "Tmp/A/B/C/D", "Tmp/A/B", "Tmp/A" }, false);
    List files = cfch.getChildren();
    
    assertEquals("Wrong number of files", 1, files.size());
    assertEquals("Wrong layerA file", fileName1, ((FileObject) files.get(0)).getNameExt());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CompoundFolderChildrenTest.java

示例4: testNoTemplateFlagUnset

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testNoTemplateFlagUnset() throws Exception {
    String folderName = "/Templates/";
    FileObject data = org.openide.filesystems.FileUtil.createData (
        FileUtil.getConfigRoot(), 
        folderName + "/" + "X.prima"
    );
    data.setAttribute ("template", Boolean.TRUE);
    FileObject fo = data.getParent ();
    assertNotNull ("FileObject " + folderName + " found on DefaultFileSystem.", fo);
    DataFolder f = DataFolder.findFolder (fo);
    DataObject templ = DataObject.find(data);
    
    DataObject res = templ.createFromTemplate(f);
    
    assertFalse("Not marked as template", res.isTemplate());
    assertEquals(SimpleLoader.class, res.getLoader().getClass());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CreateFromTemplateTest.java

示例5: testCreateForcePlain

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Forces plain default processing, although the template contains replaceable parts
 */
public void testCreateForcePlain() throws Exception {
    FileObject dataRoot = FileUtil.toFileObject(getDataDir());
    FileObject template = dataRoot.getFileObject("templates/SimpleReplacements.java");
    template.setAttribute("template", Boolean.TRUE);
    FileObject workRoot = FileUtil.toFileObject(getWorkDir());
    Map m = new HashMap();
    m.put("USER", "foobar");
    FileObject result = FileBuilder.createFromTemplate(template, workRoot, "NoReplacements", m, FileBuilder.Mode.COPY);
    FileObject pass = dataRoot.getFileObject("golden/ForceNoReplacements.java");
    assertFile(FileUtil.toFile(result), FileUtil.toFile(pass));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:TemplateUtilsTest.java

示例6: testGetActions

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testGetActions() throws Exception {
    RootNode rn = RootNode.getInstance();
    FileObject fo = FileUtil.getConfigFile("Servers/Actions");
    assertNotNull("Folder for actions precreated", fo);
    FileObject x = fo.createData(MyAction.class.getName().replace('.', '-') + ".instance");
    x.setAttribute("position", 37);
    Action[] arr = rn.getActions(true);
    assertEquals("Two actions and one separator found: " + Arrays.asList(arr), 3, arr.length);
    assertEquals("Last one is separator", null, arr[2]);
    MyAction a = MyAction.get(MyAction.class);

    if (a != arr[0] && a != arr[1]) {
        fail("My action shall be present in the node context actions: " + arr[0] + " 2nd: " + arr[1]);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:RootNodeTest.java

示例7: testCreateUpdateProviderWithOwnIcon

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testCreateUpdateProviderWithOwnIcon() throws Exception {
    FileObject f = FileUtil.getConfigRoot().createData("whatever.instance");
    f.setAttribute("url", "file:/wherever.xml");
    f.setAttribute("displayName", "Whatever");
    f.setAttribute("category", "Jarda's Updates");
    f.setAttribute("iconBase", "org/netbeans/modules/autoupdate/services/resources/icon-standard.png");
    UpdateProvider up = AutoupdateCatalogFactory.createUpdateProvider(f);
    UpdateUnitProvider uup = Trampoline.API.createUpdateUnitProvider (new UpdateUnitProviderImpl (up));
    assertEquals("whatever", uup.getName());
    assertEquals("Whatever", uup.getDisplayName());
    assertEquals(new URL("file:/wherever.xml"), uup.getProviderURL());
    Image img = ImageUtilities.loadImage("org/netbeans/modules/autoupdate/services/resources/icon-standard.png");
    assertEquals("Icons are the same", img, uup.getSourceIcon());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:AutoupdateCatalogFactoryTest.java

示例8: testBasePropertiesAlwaysPresent

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testBasePropertiesAlwaysPresent() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    String txt = "print('<html><h1>'); print(name); print('</h1>');" +
        "print('<h2>'); print(date); print('</h2>');" +
        "print('<h3>'); print(time); print('</h3>');" +
        "print('<h4>'); print(user); print('</h4>');" +
        "print('<h4>'); print(dateTime.getTime()); print('</h4>');" +
        "print('</html>');";
    os.write(txt.getBytes());
    os.close();
    fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");
    
    
    DataObject obj = DataObject.find(fo);
    
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
    
    Map<String,String> parameters = Collections.singletonMap("title", "Nazdar");
    DataObject n = obj.createFromTemplate(folder, "complex", parameters);
    
    assertEquals("Created in right place", folder, n.getFolder());
    assertEquals("Created with right name", "complex.txt", n.getName());
    
    String res = readFile(n.getPrimaryFile());
    
    if (res.indexOf("date") >= 0) fail(res);
    if (res.indexOf("time") >= 0) fail(res);
    if (res.indexOf("user") >= 0) fail(res);
    if (res.indexOf("name") >= 0) fail(res);
    if (res.indexOf("dateTime") >= 0) fail(res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:SCFTHandlerTest.java

示例9: rebind

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void rebind(Name name, Object obj) throws NamingException {
    String attrName = getRelativeName(name);
    FileObject fo = dobj.getPrimaryFile();
    
    try {
        fo.setAttribute(attrName, obj);
    } catch (IOException ex) {
        NamingException ne = new NamingException(name + " = " + obj); // NOI18N
        ne.setRootCause(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:DefaultSettingsContext.java

示例10: registerWizardProvider

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public static void registerWizardProvider(String instanceName, ServerWizardProvider provider) throws IOException {
    if (provider == null) {
        return;
    }

    Lookup.getDefault().lookup(ModuleInfo.class);

    FileObject servers = FileUtil.getConfigFile(ServerRegistry.SERVERS_PATH);
    FileObject testProvider = FileUtil.createData(servers, instanceName);

    testProvider.setAttribute("instanceOf", ServerWizardProvider.class.getName()); // NOI18N
    testProvider.setAttribute("instanceCreate", provider); // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:MockWizardProvider.java

示例11: performAction

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
protected @Override void performAction(Node[] activatedNodes) {
    NotifyDescriptor.InputLine d = new NotifyDescriptor.InputLine(
            NbBundle.getMessage(PickNameAction.class, "PickNameAction_dialog_label"),
            NbBundle.getMessage(PickNameAction.class, "PickNameAction_dialog_title"));
    if (DialogDisplayer.getDefault().notify(d) != NotifyDescriptor.OK_OPTION) {
        return;
    }
    String name = d.getInputText();
    FileObject f = findFile(activatedNodes);
    if (f == null) {
        return;
    }
    NbModuleProvider p = findProject(f);
    if (p == null) {
        return;
    }
    String bundlePath = findBundlePath(p);
    if (bundlePath == null) {
        return;
    }
    try {
        FileObject properties = p.getSourceDirectory().getFileObject(bundlePath);
        EditableProperties ep = Util.loadProperties(properties);
        final String key = LayerUtil.generateBundleKeyForFile(f.getPath());
        ep.setProperty(key, name);
        Util.storeProperties(properties, ep);
        f.setAttribute("displayName", "bundlevalue:"
                + bundlePath.substring(0, bundlePath.length() - ".properties".length())   // NOI18N
                .replace('/', '.')  // NOI18N
                + "#" + key); // NOI18N
    } catch (IOException e) {
        Util.err.notify(ErrorManager.INFORMATIONAL, e);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:PickNameAction.java

示例12: generateTenActions

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void generateTenActions() throws IOException {
    FileObject fo = df.getPrimaryFile().createFolder("1Menu");
    for (int i = 0; i < 10; i++) {
        FileObject item = fo.createData("item-" + i + ".instance");
        item.setAttribute("instanceCreate", new JMenuItem("" + i));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:MenuBarTest.java

示例13: run

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void run(FileSystem layer) throws IOException {
    FileObject folder = layer.getRoot().getFileObject("Actions/Window");// NOI18N
    if (folder == null) {
        folder = FileUtil.createFolder(layer.getRoot(), "Actions/Window"); // NOI18N
    }
    String instance = packageName.replace('.','-') + "-" + name; // NOI18N
    FileObject file = folder.createData(instance, "instance"); // NOI18N
    folder = layer.getRoot().getFileObject("Menu/Window");// NOI18N
    if (folder == null) {
        folder = FileUtil.createFolder(layer.getRoot(), "Menu/Window"); // NOI18N
    }
    file = folder.createData(name, "shadow"); // NOI18N
    file.setAttribute("originalFile", "Actions/Window/" + instance + ".instance"); // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:LayoutIterator.java

示例14: doTest

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private void doTest(boolean delete) throws Exception {
    clearWorkDir();
    
    File nf = new File(getWorkDir(), "ud");
    File var = new File(nf, "var");
    System.setProperty("netbeans.user", nf.getPath());
    
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject data = FileUtil.createData(fs.getRoot(), "My/Fld/data.txt");
    data.setAttribute("hello", "world");
    
    File root = new File(getWorkDir(), "fs");
    root.mkdirs();
    ExLocalFileSystem fs2 = ExLocalFileSystem.getInstance(root);
    
    MultiFileSystem mfs = new MultiFileSystem(new FileSystem[] { fs2, fs });
    
    FileObject ndata = mfs.findResource(data.getPath());
    assertNotNull("data found", ndata);
    assertEquals("They have the right attribute", "world", ndata.getAttribute("hello"));
 
    ndata.setAttribute("hello", "kuk");
    assertEquals("New attribute value is there", "kuk", ndata.getAttribute("hello"));

    ndata.setAttribute("hello", "buk");
    assertEquals("Newer attribute value is there", "buk", ndata.getAttribute("hello"));
    
    if (delete && var.exists() && !var.delete()) {
        for (File file : var.listFiles()) {
            file.delete();
        }
        assertTrue("Can delete " + var, var.delete());
    }

    ndata.setAttribute("hello", "muk");
    assertEquals("Newest attribute value is there", "muk", ndata.getAttribute("hello"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:ExLocalFileSystemTest.java

示例15: bind

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void bind(Name name, Object obj) throws NamingException {
    String attrName = getRelativeName(name);
    FileObject fo = dobj.getPrimaryFile();
    Object attrVal = fo.getAttribute(attrName);
    if (attrVal != null) {
        throw new NameAlreadyBoundException(attrName + " = " + attrVal); // NOI18N
    }
    
    try {
        fo.setAttribute(attrName, obj);
    } catch (IOException ex) {
        NamingException ne = new NamingException(attrName + " = " + obj); // NOI18N
        ne.setRootCause(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:DefaultSettingsContext.java


注:本文中的org.openide.filesystems.FileObject.setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。