[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

Unlocking, Editing, Locking an xml file from a Form

All,

I need  to develop a form with 'Address' fieled , and when i enter the address information and submit the form it should generating an XML file with that address info for furthur processing.

Now my problem is :

When i want to edit the address, after submitting the form by entering the address information, it should unlock the XML and edit the XML and then lock it.

How can i achive programatically, unlocking an XML file, editing the file, and locking it?.

Thanks,
Rams.
0
ramsin112400
Asked:
ramsin112400
  • 7
  • 6
  • 3
2 Solutions
 
colr__Commented:
What do you mean by 'unlocking' the xml file? xml files are simply text files,so there isnt any way to lock them.

Do you mean to lock them for read-only, as in to get the operating system to lock it from further changes?

colr__
0
 
actonwangCommented:
you can use java synchronized on your xml object assuming that editing is simple as:

synchronized(<your xml object>)
{
   <your edit statements>
}


check this:
http://www.cs.bris.ac.uk/Teaching/Resources/MR09/lectures/mk4/img17.htm
0
 
ramsin112400Author Commented:
I mean if it is read only, we can't edit the file right, so we have to unlock it for editing, and then edit it and then lock it ..so that nobody else can modify it.

How can we achieve this?

Thanks,
Ram
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
actonwangCommented:
>> unlock it for editing
    are you talking about making a readonly file as writable?
0
 
ramsin112400Author Commented:
Ya, how can we do it from a JSP?. As i explained, i have a form with address field, when i would like to edit the address field, it should unlock xml file for editing ( read only to writable mode) and after editing the address it should lock ( write to read mode).
0
 
actonwangCommented:
You can not directly change read/write attributes of files in os file system.

but you might use  FileLock to obtain shared or exclusive access to the file in the underlying file system:

refer to method FileChannel.lock(...)

 http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/FileChannel.html


Acton
0
 
actonwangCommented:
>>it should unlock xml file for editing ( read only to writable mode) and after editing the address it should lock ( write to read mode)
    If you really want to do it, you need to write a JNI or use runtime.exec("...") to use OS specific script.    
0
 
ramsin112400Author Commented:
Sorry...I'm confused ..you mean we cannot achieve (changing read/write attributes of files in OS file system) this programatically?. Can you pl eloborate on this?. I'm new to this kind of stuff.
0
 
ramsin112400Author Commented:
Sorry for the trouble...pl eloborate on this...Using runtime.exec()..how can we unlock, edit and lock the xml file?. what are the commands we need ?
0
 
actonwangCommented:
>>http://www.java-tips.org/java-se-tips/java.nio/how-to-create-a-file-lock-on-a-file.html
    this is to put a lock on file as I told you. but you can not change read/write attribute directly through java API.
0
 
actonwangCommented:
0
 
ramsin112400Author Commented:
>>http://www.java-tips.org/java-se-tips/java.nio/how-to-create-a-file-lock-on-a-file.html
    this is to put a lock on file as I told you. but you can not change read/write attribute directly through java API.
-----------
whats the meaning of 'lock' there?
0
 
actonwangCommented:
>> whats the meaning of 'lock' there?

       file lock.  either share or exclusive lock.
       Depends on OS, java uses underlying os lock mechnism to implement it.
0
 
colr__Commented:
As an extension to  my first post, Java is not a tool useable for this type of thing. Java is platform independant, so it cannot provide services that are not guareneed to run on all platforms. For example, making java able to handle file locking may be supported on windows, but not on another operating system, so if java was to support this, the language itself would become specific to windows.

You can however, integrated java with operating-specific code. This feature is called JNDI and would be used in your example to allow java to control native code (usually developed with C/C++ and opereating-system specifi) that would lock/unlock files.

colr__
0
 
colr__Commented:
As far as I'm aware, this question has been answered between actonwang  and colr__
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now