mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.14k stars 235 forks source link

File chooser - saved file name filtering #290

Open Sorceror opened 9 years ago

Sorceror commented 9 years ago

When user enters file name in the WebFileChooser space ' ' character(s) is allowed in the beginning or end of the file, which leads to InvalidPathException when File instance is converted to Path instance.

public class SaveDialogSSCCE {
    public SaveDialogSSCCE() {
        WebLookAndFeel.install();

        File f = WebFileChooser.showSaveDialog();
        if (f != null) {
            System.out.println(f.toPath().toAbsolutePath().toString());
        }
    }

    public static void main(String[] args) {
        new SaveDialogSSCCE();
    }
}
Exception in thread "main" java.nio.file.InvalidPathException: Trailing char < > at index 31: "D:\ test  "
    at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:191)
    at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
    at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
    at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
    at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
    at java.io.File.toPath(File.java:2234)
    at stile.SaveDialogSSCCE.<init>(SaveDialogSSCCE.java:26)
    at stile.SaveDialogSSCCE.main(SaveDialogSSCCE.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Here are some details: http://superuser.com/questions/738002/why-folder-or-file-name-in-windows-cannot-end-with-space .

mgarin commented 9 years ago

I have merged your changes, I guess that should fix it?

mgarin commented 9 years ago

Also I might add some kind of symbols filter later-on to allow/disallow some specific things in file name. Some basic options will probably be available in a static form to allow quick configurations.

Sorceror commented 9 years ago

Yes, it fix the particular issue I posted.. That would be great to filter it more, though our users did only append some spaces in the end of tile name so far (no special characters usage from regular users).

mgarin commented 9 years ago

I have changed this issue to enhancement with appropriate title, I will be adding more filtering options in next update.