Java Applet Read/Write Etc..

K

Kavok

Hi. I've got a java applet that needs to edit an XML file with data
captured via GET by javascript and then retrieved via getParameter()
etc..

The platform is a local only machine running Firefox 1, Java 1.5,
custom build of Linux.
The machine doesn't connect to any server, is not running apache and
so fourth.

The problem im running into is when my applet tries to overwrite the
currently existing file (works in XP) it crashes Firefox and doesn't
write the file.

Is there anyway that I can overwrite / delete a currently existing
file using a java applet?
 
O

Oliver Wong

Kavok said:
Hi. I've got a java applet that needs to edit an XML file with data
captured via GET by javascript and then retrieved via getParameter()
etc..

The platform is a local only machine running Firefox 1, Java 1.5,
custom build of Linux.
The machine doesn't connect to any server, is not running apache and
so fourth.

The problem im running into is when my applet tries to overwrite the
currently existing file (works in XP) it crashes Firefox and doesn't
write the file.

Is there anyway that I can overwrite / delete a currently existing
file using a java applet?

Since it's local only, why don't you write it as an application instead
of an applet? Applets can't write to the local file system without proper
signing, so you're just adding a lot of headaches for nothing.

- Oliver
 
K

Kavok

Since it's local only, why don't you write it as an application instead
of an applet? Applets can't write to the local file system without proper
signing, so you're just adding a lot of headaches for nothing.

- Oliver


I was brought into this project late, switching everything over to an
application rather than an applet would be too time consuming. All the
work currently done would be completely wasted. The jar is signed, and
'accepted'. It CAN write files, it just can't OVERWRITE files.
 
A

Andrew Thompson

....
I was brought into this project late, switching everything over to an
application rather than an applet would be too time consuming.

Note that it can take as little as 5-10
lines of code to launch an applet in a
frame.

Does this applet use applet 'param'
elements?

Andrew T.
 
L

Lew

Andrew said:
Note that it can take as little as 5-10
lines of code to launch an applet in a
frame.

So that would be about 10 minutes' time to code the conversion, a half hour to
test that it runs that way fine, another half day to call a meeting to show
everyone that you have done it, thus magically eliminating complicated browser
issues and reducing a major maintenance cost for your company. You are a hero
and a get a big fat raise and a bonus, and suddenly the office hottie is
making googly eyes at you.

Yup, easy to see why it isn't worth the effort.

- Lew
 
O

Oliver Wong

Lew said:
So that would be about 10 minutes' time to code the conversion, a half
hour to test that it runs that way fine, another half day to call a
meeting to show everyone that you have done it, thus magically eliminating
complicated browser issues and reducing a major maintenance cost for your
company. You are a hero and a get a big fat raise and a bonus, and
suddenly the office hottie is making googly eyes at you.

Yup, easy to see why it isn't worth the effort.

Alternative, spend the 10 minutes trying to code it. If it doesn't work,
then you're only 10 minutes worse off than you were previously. If it
actually works, lean back, put your heels on your desk and take a nap. If
someone comes in to ask what you're doing, tell them you're rearchitecturing
your applet solution into an application solution in your head, and you'd
prefer it if nobody disturbed you while you did this.

I think the solution goes something like this (off the top of my head,
might contain errors, but it gives you an idea of how the solution works):

public class AppletToApplicationWrapper {
public static void main(String[] args) {
final JApplet theOldApplet = new MyOldApplet();
final JFrame theNewJFrame = new JFrame("The Name Of The Application");
theNewJFrame.getContentPane().add(theOldApplet);
theNewJFrame.setDefaultCloseOperation(JFrame.NONE);
theNewJFrame.setWindowListener(new IWindowListener() {
public void WindowClosingEvent(Event e) {
theOldApplet.stop();
theOldApplet.destroy();
}

public void WindowResizieAndOtherEvents(Event e) {
//do nothing.
}
});
theOldApplet.init();
theOldApplet.start();
theNewJFrame.setVisible();
}
}

11 statements (including the two in the anonymous inner class), so
Andrew wasn't too far off with his 5-10 estimate.

- Oliver
 
K

Kavok

So that would be about 10 minutes' time to code the conversion, a half
hour to test that it runs that way fine, another half day to call a
meeting to show everyone that you have done it, thus magically eliminating
complicated browser issues and reducing a major maintenance cost for your
company. You are a hero and a get a big fat raise and a bonus, and
suddenly the office hottie is making googly eyes at you.
Yup, easy to see why it isn't worth the effort.

Alternative, spend the 10 minutes trying to code it. If it doesn't work,
then you're only 10 minutes worse off than you were previously. If it
actually works, lean back, put your heels on your desk and take a nap. If
someone comes in to ask what you're doing, tell them you're rearchitecturing
your applet solution into an application solution in your head, and you'd
prefer it if nobody disturbed you while you did this.

I think the solution goes something like this (off the top of my head,
might contain errors, but it gives you an idea of how the solution works):

public class AppletToApplicationWrapper {
public static void main(String[] args) {
final JApplet theOldApplet = new MyOldApplet();
final JFrame theNewJFrame = new JFrame("The Name Of The Application");
theNewJFrame.getContentPane().add(theOldApplet);
theNewJFrame.setDefaultCloseOperation(JFrame.NONE);
theNewJFrame.setWindowListener(new IWindowListener() {
public void WindowClosingEvent(Event e) {
theOldApplet.stop();
theOldApplet.destroy();
}

public void WindowResizieAndOtherEvents(Event e) {
//do nothing.
}
});
theOldApplet.init();
theOldApplet.start();
theNewJFrame.setVisible();
}

}

11 statements (including the two in the anonymous inner class), so
Andrew wasn't too far off with his 5-10 estimate.

- Oliver

This applet isn't the entire program, its a -piece- of the program.

The entire "application" consists of several thousand xhtml pages, js
files, css, xsl, xml, .class etc..

And yes the applet uses "params"
 
A

Andrew Thompson

This applet isn't the entire program, its a -piece- of the program.

Please be a bit more specific.
Is it just one applet amongst this group
of pages?
One applet that *writes* *files*?
What else does it do (and how)?
What else must this applet interact with?
The entire "application" consists of several thousand xhtml pages, js
files, css, xsl, xml, .class

What are the '.class' files, if not applets
or classes in a WEB-INF?
...etc..

And yes the applet uses "params"

Web start - but that will require tomcat
(or PHP etc.) to write the params for the
JNLP actively.

Andrew T.
 
O

Oliver Wong

Kavok said:
Hi. I've got a java applet that needs to edit an XML file with data
captured via GET by javascript and then retrieved via getParameter()
etc..

The platform is a local only machine running Firefox 1, Java 1.5,
custom build of Linux.
The machine doesn't connect to any server, is not running apache and
so fourth.

The problem im running into is when my applet tries to overwrite the
currently existing file (works in XP) it crashes Firefox and doesn't
write the file.

Is there anyway that I can overwrite / delete a currently existing
file using a java applet?

Okay, so for whatever reasons, converting the Applet to an Application
is out of the question (which surprises me: How complex could a
local-only-no-Apache-etc. applet based application get?)

And your applet is signed and everything. Great.

So you're asking if it's possible to delete a file. Did you try invoking
the File.delete() method? A signed applet has all the rights of an
application, AFAIK.

- Oliver
 
K

Kavok

Please be a bit more specific.
Is it just one applet amongst this group
of pages?
One applet that *writes* *files*?
What else does it do (and how)?
What else must this applet interact with?

Its one applet among many.

This applet needs to:
1. Open two .xml files.
2. Locate a specific line in the XML file.
3. Write new data within the specific tags.
4. Write the new file to the disk, overtop of the currently existing
file.

What are the '.class' files, if not applets
or classes in a WEB-INF?

They are applets.

Web start - but that will require tomcat
(or PHP etc.) to write the params for the
JNLP actively.

Andrew T.

I'm not allowed touching the operating system and/or installing apache/
php etc.. at this time.
 
K

Kavok

Okay, so for whatever reasons, converting the Applet to an Application
is out of the question (which surprises me: How complex could a
local-only-no-Apache-etc. applet based application get?)

And your applet is signed and everything. Great.

So you're asking if it's possible to delete a file. Did you try invoking
the File.delete() method? A signed applet has all the rights of an
application, AFAIK.

- Oliver

I've tried using File.delete() but it seemed to have no effect.

I'll be experimenting with it a bit more on Friday. However they've
given me an alternative way to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top