|
From: <tr...@us...> - 2003-07-19 13:16:50
|
Update of /cvsroot/babeldoc/babeldoc/modules/conversion/src/com/babeldoc/conversion/pipeline/stage
In directory sc8-pr-cvs1:/tmp/cvs-serv25588/src/com/babeldoc/conversion/pipeline/stage
Modified Files:
FlatToXmlPipelineStage.java XlsToXmlPipelineStage.java
Log Message:
Lots of rearrangement of the conversion module - now using dom4j in the flatfile code - moved packages around.
Index: FlatToXmlPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/conversion/src/com/babeldoc/conversion/pipeline/stage/FlatToXmlPipelineStage.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** FlatToXmlPipelineStage.java 27 Jun 2003 01:44:07 -0000 1.5
--- FlatToXmlPipelineStage.java 19 Jul 2003 13:16:47 -0000 1.6
***************
*** 66,73 ****
package com.babeldoc.conversion.pipeline.stage;
! import com.babeldoc.conversion.ConversionClient;
! import com.babeldoc.conversion.ConversionUnmarshaller;
! import com.babeldoc.conversion.digester.DigesterConversionUnmarshaller;
!
import com.babeldoc.core.I18n;
import com.babeldoc.core.option.ConfigOption;
--- 66,72 ----
package com.babeldoc.conversion.pipeline.stage;
! import com.babeldoc.conversion.ConversionHelper;
! import com.babeldoc.conversion.flatfile.FlatFileConverter;
! import com.babeldoc.conversion.flatfile.digester.DigesterConversionUnmarshaller;
import com.babeldoc.core.I18n;
import com.babeldoc.core.option.ConfigOption;
***************
*** 76,82 ****
import java.io.InputStream;
- import java.io.PrintWriter;
- import java.io.StringWriter;
-
import java.util.ArrayList;
import java.util.Collection;
--- 75,78 ----
***************
*** 84,88 ****
/**
! * Pipelinestage to convert the document from a flatfile to an xml document.
* The Rules governing the conversion is supplied as argument. This is the
* merely defers most of the work to the conversion client client.
--- 80,84 ----
/**
! * Pipelinestage to toXml the document from a flatfile to an xml document.
* The Rules governing the conversion is supplied as argument. This is the
* merely defers most of the work to the conversion client client.
***************
*** 135,147 ****
InputStream config = com.babeldoc.core.ResourceLoader.getResourceStream(configFile);
InputStream input = getDocument().getInputStream();
- StringWriter writer = new StringWriter();
-
- ConversionUnmarshaller unmarshaller = new DigesterConversionUnmarshaller(config);
- ConversionClient.doConversion(unmarshaller, input, new PrintWriter(writer));
- writer.flush();
! PipelineDocument newDocument = new PipelineDocument(this.getDocument(),
! writer.toString().getBytes());
! newDocument.setBinary(true);
return processHelper(newDocument);
--- 131,138 ----
InputStream config = com.babeldoc.core.ResourceLoader.getResourceStream(configFile);
InputStream input = getDocument().getInputStream();
! PipelineDocument newDocument = ConversionHelper.render(new FlatFileConverter(
! new DigesterConversionUnmarshaller(config)).toXml(input), this.getDocument());
! newDocument.setBinary(false);
return processHelper(newDocument);
Index: XlsToXmlPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/conversion/src/com/babeldoc/conversion/pipeline/stage/XlsToXmlPipelineStage.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** XlsToXmlPipelineStage.java 18 Jul 2003 11:54:49 -0000 1.2
--- XlsToXmlPipelineStage.java 19 Jul 2003 13:16:47 -0000 1.3
***************
*** 66,86 ****
package com.babeldoc.conversion.pipeline.stage;
! import java.io.IOException;
! import java.util.ArrayList;
! import java.util.Collection;
! import org.apache.poi.hssf.usermodel.HSSFCell;
! import org.apache.poi.hssf.usermodel.HSSFRow;
! import org.apache.poi.hssf.usermodel.HSSFSheet;
! import org.apache.poi.hssf.usermodel.HSSFWorkbook;
! import org.apache.poi.poifs.filesystem.POIFSFileSystem;
! import org.dom4j.Document;
! import org.dom4j.DocumentHelper;
! import org.dom4j.Element;
! import com.babeldoc.core.pipeline.PipelineDocument;
! import com.babeldoc.core.pipeline.PipelineException;
! import com.babeldoc.core.pipeline.PipelineStage;
! import com.babeldoc.core.pipeline.PipelineStageInfo;
! import com.babeldoc.core.pipeline.PipelineStageResult;
/**
--- 66,75 ----
package com.babeldoc.conversion.pipeline.stage;
! import com.babeldoc.conversion.ConversionException;
! import com.babeldoc.conversion.ConversionHelper;
! import com.babeldoc.conversion.excel.ExcelConverter;
! import com.babeldoc.core.pipeline.*;
! import java.util.Collection;
/**
***************
*** 92,95 ****
--- 81,86 ----
public class XlsToXmlPipelineStage extends PipelineStage {
+ public static String DATE_FORMAT = "dd.mm.yyyy";
+
public XlsToXmlPipelineStage() {
super(new PipelineStageInfo() {
***************
*** 103,211 ****
public Collection getTypeSpecificOptions() {
! return new ArrayList();
}
});
-
}
! /* (non-Javadoc)
! * @see com.babeldoc.core.pipeline.PipelineStage#process()
*/
! public PipelineStageResult[] process() throws PipelineException {
- POIFSFileSystem fs;
try {
! fs = new POIFSFileSystem(this.getDocument().getInputStream());
! HSSFWorkbook wb = new HSSFWorkbook(fs);
!
! HSSFSheet sheet = null;
! HSSFRow row = null;
! HSSFCell cell = null;
!
! Document document = DocumentHelper.createDocument();
! //
! Element root = document.addElement("workbook");
!
! int numberOfSheets = wb.getNumberOfSheets();
! root.addAttribute(
! "number-of-sheets",
! String.valueOf(numberOfSheets));
!
! for (int i = 0; i < numberOfSheets; i++) {
! Element sheetElement = root.addElement("sheet");
! sheet = wb.getSheetAt(i);
! String sheetName = wb.getSheetName(i);
! sheetElement.addAttribute("name", sheetName);
! sheetElement.addAttribute(
! "sheet-number",
! (new Integer(i)).toString());
! int rowCount = 0;
! int firstRowNum = sheet.getFirstRowNum();
! int lastRowNum = sheet.getLastRowNum();
!
! for (int m = firstRowNum; m <= lastRowNum; m++) {
! row = sheet.getRow(m);
! if (row == null)
! continue;
! Element rowElement = sheetElement.addElement("row");
! rowElement.addAttribute(
! "rowNum",
! (new Integer(m)).toString());
! rowCount++;
! int firstCellNum = row.getFirstCellNum();
! int lastCellNum = row.getLastCellNum();
! int cellCount = 0;
! for (int p = firstCellNum; p <= lastCellNum; p++) {
! cell = row.getCell((short) p);
! // if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) continue;
! if (cell == null)
! continue;
! cellCount++;
! Element cellElement = rowElement.addElement("cell");
! cellElement.addAttribute("colNum", String.valueOf(p));
- int cellType = cell.getCellType();
- switch (cellType) {
- case HSSFCell.CELL_TYPE_NUMERIC :
- cellElement.addAttribute("type", "Numeric");
- cellElement.addText(
- String.valueOf(cell.getNumericCellValue()));
- break;
- case HSSFCell.CELL_TYPE_STRING :
- cellElement.addAttribute("type", "String");
- cellElement.addText(cell.getStringCellValue());
- break;
- case HSSFCell.CELL_TYPE_BOOLEAN :
- cellElement.addAttribute("type", "Boolean");
- cellElement.addText(
- String.valueOf(cell.getBooleanCellValue()));
- break;
- case HSSFCell.CELL_TYPE_BLANK :
- cellElement.addAttribute("type", "N/A");
- break;
- default :
- break;
- }
- }
- rowElement.addAttribute(
- "number-of-cells",
- String.valueOf(cellCount));
- }
- sheetElement.addAttribute(
- "number-of-rows",
- String.valueOf(rowCount));
- }
-
- PipelineDocument doc =
- new PipelineDocument(
- this.getDocument(),
- document.asXML().getBytes());
return processHelper(doc);
! } catch (IOException e) {
// TODO Auto-generated catch block
throw new PipelineException("Error converting XLS file to XML");
}
-
}
-
}
--- 94,119 ----
public Collection getTypeSpecificOptions() {
! return null;
}
});
}
! /**
! * Process. This converts the document from Microsoft Excel (tm) data format
! * to an xml format. This uses the ExcelConverter.
*/
! public PipelineStageResult[] process()
! throws PipelineException {
try {
! PipelineDocument doc = ConversionHelper.render(new ExcelConverter().toXml(this.getDocument().getInputStream()),
! this.getDocument());
! doc.setBinary(false);
return processHelper(doc);
! } catch (ConversionException e) {
// TODO Auto-generated catch block
throw new PipelineException("Error converting XLS file to XML");
}
}
}
|