hey thanks reamon,
I feel that i have not made the varaibles in the beow function visible to the shared code…!
the code goes a follows,
[highlight=java] public static void samparser(IData pipeline) throws service exception
//pipeling
IDataCursor idc = pipeline.getCursor();
String fileName = IDataUtil.getString(idc,“file_Name”);
ByteArrayInputStream donneesExcel;
Workbook workbook;
Sheet sheet;
StringBuffer line;
int maxLines ;
donneesExcel = new ByteArrayInputStream(fileData.getBytes());
IDataUtil.put(idc,“fileused”,fileName);
workbook = Workbook.getWorkbook(new File(fileName));
sheet = workbook.getSheet(0);
line = new StringBuffer() ;
maxLines = sheet.getRows() ;
String fileData = parseFileData(sheet,line,maxLine); - is this decleration correct.
return};
and the shared code is
private static String parseFileData(Sheet sheet,StringBuffer line, int maxLines) throws Exception {
List tab = new ArrayList() ;
int curRec = 1 ;
String curLine = “” ;
boolean endLoop = false ;
boolean hrcl = false ;
String cellVal = “” ;
if ( readCell(0,6,false,false).toLowerCase().indexOf(“quality”) >= 0 ) {
hrcl = true ;
} else {
hrcl = false ;
}
while ( !endLoop & curRec < maxLines) {
if ( readCell(curRec,0,false,false).equals(“”) )
endLoop = true ;
else {
line =new StringBuffer();
line.append(“”);
parseCell(“SerialNumber”, curRec,0,false,false ) ;
parseCell(“MaterialID”, curRec,1,false,false ) ;
String dateRes = dateFormat(readCell(curRec,4,false,false));
parseTag(“SwbDate”, dateRes);
String productiondate = dateFormat(readCell(curRec,5,false,false));
parseTag(“ProductionDate”, productiondate);
parseTag(“Date_identification”,productiondate);
if ( hrcl ) {
// HRCL
parseCell(“AnalyseB”, curRec,26,true,true ) ;
parseCell(“AnalyseNb”, curRec,27,true,true) ;
parseCell(“AnalyseV”, curRec,28,true,true ) ;
parseCell(“AnalyseTi”, curRec,29,true,true ) ;
parseCell(“AnalyseN”, curRec,49,true,true);
String flag = uFormat(readCell(curRec,57,false,false));
parseTag(“Comet1Flag”, flag);
} else {
// HDCL
parseCell(“SwbStatus”, curRec,6,false,false ) ;
parseCell(“ShlStatus”, curRec,7,false,false) ;
String flag = uFormat(readCell(curRec,65,false,false));
parseTag(“Comet1Flag”, flag);
//parseCell(“Comet1Flag”, curRec,65,false,false);
}
line.append(“”);
tab.add(line.toString());
curRec ++;
}
}
return (String) tab.toArray( new String[tab.size()] );
}
private static String readCell(int lig, int col, boolean replace, boolean format) throws Exception {
String val ;
Cell c = sheet.getCell(col,lig);
val = ( String ) c.getContents().trim();
if(val != null && replace)
val = val.replace(‘,’, ‘.’);
if (!“”.equals(val) && format)
{try {
java.text.DecimalFormat df = new java.text.DecimalFormat(“######.###”);
if (val.indexOf(“.”) == 0)
val=“0”+val;
val=df.format(val);
}
catch (Throwable e)
{
val=val;
}
}
//if(“”.equals(val) && replace) {
// val = “0”;
//}
return val ;
}
private static void parseCell(String tag,int lig, int col, boolean replace, boolean format) throws Exception {
line.append(“<”+tag+“>”) ;
line.append(normalize(readCell(lig,col, replace, format)));
line.append(“</”+tag+“>”) ;
}
private static String dateFormat(String dateAFormater) throws Exception {
String dateCal = “”;
if(dateAFormater.trim().length() > 0) {
String jour = dateAFormater.substring(0, 2);
String mois = dateAFormater.substring(3, 5);
String annee = dateAFormater.substring(6, 10);
dateCal=annee+mois+jour;
}
return dateCal ;
}
private static String dateHeureFormat(String dateAFormater) throws Exception {
String dateCal = “”;
if(dateAFormater.trim().length() > 0) {
String jour = dateAFormater.substring(0, 2);
String mois = dateAFormater.substring(3, 5);
String annee = dateAFormater.substring(6, 10);
String heure = dateAFormater.substring(11, 20);
dateCal=mois+“/”+jour+“/”+annee+" “+heure ;
}
return dateCal ;
}
private static void parseTag(String tag, String dateRes ) throws Exception {
line.append(”<“+tag+”>“);
line.append(dateRes);
line.append(”</“+tag+”>");
}
private static String uFormat(String flagAFormater) throws Exception {
String flagMAJ = “”;
if(flagAFormater.trim().length() > 0) {
flagMAJ= flagAFormater.toUpperCase();
}
return flagMAJ; }
private static String normalize(String s) throws Exception {
StringBuffer str = new StringBuffer();
int len = (s != null) ? s.length() : 0;
for (int i = 0; i < len; i++) {
char ch = s.charAt(i);
switch (ch) {
case ‘<’ :
{
str.append(“<”);
break;
}
case ‘>’ :
{
str.append(“>”);
break;
}
case ‘&’ :
{
str.append(“&”);
break;
}
case ‘"’ :
{
str.append(“"”);
break;
}
case ‘'’ :
{
str.append(“'”);
break;
}
case ‘\r’ :
case ‘\n’ :
default :
{
str.append(ch);
}
}
}
return str.toString();
}[/highlight]