| 1 19 package org.openbravo.erpCommon.ad_forms; 20 21 import org.openbravo.data.FieldProvider; 22 import org.openbravo.base.MultipartRequest; 23 import java.io.*; 24 import org.apache.log4j.Logger; 25 import org.openbravo.base.VariablesBase; 26 27 public class FileLoadData extends MultipartRequest { 28 static Logger log4j = Logger.getLogger(FileLoadData.class); 29 30 public FileLoadData() { 31 } 32 33 public FileLoadData(VariablesBase _vars, String _filename, boolean _firstLineHeads, String _format, FieldProvider[] _data) throws IOException { 34 super(_vars, _filename, _firstLineHeads, _format, _data); 35 } 36 37 public FileLoadData(VariablesBase _vars, String _filename, boolean _firstLineHeads, String _format) throws IOException { 38 super(_vars, _filename, _firstLineHeads, _format, null); 39 } 40 41 public FieldProvider lineSeparatorFormated(String linea) { 42 if (linea == null || linea.length() < 1) return null; 43 FileLoadData fileLoadData = new FileLoadData(); 44 int siguiente=0; 45 int anterior=0; 46 String texto=""; 47 while (siguiente<linea.length()) { 48 siguiente=linea.indexOf( format,siguiente+1); 49 if (siguiente==-1) siguiente=linea.length(); 50 texto = linea.substring(anterior,siguiente); 51 if (texto.length()>0) { 52 if (texto.charAt(0)=='"'){ 53 texto = texto.substring(1); 54 if (texto.charAt(texto.length()-1)=='"'){ 55 texto=texto.substring(0,texto.length()-1); 56 }else{ 57 anterior=siguiente+1; 58 siguiente=linea.indexOf( "\"",siguiente+1); 59 if (siguiente==-1) siguiente=linea.length(); 60 texto = texto + format + linea.substring(anterior, siguiente); 61 siguiente = siguiente +1; 62 } 63 } 64 } 65 try 66 { 67 String textAux = new String (texto.getBytes(System.getProperty("file.encoding")),"UTF-8"); 68 if (log4j.isDebugEnabled()) log4j.debug("FileLoadData - setFieldProvider - text = " + textAux); 69 fileLoadData.addField(textAux); 70 } catch(Exception e) { 71 log4j.warn("File.load: " + e); 72 } 73 anterior=siguiente+1; 74 } 75 return fileLoadData; 76 } 77 78 } 79 | Popular Tags |