How to call xsl from java?

Hi All,
My main java class 'OrderCustomerEntry' is located in package 'Order.Profiles.Customer'
I have my xml input stored in a String object. Now I have stored a xsl in the same package 'Order.Profiles.Customer'.
I make certain updations to my xml. After that, I have to call a xsl, which will finally do some transformations on my xml.
Kindly tell me how to call this xsl file from java.
Thanks,
Sabarisri. N
Edited by: Sabarisri N on Oct 11, 2011 11:15 AM

This can be complicated with many factors coming into play. Suppose everything is set up in good order, if the xsl is stored in the jar containing the package Order.Profiles.Customer at its root. That means, the jar has some structure like this:
Order/Profiles/CustomerOrderCustomerEntry.class
META-INF/...
xyz.xsl
etcYou may try this when load it up.
String xslFile="xyz.xsl";
//tf being the factory
Transformer transformer = tf.newTransformer(new StreamSource(ClassLoader.getSystemResourceAsStream(xslFile)));The change with respect to the case where the xslFile is in the current directory is the ClassLoader part.
Suppose it is stored in a resource directory say "res".
Order/Profiles/CustomerOrderCustomerEntry.class
META-INF/...
res/xyz.xsl
etcThe corresponding lines would look like this.
String xslFile="res/xyz.xsl";
//tf being the factory
Transformer transformer = tf.newTransformer(new StreamSource(ClassLoader.getSystemResourceAsStream(xslFile)));Hopefully, this may be enough to get you going...
ps: Although no one should force anyone on the way to name packages, the majority in the industry uses all lowercase characters whenever possible.

Similar Messages

  • How to call xml from java

    Hi
    I want to use xml for updating files in an existing jar . so i want to call xml from java code and then come back to java code and do the remaining work in java code, pl guide me how to do this . what APIs are helpful for this regard
    Thanks

    You can't update files in a jar. Even if you could, you wouldn't use XML for that. You don't call XML. XML is not a programming language. So, basically your entire question is misguided.

  • How to call webservice from Java application

    Hi XI gurus
    Pls let me know how to call a webservice from Java application.
    I wanted to build synchronous interface from Java Application to SAP using SAP XI
    For example, i need to create Material master from Java application and the return message from SAP, should be seen in Java application
    Regards
    MD

    Hi,
    If your  JAVA Application is Web based application, you can expose it as Webservice.
    JAVA People will pick the data from Dbase using their application and will send the data to XI by using our XI Details like Message Interface and Data type structure and all.
    So we can Use SOAP Adapter or HTTP in XI..
    If you use HTTP for sending the data to XI means there is no need of Adapter also. why because HTTP sits on ABAP Stack and can directly communicate with the XI Integration Server Directly
    If you are dealing with the Webservice and SAP Applications means check this
    Walkthrough - SOAP  XI  RFC/BAPI
    REgards
    Seshagiri

  • How to call javascript from java application

    How can we call a function written in javascript from java application (core java not applet)? How will java identify javascript?
    Is there any such options ?

    Try creating a page called launcher.html (for example). That does this:
    <html>
    <head>
    <script language="javascript">
    windowHandle=window.open("http://www.javasoft.com", "", "height=700,width=1000,status=no,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,top=5,left=5");
    </script>
    </head>
    </html>Now you launch IE (or whatever) with this page using the Runtime class. After x seconds (after the second window has been launched) try killing the process. Hopefully it will kill the original window you opened and not the window you popup (the one without toolbars etc)
    It might kill both windows but I can't be bothered to test it. If it does you'll have to try and find a workaround.

  • How to generate XSL from java

    Dear All,
    I got the data from a database Actually that are having some conditions.I want to to create xsl style sheet for the condtions ?
    I dont dont know how to sreate xsl fro that one.
    plz help me .thanx in advance

    Do you know you can pass parameters before calling the xsl transformation.
               // Use the factory to create a template containing the xsl file
                Templates template = factory.newTemplates(new StreamSource(
                    new FileInputStream(xslFilename)));
              // Use the template to create a transformer
                Transformer xformer = template.newTransformer();
                xformer.setParameter("key1", valueA);
                xformer.setParameter("key2", valueB);
                // Prepare the input file
                Source source = new StreamSource(new FileInputStream(inFilename));
                // Create a new document to hold the results
                DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document doc = builder.newDocument();
                Result result = new DOMResult(doc);
                // Apply the xsl file to the source file and create the DOM tree
                xformer.transform(source, result);
                return doc;and in your XSL you can get the passed value
    <xsl:param name="key1" select="'default value'"/>
    <xsl:param name="key2" select="'other default value'"/>

  • How to call 'WordPad' from java program........

    The following code will open 'Notepad'
    Runtime runt = Runtime.getRuntime();
    Process pr = runt.exec( "notepad" );likewise, I want to open 'Wordpad'
    Runtime runt = Runtime.getRuntime();
    Process pr = runt.exec( "wordpad" );The above two line code, compiles successfully, but it doesn't give the correct result.
    If I give 'wordpad' in start->run->'wordpad', in windowXP means, the Runtime executer opens 'WordPad',
    can anyone give the solution to open WordPad from Java Programming.
    thanks
    Sarwan_Gres

    Try this:
            Runtime runt = Runtime.getRuntime();
            Process pr = runt.exec("cmd /c start wordpad");

  • How to call dll from Java

    Hi everybody,
    I am trying to call a dll from my java application. Pls tell me how to do it, I seached and found JNI. Is it true
    pls help me and send me some examples
    Thank you and have a nice day

    java_and_me wrote:
    I am trying to call a dll from my java application. Pls tell me how to do it, I seached and found JNI. Is it trueYes, it is true. JNI is the way to go. You'll probably have to write some C code on your own as well, as the DLL is unlikely to be in the format expected by Java already.
    pls help me and send me some examplesOf course. [Here you are|http://www.lmgtfy.com/?q=JNI+tutorial].

  • How to call procedure from java

    My database : oracle xe 10g
    I develop my application by use jdeveloper
    I call procedure following code :
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection c = (Connection)DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "shm", "shm");
    CallableStatement cs = c.prepareCall("begin shm_increase_capital.ins_upd_tb_payment_rec_pc(:1,:2,:3,:4,:5,:6,:7);end;");
    cs.setLong(1, shareHolderId);
    cs.setString(2, companyCode);
    cs.setString(3, lotYear);
    cs.setLong(4, seqLot);
    cs.setLong(5, allocateId);
    cs.setLong(6, originateFrom);
    cs.setString(7, curUser);
    cs.execute();
    cs.close();
    c.close();
    When I run my application several times I found error :
    Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
    ORA-12519, TNS:no appropriate service handler found
    The Connection descriptor used by the client was:
    localhost:1521:XE
    Do you have another way for call procedure
    Please recommend me
    Thank you,
    Ja-ae

    I can call procedure
    but when I using my application too long
    I found error :
    Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
    ORA-12519, TNS:no appropriate service handler found
    The Connection descriptor used by the client was:
    localhost:1521:XE
    so, I think perhaps another way to call procedure for avoid this error

  • How to call procedure in Java from SQL Server Database

    Hello Every Body
    i Have Question about
    How to call procedure in Java from SQL Server Database
    Thanks

    Hi,
    have you tried a Google search? I just gave it a 3 second try and already found: http://stackoverflow.com/questions/6113674/how-do-i-execute-a-ms-sql-server-stored-procedure-in-java-jsp-returning-table-d
    Frank

  • Related documents or links on how to call webservices from WDJ

    Hi all
    i need documents & links on how to call webservices from Webdynpro for Java.
    if anybody send the documents on sample scenarios on the same then it is the great help to me...
    Thanks
    Sunil

    Hi Sunil,
    May these links help you.
    http://help.sap.com/saphelp_nw04/helpdata/en/f7/f289c67c759a41b570890c62a03519/frameset.htm
    http://help.sap.com/saphelp_nwce10/helpdata/en/64/0e0ffd314e44a593ec8b885a753d30/frameset.htm
    http://help.sap.com/saphelp_nw04s/helpdata/en/d2/0357425e060d53e10000000a155106/frameset.htm
    and  the below thread to call weservices in java.
    Re: How to call a web service from Java
    Regards,
    Supraja

  • How to run openscript from Java?

    Hi!
    I have recorded a web script using OpenScript. But instead of doing the playback in the OpenScript environment, I want to run the script from regular Java code.
    Does anyone know how to do that?
    Basically what I have tried out, is copying the code from the Java code view in Openscript, into a class in my Java project and imported all the oracle.oats... jar-files into my build path. It compiles fine.
    Then I try to call;
    MyOpenscriptClassInstance.initialize();
    MyOpenscriptClassInstance.run();
    MyOpenscriptClassInstance.finish();
    The initialize fails on a NullPointer on the browser.launch(), so clearly some more setup is needed to get the script running.
    I found one useful tip here How to call openscript from a flat java file about an alternative method, but I do not have oracle.oats.jagent.applications.qos among my jar-files in C:\OracleATS\openscript\plugins, so I am not able to locate the JavaAgentWrapper-class, the ScriptResult-class and the RunParameters-class.
    If anyone could guide me in the right direction, I would be grateful.
    I am running OpenScript version 9.2.0.0 by the way.

    Hi again!
    I found theoracle.oats.jagent.applications.qos jarr file now, so I feel like I am getting closer. I also set up log4j (hopefully correct using this guideline: http://snippets.dzone.com/posts/show/3248).
    However, the execution fails with this error message:
    *[2011-02-09 14:43:45,960]ERROR 0[Thread-2] - oracle.oats.jagent.applications.qos.JavaAgentWrapper.run(JavaAgentWrapper.java:82) - runScript.bat can't be found at null\runScript.bat*
    There are errors when running the script.
    My code looks like this:
    package guiDriver;
    import oracle.oats.jagent.applications.qos.JavaAgentWrapper;
    import oracle.oats.jagent.applications.qos.RunParameters;
    import oracle.oats.jagent.applications.qos.ScriptResult;
    public class OpenScriptWrapper {
         private String m_jwgFile;
         private JavaAgentWrapper m_qos;
         private ScriptResult m_result;
         private RunParameters m_param;
         private static final String RESULT_FOLDER = "C:\\OracleATS\\OFT\\DatabaseChangeTest\\results";
         // the JavaAgent playback process is supposed to finish
         // within this duration specified by users.
         private static final long JAGENT_TIMEOUT = 90000L;
         public OpenScriptWrapper() {
              m_qos = new JavaAgentWrapper();
              m_jwgFile = getJWGFile();
              m_param = new RunParameters();
              m_param.setScriptJWGFile(m_jwgFile);
              m_param.setResultFolder(RESULT_FOLDER);
         private String getJWGFile() {
              return "C:\\OracleATS\\OFT\\DatabaseChangeTest\\DatabaseChangeTest.jwg";
         public void runJAWrapperWithTimeout() {
              m_result = m_qos.run(m_param, JAGENT_TIMEOUT);
              if (m_result == null) {
                   System.out.println("There are errors when running the script.");
                   return;
              System.out.println("Overall Result: " + m_result.getOverallResult());
              System.out.println("Overall Duration: " + m_result.getOverallDuration()
                        + "ms");
              System.out
                        .println("Result Report File: " + m_result.getCsvReportFile());
         public static void main(String[] args) {
              OpenScriptWrapper jaws = new OpenScriptWrapper();
              jaws.runJAWrapperWithTimeout();
    Tips anyone?

  • Calling Matlab from Java

    Hi everybody,
    I need to call Matlab from Java, run some programs in matlab and get the standard output.
    I know I can start matlab with:
    Process proc = Runtime.getRuntime().exec("matlab");
    But then how do i run a program in matlab? (For example, if I have "myprogram.m", I would run it in matlab by typing "myprogram")
    If I start a new process [Process proc2 = Runtime......exec("myprogram")], it does not start in matlab.
    Any ideas?
    thanx in advance.

    Sounds like myprogram is just a parameter of a call to matlab.
    Try some variations on
    exec("matlab myprogram");
    There is also - I believe - an exzec call that takes an array of parameters.

  • Calling ant from java

    public static void main(String[] args) {
              String arr[] = null;
              arr = new String[2];
              arr[0] = "-buildfile";
              arr[1] = "C:\\workspace\\my projects\\ANTTASKS\\bin\\build.xml";
              try {
                   Launcher launcher = new Launcher();
                   launcher.main(arr);     
              } catch (Exception e) {
                   System.out.println(e.getMessage());
                   // TODO: handle exception
    I tried calling ant from java. But the problem is that, i am not sure how to get the handle of error & input stream from this.
    I also need to know how do I kill the ant executable if there is some kind of exception like ConnectionTimeOut or is there any some kind of timeout mechanism.
    Earlier i was calling ant as an external process like Process P = new Process(), where p.execute("ant.bat xxxxx"). I used to get the error & input stream from the process itself.
    Please help!!!
    thanks

    A better approach would be to use the classes provided in Ant. The API documentation for Ant has all the necessary information.
    The sample code would look like:
    Project ant = new Project();
    ProjectHelper helper = new ProjectHelperImpl();
    ant.init();
    helper.parse(ant, new File("build.xml"));
    ant.executeTarget("clean");

  • Calling searchadminctl from Java failing

    I am trying to call searchadminctl from a Java application, to make some automation around installing thesaurus. The searchadminctl batch file gets called alright and its own Java application gets started, but it gives me this error:
    16:48:26:812 INFO     main          url:null user:eqsys
    16:48:27:530 INFO     main          cmd mode=1
    16:48:27:546 INFO     main          thesaurus:default:null:null
    16:48:27:546 INFO     main          delete:thesaurus:default
    16:48:27:593 INFO     main          thesaurus delete:1
    16:48:27:890 INFO     main          url:null user:eqsys
    16:48:28:609 INFO     main          cmd mode=1
    16:48:28:609 INFO     main          thesaurus:null:null:null
    16:48:28:609 INFO     main          create:thesaurus:C:/ses-thesaurus-importer/export/thesaurus.xml:null
    16:48:28:749 DEBUG     main          thesaurus:null
    16:48:28:749 INFO     main          thesaurus null null
    16:48:28:843 DEBUG     main     ThesaurusDBAdapter          insert to run command:ctxload userName:eqsys
    16:48:30:812 DEBUG     output     ThesaurusDBAdapter$1          Enter user: Connecting...
    16:48:30:827 DEBUG     output     ThesaurusDBAdapter$1          Creating thesaurus DEFAULT...
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          Thesaurus DEFAULT created...
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          Processing...
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          0 lines processed successfully
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          Beginning insert...DRG-50857: oracle error in drzmiai
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          ORA-20000: Oracle Text-fejl:
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          ORA-04002: INCREMENT skal være et heltal forskelligt fra nul
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          ORA-06512: ved "CTXSYS.DRUE", linje 160
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          ORA-06512: ved "CTXSYS.DRITHSL", linje 129
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          ORA-06512: ved linje 1
    16:48:30:843 DEBUG     output     ThesaurusDBAdapter$1          
    16:48:30:859 DEBUG     output     ThesaurusDBAdapter$1          Disconnected
    16:48:30:952 DEBUG     main     ThesaurusDBAdapter          finish command with status 1
    16:48:30:952 ERROR     main     Error creating thesaurus: the NLS_LANG environment variable may be inconsistent with the thesaurus encoding java.lang.Exception     oracle.search.admin.db.ThesaurusDBAdapter:insert:310     oracle.search.admin.manager.JDBCDataManagerService:create:148     oracle.search.admin.manager.AbstractAdminDataManager:create:54     oracle.search.admin.manager.ThesaurusManager:create:52     oracle.search.admin.cmd.AdminCMDHandler:create:334     oracle.search.admin.cmd.AdminConsole:runAdminModuleJob:672     oracle.search.admin.cmd.AdminConsole:runAdminComand:541     oracle.search.admin.cmd.AdminConsole:main:227
    As you can see, the delete operation goes well, but create fails. The NLS_LANG message seems to be shown no matter what the real error was though.
    The funny thing is, that I have tried to take the EXACT command with the EXACT parameters my Java application calls, and call it manually, and then it works just fine. Any ideas on how to get this to work? Any ideas what these ORA-XXXXX errors is?
    Thank you
    Søren

    Last night when I was somewhere between this world and dream world I scanned through my code in my mind and found the error, and it is my bad... I called the searchadminctl with my thesaurus file as argument, just before I closed my OutputStream to the file, which we all know is quite a bad idea.
    So the answer is: it is absolutly no problem to call searchadminctl from Java :)
    /Søren

  • Calling C from Java. C takes in a command line input

    Hello,
    I have created some basic JNI programs, in which the java file calls the C files. The way I could do it was directly calling the functions in the C files, which I needed. Now I am trying to call a C file from Java, and the C files takes in a command line argument after being compiled.
    Also after compiling the C file, it produces an exe. I cannot change the C file and also want to call it from Java using JNI (as I want to later put all this into a jar and jnlp file and put it on webstart).
    If anyone can help me on how to call the compiled C file and how to send in the input as a command line argument I would greatly appreciate it.
    Thanks
    Nick

    Now I know how to create a C wrapper file and a Java file in JNI format. Does this mean you want to run the exe files by calling the main() method through JNI. Yes you can do that BUT you will need to turn your exe file into a dll and then write a JNI wrapper to act as a bridge between the Java and the dll.Yes. Thats exactly what I want to do. I want to call the C files through JNI. But what I am asking is, how do I send in the input which is originally sent in as stdin? And also what are the steps to follow if I want to call a main method of the C files in the JNI.
    Up till now I have been using JNI to call functions from the initial C files from the C wrapper file. But now I want to call the .exe file by sending it a command line input. Or if you can suggest a better method that would be great.
    You can execute an exe file using ProcessBuilder then there is no need for a JNI wrapper. You must read the 4 sections of [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] and implement ALL the recommendations. Failure to do so will cause you much grief.
    You could achieve the same result but using a lot more code and a hell of a lot more effort by invoking the exe executables from JNI code that invokes the 'C' exec() library. Just thinking about that approach makes my eyes water!
    Well if I just use the exec() library I can do it, yes thats ture. But I wasnt sure if I did that, and then put this on Java Web Start, if non PC users can access it or not. If macs, and linux machines can access this even If i use exec, then my problem is solved.
    Thanks
    Nick

Maybe you are looking for

  • Backing up from an external hard drive??..

    Hello, My computer died but before it did I was able to back everything including my itunes onto an external hard drive. I am now using a new computer and when I plug my phone it only shows all the data which is on there. Can anyone help me transferi

  • Can't open files in microsoft office

    I can create documents using Pages but then when I email them to other people they cannot open the files on their computers.  Im assuming that they microsoft word proccessor.  Very frusterating

  • Generating delimited file from a report in reports 6i gives error rep-1814

    Hi all, We are using reports 6i. We have a report from which we are trying to generate a delimited file. We are encounterign the error REP-1814 The object vertically can never fit. After looking into forums we came to know that there is something lik

  • Opening PDF Email Attachments

    My PDF email attachments open in Microsoft Word and can't be read. How can I open PDF attachments in Adobe without first having to do a 'Save As'? I have Adobe on my laptop.

  • Adobe Premiere Elements 11 Editor and OS Mavericks

    I installed OS Mavericks for Mac and my Adobe Premiere Elements 11 Editor doesn't work more. What must I do?