Skip to Content
Author's profile photo Gagandeep Batra

Adding Carriage Return or Line Feed IN xml FILE using JAVA Mapping through Command Prompt:

Problem Statements:

Adding Carriage Return or Line Feed after tag.

This problem can be solved by using XSLT and Java Mapping I am here define only  through .

JAVA Mapping:

Here I take example of customer balance interface which Proxy to file scenario. And I am not using any java base tool like Eclipse for java or Netweaver Developer Studio. I am using simple java commands using command prompt to execute java file and creating jar file.This blog also explain basics of java mapping.

1.  For Java Mapping first we need “aii_map_api.jar” jar files that can find from various ways

You can check below Wiki for that:

http://wiki.sdn.sap.com/wiki/display/XI/Where+to+get+the+libraries+for+XI+development

I used the last option define there

Copy files from the local cache directory:

C:\Users\BatraG(logon- user)\AppData\LocalLow\Sun\Java\Deployment\cache\javaws\http\DAM001(PISERVER) \P51000\DMrep\DMrepository

File name: RMaii_map_api.jar

You can rename that file to: aii_map_api.jar

  •   I create a file named: AddCRorLF.java with following code.

A simple code is written in java for add Carriage Return or Line Feed after tags.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Map;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import javax.xml.transform.OutputKeys;

import org.w3c.dom.Document;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

public class AddCRorLF implements StreamTransformation{

            public void execute(InputStream in, OutputStream out)

                                    throws StreamTransformationException {

                         try

          {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setNamespaceAware(true);

DocumentBuilder builder = factory.newDocumentBuilder();

Document doc = builder.parse(in);

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer t = tFactory.newTransformer();

t.setOutputProperty(OutputKeys.INDENT, “yes”);

t.transform(new DOMSource(doc), new StreamResult(out));

          }

          catch(Exception e)

          {

e.printStackTrace();

               throw new StreamTransformationException(“Error During Mapping”, e);

          }

            }

            public void setParameter(Map arg0) {

            }

}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  • A time to compile the file.

Put both files in one folder as below:

1.JPG

Commands:

Cd\

Cd d:\gagan

Javac –classpath aii_map_api.jar AddCRorLF.java

After that class file will created.

Then use following command for creating jar file:

Jar cvf  AddCRorLF.jar AddCRorLF.class AddCRorLF.java

2.JPG

Then you can see following file in the folder:

3.JPG

  • Go to Repository part and I have created following Message mapping for Customer Balance:

4.JPG

Right click on imported archive and create new.

5.JPG

Give the name and click on create.

6.JPG

Click on import archive and then select “AddCRorLF.jar” then open.

7.JPG

Following files are uploaded.

71.JPG

Then Save And Activate.

Then Go to Interface Mapping that I have all ready created.

8.JPG

Earlier it is showing like that at test tab all result is coming in one line:

9.JPG

Now add our java mapping after message mapping.

10.JPG

Select our Class

11.JPG

You can see following java mapping added after message mapping

12.JPG

In Test tab.

13.JPG

I hope you enjoyed  this……………….:)

 

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Gagan,

      I appreciate your nice blog.

      It is a nice blog for a beginner to learn java mapping in a simple way   .

      I hope more blogs from you.

      Best Regards

      Raja

      Author's profile photo Former Member
      Former Member
      Author's profile photo Muni M
      Muni M

      Hi Gagan,

      i found this blog very useful for learning java mapping.Good work.

      Regards,

      Muniyappan.

      Author's profile photo Anupam Ghosh
      Anupam Ghosh

      Hi Gagan,

                     I think this technique has been explained earlier in a wiki article.

      http://wiki.sdn.sap.com/wiki/display/XI/Indent+XML+file

      Regards

      Anupam