<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Java or XSLT mapping suits this requirement in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615404#M148989</link>
    <description>&lt;P&gt;Hi Ramu!&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;public class StringReplacer extends AbstractTransformation {
@Override
public void transform(TransformationInput in, TransformationOutput out)throws StreamTransformationException {
executeMapping(in.getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream());
}

public void executeMapping(InputStream is, OutputStream os) throws StreamTransformationException {
try {
byte[] payloadBytes = getByteArrayFromInputStream(is);
String payloadString = new String(payloadBytes, "UTF-8");
payloadString = payloadString.replaceAll("&amp;lt;", "&amp;lt;").replaceAll("&amp;gt;", "&amp;gt;");
os.write(payloadString.getBytes("UTF-8"));
}
catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}

public byte[] getByteArrayFromInputStream(InputStream is) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1)
  buffer.write(data, 0, nRead);
buffer.flush();
is.close();
return buffer.toByteArray();
}
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Editor changes the representation of symbols, so, you should use your source values for "&amp;lt;" and "&amp;gt;" as the first argument in both replaceAll() methods.&lt;/P&gt;
  &lt;P&gt;Regards, Evgeniy.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Apr 2018 09:13:54 GMT</pubDate>
    <dc:creator>former_member190293</dc:creator>
    <dc:date>2018-04-13T09:13:54Z</dc:date>
    <item>
      <title>Java or XSLT mapping suits this requirement</title>
      <link>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaq-p/615400</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;We have requirement to transform the input &amp;amp; output payload as shown below screen shot where it should parse payload and &lt;STRONG&gt;" &amp;lt; " should be replaced with &amp;lt;&lt;/STRONG&gt; &amp;amp; &lt;STRONG&gt; "&lt;/STRONG&gt; &lt;STRONG&gt;#62 "should be replaced with " &amp;gt; " &lt;/STRONG&gt;.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/128016-req.jpg" /&gt;&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;If you observe the whole xml payload contains &lt;STRONG&gt;ServiceOrder&lt;/STRONG&gt; string with set of characters should be replaced with &amp;lt; infront &amp;amp; &amp;gt; after that string.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Please suggest Java or XSLT mapping suits this requirement.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Thanks.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Ramu.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 14:47:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaq-p/615400</guid>
      <dc:creator>ramu_g4</dc:creator>
      <dc:date>2018-04-12T14:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Java or XSLT mapping suits this requirement</title>
      <link>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615401#M148986</link>
      <description>&lt;P&gt;I would try with XSLT first.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 16:08:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615401#M148986</guid>
      <dc:creator>che_eky</dc:creator>
      <dc:date>2018-04-12T16:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Java or XSLT mapping suits this requirement</title>
      <link>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615402#M148987</link>
      <description>&lt;P&gt;Hi Ramu!&lt;/P&gt;
  &lt;P&gt;I would read payload into string using java mapping and simply call replaceAll() method.&lt;/P&gt;
  &lt;P&gt;Regards, Evgeniy.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 18:22:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615402#M148987</guid>
      <dc:creator>former_member190293</dc:creator>
      <dc:date>2018-04-12T18:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Java or XSLT mapping suits this requirement</title>
      <link>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615403#M148988</link>
      <description>&lt;P&gt;Hi Evgeniy,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Thank you for your response.&lt;/P&gt;
  &lt;P&gt;Can you help with Java mapping code to read the payload &amp;amp; use replaeAll() method to achieve this requirement so that I can export the java code as jar file &amp;amp; import it.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Thanks,&lt;/P&gt;
  &lt;P&gt;Ramu.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 07:39:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615403#M148988</guid>
      <dc:creator>ramu_g4</dc:creator>
      <dc:date>2018-04-13T07:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Java or XSLT mapping suits this requirement</title>
      <link>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615404#M148989</link>
      <description>&lt;P&gt;Hi Ramu!&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;public class StringReplacer extends AbstractTransformation {
@Override
public void transform(TransformationInput in, TransformationOutput out)throws StreamTransformationException {
executeMapping(in.getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream());
}

public void executeMapping(InputStream is, OutputStream os) throws StreamTransformationException {
try {
byte[] payloadBytes = getByteArrayFromInputStream(is);
String payloadString = new String(payloadBytes, "UTF-8");
payloadString = payloadString.replaceAll("&amp;lt;", "&amp;lt;").replaceAll("&amp;gt;", "&amp;gt;");
os.write(payloadString.getBytes("UTF-8"));
}
catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}

public byte[] getByteArrayFromInputStream(InputStream is) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1)
  buffer.write(data, 0, nRead);
buffer.flush();
is.close();
return buffer.toByteArray();
}
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;Editor changes the representation of symbols, so, you should use your source values for "&amp;lt;" and "&amp;gt;" as the first argument in both replaceAll() methods.&lt;/P&gt;
  &lt;P&gt;Regards, Evgeniy.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 09:13:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615404#M148989</guid>
      <dc:creator>former_member190293</dc:creator>
      <dc:date>2018-04-13T09:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Java or XSLT mapping suits this requirement</title>
      <link>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615405#M148990</link>
      <description>&lt;P&gt;Hi Evgeniy,&lt;/P&gt;
  &lt;P&gt;Regarding this line payloadString = payloadString.replaceAll("&amp;lt;", "&amp;lt;").replaceAll("&amp;gt;", "&amp;gt;");&lt;/P&gt;
  &lt;P&gt;should it corrected to achieve my requirement to replace &amp;lt; with "&amp;lt;" and to replace &amp;gt; with "&amp;gt;" .&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;payloadString = payloadString.replaceAll("&amp;lt;", "&amp;lt;") ;&lt;/P&gt;
  &lt;P&gt;payloadString = payloadString.replaceAll("&amp;gt;", "&amp;gt;") ;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Thanks,&lt;/P&gt;
  &lt;P&gt;Ramu.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 11:17:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615405#M148990</guid>
      <dc:creator>ramu_g4</dc:creator>
      <dc:date>2018-04-13T11:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Java or XSLT mapping suits this requirement</title>
      <link>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615406#M148991</link>
      <description>&lt;P&gt;Hi Ramu!&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/126972-replacestring-jm01.png" /&gt;&lt;/P&gt;
  &lt;P&gt;Regards, Evgeniy.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 15:26:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/java-or-xslt-mapping-suits-this-requirement/qaa-p/615406#M148991</guid>
      <dc:creator>former_member190293</dc:creator>
      <dc:date>2018-04-13T15:26:52Z</dc:date>
    </item>
  </channel>
</rss>

