java mapping issue
Hi
I am following http://www.riyaz.net/blog/xipi-java-mapping-demystified/technology/sap/415/
and have written a sample java mapping code...but am getting the error " XML not welformed " content not allowed in prolog while testing the Operation mapping...
what may be the issue ??
package jmapsax;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.sap.aii.mapping.api.StreamTransformation;
import java.io.*;
import java.util.Map;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
public class saxmapfinal1 extends DefaultHandler implements StreamTransformation{
private Map map;
private OutputStream out;
private boolean input1 = false;
private boolean input2 = false;
private int number1;
private int number2;
private int addvalue;
private int mulvalue;
private int subvalue;
String lineEnd = System.getProperty("line.separator");
public void setParameter (Map param) {
map = param;
}
public void execute (InputStream in, OutputStream out)
throws com.sap.aii.mapping.api.StreamTransformationException {
DefaultHandler handler = this;
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
SAXParser saxParser = factory.newSAXParser();
this.out = out;
saxParser.parse(in, handler);
}
catch (Throwable t){
t.printStackTrace();
}
}
private void write (String s) throws SAXException{
try{
out.write(s.getBytes());
out.flush();
}
catch (IOException e){
throw new SAXException("I/O error", e);
}
}
public void startDocument () throws SAXException{
write("");
write(lineEnd);
write("");
write(lineEnd);
}
public void endDocument () throws SAXException {
write("");
try { out.flush();
}
catch (IOException e) {
throw new SAXException("I/O error", e);
}
}
public void startElement (String namespaceURI, String sName,
String qName, Attributes attrs) throws SAXException {
String eName = sName;
if ("".equals(eName)) eName = qName;
if(eName.equals("NUMBER1")) input1 = true;
if(eName.equals("NUMBER2")) input2 = true;
}
public void endElement (String namespaceURI, String sName, String qName) throws SAXException {
String eName = sName;
if ("".equals(eName)) eName = qName;
if(eName.equals("NUMBER1")) input1 = false;
if(eName.equals("NUMBER2")) input2 = false;
}
public void characters(char[] chars,int startIndex, int endIndex) throws SAXException {
String dataString =
new String(chars, startIndex, endIndex).trim();
if (input1) {
try {
number1 = Integer.parseInt(dataString);
} catch(NumberFormatException nfe){
}
}
if (input2) {
number2 = Integer.parseInt(dataString);
}
if (input2 == true){
addvalue = number1 + number2;
mulvalue = number1 * number2;
subvalue = number1 - number2;
write("" + addvalue +"");
write(lineEnd);
write("" + mulvalue +"");
write(lineEnd);
write("" + subvalue +"");
write(lineEnd);
}
}
}
Edited by: Tarang Shah on Jun 4, 2011 8:17 PM