Transforming a String in a FileReader

Dear Srs,
I'm developing an ASP page that write a text file to server. In the next page I developed an applet that read this file and calls a class to process it. I read the text file and I have a String as file content. But the class wait for a FileReader parameter and I can't modify the class to receive a String. As not is possible to write this String in a file in the client, read it and pass to my class, I aks for you: How can I convert my String in a FileReader? If not, what is the other manner to pass the string for my class?
Thanks a lot,
Vinicius Machado

A FileReader needs to read from a file. You can't create a file, so you cannot use the method that requires a FileReader. Is there no other method that just uses a Reader, or something general like that? That would have been a good design. Requiring a specific input source is a bad design. If you have the ability to change this class, I suggest you do so. If you don't, you appear to be out of luck until you find something better.

Similar Messages

  • Error after transforming xml string

    I have an XML string that I have to parse and update (transformer)
              String ji = "<book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book>";
              ByteArrayInputStream str = new ByteArrayInputStream(ji.getBytes());
                   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
                   Document doc = docBuilder.parse(str);
                   doc.getDocumentElement().normalize();
                   str.reset();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   NodeList listOfPersons = doc.getElementsByTagName("person");
                             int total = listOfPersons.getLength();
                             for(int i = 0; i < total; i++)
                                  Node firstpersonnode = listOfPersons.item(i);
                                  if(firstpersonnode.getNodeType() == Node.ELEMENT_NODE)
                                       Element firstPersonElement = (Element)firstpersonnode;
                                       NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                                       Element firstNameElement = (Element)firstNameList.item(0);
                                       NodeList textFNList = firstNameElement.getChildNodes();
                                       Text t = (Text) textFNList.item(0);
                                       String p = t.toString();
                                       System.out.println("First Name : " +p);
                                       t.setData("sdasdsa");
                                       //String q = t.toString();
                                       //response.write("First Name : " +q);
                                       NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                                       Element lastNameElement = (Element)lastNameList.item(0);
                                       NodeList textLNList = lastNameElement.getChildNodes();
                                       System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
                                       NodeList ageList = firstPersonElement.getElementsByTagName("age");
                                       Element ageElement = (Element)ageList.item(0);
                                       NodeList textAgeList = ageElement.getChildNodes();
                                       System.out.println("Age : " + ((Node)textAgeList.item(0)).getNodeValue().trim());
    I then write the ByteArrayOutputStream to an OutputStream becoz I need it in that format for the Transformer.
    oos = bos;
    str.reset();
    Source source = new DOMSource(doc);
    Result res = new StreamResult(oos);
    Transformer x = TransformerFactory.newInstance().newTransformer();
    x.transform(source,res);
    System.out.println("now the string is = "+oos.toString());
    Which Transforms it:
    Now my output is the Old XML string + some xml declaration + the Updated XML string.
    First Name : p
    Last Name : m
    Age : 22
    First Name : b
    Last Name : g
    Age : 46
    First Name : s
    Last Name : j
    Age : 40
    now the string is = <book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book><?xml version="1.0" encoding="utf-8"?>
    <book><person><first>sdasdsa</first><last>m</last><age>22</age></person><person><first>sdasdsa</first><last>g</last><age>46</age></person><person><first>sdasdsa</first><last>j</last><age>40</age></person></book>
    I only need to update the string

    Clap... here is the compilable code complete:
    Tried to make it shorter...:
    public class TestXML {
         public static void main(String[] args) {
              String ji = "<book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book>";
              ByteArrayInputStream str = new ByteArrayInputStream(ji.getBytes());
              ByteArrayOutputStream os=null;
              OutputStream oos = null;
              try
                   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder =  documentBuilderFactory.newDocumentBuilder();
                   Document doc = docBuilder.parse(str);
                   doc.getDocumentElement().normalize();
                   str.reset();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   NodeList listOfPersons = doc.getElementsByTagName("person");
                             int total = listOfPersons.getLength();
                             for(int i = 0; i < total; i++)
                                  Node firstpersonnode = listOfPersons.item(i);
                                  if(firstpersonnode.getNodeType() == Node.ELEMENT_NODE)
                                       Element firstPersonElement =  (Element)firstpersonnode;
                                       NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                                       Element firstNameElement = (Element)firstNameList.item(0);
                                       NodeList textFNList = firstNameElement.getChildNodes();
                                       Text t = (Text) textFNList.item(0);
                                       String p = t.toString();
                                       System.out.println("First Name : " +p);
                                       t.setData("sdasdsa");
                                                                     NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                                       Element lastNameElement = (Element)lastNameList.item(0);
                                       NodeList textLNList = lastNameElement.getChildNodes();
                                       System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
                                       NodeList ageList = firstPersonElement.getElementsByTagName("age");
                                       Element ageElement = (Element)ageList.item(0);
                                       NodeList textAgeList = ageElement.getChildNodes();
                                       System.out.println("Age : " +   ((Node)textAgeList.item(0)).getNodeValue().trim());
                   byte b;
                   while ((b =(byte) str.read()) != -1) {
                        bos.write(b);
                   oos = bos;
                                            str.reset();
                             Source source = new DOMSource(doc);
                             Result res = new StreamResult(oos);
                             Transformer x =  TransformerFactory.newInstance().newTransformer();
                             x.transform(source,res);
                             System.out.println("now the string is = "+oos.toString());
         catch(Exception e){System.out.println(e);}
    }The o/p is as I mentioned in my first post
    Message was edited by:
    PremPrem
    Message was edited by:
    PremPrem

  • Write and transform to String XML

    I have a big trable.
    I dinamicly generate XML File and try to transform it to String. I use standart toString() method for root Element of XML Document.
    My data are in Windows-1251 encoding, but result String is in UTF-8 encoding.
    When I write dinamicly generated XML Document in File.
    I set encoding Windows-1251, but result is in UTF-8.
    PLEASE HELP ME!!!!!

    Well, regarding file encodings Java has a history and so does MS-Windows. I don't know all the details for the Russian (let's rather use the term Cyrillic from now on) encodings but I went through a similar problem with German and iso-8859-1 encoding. The problem was similar in that some characters above 127 got displayed as '?'.
    Java uses a default encoding which changed in versions later than 1.1.7 from iso-8859-1 to CP1252 (I assume that for Cyrillic that translates to iso-8859-5 and cp1251, respectively).
    Windows and DOS have a whole list of changes with respect to Cyrillian encodings: CP855, CP866 and finally CP1251, which is incompatible with both iso-8859-5 and ISO-IR-111 (aka KOI8).
    Since your characters are displayed as '?' it's very unlikely you'll see a UTF-8 encoding in your output file (with all due respect), it rather seems to be a mismatch between one of the iso encodings and CP1251, that's my guess.
    Anyways, let me describe my problem a bit, and hopefully you can deduce a solution for yours.
    My XML file contained character 129 (that's a u with two dots on top) and displaying as well as writing that character to a file put a '?' in its place. DOS ASCII editors (as well as older Windows editors) use iso-8859-1 and display and input character 129 correctly and when I used JSDK1.1.6 everything was fine. Now, Java assumes CP1251 and by forcing it to use iso-8859-1 I got input and output working just fine.
    Since I don't have a Cyrillic Windows version at my disposal I can't find out which encoding will work for you, but it has to do with the default encoding Java is using, not so much with the XML and its parsing.
    You can use the following test program to find out what the correct settings are. Play with the encoding settings (CP8xx, iso-8859-5, CP1251) until both input and output files are identical and contain the correct characters.
    import java.io.*;
    class x{
       public static void main(String[] args)
          try
             InputStreamReader  isr = new InputStreamReader(new FileInputStream("ascii.txt"), "iso-8859-1");
             OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("ascii_out.txt"), "iso-8859-1");
             char[] buf=new char[1024];
             int n;
             while((n=isr.read(buf,0,1024))!=-1)
                osw.write(buf,0,n);
             isr.close();
             osw.close();
          catch(Exception e)
             e.printStackTrace();
    }If you still have problems, please provide more information:
    1. encoding attribute you're setting in the XML file
    2. the default file encoding of your Java version (a system property) + JSDK version
    3. XML parser vendor + version
    4. What you exactly mean by "transform" (XSLT ? just outputting ?)
    5. Some code samples might help, too.
    Hope that helps,
    Good luck.
    P.S.
    Here are some links for info on character sets and encodings:
    http://czyborra.com/charsets/codepages.html
    http://czyborra.com/charsets/iso8859.html
    http://www.cl.cam.ac.uk/~mgk25/unicode.html

  • Error transforming XML string

    I have an XML string that I have to parse and update (transformer)
              String ji = "<book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book>";
              ByteArrayInputStream str = new ByteArrayInputStream(ji.getBytes());
                   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder =  documentBuilderFactory.newDocumentBuilder();
                   Document doc = docBuilder.parse(str);
                   doc.getDocumentElement().normalize();
                   str.reset();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   NodeList listOfPersons = doc.getElementsByTagName("person");
                             int total = listOfPersons.getLength();
                             for(int i = 0; i < total; i++)
                                  Node firstpersonnode = listOfPersons.item(i);
                                  if(firstpersonnode.getNodeType() == Node.ELEMENT_NODE)
                                       Element firstPersonElement =  (Element)firstpersonnode;
                                       NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                                       Element firstNameElement = (Element)firstNameList.item(0);
                                       NodeList textFNList = firstNameElement.getChildNodes();
                                       Text t = (Text) textFNList.item(0);
                                       String p = t.toString();
                                       System.out.println("First Name : " +p);
                                       t.setData("sdasdsa");
                                       //String q = t.toString();
                                       //response.write("First Name : " +q);
                                       NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                                       Element lastNameElement = (Element)lastNameList.item(0);
                                       NodeList textLNList = lastNameElement.getChildNodes();
                                       System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
                                       NodeList ageList = firstPersonElement.getElementsByTagName("age");
                                       Element ageElement = (Element)ageList.item(0);
                                       NodeList textAgeList = ageElement.getChildNodes();
                                       System.out.println("Age : " +   ((Node)textAgeList.item(0)).getNodeValue().trim());
                             }I then write the ByteArrayOutputStream to an OutputStream becoz I need it in that format for the Transformer.
    oos = bos;
    str.reset();
                             Source source = new DOMSource(doc);
                             Result res = new StreamResult(oos);
                             Transformer x = TransformerFactory.newInstance().newTransformer();
                             x.transform(source,res);
                             System.out.println("now the string is = "+oos.toString());
    Which Transforms it:
    Now my output is the Old XML string + some xml declaration + the Updated XML string.
    First Name : p
    Last Name : m
    Age : 22
    First Name : b
    Last Name : g
    Age : 46
    First Name : s
    Last Name : j
    Age : 40
    now the string is = <book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book><?xml version="1.0" encoding="utf-8"?>
    <book><person><first>sdasdsa</first><last>m</last><age>22</age></person><person><first>sdasdsa</first><last>g</last><age>46</age></person><person><first>sdasdsa</first><last>j</last><age>40</age></person></book>I only need to update the string

    I have an XML string that I have to parse and update (transformer)
              String ji = "<book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book>";
              ByteArrayInputStream str = new ByteArrayInputStream(ji.getBytes());
                   DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder docBuilder =  documentBuilderFactory.newDocumentBuilder();
                   Document doc = docBuilder.parse(str);
                   doc.getDocumentElement().normalize();
                   str.reset();
                   ByteArrayOutputStream bos = new ByteArrayOutputStream();
                   NodeList listOfPersons = doc.getElementsByTagName("person");
                             int total = listOfPersons.getLength();
                             for(int i = 0; i < total; i++)
                                  Node firstpersonnode = listOfPersons.item(i);
                                  if(firstpersonnode.getNodeType() == Node.ELEMENT_NODE)
                                       Element firstPersonElement =  (Element)firstpersonnode;
                                       NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                                       Element firstNameElement = (Element)firstNameList.item(0);
                                       NodeList textFNList = firstNameElement.getChildNodes();
                                       Text t = (Text) textFNList.item(0);
                                       String p = t.toString();
                                       System.out.println("First Name : " +p);
                                       t.setData("sdasdsa");
                                       //String q = t.toString();
                                       //response.write("First Name : " +q);
                                       NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                                       Element lastNameElement = (Element)lastNameList.item(0);
                                       NodeList textLNList = lastNameElement.getChildNodes();
                                       System.out.println("Last Name : " + ((Node)textLNList.item(0)).getNodeValue().trim());
                                       NodeList ageList = firstPersonElement.getElementsByTagName("age");
                                       Element ageElement = (Element)ageList.item(0);
                                       NodeList textAgeList = ageElement.getChildNodes();
                                       System.out.println("Age : " +   ((Node)textAgeList.item(0)).getNodeValue().trim());
                             }I then write the ByteArrayOutputStream to an OutputStream becoz I need it in that format for the Transformer.
    oos = bos;
    str.reset();
                             Source source = new DOMSource(doc);
                             Result res = new StreamResult(oos);
                             Transformer x = TransformerFactory.newInstance().newTransformer();
                             x.transform(source,res);
                             System.out.println("now the string is = "+oos.toString());
    Which Transforms it:
    Now my output is the Old XML string + some xml declaration + the Updated XML string.
    First Name : p
    Last Name : m
    Age : 22
    First Name : b
    Last Name : g
    Age : 46
    First Name : s
    Last Name : j
    Age : 40
    now the string is = <book><person><first>p</first><last>m</last><age>22</age></person><person><first>b</first><last>g</last><age>46</age></person><person><first>s</first><last>j</last><age>40</age></person></book><?xml version="1.0" encoding="utf-8"?>
    <book><person><first>sdasdsa</first><last>m</last><age>22</age></person><person><first>sdasdsa</first><last>g</last><age>46</age></person><person><first>sdasdsa</first><last>j</last><age>40</age></person></book>I only need to update the string

  • Transform XML-String to human readable XML-File

    I need to transform a XML-String as coming from a simple transformation into a human readable XML-File. That means with linebreaks and logical indenting, each line not longer than n charactors.
    Example:
    <one><two>text</two><three><four>text</four></three></one>
    into
    <one>
      <two>text</two>
      <three>
        <four>text</four>
      </three>
    </one>

    I wrote a method that will do this, but the method can not handle all kinds of XML-strings, but it works with most simple XML-Strings:
    METHOD xml_str2table.
    *** Importing
    **    I_XMLSTRING type csequence
    *** Returning
    ***   e_tab_XMLtab type table of string.        
      DATA l_cnt_length TYPE i.
      l_cnt_length = STRLEN( i_xmlstring ).
      DATA l_cnt_index TYPE i.
      DATA l_xmlline TYPE string.
      DATA l_oldchar TYPE c.
      DATA l_char TYPE c.
      DATA l_nextchar TYPE c.
      DATA l_indent TYPE i.
      DO l_cnt_length TIMES.
        l_cnt_index = sy-index - 1.
        l_char = i_xmlstring+l_cnt_index(1).
        IF sy-index < l_cnt_length.
          l_nextchar = i_xmlstring+sy-index(1).
        ENDIF.
        IF  l_char <> cl_abap_char_utilities=>newline.
          IF ( l_char = '<' AND l_nextchar = '/' ) OR
             ( l_char = '/' AND l_nextchar = '>' ).
            l_indent = l_indent - 1.
            IF l_indent < 0.
              l_indent = 0.
            ENDIF.
          ENDIF.
          IF l_char = '<' AND l_oldchar = '>'.
            APPEND l_xmlline TO e_tab_xmltab.
    *      write: / l_xmlline.
            CLEAR l_xmlline.
            DO l_indent TIMES.
              CONCATENATE space space l_xmlline INTO l_xmlline SEPARATED BY space.
            ENDDO.
          ENDIF.
          if l_char <> space.
            CONCATENATE l_xmlline l_char INTO l_xmlline.
          else.
            CONCATENATE l_xmlline l_char INTO l_xmlline SEPARATED BY space.
          endif.
          IF l_char = '<' AND l_nextchar <> '/'.
            l_indent = l_indent + 1.
          ENDIF.
        ELSE.
          l_indent = 0.
          APPEND l_xmlline TO e_tab_xmltab.
    *    write: / l_xmlline.
          CLEAR l_xmlline.
        ENDIF.
        l_oldchar = l_char.
      ENDDO.
      APPEND l_xmlline TO e_tab_xmltab.
    *write: / l_xmlline.
    ENDMETHOD.
    The second Method does the same not with an string, but with an X-String:
    METHOD xml_xstr2table.
    *** Importing
    **    I_XMLSTRING type xsequence
    *** Returning
    ***   e_tab_XMLtab type table of string.     
      DATA l_tmp_string TYPE string.
      DATA conv TYPE REF TO cl_abap_conv_in_ce.
      conv = cl_abap_conv_in_ce=>create(
                encoding = 'UTF-8'
                endian = 'L' ).
      conv->convert(
        EXPORTING input = i_xmlstring
        IMPORTING data = l_tmp_string ).
      e_tab_xmltab = xml_str2table( l_tmp_string ).
    ENDMETHOD.

  • V 8.04 : Raw(16) datatype not correct transformed to string ...

    Hi,
    executing
    SELECT SYS_GUID() FROM DUAL;
    results in
    [B@f42ea0
    but should result in
    SQL> SELECT SYS_GUID() FROM DUAL;
    SYS_GUID()
    8667F9E0021F4F76AEA70C2AEAB693A7
    SQL>
    Regeards
    Karl

    I heard about this from someone inside Oracle too and will discuss with the rest of the development team today and log the appropriate bug.
    When I tested it messes up in Results (and Table > Data) but not Script output.
    -- Sharon

  • Transform String[][] to Double[][]

    Hi, I nedd to transform a String Table1[][] into a Double Table2[][].
    In the String[][] I have values like:
    0,30
    0,51
    1,26I have try to do typping:
    for(int i =0;i<Table1.length;i++)
       for(int j =0;j<Table1[0].length;j++)
          Table2[i][j] = Double.parseDouble(Table1[i][j]);But I obtain this error when I compile:
    ...: incompatible types
    found   : double
    required: java.lang.Double
    Table2[i][j] = Double.parseDouble(Table1[i][j]);
                                     ^How to do?? Thanks

    Thanks every body,
    Before doing
    Table2[i][j] = new Double(Table1[i][j]);I have make two changes:
    I have change the "," insteadof "." in Table1 For example:
    1,23 -> 1.23
    Later I have do:
    if(null != Tabl1[i][j])
         Table2[i][j] = new Double(Table1[i][j]);
    if(null == Tabl1[i][j])
         Table2[i][j] = new Double(0.0);Is correct to do this??
    Thanks

  • Transform string to a unicode

    Hello all,
    I want to know how can we transform a string to a 16-bit unicode, please?
    ( i want to transform a string to look like "\u062a\u0635\u0628\u062d "
    and then store it in a string variable to use it).
    can you give me the code?
    it's urgent

    your right that I asked how to turn a String into UNICODE
    and if you noticed my code you will find that I used the code that turn a string retrieved from database into unicode then store in a PDF file,but my problem here is when I tried to store these data in the PDF File, it stored as it is, I mean it stored the unicode string as it is (string) not convert it to the equivalent character as in the following example.
    I used this way (turn a String into UNICODE) because I found an example of how to put data written in a language other than english in a PDF file.
    this is the example:
    import java.awt.Color;
    import java.io.FileOutputStream;
    import com.lowagie.text.Chunk;
    import com.lowagie.text.Document;
    import com.lowagie.text.Element;
    import com.lowagie.text.Font;
    import com.lowagie.text.PageSize;
    import com.lowagie.text.Phrase;
    import com.lowagie.text.pdf.BaseFont;
    import com.lowagie.text.pdf.ColumnText;
    import com.lowagie.text.pdf.PdfContentByte;
    import com.lowagie.text.pdf.PdfPCell;
    import com.lowagie.text.pdf.PdfPTable;
    import com.lowagie.text.pdf.PdfWriter;
    * Writing RTL text such as Arabic or Hebrew.
    public class RightToLeft {
    * Writing RTL text such as Arabic or Hebrew.
    * @param args no arguments needed
    public static void main(String[] args) {
    try {
         // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("righttoleft.pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();
    BaseFont bf = BaseFont.createFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, true);
    Font f2 = new Font(bf, 24, Font.NORMAL, Color.BLUE);
    float llx = 100;
    float lly = 100;
    float urx = 500;
    float ury = 800;
    ColumnText ct = new ColumnText(cb);
    ct.setSimpleColumn(llx, lly, urx, ury, 24, Element.ALIGN_LEFT);
    ct.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
    ct.setLeading(0, 1);
    ct.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(ar1, new Font(bf, 16)));
    ct.addText(new Chunk(ar2, new Font(bf, 16, Font.NORMAL, Color.red)));
    ct.go();
    ct.setAlignment(Element.ALIGN_JUSTIFIED);
    ct.addText(new Chunk(ar3, new Font(bf, 12)));
    ct.go();
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(ar4, new Font(bf, 14)));
    ct.go();
    ct.setSpaceCharRatio(PdfWriter.SPACE_CHAR_RATIO_DEFAULT);
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk("\n\n\n", new Font(bf, 16)));
    ct.addText(new Chunk(he1, new Font(bf, 16)));
    ct.addText(new Chunk(he2, new Font(bf, 16, Font.NORMAL, Color.red)));
    ct.go();
    ct.setAlignment(Element.ALIGN_JUSTIFIED);
    ct.addText(new Chunk(he3, new Font(bf, 12)));
    ct.go();
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(he4, new Font(bf, 14)));
    ct.go();
    document.newPage();
    String atext = "\u062a\u0635\u0628\u062d ";
    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_NO_BIDI);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    document.add(table);
    // step 5
    document.close();
    catch (Exception e) {
    e.printStackTrace();
    /** arabic text */
    public static String ar1 = "\u0623\u0648\u0631\u0648\u0628\u0627, \u0628\u0631\u0645\u062c\u064a\u0627\u062a \u0627\u0644\u062d\u0627\u0633\u0648\u0628 + \u0627\u0646\u062a\u0631\u0646\u064a\u062a :\n\n";
    /** arabic text */
    public static String ar2 = "\u062a\u0635\u0628\u062d \u0639\u0627\u0644\u0645\u064a\u0627 \u0645\u0639 \u064a\u0648\u0646\u064a\u0643\u0648\u062f\n\n";
    /** arabic text */
    public static String ar3 = "\u062a\u0633\u062c\u0651\u0644 \u0627\u0644\u0622\u0646 \u0644\u062d\u0636\u0648\u0631 \u0627\u0644\u0645\u0624\u062a\u0645\u0631 \u0627\u0644\u062f\u0648\u0644\u064a " +
    "\u0627\u0644\u0639\u0627\u0634\u0631 \u0644\u064a\u0648\u0646\u064a\u0643\u0648\u062f, \u0627\u0644\u0630\u064a \u0633\u064a\u0639\u0642\u062f \u0641\u064a 10-12 \u0622\u0630\u0627\u0631 1997 " +
    "\u0628\u0645\u062f\u064a\u0646\u0629 \u0645\u0627\u064a\u0646\u062a\u0633, \u0623\u0644\u0645\u0627\u0646\u064a\u0627. \u0648\u0633\u064a\u062c\u0645\u0639 \u0627\u0644\u0645\u0624\u062a\u0645\u0631 " +
    "\u0628\u064a\u0646 \u062e\u0628\u0631\u0627\u0621 \u0645\u0646 \u0643\u0627\u0641\u0629 \u0642\u0637\u0627\u0639\u0627\u062a \u0627\u0644\u0635\u0646\u0627\u0639\u0629 \u0639\u0644\u0649 " +
    "\u0627\u0644\u0634\u0628\u0643\u0629 \u0627\u0644\u0639\u0627\u0644\u0645\u064a\u0629 \u0627\u0646\u062a\u0631\u0646\u064a\u062a \u0648\u064a\u0648\u0646\u064a\u0643\u0648\u062f, \u062d\u064a\u062b " +
    "\u0633\u062a\u062a\u0645, \u0639\u0644\u0649 \u0627\u0644\u0635\u0639\u064a\u062f\u064a\u0646 \u0627\u0644\u062f\u0648\u0644\u064a \u0648\u0627\u0644\u0645\u062d\u0644\u064a \u0639\u0644\u0649 " +
    "\u062d\u062f \u0633\u0648\u0627\u0621 \u0645\u0646\u0627\u0642\u0634\u0629 \u0633\u0628\u0644 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u064a\u0648\u0646\u0643\u0648\u062f \u0641\u064a " +
    "\u0627\u0644\u0646\u0638\u0645 \u0627\u0644\u0642\u0627\u0626\u0645\u0629 \u0648\u0641\u064a\u0645\u0627 \u064a\u062e\u0635 \u0627\u0644\u062a\u0637\u0628\u064a\u0642\u0627\u062a " +
    "\u0627\u0644\u062d\u0627\u0633\u0648\u0628\u064a\u0629, \u0627\u0644\u062e\u0637\u0648\u0637, \u062a\u0635\u0645\u064a\u0645 \u0627\u0644\u0646\u0635\u0648\u0635 \u0648\u0627\u0644\u062d\u0648\u0633\u0628\u0629 " +
    "\u0645\u062a\u0639\u062f\u062f\u0629 \u0627\u0644\u0644\u063a\u0627\u062a.\n\n";
    /** arabic text */
    public static String ar4 = "\u0639\u0646\u062f\u0645\u0627 \u064a\u0631\u064a\u062f \u0627\u0644\u0639\u0627\u0644\u0645 \u0623\u0646 \u064a\u062a\u0643\u0644\u0651\u0645, \u0641\u0647\u0648 \u064a\u062a\u062d\u062f\u0651\u062b \u0628\u0644\u063a\u0629 \u064a\u0648\u0646\u064a\u0643\u0648\u062f\n\n";
    /** hebrew text */
    public static String he1 = "\u05d0\u05d9\u05e8\u05d5\u05e4\u05d4, \u05ea\u05d5\u05db\u05e0\u05d4 \u05d5\u05d4\u05d0\u05d9\u05e0\u05d8\u05e8\u05e0\u05d8:\n\n";
    /** hebrew text */
    public static String he2 = "Unicode \u05d9\u05d5\u05e6\u05d0 \u05dc\u05e9\u05d5\u05e7 \u05d4\u05e2\u05d5\u05dc\u05de\u05d9\n\n";
    /** hebrew text */
    public static String he3 = "\u05d4\u05d9\u05e8\u05e9\u05de\u05d5 \u05db\u05e2\u05ea \u05dc\u05db\u05e0\u05e1 Unicode \u05d4\u05d1\u05d9\u05e0\u05dc\u05d0\u05d5\u05de\u05d9 \u05d4\u05e2\u05e9\u05d9\u05e8\u05d9, \u05e9\u05d9\u05d9\u05e2\u05e8\u05da \u05d1\u05d9\u05df \u05d4\u05ea\u05d0\u05e8\u05d9\u05db\u05d9\u05dd " +
    "12\u05be10 \u05d1\u05de\u05e8\u05e5 1997, \u05d1\u05de\u05d9\u05d9\u05e0\u05e5 \u05e9\u05d1\u05d2\u05e8\u05de\u05e0\u05d9\u05d4. \u05d1\u05db\u05e0\u05e1 \u05d9\u05e9\u05ea\u05ea\u05e4\u05d5 \u05de\u05d5\u05de\u05d7\u05d9\u05dd \u05de\u05db\u05dc \u05e2\u05e0\u05e4\u05d9 \u05d4\u05ea\u05e2\u05e9\u05d9\u05d9\u05d4 " +
    "\u05d1\u05e0\u05d5\u05e9\u05d0 \u05d4\u05d0\u05d9\u05e0\u05d8\u05e8\u05e0\u05d8 \u05d4\u05e2\u05d5\u05dc\u05de\u05d9 \u05d5\u05d4\u05beUnicode, \u05d1\u05d4\u05ea\u05d0\u05de\u05d4 \u05dc\u05e9\u05d5\u05e7 \u05d4\u05d1\u05d9\u05e0\u05dc\u05d0\u05d5\u05de\u05d9 \u05d5\u05d4\u05de\u05e7\u05d5\u05de\u05d9, " +
    "\u05d1\u05d9\u05d9\u05e9\u05d5\u05dd Unicode \u05d1\u05de\u05e2\u05e8\u05db\u05d5\u05ea \u05d4\u05e4\u05e2\u05dc\u05d4 \u05d5\u05d1\u05d9\u05d9\u05e9\u05d5\u05de\u05d9\u05dd, \u05d1\u05d2\u05d5\u05e4\u05e0\u05d9\u05dd, \u05d1\u05e4\u05e8\u05d9\u05e1\u05ea \u05d8\u05e7\u05e1\u05d8 \u05d5\u05d1\u05de\u05d7\u05e9\u05d5\u05d1 " +
    "\u05e8\u05d1\u05be\u05dc\u05e9\u05d5\u05e0\u05d9.\n\n";
    /** hebrew text */
    public static String he4 = "\u05db\u05d0\u05e9\u05e8 \u05d4\u05e2\u05d5\u05dc\u05dd \u05e8\u05d5\u05e6\u05d4 \u05dc\u05d3\u05d1\u05e8, \u05d4\u05d5\u05d0 \u05de\u05d3\u05d1\u05e8 \u05d1\u05beUnicode\n\n";
    if you noticed this code, you will find that the data that he want to put it in a PDF file,he already know its unicode as in (ar1,ar2,ar3,.....) and when you run this code you will get a PDF file with an Arabic and hebrew language.
    that means he can convert the unicode to the equivalent character.
    but in my code that I put in the previous post does not do that.
    and this is my problem again:
    if you noticed these classes or objects :
    PdfPCell (class), table (object ), document (object)
    I used these classes from free library called (iText) if you know it.
    to help me store data that i retrieve it from database in a PDF file.
    my problem is when I used the above code as it is, it will stores the data that I retrieve it from database as "\u0030\u0039\u0061\u0041"
    and it didn't give me the equivalent word for this unicode.
    but if I changed the variable (w) in the following statement from the code:
    PdfPCell cell = new PdfPCell(new Phrase(w,f2));
    and put this string "\u0030\u0039\u0061\u0041" instead of it
    it will store the equivalent word for this unicode in the PDF file.
    what can I do now?
    and what is the problem in my code?
    is there any improvments can I do it ?
    please help
    Message was edited by:
    ahd292000

  • CALL TRANSFORMATION on Unicode WebAS 6.20: No valid source context supplied

    Hello,
    in the last day's I was stuck into a strange problem. I had to develop a Web Service Client on our Web AS 6.20 Unicode system. I followed the Blog <a href="/people/durairaj.athavanraja/blog/2004/09/20/consuming-web-service-from-abap">Consuming Web Service from ABAP</a>. The problem was that my CALL TRANSFORMATION always throwed an exception "No valid source context supplied". I've tested the transformation with a local copy of the XML the Web Service returned and it works quite well. I had a look into the Documentaion of CALL TRANSFORMATION and it says:
    == Documentation Quote Begin ==
    Addition 3a
    ... SOURCE  XML sxml
    Effect
    Specification of the transformation source
    Transfer the XML document sxml using addition 3a. The following three possibilities exist for specifiying sxml:
    The XML document can be in an ABAP variable sxml of the type STRING or XSTRING or in an internal standard table sxml of the elementary line type C.
    == Documentation Quote End ==
    So there should be no difference between STRING and XSTRING. But there is a difference! Here is my testcase which I've derived from my Blog <a href="/people/gregor.wolf3/blog/2006/06/27/geocode-business-partner-with-google-maps">Geocode Business Partner with Google Maps</a>:
    <b>XSLT Transformation - ZGOOGLE_GEOCODE_TO_ABAP</b>
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asx="http://www.sap.com/abapxml" xmlns:kml="http://earth.google.com/kml/2.0" version="1.0">
      <xsl:template match="/">
        <asx:abap version="1.0">
          <asx:values>
            <GEOCODE>
              <LON>
                <xsl:value-of select="substring-before(kml:kml/kml:Response/kml:Placemark/kml:Point/kml:coordinates,',')"/>
              </LON>
              <LAT>
                <xsl:value-of select="substring-before(substring-after(kml:kml/kml:Response/kml:Placemark/kml:Point/kml:coordinates,','),',')"/>
              </LAT>
              <ALT>
                <xsl:value-of select="substring-after(substring-after(kml:kml/kml:Response/kml:Placemark/kml:Point/kml:coordinates,','),',')"/>
              </ALT>
            </GEOCODE>
          </asx:values>
        </asx:abap>
      </xsl:template>
    </xsl:transform>
    <b>ABAP Report</b>
    REPORT  z_gw_test_geocode.
    DATA:
    BEGIN OF geocode,
      lon TYPE string,
      lat TYPE string,
      alt TYPE string,
    END OF geocode.
    DATA: client TYPE REF TO if_http_client,
           url TYPE string,
           c_xml TYPE string,
           x_xml type xstring.
    * Build URL to call Googe Maps Geocoding
    CONCATENATE 'http://maps.google.com/maps/geo?'
      'q=Tacherting,+DE'
      '&output=xml'
      '&key=ABQIAAAA2WL-mG7HpdSjlxystL3uBhRvBuAcdiWwcJAQgt9kNvfse-yNqBQuxwHkHo31WjTJ_RzVPIhXNludVg'
      INTO url.
    ****Create the HTTP client
    CALL METHOD cl_http_client=>create_by_url
      EXPORTING
        url    = url
      IMPORTING
        client = client
      EXCEPTIONS
        OTHERS = 1.
    client->send( ).
    client->receive( ).
    ****Get the response content in Character format
    c_xml = client->response->get_cdata( ).
    ****Get the response content as Binary
    x_xml = client->response->get_data( ).
    ****Transform XML as String to ABAP Values
    DATA: xslt_err TYPE REF TO cx_xslt_exception,
          error_text TYPE string.
    WRITE: / 'Transformation with STRING'.
    TRY.
        CALL TRANSFORMATION zgoogle_geocode_to_abap
        SOURCE XML c_xml
        RESULT geocode = geocode.
      CATCH cx_xslt_exception INTO xslt_err.
        error_text = xslt_err->get_text( ).
        WRITE: / error_text.
    ENDTRY.
    WRITE: / 'LON: ', geocode-lon.
    WRITE: / 'LAT: ', geocode-lat.
    WRITE: / 'ALT: ', geocode-alt.
    ****Transform XML as XString to ABAP Values
    WRITE: / 'Transformation with XSTRING'.
    TRY.
        CALL TRANSFORMATION zgoogle_geocode_to_abap
        SOURCE XML x_xml
        RESULT geocode = geocode.
      CATCH cx_xslt_exception INTO xslt_err.
        error_text = xslt_err->get_text( ).
        WRITE: / error_text.
    ENDTRY.
    WRITE: / 'LON: ', geocode-lon.
    WRITE: / 'LAT: ', geocode-lat.
    WRITE: / 'ALT: ', geocode-alt.
    <b>Result</b>
    This is the result on our 6.20 Unicode System:
    Transformation with STRING
    No valid source context supplied
    LON:
    LAT:
    ALT:
    Transformation with XSTRING
    LON:  12.570504
    LAT:  48.078269
    ALT:  0
    I've tried it on our 6.20 and 6.40 NON-Unicode systems and the result was:
    Transformation with STRING
    LON:  12.570504
    LAT:  48.078269
    ALT:  0
    Transformation with XSTRING
    LON:  12.570504
    LAT:  48.078269
    ALT:  0
    Finaly I've tried it on our Solutin Manager 4.0 which runs on Web AS 7.00 and is also a Unicode installation. Here the result is correct:
    Transformation with STRING
    LON:  12.570504
    LAT:  48.078269
    ALT:  0
    Transformation with XSTRING
    LON:  12.570504
    LAT:  48.078269
    ALT:  0
    So now what to do? I've found nothing in OSS regarding this behaviour. Any tips? I also try a OSS Message.
    Regards
    Gregor

    Hi,
    Can you tell me about your project on short notes. For information.
    Regards
    R.Rajendran

  • Webservice returning string (but I need XML for XSLT Tranformation)

    Hello everybody,
    I have configured an ip with a webservice. So far so good - everything works fine.
    Now I want to transform the output of the webservice with xslt. The webservice returns the data as a String in form of XML.
    e.g.
        <!XML>
    <!String>
    <!String> </b>
    </Bill> <!XML>
    But XSLT don't find e.g the node , because it is a String. I think the right way is first to transform the String into XML. I tried this step with Java with the method
    public void execute(InputStream inputStream, OutputStream outputStream)
            throws StreamTransformationException {
    but it doesn't work. I am not sure, if this is the right way.I have searched for a code sample, but I didn't find anything.
    What do you think?
    Do you have a code sample?
    This would be great!
    Best regards,
    Jürgen

    Hello Bhavesh,
    thx very much for your help.
    Here is my Java Mapping:
    public class ModusLebenTransformation implements StreamTransformation
    public static byte[] readStream(InputStream in, boolean close)
        throws IOException
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int c = in.read();
        while (c > -1)
            out.write(c);
            c = in.read();
        out.flush();
        byte[] result = out.toByteArray();
        out.close();
        if (close)
            in.close();
        return result;
    public void setParameter(Map map) {
    public void execute(InputStream inputStream, OutputStream outputStream)
            throws StreamTransformationException {
       try {
    TransformerFactory tFactory = TransformerFactory.newInstance();
                Transformer transformer = tFactory.newTransformer();
       StreamResult result = new StreamResult(outputStream);
    String input = new String(readStream(inputStream,true));
    transformer.transform(new StreamSource(input), result);      
      } catch (Exception e) {
                 throw new StreamTransformationException("Mapping failed", e);
    But I don't know if this code is enough to convert the String( from the webservice) into XML.
    And then I would like to use XSLT for transformation in a new mapping step.
    Do you think this is possible?
    Do you have a code sample, that will tranform the String (from the webservice) into XML?
    This would be very helpful!
    regards,
    Jürgen

  • Key from a String

    Hi to all,
    i have a big problem.
    I must set an RSA key value (Modulus and Exponent) from a String conteining the encrypted value
    ( for example :hVqLzLgUeZTxQ95UdJDTpIwbf6F7v.... ).
    Is possible to do this ?
    I didn't found classes and method to do this from the API.
    Somebody can help me?
    thank you!

    ghstark wrote:
    z4c4gn0 wrote:
    Hi to all,
    i have a big problem.
    I must set an RSA key value (Modulus and Exponent) from a String conteining the encrypted value
    ( for example :hVqLzLgUeZTxQ95UdJDTpIwbf6F7v.... ). Is possible to do this ?
    I didn't found classes and method to do this from the API.
    Somebody can help me?
    I cannot offer much help without more clarifying details, though perhaps others can deduce what you need. Just from the little you have written, I might guess that you have a base64 encoded (*not* encrypted) string or strings containing the RSA modulus and exponent. In that case, I know sabre150 has shown what to do, so search this forum for posts containing keywords "XML " and "RSA". Also, examine the class http://java.sun.com/javase/6/docs/api/java/security/spec/RSAPublicKeySpec.html as well as the base64 decoders from the jakarta commons codex classes.
    I must get the keyinfo from an XML Signed file, and use this parameters for sign another one, so
    i have my class that return the String value of RSA Module and Exponent parsed.
    Now i need to sign using this parameters, and i tried the RSAPublicKeySpec that you said
    in this way:
    String mod="blablalba"; //the string module parsed
    String exp ="blablalba"; //the string exponend parsed
    byte [] modbyte=mod.getBytes();
    byte [] expbyte=exp.getBytes();
    BigInteger modulus = new BigInteger(modbyte);
    BigInteger publicExponent =new BigInteger(expbyte);
    System.out.println(exp+" = "+publicExponent);
    System.exit(0);
    RSAPublicKeySpec keySpec = new RSAPublicKeySpec(modulus, publicExponent);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    RSAPublicKey pk = (RSAPublicKey)keyFactory.generatePublic(keySpec);
    that's work but don't return the right value of parameters, because Transform the strings in BigInteger.
    What can i do?
    thanks

  • Transformer.transform  - xml transformation

    Hi all,
    I'd like to transform a string in XML format (i.e String testXML = "<test><option>red</option></test>") using an xslt.
    I can do something similar right now when the xml is a file which I load as a StreamSource into the TransformerFactory.
    example of javax transformerFactory:
    transformer.transform(new StreamSource("test.xml"), new StreamResult(new FileOutputStream("resutl.xml")));
    However, right now I construct the XML from the DB and store it as a string. I'd like to transform this string right away. I don't want to store it in a file first and then transform it.
    Does anyone have an example or a solution for this? Any and all help is appreciated.
    Thanks,
    Nik

    ie:
    StreamSource s = new StreamSource(new StringReader(myString));

  • Unicode to ASCII transform...

    I write a little class the transforma Unicode string into an ASCII one.
    it works good if i don't use char as ?, ?, ?, ?, ? and i dont'know how i can solve the problem. the code i write is this:
    [tt]public class Unicode2ASCII{
      public static void main(String argv[]){
        String s = argv[0];
        byte b[] = null;
        b = s.getBytes();
        for(int i=0; i<b.length; i++){
          System.out.print(b[i] + " ");
        System.out.println();
        System.out.println("====");
        try{
          s = new String(b, "ASCII");   
          System.out.println(s);
          System.out.println("====");
          for(int h=0; h<s.length(); h++){
            char c = s.charAt(h);
            System.out.print(c + " ");
            System.out.print((int)c % 127);
          System.out.println();
          System.out.println("====");
        }catch (Exception e){
          System.out.println(e);
    }[tt]

    You may not store a string as ASCII values.
    Any string you create is stored in Unicode.
    The first 128 elements of Unicode are the same as ASCII.
    If you want the ASCII representation of the letter "a", then:
    System.out.println( java.lang.Character().getNumericValue( 'a' ) );
    As DrClap said, there is no reason to save a string in ASCII format since it will be saved in unicode format and thus Java already knows what the ASCII values will be.
    If you want to output a string in ASCII format, do it like this:
    public Vector convert( String input ) {
    StringBuffer tmpIn = new StringBuffer( input );
    Vector tmpOut = new Vector
    for ( int index = 0; index < tmpIn.length; index++ ) {
    char tmpCharacter = tmpIn[ index ];
    int tmpValue = java.lang.Character().getNumbericValue( tmpCharacter ) );
    tmpOut.addElement( tmpValue );
    return tmpOut;
    And then display each element as you see fit.
    Fixing the bugs in this code is an exercise for the reader. If you want to do something like this, you should be thinking about why you want to do this as well as how to do this.

  • Re: String data type

    the string scalar type doesn't have that functionality, but if you use a
    TextData it has the methods you are looking for.
    Anthony N wrote:
    >
    Hi
    Is there a built-in function/method to perform substring on an input
    string?
    If there is no such method, what is the quick and easy way to do
    substring on a string?
    Thanks
    Anthony
    Do You Yahoo!?
    Get your free @yahoo.com address at http://mail.yahoo.com
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>--
    Paul Monax
    Senior Consultant
    Sage IT Partners
    303.779.3309 x204
    [email protected]
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    There is a Std FM RFC_GET_TABLE_ENTRIES available to read the entries using the RFC destination. This FM returns the output in the flat structure. You need to transform this flat structure to your specific structure.
    You mentioned:
    PS: I know I could transform each DB field into a String, transfer it via RFC, and then re-transform this String back into the original data type. However, I would like to avoid this data transformation if possible.
    What are the reasons you want to avoid this?
    Regards,
    Naimesh Patel

  • How to replace a string in a text file?

    Hi All,
    i read one text file and based on that i replaced the old character with the new string but it doesnt works.do any one of you have idea on this?
    My Code:
    String newPassword=(String) getInputText1().getValue();
    String password=(String)getSimNo().getValue();
    String sampleText = (String) getMobileNo().getValue();
    FileReader fr =new FileReader("c:/newLogin.txt");
    BufferedReader br =new BufferedReader(fr);
    String record=br.readLine();
    while (record !=null)
    String[] afterSplit=record.split(":");
    for (int p = 0; p < 1; p++) {
    String userName=afterSplit[1];
    String passWord=afterSplit[3];
    if(userText.equals(userName) && password.equals(passWord)) {
    passWord.replaceAll(passWord,newPassword);
    System.out.println("password: " + password +" changed to : "+ newPassword +" successfully");
    record =br.readLine();
    sample fiile in the text:
    userName:sebas:password:navin
    userName:sebas1:password:navin1

    All readLine does is copy a line of the file into a local variable. Change the copy as you will, the file won't change.
    You need to write a new version of the file, with the altered lines. Then, if required, you can delete the original file and rename the new file to the old file name.

Maybe you are looking for