Search code examples
javafile-iojnlpjava-web-startsavefiledialog

JNLP FileSaveService ignoring the name and extension given while invoking the saveAsFileDialog method


I have a requirement of passing command line parameters when mounting .dmg on MAC for this I have used JNLP which is dynamically composed using JSP with response content-type as application/x-java-jnlp-file. The content of JSP is as following:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://10.40.42.134:8080/TestJNLP/">
 <information>
    <title>jnlp.JSP</title>
    <vendor>Sun Microsystems, Inc.</vendor>
 </information>
 <resources>
    <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="lib/faren2.jar" main="true" />
 </resources>
 <application-desc name="Dynamic Tree Demo Application" main-class="org.Test" width="300" height="300">
    <argument><%=request.getParameter("arg1")%></argument>  
    <argument><%=request.getParameter("arg2")%></argument> 
 </application-desc>
 <security>
    <all-permissions/>
 </security>
</jnlp>

JNLP is correctly invoked with the parameters I pass.

Now there are two problems moving further:

First, After triggering JNLP my main-class invokes saveFileDialog from FileSaveService for saving the .dmg on user system but JNLP Client (Save Dialog which open on MAC) is ignoring the name and extensions which I am passing while invoking the method. How can we make the JNLP Client to honor the name and extension I am passing?

Second, How can I know the path where user has saved the .dmg so that I can mount it programatically? This is very critical knowing the path where user has saved the file.


Solution

  • I do not think this is possible with FileSaveService.

    The path and extension arguments to saveFileDialog are only hints. The implementation is free to ignore them.

    FileContents.getName() will tell you only the name, not the directory. This is by design. JNLP apps that depend on FileSaveService are considered untrusted, and paths are potentially a privacy issue. If I choose to save the DMG file in a directory called C:\Users\S_Rushdie\My Documents\Porn I may not want your program to include that in a log that is later uploaded to your server.

    If you need greater control, I think you will need to sign your app, grant it <all-permission/> and use a JFileChooser and FileOutputStream instead.