KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_forms > FileLoadData


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

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 JavaDoc _filename, boolean _firstLineHeads, String JavaDoc _format, FieldProvider[] _data) throws IOException {
34       super(_vars, _filename, _firstLineHeads, _format, _data);
35     }
36
37     public FileLoadData(VariablesBase _vars, String JavaDoc _filename, boolean _firstLineHeads, String JavaDoc _format) throws IOException {
38       super(_vars, _filename, _firstLineHeads, _format, null);
39     }
40
41     public FieldProvider lineSeparatorFormated(String JavaDoc 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 JavaDoc 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 JavaDoc textAux = new String JavaDoc(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 JavaDoc e) {
71             log4j.warn("File.load: " + e);
72         }
73         anterior=siguiente+1;
74       }
75       return fileLoadData;
76     }
77
78   }
79
Popular Tags