Hello,
I'm trying to load and write file on local disc drive using signed
javascript file. But I have experienced problem running this url:
jar:http://www.domain.com/secure-scripts...!/thepage.html
(sample)
in browser (Firefox) which simply won't work. I can't access to
html file embedded in jar file. My sample applet IO.java together
with IO.html was properly signed with valid certificate (real one,
no test certificate) by using signtool as is written here:
http://www.mozilla.org/projects/secu...d-scripts.html .
Is there someone who can help me or experienced same problems
with running embeded html file in signed jar file? Your help
is very appreciated. Thank you.
[code=java]
Sample IO.java:
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.util.regex .*;
import java.util.Map;
import java.util.Array List;
@SuppressWarnin gs("deprecation ")
public class IO extends Applet {
private ArrayList<Strin g[]> envvars = new ArrayList<Strin g[]>();
public static String newLine = System.getPrope rty("line.separ ator");
public boolean boolSwitch = true;
public void init() {
Map<String, String> env = System.getenv() ;
for (String envName : env.keySet()) {
String[] tmpfield;
tmpfield = new String[2];
tmpfield[0] = envName;
tmpfield[1] = env.get(envName );
envvars.add(tmp field);
}
}
public void write(String path, String data) {
try {
path = expEnvironment( path);
File file = new File(path);
DataOutputStrea m dos = new DataOutputStrea m(
new BufferedOutputS tream(
new FileOutputStrea m(file)));
dos.writeBytes( data);
dos.close();
}
catch (SecurityExcept ion se) {
System.err.prin tln(se.getMessa ge());
}
catch (IOException ioe) {
System.err.prin tln(ioe.getMess age());
}
}
public String load(String path) {
String tmpStr = new String();
try {
path = expEnvironment( path);
File file = new File(path);
DataInputStream dis = new DataInputStream (
new BufferedInputSt ream(
new FileInputStream (file)));
do {
tmpStr = tmpStr.concat(d is.readLine());
if (dis.available( ) != 0) {
tmpStr = tmpStr.concat(n ewLine);
}
} while (dis.available( ) != 0);
dis.close();
}
catch (SecurityExcept ion se) {
System.err.prin tln(se.getMessa ge());
}
catch (IOException ioe) {
System.err.prin tln(ioe.getMess age());
}
return tmpStr;
}
public void paint(Graphics g) {
}
private String expEnvironment( String path) {
String envPer = new String();
String env = new String();
Pattern pattern = Pattern.compile ("%\\w+%");
Matcher matcher = pattern.matcher (path);
while (matcher.find() ) {
envPer = matcher.group() ;
env = envPer.replace( "%", "");
for (int i = 0; i < envvars.size(); i++) {
if (env.equalsIgno reCase(envvars. get(i)[0])) {
path = path.replace(en vPer, envvars.get(i)[1]);
}
}
}
return path;
}
}[/code]
Sample IO.html:
[code=html]
<html>
<applet archive="IO.jar " code="IO.class" name="io" width="0" height="0"></applet>
<script type="text/javascript">
function saveText() {
var strFile = document.getEle mentById("file" ).value;;
var strText = document.getEle mentById("text" ).value;
document.applet s[0].write(strFile, strText);
}
function loadText() {
var strFile = document.getEle mentById("file" ).value;;
document.getEle mentById("text" ).value = document.applet s[0].load(strFile);
}
</script>
<input type="text" id="file" value="c:\\test .txt" /><br />
<textarea rows="25" cols="100" id="text">text </textarea><br />
<input type="button" value="Save" onclick="saveTe xt()" />
<input type="button" value="Load" onclick="loadTe xt()" />
</html>[/code]
I'm trying to load and write file on local disc drive using signed
javascript file. But I have experienced problem running this url:
jar:http://www.domain.com/secure-scripts...!/thepage.html
(sample)
in browser (Firefox) which simply won't work. I can't access to
html file embedded in jar file. My sample applet IO.java together
with IO.html was properly signed with valid certificate (real one,
no test certificate) by using signtool as is written here:
http://www.mozilla.org/projects/secu...d-scripts.html .
Is there someone who can help me or experienced same problems
with running embeded html file in signed jar file? Your help
is very appreciated. Thank you.
[code=java]
Sample IO.java:
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.util.regex .*;
import java.util.Map;
import java.util.Array List;
@SuppressWarnin gs("deprecation ")
public class IO extends Applet {
private ArrayList<Strin g[]> envvars = new ArrayList<Strin g[]>();
public static String newLine = System.getPrope rty("line.separ ator");
public boolean boolSwitch = true;
public void init() {
Map<String, String> env = System.getenv() ;
for (String envName : env.keySet()) {
String[] tmpfield;
tmpfield = new String[2];
tmpfield[0] = envName;
tmpfield[1] = env.get(envName );
envvars.add(tmp field);
}
}
public void write(String path, String data) {
try {
path = expEnvironment( path);
File file = new File(path);
DataOutputStrea m dos = new DataOutputStrea m(
new BufferedOutputS tream(
new FileOutputStrea m(file)));
dos.writeBytes( data);
dos.close();
}
catch (SecurityExcept ion se) {
System.err.prin tln(se.getMessa ge());
}
catch (IOException ioe) {
System.err.prin tln(ioe.getMess age());
}
}
public String load(String path) {
String tmpStr = new String();
try {
path = expEnvironment( path);
File file = new File(path);
DataInputStream dis = new DataInputStream (
new BufferedInputSt ream(
new FileInputStream (file)));
do {
tmpStr = tmpStr.concat(d is.readLine());
if (dis.available( ) != 0) {
tmpStr = tmpStr.concat(n ewLine);
}
} while (dis.available( ) != 0);
dis.close();
}
catch (SecurityExcept ion se) {
System.err.prin tln(se.getMessa ge());
}
catch (IOException ioe) {
System.err.prin tln(ioe.getMess age());
}
return tmpStr;
}
public void paint(Graphics g) {
}
private String expEnvironment( String path) {
String envPer = new String();
String env = new String();
Pattern pattern = Pattern.compile ("%\\w+%");
Matcher matcher = pattern.matcher (path);
while (matcher.find() ) {
envPer = matcher.group() ;
env = envPer.replace( "%", "");
for (int i = 0; i < envvars.size(); i++) {
if (env.equalsIgno reCase(envvars. get(i)[0])) {
path = path.replace(en vPer, envvars.get(i)[1]);
}
}
}
return path;
}
}[/code]
Sample IO.html:
[code=html]
<html>
<applet archive="IO.jar " code="IO.class" name="io" width="0" height="0"></applet>
<script type="text/javascript">
function saveText() {
var strFile = document.getEle mentById("file" ).value;;
var strText = document.getEle mentById("text" ).value;
document.applet s[0].write(strFile, strText);
}
function loadText() {
var strFile = document.getEle mentById("file" ).value;;
document.getEle mentById("text" ).value = document.applet s[0].load(strFile);
}
</script>
<input type="text" id="file" value="c:\\test .txt" /><br />
<textarea rows="25" cols="100" id="text">text </textarea><br />
<input type="button" value="Save" onclick="saveTe xt()" />
<input type="button" value="Load" onclick="loadTe xt()" />
</html>[/code]
Comment