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

The following examples show how to use org.openide.filesystems.FileObject#setAttribute() . 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 check out the related API usage on the sidebar.
Example 1
/**
 * Adds an action references into the folder given by {@code path} of the SNAP Desktop / NetBeans file system at the given {@code position}.
 * The following are standard folders in SNAP Desktop/NetBeans where actions and action references may be placed to
 * become visible:
 * <ol>
 * <li>{@code Menu/*} - the main menu</li>
 * <li>{@code Toolbars/*} - the main tool bar</li>
 * </ol>
 *
 * @param instanceFile The file object representing an action instance.
 * @param path         The folder path.
 * @param position     The position within the folder. May be {@code null}.
 * @return The file object representing the action reference.
 */
public synchronized static FileObject addActionReference(FileObject instanceFile, String path, Integer position) {
    Action actualAction = TransientAction.getAction(instanceFile.getPath());
    if (actualAction == null) {
        return null;
    }
    String shadowId = instanceFile.getName() + SHADOW_SUFFIX;
    FileObject configRoot = FileUtil.getConfigRoot();
    try {
        FileObject actionFile = FileUtil.createData(configRoot, path + "/" + shadowId);
        actionFile.setAttribute("originalFile", instanceFile.getPath());
        if (position != null) {
            actionFile.setAttribute("position", position);
        }
        return actionFile;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }

    return null;
}
 
Example 2
Source Project: netbeans   File: FolderObjTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testMoveWithAttributes() throws Exception {
    final FileObject workDirFo = FileBasedFileSystem.getFileObject(getWorkDir());
    FileObject target = workDirFo.createFolder("target");
    FileObject folder = workDirFo.createFolder("a");
    folder.createData("non.empty");
    folder.setAttribute("name", "jmeno");
    assertEquals("jmeno", folder.getAttribute("name"));
    FileLock lock = folder.lock();
    FileObject newF = folder.move(lock, target, "b", null);
    assertFalse("Invalidated", folder.isValid());
    lock.releaseLock();
    assertEquals("Name is not b", "b", newF.getNameExt());
    WeakReference<?> ref = new WeakReference<FileObject>(newF);
    newF = null;
    assertGC("Folder can disappear", ref);
    folder = target.getFileObject("b");
    assertNotNull("Folder b found", folder);
    assertEquals("The attribute remains even after rename", "jmeno", folder.getAttribute("name"));
    assertEquals("One children", 1, folder.getChildren().length);
}
 
Example 3
Source Project: netbeans   File: SettingsTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testCategoryVisible() throws Exception {
    FileObject cat1 = getCategoryFile( categoryNames[0] );
    FileObject cat2 = getCategoryFile( categoryNames[1] );
    FileObject cat3 = getCategoryFile( categoryNames[2] );
    
    cat2.setAttribute( PaletteController.ATTR_IS_VISIBLE, new Boolean(false) );
    cat3.setAttribute( PaletteController.ATTR_IS_VISIBLE, new Boolean(true) );
    
    PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() );
    Settings settings = pc.getSettings();
    Model model = pc.getModel();
    Category[] categories = model.getCategories();
    
    assertTrue( "Categories are visible by default", settings.isVisible( categories[0] ) );
    assertTrue( !settings.isVisible( categories[1] ) );
    assertTrue( settings.isVisible( categories[2] ) );
    
    settings.setVisible( categories[0], false );
    settings.setVisible( categories[1], true );
    settings.setVisible( categories[2], false );

    assertTrue( !settings.isVisible( categories[0] ) );
    assertTrue( settings.isVisible( categories[1] ) );
    assertTrue( !settings.isVisible( categories[2] ) );
}
 
Example 4
@Override
public void actionPerformed(ActionEvent e) {
    FileObject menuFolder = FileUtil.getConfigFile("Menu/Tools/Examples");
    try {
        FileObject itemsFolder = menuFolder.getFileObject("Generated Items");
        if (itemsFolder == null) {
            itemsFolder = menuFolder.createFolder("Generated Items");
            itemsFolder.setAttribute("position", 51);
        }
        GeneratedItemAction action = new GeneratedItemAction();
        FileObject newMenuItem = itemsFolder.createData(action.getName(), "instance");
        newMenuItem.setAttribute("instanceCreate", action);
        newMenuItem.setAttribute("instanceClass", action.getClass().getName());
    } catch (IOException e1) {
        Dialogs.showError("Error: " + e1.getMessage());
    }
}
 
Example 5
Source Project: netbeans   File: DataShadowTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks that findOriginal returns null on broken (but formally
 * correct) shadow
 * @throws Exception C
 */
public void testFindMissingOriginal() throws Exception {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject shadow = FileUtil.createData(fs.getRoot(), "link.shadow");
    shadow.setAttribute("originalFile", "path/to/orig");
    assertNull("null should be returned for missing target", DataShadow.findOriginal(shadow));
}
 
Example 6
Source Project: netbeans   File: LocatorTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testOsSpecificFiles() throws Exception {
    String currentOs = getCurrentOsId();
    String [] files = new String [] {
        "Editors/text/x-whatever/FontsColors/PPP/Defaults/f.xml",
        "Editors/text/x-whatever/FontsColors/PPP/Defaults/e.xml",
        "Editors/text/x-whatever/FontsColors/PPP/Defaults/d.xml",
        "Editors/text/x-whatever/FontsColors/PPP/Defaults/a.xml",
        "Editors/text/x-whatever/FontsColors/PPP/file4.xml",
        "Editors/text/x-whatever/FontsColors/PPP/file1.xml",
        "Editors/text/x-whatever/FontsColors/PPP/file99.xml",
    };
    
    createOrderedFiles(files, FC_CONTENTS);
    
    FileObject f = FileUtil.getConfigFile("Editors/text/x-whatever/FontsColors/PPP/Defaults/e.xml");
    f.setAttribute("nbeditor-settings-targetOS", currentOs);

    String [] osOrderedFiles = new String [] {
        "Editors/text/x-whatever/FontsColors/PPP/Defaults/f.xml",
        "Editors/text/x-whatever/FontsColors/PPP/Defaults/d.xml",
        "Editors/text/x-whatever/FontsColors/PPP/Defaults/a.xml",
        "Editors/text/x-whatever/FontsColors/PPP/Defaults/e.xml",
        "Editors/text/x-whatever/FontsColors/PPP/file4.xml",
        "Editors/text/x-whatever/FontsColors/PPP/file1.xml",
        "Editors/text/x-whatever/FontsColors/PPP/file99.xml",
    };
    
    FileObject baseFolder = FileUtil.getConfigFile("Editors");
    Map<String, List<Object []>> results = new HashMap<>();
    scan(ColoringStorage.ID, baseFolder, "text/x-whatever", null, true, true, true, results);
    
    assertNotNull("Scan results should not null", results);
    assertEquals("Wrong number of profiles", 1, results.size());
    
    List<Object []> profileFiles = results.get("PPP");
    checkProfileFiles(osOrderedFiles, null, profileFiles, "PPP");
}
 
Example 7
public void testUnderstandsShadowFiles() throws Exception {
    LOG.info("creating instances");
    
    FileObject inst = FileUtil.createData(root, "inst/real/X.instance");
    inst.setAttribute("instanceCreate", Long.valueOf(1000));

    FileObject shadow = FileUtil.createData(root, "inst/shadow/X.shadow");
    shadow.setAttribute("originalFile", inst.getPath());
    
    Long l = Lookups.forPath("inst/shadow").lookup(Long.class);
    assertEquals("1000 found", Long.valueOf(1000), l);
}
 
Example 8
Source Project: netbeans   File: PickIconAction.java    License: Apache License 2.0 5 votes vote down vote up
protected @Override void performAction(Node[] activatedNodes) {
    FileObject f = PickNameAction.findFile(activatedNodes);
    if (f == null) {
        return;
    }
    NbModuleProvider p = PickNameAction.findProject(f);
    if (p == null) {
        return;
    }
    FileObject src = p.getSourceDirectory();
    JFileChooser chooser = UIUtil.getIconFileChooser();
    chooser.setCurrentDirectory(FileUtil.toFile(src));
    if (chooser.showOpenDialog(WindowManager.getDefault().getMainWindow()) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    FileObject icon = FileUtil.toFileObject(chooser.getSelectedFile());
    // XXX might instead get WritableXMLFileSystem.cp and search for it in there:
    String iconPath = FileUtil.getRelativePath(src, icon);
    try {
        if (iconPath == null) {
            String folderPath;
            String layerPath = ManifestManager.getInstance(Util.getManifest(p.getManifestFile()), false).getLayer();
            if (layerPath != null) {
                folderPath = layerPath.substring(0, layerPath.lastIndexOf('/'));
            } else {
                folderPath = p.getCodeNameBase().replace('.', '/') + "/resources"; // NOI18N
            }
            FileObject folder = FileUtil.createFolder(src, folderPath);
            FileUtil.copyFile(icon, folder, icon.getName(), icon.getExt());
            iconPath = folderPath + '/' + icon.getNameExt();
        }
        f.setAttribute("iconBase", iconPath); // NOI18N
    } catch (IOException e) {
        Util.err.notify(ErrorManager.INFORMATIONAL, e);
    }
}
 
Example 9
private static String checkPath(FileObject jarRoot, FileObject fo) {
    String toRet = null;
    FileObject root = JavadocAndSourceRootDetection.findSourceRoot(jarRoot);
    try {
        if (root != null && !root.equals(jarRoot)) {
            toRet = FileUtil.getRelativePath(jarRoot, root);
            fo.setAttribute(ATTR_PATH, toRet);
        }
        fo.setAttribute(ATTR_STAMP, new Date());
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return toRet;
}
 
Example 10
private void doLoad(String lkpName) throws Exception {
    FileObject inst = FileUtil.createData(root, "inst/sub/X.instance");
    inst.setAttribute("instanceCreate", Long.valueOf(1000));
    
    Lookup l = Lookups.forPath(lkpName);
    Long lng = l.lookup(Long.class);
    assertNotNull("A value found", lng);
    
    inst.delete();
    
    assertNull("Now it is null", l.lookup(Long.class));
}
 
Example 11
private void hackIgnoreSCSSErrorsInOJET(FileObject projectDirectory) {
    Enumeration<? extends FileObject> children = projectDirectory.getChildren(true);
    while (children.hasMoreElements()) {
        FileObject file = children.nextElement();
        if ("scss".equals(file.getName())) { //NOI18N
            try {
                file.setAttribute("disable_error_checking_CSS", Boolean.TRUE.toString()); //NOI18N
                break;
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
}
 
Example 12
Source Project: netbeans   File: JShellEnvironment.java    License: Apache License 2.0 5 votes vote down vote up
void init(FileObject workRoot) throws IOException {
    this.workRoot = workRoot;
    workRoot.setAttribute("jshell.scratch", true);
    consoleFile = workRoot.createData("console.jsh");
    
    EditorCookie.Observable eob = consoleFile.getLookup().lookup(EditorCookie.Observable.class);
    inst = new L();
    eob.addPropertyChangeListener(WeakListeners.propertyChange(inst, eob));

    platform = org.netbeans.modules.jshell.project.ShellProjectUtils.findPlatform(project);
}
 
Example 13
Source Project: netbeans   File: CategoryNode.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setDisplayName( String displayName ) {
    try {
        DataFolder folder = (DataFolder)getCookie( DataFolder.class );
        if( null != folder ) {
            FileObject fo = folder.getPrimaryFile();
            fo.setAttribute( CAT_NAME, displayName );
        }
    } catch (java.io.IOException ex) {
        RuntimeException e = new IllegalArgumentException();
        org.openide.ErrorManager.getDefault().annotate(e, ex);
        throw e;
    }
    super.setDisplayName( displayName );
}
 
Example 14
Source Project: netbeans   File: PDFOpenSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Store custom command to System Filesystem.
 *
 * @param customCommand Command to store.
 */
private void storeCustomCommand(String customCommand) throws IOException {
    FileObject root = FileUtil.getConfigRoot();
    FileObject folder = root.getFileObject(DATA_FOLDER);
    if (folder == null) {
        folder = root.createFolder(DATA_FOLDER);
    }
    FileObject data = folder.getFileObject(DATA_FILE);
    if (data == null) {
        data = folder.createData(DATA_FILE);
    }
    data.setAttribute(CMD_ATTR, customCommand);
}
 
Example 15
Source Project: netbeans   File: DynamicSFSFallbackTest.java    License: Apache License 2.0 4 votes vote down vote up
public void testDynamicSystemsCanAlsoBeBehindLayers() throws Exception {
    FileObject global = FileUtil.getConfigFile("Toolbars/Standard.xml");
    assertNotNull("File Object installed: " + global, global);
    if (global.asText().indexOf("<Toolbar name=") == -1) {
        fail("Expecting toolbar definition: " + global.asText());
    }

    final LocalFileSystem lfs1 = new LocalFileSystem();
    File dir1 = new File(getWorkDir(), "dir1");
    dir1.mkdirs();
    lfs1.setRootDirectory(dir1);
    lfs1.getRoot().setAttribute("fallback", Boolean.TRUE);
    assertEquals("Position attribute is there", Boolean.TRUE, lfs1.getRoot().getAttribute("fallback"));
    fs1 = lfs1;
    fs2 = FileUtil.createMemoryFileSystem();

    FileObject fo1 = FileUtil.createData(fs1.getRoot(), global.getPath());
    fo1.setAttribute("one", 1);
    write(fo1, "fileone");

    FileObject fo11 = FileUtil.createData(fs1.getRoot(), "test-fs-is-there.txt");
    write(fo11, "hereIam");

    MainLookup.register(fs1, this);
    MainLookup.register(fs2, this);

    Iterator<? extends FileSystem> it = Lookup.getDefault().lookupAll(FileSystem.class).iterator();
    assertTrue("At least One", it.hasNext());
    assertEquals("first is fs1", fs1, it.next());
    assertTrue("At least two ", it.hasNext());
    assertEquals("first is fs2", fs2, it.next());

    if (global.asText().indexOf("<Toolbar name=") == -1) {
        fail("Still Expecting toolbar definition: " + global.asText());
    }
    assertTrue("Still valid", global.isValid());

    FileObject fo = FileUtil.getConfigFile("test-fs-is-there.txt");
    assertNotNull("File found: " + Arrays.toString(FileUtil.getConfigRoot().getChildren()), fo);
    assertEquals("Text is correct", "hereIam", fo.asText());
}
 
Example 16
Source Project: netbeans   File: SCFTHandlerTest.java    License: Apache License 2.0 4 votes vote down vote up
public void testTemplateWizardCopiesItsPropertiesToMapForOverridenEntryOnMoreEntries() throws Exception {
    LocalFileSystem fs = new LocalFileSystem();
    fs.setRootDirectory(getWorkDir());
    
    FileObject root = fs.getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.java");
    FileObject fo2 = FileUtil.createData(root, "simpleObject.form");
    fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");
    fo2.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");

    Charset set = Charset.forName("iso-8859-2");
    OutputStream os = fo2.getOutputStream();
    OutputStreamWriter w = new OutputStreamWriter(os, set);
    String txt = "print('skvělej tým, co nikdy neusíná - ěščřžýáíéúů')";
    w.write(txt);
    w.close();
    
    
    DataObject obj = DataObject.find(fo);
    assertEquals(TwoPartObject.class, obj.getClass());
    TwoPartObject tpo = (TwoPartObject)obj;
    tpo.encoding = set;
    
    FileObject root2 = FileUtil.createMemoryFileSystem().getRoot();
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root2, "target"));
    
    Map<String,String> parameters = Collections.singletonMap("type", "empty");
    
    FEQI.fs = root2.getFileSystem();
    FEQI.result = Charset.forName("UTF-8");
    
    DataObject n = obj.createFromTemplate(folder, "complex", parameters);
    Integer cnt = TwoPartLoader.queried.get(n.getPrimaryFile());
    assertEquals("No query", null, cnt);
    
    assertEquals("Created in right place", folder, n.getFolder());
    assertEquals("Created with right name", "complex", n.getName());
    Iterator<FileObject> it = n.files().iterator();
    it.next();
    FileObject snd = it.next();
    
    long length = snd.getSize();
    if (length <= 0) {
        fail("Too small file: " + length + " for " + snd);
    }
    
    String normRead = readChars(snd, Charset.forName("UTF-8"));

    txt = txt.replaceAll("print\\('", "").replaceAll("'\\)", "") + "\n";
    
    assertEquals(txt, normRead);
}
 
Example 17
public void testCreateFileWithContents() throws Exception {
    Layer l = new Layer("");
    FileSystem fs = l.read();
    FileObject f = FileUtil.createData(fs.getRoot(), "Templates/Other/Foo.java");
    f.setAttribute("hello", "there");
    TestUtil.dump(f, "some stuff");
    String xml =
            "    <folder name=\"Templates\">\n" +
            "        <folder name=\"Other\">\n" +
            // We never want to create *.java files since they would be compiled.
            "            <file name=\"Foo.java\" url=\"Foo_java\">\n" +
            "                <attr name=\"hello\" stringvalue=\"there\"/>\n" +
            "            </file>\n" +
            "        </folder>\n" +
            "    </folder>\n";
    assertEquals("correct XML written", xml, l.write());
    Map<String,String> m = new HashMap<String,String>();
    m.put("Foo_java", "some stuff");
    assertEquals("one external file created in " + l, m, l.files());
    TestUtil.dump(f, "new stuff");
    assertEquals("same XML as before", xml, l.write());
    m.put("Foo_java", "new stuff");
    assertEquals("different external file", m, l.files());
    f = FileUtil.createData(fs.getRoot(), "Templates/Other2/Foo.java");
    TestUtil.dump(f, "unrelated stuff");
    f = FileUtil.createData(fs.getRoot(), "Templates/Other2/Bar.xml");
    TestUtil.dump(f, "unrelated XML stuff");
    f = FileUtil.createData(fs.getRoot(), "Services/foo.settings");
    TestUtil.dump(f, "scary stuff");
    xml =
            "    <folder name=\"Services\">\n" +
            // *.settings are also potentially dangerous in module sources, so rename them.
            "        <file name=\"foo.settings\" url=\"fooSettings.xml\"/>\n" +
            "    </folder>\n" +
            "    <folder name=\"Templates\">\n" +
            "        <folder name=\"Other\">\n" +
            "            <file name=\"Foo.java\" url=\"Foo_java\">\n" +
            "                <attr name=\"hello\" stringvalue=\"there\"/>\n" +
            "            </file>\n" +
            "        </folder>\n" +
            "        <folder name=\"Other2\">\n" +
            // But *.xml files and other things are generally OK.
            "            <file name=\"Bar.xml\" url=\"Bar.xml\"/>\n" +
            "            <file name=\"Foo.java\" url=\"Foo_1_java\"/>\n" +
            "        </folder>\n" +
            "    </folder>\n";
    assertEquals("right XML written for remaining files", xml, l.write());
    m.put("Foo_1_java", "unrelated stuff");
    m.put("Bar.xml", "unrelated XML stuff");
    m.put("fooSettings.xml", "scary stuff");
    assertEquals("right external files", m, l.files());
    l = new Layer("", Collections.singletonMap("file.txt", "existing stuff"));
    fs = l.read();
    f = FileUtil.createData(fs.getRoot(), "wherever/file.txt");
    TestUtil.dump(f, "unrelated stuff");
    xml =
            "    <folder name=\"wherever\">\n" +
            // Need to pick a different location even though there is no conflict inside the layer.
            // Also should use a suffix before file extension.
            "        <file name=\"file.txt\" url=\"file_1.txt\"/>\n" +
            "    </folder>\n";
    assertEquals("wrote new file contents to non-clobbering location", xml, l.write());
    m.clear();
    m.put("file.txt", "existing stuff");
    m.put("file_1.txt", "unrelated stuff");
    assertEquals("right external files", m, l.files());
    l = new Layer("");
    fs = l.read();
    f = FileUtil.createData(fs.getRoot(), "one/bare");
    TestUtil.dump(f, "bare #1");
    f = FileUtil.createData(fs.getRoot(), "two/bare");
    TestUtil.dump(f, "bare #2");
    f = FileUtil.createData(fs.getRoot(), "three/bare");
    TestUtil.dump(f, "bare #3");
    xml =
            "    <folder name=\"one\">\n" +
            "        <file name=\"bare\" url=\"bare\"/>\n" +
            "    </folder>\n" +
            // Note alpha ordering.
            "    <folder name=\"three\">\n" +
            // Count _1, _2, _3, ...
            "        <file name=\"bare\" url=\"bare_2\"/>\n" +
            "    </folder>\n" +
            "    <folder name=\"two\">\n" +
            // No extension here, fine.
            "        <file name=\"bare\" url=\"bare_1\"/>\n" +
            "    </folder>\n";
    assertEquals("right counter usage", xml, l.write());
    m.clear();
    m.put("bare", "bare #1");
    m.put("bare_1", "bare #2");
    m.put("bare_2", "bare #3");
    assertEquals("right external files", m, l.files());
}
 
Example 18
Source Project: netbeans   File: JspServletDataObject.java    License: Apache License 2.0 4 votes vote down vote up
public static void setSourceJspPage(FileObject generatedServlet, DataObject jspPage) throws IOException {
    generatedServlet.setAttribute(EA_ORIGIN_JSP_PAGE, jspPage.getPrimaryFile());
}
 
Example 19
public void testDeleteFileOrFolder() throws Exception {
    Layer l = new Layer("");
    FileSystem fs = l.read();
    FileObject f = fs.getRoot().createFolder("f");
    FileObject x = f.createData("x");
    x.setAttribute("foo", "bar");
    TestUtil.dump(x, "stuff");
    FileObject y = FileUtil.createData(fs.getRoot(), "y");
    x.delete();
    assertEquals("one file and one folder left",
            "    <folder name=\"f\"/>\n" +
            "    <file name=\"y\"/>\n",
            l.write());
    assertEquals("kept external file", Collections.singletonMap("x", "stuff"), l.files());
    f.delete();
    assertEquals("one file left",
            "    <file name=\"y\"/>\n",
            l.write());
    y.delete();
    assertEquals("layer now empty again", "", l.write());
    l = new Layer("");
    fs = l.read();
    f = fs.getRoot().createFolder("f");
    x = f.createData("x");
    TestUtil.dump(x, "stuff");
    f.delete();
    assertEquals("layer empty again", "", l.write());
    assertEquals("kept external files after implicitly deleting file", Collections.singletonMap("x", "stuff"), l.files());
    // XXX should any associated ordering attrs also be deleted? not acc. to spec, but often handy...
    l = new Layer("");
    fs = l.read();
    FileObject a = fs.getRoot().createData("a");
    FileObject b = fs.getRoot().createData("b");
    FileObject c = fs.getRoot().createData("c");
    FileObject d = fs.getRoot().createData("d");
    a.delete();
    assertEquals("right indentation cleanup for deletion of first child",
            "    <file name=\"b\"/>\n" +
            "    <file name=\"c\"/>\n" +
            "    <file name=\"d\"/>\n",
            l.write());
    c.delete();
    assertEquals("right indentation cleanup for deletion of interior child",
            "    <file name=\"b\"/>\n" +
            "    <file name=\"d\"/>\n",
            l.write());
    d.delete();
    assertEquals("right indentation cleanup for deletion of last child",
            "    <file name=\"b\"/>\n",
            l.write());
    l = new Layer("    <file name=\"f\">\n        <attr name=\"a\" intvalue=\"0\"/>\n        <attr name=\"b\" intvalue=\"0\"/>\n    </file>\n");
    fs = l.read();
    f = fs.findResource("f");
    f.setAttribute("b", null);
    assertEquals("cleanup of last attribute",
            "    <file name=\"f\">\n" +
            "        <attr name=\"a\" intvalue=\"0\"/>\n" +
            "    </file>\n",
            l.write());
}
 
Example 20
Source Project: netbeans   File: SCFTHandlerTest.java    License: Apache License 2.0 3 votes vote down vote up
public void testUTF8() throws Exception {
    FileObject root = FileUtil.getConfigRoot();
    FileObject xmldir = FileUtil.createFolder(root, "xml");
    FileObject xml = FileUtil.createData(xmldir, "class.txt");
    OutputStream os = xml.getOutputStream();
    FileUtil.copy(getClass().getResourceAsStream("utf8.xml"), os);
    xml.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");
    os.close();
    
    DataObject obj = DataObject.find(xml);
    
    
    FileObject target = FileUtil.createFolder(FileUtil.createMemoryFileSystem().getRoot(), "dir");
    DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(target, "target"));
    
    
    
    Charset set = Charset.forName("iso-8859-2");
    FEQI.fs = target.getFileSystem();
    FEQI.result = set;
    
    
    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 read = readChars(n.getPrimaryFile(), set).replaceAll("print\\('", "").replaceAll("'\\);", "");
    String exp = readChars(xml, Charset.forName("utf-8")).replaceAll("print\\('", "").replaceAll("'\\);", "");
    assertEquals(exp, read);
    
}