on 12-10-2013 3:57 PM
Hi All,
I have a file with the following format (i.e. as shown below) to process in my interface and this has each field in one line and end of each record is indicated with carriage return as shown below.The number of fields coming in each record are not static and they change for each record.I need to identify the start for a new record only with carriage return.Please help me out if this is possible with FCC or not.Please suggest me the best way to do this through Java Mapping or through a Custom Module. Sample file is attached.::
field1
field2
field3
....
.....
....
fieldn
<carriage return>
field1
field2
field3
.....
.....
fieldn
<carriage return>
field1
field2
field3
.....
.....
fieldn
<carriage return>
Hi Indrajit,
I have a written a java program for reading the text file and converting it to XML but in the File adapter it expects the FCC parameters to read the text file.
I am not sure about the parameters that are to be mentioned in FCC as I wanted to read to the entire text file into my Java Mapping program.
Please suggest.
You can find my Java Mapping Program below::
package costInterface;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import java.io.InputStream;
import com.sap.aii.mapping.api.*;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import org.w3c.dom.views.AbstractView;
public class CreateXML {
public void transform(InputStream arg0, OutputStream arg1)
throws StreamTransformationException, TransformerException, ParserConfigurationException, DOMException, IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(arg0));
String inputLine = null;
ArrayList<String> records = new ArrayList<String>();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element empsRootEle = doc.createElement("MT_CostInterfaceFromLegacy");
while((inputLine = br.readLine()) != null ){
if (inputLine.equals("")){
System.out.println("This is my carraige return " + inputLine);
// Parse XMl file to get the records
Element empEle = doc.createElement("EMPLOYEES");
Element currency = doc.createElement("CURRECY");
Element date = doc.createElement("DATE");
Element costNumber = doc.createElement("COSTNUMBER");
Element index = doc.createElement("INDEX");
Element t1 = doc.createElement("T1");
Element price = doc.createElement("PRICE");
Element sNo = doc.createElement("SNO");
Element t2 = doc.createElement("T2");
Element t3 = doc.createElement("T3");
Element number = doc.createElement("NUMBER");
Element t4 = doc.createElement("T4");
Element t5 = doc.createElement("T5");
Element t6 = doc.createElement("T6");
Element t7 = doc.createElement("T7");
Element t8 = doc.createElement("T8");
Element desc1 = doc.createElement("DESC1");
Text currentText = null; Text dateText = null; Text costNumberText = null;
Text indexText = null; Text t1Text = null; Text priceText = null;
Text sNoText = null; Text t2Text = null; Text t3Text = null;
Text numberText = null; Text t4Text = null; Text t5Text = null;
Text t6Text = null; Text t7Text = null; Text t8Text = null;
Text desc1Text = null;
if(records.size()>14){
currentText = doc.createTextNode(records.get(0));
dateText = doc.createTextNode(records.get(1));
costNumberText = doc.createTextNode(records.get(2));
indexText = doc.createTextNode(records.get(3));
t1Text = doc.createTextNode(records.get(4));
priceText = doc.createTextNode(records.get(5));
sNoText = doc.createTextNode(records.get(6));
t2Text = doc.createTextNode(records.get(7));
t3Text = doc.createTextNode(records.get(8));
numberText = doc.createTextNode(records.get(9));
t4Text = doc.createTextNode(records.get(10));
t5Text = doc.createTextNode(records.get(11));
t6Text = doc.createTextNode(records.get(12));
t7Text = doc.createTextNode(records.get(13));
t8Text = doc.createTextNode(records.get(14));
String S = "";
for (int j = 15; j<records.size(); j++){
S = S + records.get(j) + " ";
}
desc1Text = doc.createTextNode(S);
} else if (records.size()<=14){
currentText = doc.createTextNode(records.get(0));
dateText = doc.createTextNode(records.get(1));
costNumberText = doc.createTextNode(records.get(2));
indexText = doc.createTextNode(records.get(3));
t1Text = doc.createTextNode(records.get(4));
priceText = doc.createTextNode(records.get(5));
sNoText = doc.createTextNode(records.get(6));
t2Text = doc.createTextNode(records.get(7));
t3Text = doc.createTextNode(records.get(8));
numberText = doc.createTextNode(records.get(9));
t4Text = doc.createTextNode(records.get(10));
t5Text = doc.createTextNode(records.get(11));
t6Text = doc.createTextNode(records.get(12));
t7Text = doc.createTextNode(records.get(13));
t8Text = doc.createTextNode(records.get(14));
}
currency.appendChild(currentText);
date.appendChild(dateText);
costNumber.appendChild(costNumberText);
index.appendChild(indexText);
t1.appendChild(t1Text);
price.appendChild(priceText);
sNo.appendChild(sNoText);
t2.appendChild(t2Text);
t3.appendChild(t3Text);
number.appendChild(numberText);
t4.appendChild(t4Text);
t5.appendChild(t5Text);
t6.appendChild(t6Text);
t7.appendChild(t7Text);
t8.appendChild(t8Text);
desc1.appendChild(desc1Text);
empEle.appendChild(currency);
empEle.appendChild(date);
empEle.appendChild(costNumber);
empEle.appendChild(t1);
empEle.appendChild(price);
empEle.appendChild(sNo);
empEle.appendChild(t2);
empEle.appendChild(t3);
empEle.appendChild(number);
empEle.appendChild(t4);
empEle.appendChild(t5);
empEle.appendChild(t6);
empEle.appendChild(t7);
empEle.appendChild(t8);
empEle.appendChild(desc1);
empsRootEle.appendChild(empEle);
records.clear();
} else {
records.add(inputLine);
}
//System.out.println("This is not my carraige return" + inputLine);
}
if(records.iterator().hasNext()){
Element empEle = doc.createElement("EMPLOYEES");
Element currency = doc.createElement("CURRECY");
Element date = doc.createElement("DATE");
Element costNumber = doc.createElement("COSTNUMBER");
Element index = doc.createElement("INDEX");
Element t1 = doc.createElement("T1");
Element price = doc.createElement("PRICE");
Element sNo = doc.createElement("SNO");
Element t2 = doc.createElement("T2");
Element t3 = doc.createElement("T3");
Element number = doc.createElement("NUMBER");
Element t4 = doc.createElement("T4");
Element t5 = doc.createElement("T5");
Element t6 = doc.createElement("T6");
Element t7 = doc.createElement("T7");
Element t8 = doc.createElement("T8");
Element desc1 = doc.createElement("DESC1");
Text currentText = null; Text dateText = null; Text costNumberText = null;
Text indexText = null; Text t1Text = null; Text priceText = null;
Text sNoText = null; Text t2Text = null; Text t3Text = null;
Text numberText = null; Text t4Text = null; Text t5Text = null;
Text t6Text = null; Text t7Text = null; Text t8Text = null;
Text desc1Text = null;
if(records.size()>14){
currentText = doc.createTextNode(records.get(0));
dateText = doc.createTextNode(records.get(1));
costNumberText = doc.createTextNode(records.get(2));
indexText = doc.createTextNode(records.get(3));
t1Text = doc.createTextNode(records.get(4));
priceText = doc.createTextNode(records.get(5));
sNoText = doc.createTextNode(records.get(6));
t2Text = doc.createTextNode(records.get(7));
t3Text = doc.createTextNode(records.get(8));
numberText = doc.createTextNode(records.get(9));
t4Text = doc.createTextNode(records.get(10));
t5Text = doc.createTextNode(records.get(11));
t6Text = doc.createTextNode(records.get(12));
t7Text = doc.createTextNode(records.get(13));
t8Text = doc.createTextNode(records.get(14));
String S = "";
for (int j = 15; j<records.size(); j++){
S = S + records.get(j) + " ";
}
desc1Text = doc.createTextNode(S);
} else if (records.size()<=14){
currentText = doc.createTextNode(records.get(0));
dateText = doc.createTextNode(records.get(1));
costNumberText = doc.createTextNode(records.get(2));
indexText = doc.createTextNode(records.get(3));
t1Text = doc.createTextNode(records.get(4));
priceText = doc.createTextNode(records.get(5));
sNoText = doc.createTextNode(records.get(6));
t2Text = doc.createTextNode(records.get(7));
t3Text = doc.createTextNode(records.get(8));
numberText = doc.createTextNode(records.get(9));
t4Text = doc.createTextNode(records.get(10));
t5Text = doc.createTextNode(records.get(11));
t6Text = doc.createTextNode(records.get(12));
t7Text = doc.createTextNode(records.get(13));
t8Text = doc.createTextNode(records.get(14));
}
currency.appendChild(currentText);
date.appendChild(dateText);
costNumber.appendChild(costNumberText);
index.appendChild(indexText);
t1.appendChild(t1Text);
price.appendChild(priceText);
sNo.appendChild(sNoText);
t2.appendChild(t2Text);
t3.appendChild(t3Text);
number.appendChild(numberText);
t4.appendChild(t4Text);
t5.appendChild(t5Text);
t6.appendChild(t6Text);
t7.appendChild(t7Text);
t8.appendChild(t8Text);
desc1.appendChild(desc1Text);
empEle.appendChild(currency);
empEle.appendChild(date);
empEle.appendChild(costNumber);
empEle.appendChild(t1);
empEle.appendChild(price);
empEle.appendChild(sNo);
empEle.appendChild(t2);
empEle.appendChild(t3);
empEle.appendChild(number);
empEle.appendChild(t4);
empEle.appendChild(t5);
empEle.appendChild(t6);
empEle.appendChild(t7);
empEle.appendChild(t8);
empEle.appendChild(desc1);
empsRootEle.appendChild(empEle);
}
doc.appendChild(empsRootEle);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t;
t = tf.newTransformer();
DOMSource docObj = new DOMSource(doc);
StreamResult sr = new StreamResult(new OutputStreamWriter(arg1));
t.transform(docObj, sr);
System.out.println("XML File is created");
// }
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
>>I have a written a java program for reading the text file and converting it to XML but in the File adapter it expects the FCC parameters to read the text file.
U can certainly pass entire text file as a binary file to java mapping program. Remove FCC from sender file adapter and use any dummy sender structure.
In case u are using ICO then you have to explicitly remove the SWCV entry in the ICO config:
Thanks
Amit Srivastava
Thanks a lot Amit for your reply.
I could able to solve this and by-pass the file without content conversion.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shyam
You can not use new line as a field separator. So it is not possible to convert this file to xml using content conversion.
You can write an adapter module to convert it to xml or you can write an java mapping to read this text file and populate the output structure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Harish,
Thanks a lot for your reply.
I did try with the above paramaters but no luck.
Please find my parameters below::
Employees.endSeparator -------------- '0x0D'
Employees.fieldSeparator ---------------- 'nl'
Employees.fieldNames -------------------- field1,field2......................fieldn
I am not getting the content in the channel after content conversion.
I am seeing blank in the content.
Please suggest.
Thanks
Shyam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shyam,
Please tri with below configuration
Employees.endSeparator -------------- '0x0D"0x0A"'
Employees.fieldSeparator ---------------- 'nl'
Employees.fieldNames -------------------- field1,field2......................fieldn
and also
Employees.endSeparator -------------- '"0x0A"0x0D'
Employees.fieldSeparator ---------------- 'nl'
Employees.fieldNames -------------------- field1,field2......................fieldn
Regards,
Harish
Hi Shyam,
tri with the following setting
Header.endSeparator = '0x0D'
0x0D --> Carriage return
0x0A --> NL line feed, new line
you field separator is 'nl' and end separator is '0x0D'
Regards,
Harish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.