on 07-06-2006 12:15 PM
Hi all,
I am Krishna..
I need to basically parse the content of the XML form and do a text replace. The Promotions that are created by the users will also reference images. These references are stored in the XMLforms (which are basically XML files). When the Promotions are being 'submitted' the file path within the XMLForms should be updated with the target location.
<b>Example:</b>
Source Location where Promotion was created:
/myForms/filesystem/Partner Promotion/user1_folder/
Target Location where the Promotion is to be copied:
/myForms/filesystem/Submitted Promotions/user1_folder/
The Promotion XMLForm should be parsed for occurrences of /myForms/filesystem/Partner Promotion/user1_folder/ and replaced
with /myForms/filesystem/Submitted Promotions/user1_folder/
Problem is that, i am unable to build the XML file:
try {
String rpathString = "/documents/Test/promotions/Contacts.xml";
com.sapportals.portal.security.usermanagement.IUser user =
WPUMFactory.getUserFactory().getEP5User(request.getUser());
IResourceContext ctxt = new ResourceContext(user);
RID rid = RID.getRID(rpathString);
IResource resource =
ResourceFactory.getInstance().getResource(rid, ctxt);
//read the xml file
SAXBuilder builder = new SAXBuilder();
<b>Document doc = builder.build(new File(resource.getName()));</b> <i>//getting exception at this line</i>
Element root = doc.getRootElement();
List list = root.getChildren("contact");
Iterator iter = list.iterator();
while(iter.hasNext()) {
Element e = (Element)iter.next();
String name = e.getChild("name").getText();
response.write("<br>name:"+name);
String address = e.getChild("address").getText();
response.write(":::address:"+address);
}
} catch (Exception e) {
response.write(e.getLocalizedMessage());
e.printStackTrace();
}
I have also tried with
new File("http://<server>:50000/irj/go/km/docs/documents/Test/promotions/Contacts.xml");
and
new File(resource.getAccessURI());
.. but i don't get it.
<b>PS:</b> i have added <b>jdom.jar</b> file in the build path
Plz help . .. Thanking you in advance!
Regards,
Krish.
It's going to CATCH block ..and saying:
<b>E:documentsTestpromotionsContacts.xml (The system cannot find the path specified)</b>
Plz help...
Regards,
Krish.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Krish,
The <i>File</i> class doen't apply here.
xmlforms are resources, represented by the class <i>IResource</i>.
I am working with DOM, rather the SAX, but I guess same could work here.
The idea is to get the <i>InputStream</i> of the resource, and use it in the builder:
myResource.getUnfilteredContent().getInputStream().
The writing should then be done by IResource's updateContent.
Usefull javadoc:
http://www.ajvic.es/irj/portalapps/javadocs/km/com/sapportals/wcm/repository/iresource.html
Hope that helps,
Yoav.
EDIT:
Corrected 'setContent' to 'updateContent'
Hi Yoav, All,
Thanks..
Now, I have the output as a String.
String OutputString = OriginalString.replaceAll("/myForms/~filesystem~/Partner Promotion/user1_folder/","/myForms/~filesystem~/Submitted Promotions/user1_folder/");
How to convert this OutputString into IContent ?? so that i can use it in
resource.updateContent(??????????????);
for updating the resource (XML file) ..
Plz help..
Regards,
Krish..
Well, a resource in KM is not a Java file.
Have a look at
IResource.getUnfilteredContent()
.
Best regards, Julian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.