How to save an XML file with a proper name and how to maintain the history?

Hi All,
As per the requirement, I have to remane the name of the XML file which is under the KM repository Userhome/personaldocuments based on the user logon information.
I have created a Repository service for the same and following is the code for the same. The service is working, but only for the first entry in the XML form. Second onwards, the file does not get remaned to the preferred one.
Request you to throw some light as what is wrong or missing in the code, so that I can follow the right approach. Many thanks in advance.
// Code snippet is here//
//Starts here//
com.sap.security.api.IUser epUser;
                                        epUser = UMFactory.getAuthenticator().getLoggedInUser();
                                 String EntID = epUser.getUniqueName();
IResourceContext resContext = null;
try {
     resContext = ResourceFactory.getInstance().getServiceContext("cmadmin_service");
} catch (ResourceException e1) {
          e1.printStackTrace();
RID rid = RID.getRID("/userhome""/"EntID+"/Personal Documents");
IResource resource = null;
try {
     resource = (ResourceFactory.getInstance().getResource(rid, resContext));
} catch (ResourceException e2) {
          e2.printStackTrace();
ICollection collection = (ICollection)resource;
IResourceList resourseList = null;
try {
     resourseList = collection.getChildren();
} catch (AccessDeniedException e3) {
          e3.printStackTrace();
} catch (ResourceException e3) {
          e3.printStackTrace();
     for(int i=0;i<resourseList.size();i++){
          IResource res_new = resourseList.get(i);
            try {
               res_new.rename("Address_new.xml");
          } catch (NotSupportedException e) {
                              e.printStackTrace();
          } catch (AccessDeniedException e) {
                              e.printStackTrace();
          } catch (ResourceException e) {
                              e.printStackTrace();
//Code ends here//
Regards
DK
Edited by: DIPENDRA MOHANTY on Jun 5, 2009 5:20 PM

Hi,
The code seems ok.
But you have mentioned about a KM Rep service, what service is that? which event it is listening to?
Regards
BP

Similar Messages

  • How can I save a XML file with JAXP1.1?

    Dear All.
    I write a program to create XML file with DOM model, but I can't know how to save it? My environment is JAXP1.1 and JDK1.3.1,I has been required not use other XML parser toolkits,only JAXP1.1.
    How can I do? thank you.
    Many person give me a idea the com.sun.xml.tree.XmlDocument, but I can't find the class in API document or JAXP1.1's packages. why?
    what is it? How can i use it?
    thank you very much.

    The way to save an XML Document is using a Transformer.
    To have access to a transformer use the packages :
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    Then for saving your Document Object (named dXml) get a Transformer Object with the TransformerFactory Object :
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    Now you have got your Transformer Object, to save your Document Object use the method :
    Document dXml = getMyDocument(); // this is your Document Object.
    OutputStream osSave = getMySaveStream(); // this the OutputStream you need to save your Document.
    try
    t.transform(new DomSource(dXml), new StreamResult(new OutputStreamWriter(osSave)));
    finally
    osSave.close();
    And your Document was now saved.

  • How do you display xml file with xlst sheet in jsp

    I have an xml file with accompanying xslt file (and several images that are used in a single directory. If I doubleclick on the xml file, it displays perfectly in my browser - Formatting, images and all!
              The 100 dollar question - How do I duplicate this behavior in a JSP page in WebLogic 8.1 using the code in the xml and the accompanying xslt (formatting) file? I tried simple embedding the xml code in the jsp, but that didn't seem to work. What is the secret?
              Okay, I need to add a bit more information here. I understand that it is really easy to just redirect to the XML file. The issue is really security. I want the XML to be inside a jsp that will only allow validated users to view it.
              Another way to look at the problem would be, can I add a jsp security tag to the xml file? Or how to I add the xml code inside a jsp and keep the path references to the xslt and graphics.
              Hope the added information helps
              Thanks,
              Ken
              Message was edited by: KLee - 20050609 10:25 MST
              [email protected]

    This proved out to be the answer. Thanks for the direction!
              import java.io.File;
              import java.io.IOException;
              import java.io.InputStream;
              import java.io.OutputStream;
              import java.io.FileNotFoundException;
              import java.io.FileOutputStream;
              import javax.servlet.ServletException;
              import javax.servlet.http.HttpServlet;
              import javax.servlet.http.HttpServletRequest;
              import javax.servlet.http.HttpServletResponse;
              import javax.xml.transform.Transformer;
              import javax.xml.transform.TransformerConfigurationException;
              import javax.xml.transform.TransformerException;
              import javax.xml.transform.TransformerFactory;
              import javax.xml.transform.stream.StreamResult;
              import javax.xml.transform.stream.StreamSource;
              public class XML_XSLT_Servlet extends HttpServlet {
              protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
                        String xmlfile = req.getParameter("xmlfile"); if (xmlfile==null) xmlfile = "test.xml";
                        String xsltfile = req.getParameter("xsltfile"); if (xsltfile==null) xsltfile = "test.xslt";
                        /* Test if file exists!, or use default file */
                        File f1 = new File(getServletContext().getRealPath("WEB-INF/displayfiles/"), xmlfile);
                        File f2 = new File(getServletContext().getRealPath("WEB-INF/displayfiles/"), xsltfile);
                   if (f1.exists() && f2.exists()) {
                             // System.out.println("Files Found");
                        } else {
                             System.out.println("XML and XSLT Files NOT Found");
                             System.out.println(f1.getPath());
                             System.out.println(f1.getName());
                             xmlfile = "test.xml";
                             xsltfile = "test.xslt";
              InputStream fileXML = getServletContext().getResourceAsStream("WEB-INF/displayfiles/" + xmlfile);
              InputStream fileXSLT = getServletContext().getResourceAsStream("WEB-INF/displayfiles/" + xsltfile);
              OutputStream os = res.getOutputStream();
              TransformerFactory xFactory = TransformerFactory.newInstance();
              StreamSource stylesheet = new StreamSource(fileXSLT);
              Transformer xformer = null;
              try {
              xformer = xFactory.newTransformer(stylesheet);
              } catch (TransformerConfigurationException tfce) {
              tfce.printStackTrace();
              StreamSource input = new StreamSource(fileXML);
              StreamResult output = null;
              try {
              output = new StreamResult(os);
              } catch (Exception e) {
              e.printStackTrace();
              try {
              xformer.transform(input, output);
              } catch (TransformerException xfe) {
              xfe.printStackTrace();
              <pre></pre><pre></pre>

  • How to validate an XML file with XSD Schema on JDK 1.4

    Hi
    I'm looking for samples how to validate xml files with xsd schema using jsdk 1.4
    Thank you.

    This is how.
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.dom.DOMResult;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    dbfac.setNamespaceAware(true);
    SchemaFactory factory1 = SchemaFactory
                        .newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = factory1.newSchema(new File("person.xsd"));
    dbfac.setSchema(schema);
    DocumentBuilder dbparser1 = dbfac.newDocumentBuilder();
    Document doc1 = dbparser1.parse(new File("person.xml"));
    Validator validator1 = schema.newValidator();
    DOMSource dm1 = new DOMSource(doc1);
    DOMResult domresult1 = new DOMResult();
    validator1.validate(dm1, domresult1);

  • How To read an XML file with JDom

    I have read through some tutorials after installing JDom on how to read an existing XML file and I was confused by all of them. I simply want to open an XML file and read one of the node's content. Such as <username>john doe</username> this way I can compare values with what the user has entered as their username. I am not sure were to start and I was hoping someone could help me out.
    I know that this seems like an insecure way to store login information but after I master opening and writing XML files with JDom I am going to use AES to encrypt the XML files.

    Here is a test program for JDom and XPath use considering your XML file is named "test.xml" :import org.jdom.input.*;
    import org.jdom.xpath.*;
    public class JDomXPath {
    public static void main(String[] args) {
      SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
      try {
       org.jdom.Document jdomDocument = saxBuilder.build("test.xml");
       org.jdom.Element usernameNode = (org.jdom.Element)XPath.selectSingleNode(jdomDocument, "//username");
       System.out.print(usernameNode.getText());
      } catch (Exception e) {
       e.printStackTrace();
    }(tested with Eclipse)

  • How Can I dispaly XML file with CSS?

    hi,all
    There is maybe a simple way to dispaly a XML file with a CSS file in program.But I don't know.Who can tell me?
    Thank you very much!

    Hi,
    XML documents don't have the link or style elements that are used in HTML to connect style information to particular documents. Instead, the W3C has defined a processing instruction that provides that information, based on the model of the HTML link element. To connect a CSS style sheet to your XML document so that the browser can find it, use a processing instruction like
    <?xml-stylesheet type="text/css" href="URI"?>
    where URI is the address of the style sheet. We'll use a style sheet called display1.css for our first test document. The processing instruction can go right after the XML declaration.
    <?xml version="1.0" ?>
    <?xml-stylesheet type="text/css" href="display1.css"?>
    <test>
    Hope this may help you.
    Regards,
    Anil.
    Technical Support Engineer.

  • How to generate a xml file with JSP?

    Hi,
    I want to dynamically generate maths formula in my web page. I think MathMl is a good choice. However, it needs xml file. I try to use JSP to generate the
    content of the xml file. However, it doesn't work. What should I do?
    Best regards.

    Hi,
    Thanks a lot for your replies. I used to write JSP to present quiz fetching from a database. To use MathML, xml file has to be used. I've tried to copy the content of the xml file to a jsp file and let the brower to display it. However, it doesn't work. I view the content of the page displayed by the brower. I simply contain nothing. So what it's the most convenience way to present the MathML dynamically.
    Best regards.
    From hoifo

  • Open XML file with user default browser and not the default editor.

    Hi,
    I'm writing a java program that appends numerous XML files together. The result is a NEW well formed XML document. Since i have an XSLT that performs several UI modifications on this xml file, the file extension must remain '.xml'. I need to open this xml file with the users default web browser. The problem is that:
    Runtime.getRuntime().exec(cmd);
    ....opens the xml file with the users default program for opening xml files which in my case is Oxygen. I want to force java to open this xml file with the users default web browser and nothing else.
    I guess i need the Windows command to perform the 'open with' feature but i have no idea what that command is or how to find it.
    Any ideas?
    Thanks,
    Varun Singh
    Edited by: Jagara00 on Jul 2, 2009 3:49 PM

    sabre150 wrote:
    Jagara00 wrote:
    Your right, but my question relates to the java issue and not the XSLT aspect of the problem. I am looking for a java solution for reasons i will no go into here. You have lost me.Me too.
    People do not often ask questions (or make challenges or observations) idly for the sake of 'theory'. It is most useful to explain to the best of your ability.
    As to
    "Since the Desktop class was only released with SE 6 I am forced to find another alternative. "
    There is an 'alternative'. You can import it into a 1.5 project. It was available as a free standing API before 1.6 - through JDIC. See [https://jdic.dev.java.net/documentation/Examples.html|https://jdic.dev.java.net/documentation/Examples.html] for more info.
    Edit 1:
    To a later reply
    "Do u .."
    ..want to spell incorrectly when you get frustrated?
    "..do not wish to.."
    ..get any help? That is the way you are heading.
    Edited by: AndrewThompson64 on Jul 3, 2009 9:27 AM

  • How to output a postscript file with .ps extension name in jsp?

    Hi,
    I could use a servlet to output a postscript file with .ps file extension name. But I tried to do the same with jsp, for some reason, jsp always outputs a file with .jsp extension name though the content is postscript. Could anyone help me on this? Here is my jsp code:
    <%@page contentType="application/postscript"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="java.util.*" %>
    <%@page import="java.io.*" %>
    <jsp:useBean id="corresv" class="oiintranet.CorresVBean" scope="request"/>
    <%
    response.setContentType("application/postscript");
    String corresId = request.getParameter("Id");
    corresv.setCorresId(corresId);
    PrintWriter output = response.getWriter();
    output = corresv.getResult(output);
    output.flush();
    %>
    In the bean corresv:
    public class CorresVBean extends BaseBean {
    private String corresId;
    public void setCorresId(String s) {
    this.corresId = s;
    public PrintWriter getResult(PrintWriter output) {
    //get postscript file content from a socket, one string line each time until reaches "X_END"
    String str;
    while ((str = in.readLine()) != null) {
    if (str.equals("X_END")) break;
    output.println (str);
    output.close();
    }catch(Exception e) {
    e.printStackTrace();
    return output;
    Thank you in advance.
    Geraldine

    Hi
    Every time u want to make a file u need to make its extension. I am talking
    about general scenario like word, excel so even when u make spool file
    so u need to give extension.
    like
    Spool temp.sql
    it will save u r file as sql file.
    hope it will help
    regards

  • SPD 2010 - How to know if a file with a given name already exists in a document library

    Hi,
    I've created a workflow using SPD. One of the steps in there is changing the name of the document to a clean name. This workflow fails if a document with this same name already exists in my document library. Is there a way to check in a SPD workflow if
    a document with a given name already exists in my document library ?
    Marc Nemegeer

    Hi,
    According to your post, my understanding is that you wanted to know if a file with a given name already exists in a document library.
    You can use a SharePoint Designer workflow to achive it.
    To test to see if a document exists, you need to use condition:
    If Current List:Name  equals  [%Current Item:Title%].docx
    Here is a similar thread for you to take a look at:
    http://social.technet.microsoft.com/Forums/en-US/cc227020-ce81-4c08-aee0-a66789d8ad05/test-to-see-if-document-exists?forum=sharepointcustomizationprev
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • How to "use" a xml file with a script?

    Hey Guys!
    I use the normal Button with the send-option to send the xml file to an url.
    My question is how it's possible to work in a php-script with the xml data out of the formular?
    Thanks for help.
    LG
    Adrian

    Hi,
    I need to read a XML document with StringReade class.
    My aplication receives an absolute path but this
    doesn't work:
    StringReader oStringReader =
    new StringReader(c:\java\libros.xml);
    However it works with:
    StringReader oStringReader =
    new StringReader("<?xml version="1.0" e......");
    ie, with the whole document as a String, but I need
    to do it as the frist way.
    Thankstake a look at this link:
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/2a_echo.html

  • How can i send xml file with a http servlet request

    Hi
    Please tell me how can I send a xml file into http servlet request.
    I have a servlet(action) java file.From this servlet I have generate a xml file. Now I need to send that xml file to another servlet with http servlet request object.
    Dave.

    When you say you have generated an XML file what do you mean?
    Is it a file stored on disk? Then pass the file path as a string to the servlet.
    Is it stored in memory as an object? The pass a reference to the object to the servlet.
    Or are you asking how to communicate between servlets?
    Look in the JavaDocs for the RequestDispatcher class. You can use this class to forward the request to another servlet. Data can be passes using the RequestDispatcher by storing it as attributes using the request getAttribute and setAttribute methods. Also described in the JavaDOcs.
    http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html

  • How to save as AI file with PDF compatability at the same location?

    Hi Guys,
    Requesting for script. Here are the details..
    I  do have lot of AI files (from different paths) which are do not have PDF compatability switch  on. So now I am looking for script that all the files should save as at  the same place (over write) and should switch on the PDF compatability  switch on.
    I tried with Action script, But the problem  is, action scripting is recording the path where I saved first time.  That means, all the files are save as into recorded path. This makes me  some what confusion, because source file will be 1 and save file with PDF  1. So in total 2 files will create which is not good.
    So I am  requesting you that script schould overwirte at the same path and should  switch on the PDF compatability.
    FYI: Using Adobe CS4...
    If you help for this, it is really greatful for me.
    Thanks in advance...
    Regards
    HARI

    #target illustrator
    var df = new Folder('~/Desktop');
    var topLevel = Folder.selectDialog('Please choose your Top Level Folder…', df);
    if (topLevel != null) {
         topLevel = topLevel.fsName
         var fileList = new Array();
         fileListRecursive(topLevel, /\.ai$/i);
         if (fileList.length > 0) {
              main();    
         } else {
              alert('This Folder or sub folders contained NO Illustrator AI files?');    
    function main() {
         with (app) {
              while (documents.length) {
                     activeDocument.close(SaveOptions.PROMPTTOSAVECHANGES);
              //var orginalUIL = userInteractionLevel;    
              //userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
              for (var a = 0; a < fileList.length; a++) {
                   var docRef = open(fileList[a]);
                   with (docRef) {
                        var aiOptions = new IllustratorSaveOptions();
                        aiOptions.compatibility = Compatibility.ILLUSTRATOR12; // Change to 14 for CS4
                        aiOptions.compressed = true;
                        aiOptions.embedICCProfile = true;
                        aiOptions.embedLinkedFiles = false;
                        aiOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
                        aiOptions.fontSubsetThreshold = 0;
                        aiOptions.overprint = PDFOverprint.PRESERVEPDFOVERPRINT;
                        aiOptions.pdfCompatible = true;
                        aiFilePath = new File(fullName);
                        saveAs(aiFilePath, aiOptions);
                        close(SaveOptions.DONOTSAVECHANGES);
              //userInteractionLevel = orginalUIL;
    function fileListRecursive(f, exp) {         
         var t = Folder(f).getFiles();
         for (var i = 0; i < t.length; i++) {
              if (t[i] instanceof File && RegExp(exp).test(t[i].fsName)) fileList.push(t[i]);
              if (t[i] instanceof Folder) fileListRecursive(t[i].fsName, exp);
    }

  • How to Save a XML file using Document Object

    Hai all,
    I am new to XML and i created a application to insert a node in the XML file using org.w3c.dom.Document object. And want to know which method has to be used to store the Document object into a XML fille.

    The standard way would be to use a transformer with no transformation where the destination is a StreamResult.
    something like:
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    transformer.transform(new DOMSource(doc), new StreamResult("output.xml"));

  • How to read a xml file with StringReader class

    Hi,
    I need to read a XML document with StringReade class. My aplication receives an absolute path but this doesn't work:
    StringReader oStringReader =
    new StringReader(c:\java\libros.xml);
    However it works with:
    StringReader oStringReader =
    new StringReader("<?xml version="1.0" e......");
    ie, with the whole document as a String, but I need to do it as the frist way.
    Thanks

    Hi,
    I need to read a XML document with StringReade class.
    My aplication receives an absolute path but this
    doesn't work:
    StringReader oStringReader =
    new StringReader(c:\java\libros.xml);
    However it works with:
    StringReader oStringReader =
    new StringReader("<?xml version="1.0" e......");
    ie, with the whole document as a String, but I need
    to do it as the frist way.
    Thankstake a look at this link:
    http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/sax/2a_echo.html

Maybe you are looking for

  • Hp Laserjet 200 Color MFP M276nw Fax error report

    Hi Team Will you please assist me in turning off , Fax error report ? I have checked all the settings on this machine , i cant't find this setting, i want to turn off the error report on failed/error  faxes. Regards James R

  • Photoshop CS faults after upgrade to iPhoto 6

    This may be off topic, but I am not finding relevant info elsewhere. I hope someone here can point me in the right direction. An artist friend upgraded to iPhoto 6 recently. Since then she has problems with EPS files created in Photoshop CS when savi

  • ERR  = -50

    I have a ton of .avi movies and recently I cannot access them animore with QT. I have the Divx doctor and I get the error= -50 message everytime I try to open a movie. Does anybody know what this means?

  • Authentication, Multiple domain,different forest lowercase domain.

    We have succesfully configured a BOXI 3.1 SP3 to use SSO using vintela,tomcat for our domain that is on 2000 native mode. Let's call this one Domain1. In our domain there is another separate domain sitting on a 2003 domain level. (Let's call this one

  • Drag object won't drop in Presenter

    Using a drag and drop quiz component from within Flash 8, my swf file works correctly in ppt but not in Presenter. Once compiled the object will drag but will not drop using Presenter 6.0. Using Flash 8 professional and Flash 8 player. Does anyone kn