diff --git a/src/java/org/oddjob/dido/poi/data/PoiRowsIn.java b/src/java/org/oddjob/dido/poi/data/PoiRowsIn.java index 618168f..83a8fb2 100644 --- a/src/java/org/oddjob/dido/poi/data/PoiRowsIn.java +++ b/src/java/org/oddjob/dido/poi/data/PoiRowsIn.java @@ -138,6 +138,7 @@ public T provideDataIn(Class type) throws DataException { throw new UnsupportedDataInException(this.getClass(), type); } + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public CellIn inFor(Field column) { diff --git a/src/java/org/oddjob/dido/poi/layouts/DataCell.java b/src/java/org/oddjob/dido/poi/layouts/DataCell.java index acba298..f84a39e 100644 --- a/src/java/org/oddjob/dido/poi/layouts/DataCell.java +++ b/src/java/org/oddjob/dido/poi/layouts/DataCell.java @@ -128,7 +128,7 @@ public Object read() throws DataException { logger.trace("[" + DataCell.this + "] value is [" + field + "]"); - nextReader = nextReaderFor(new VoidIn()); + nextReader = nextReaderFor(childDataIn()); return read(); } @@ -142,6 +142,10 @@ public void close() throws DataException { } } + protected DataIn childDataIn() { + return new VoidIn(); + } + @SuppressWarnings("unchecked") @Override public DataReader readerFor(DataIn dataIn) throws DataException { @@ -183,6 +187,23 @@ public String getDefaultStyle() { return null; } + /** + * + * @author rob + * + * @param + */ + protected interface DataOutControl { + + public DataOut dataOut(); + + public boolean isWrittenTo(); + + public void resetWrittenTo(); + + public T value(); + } + /** * The Data Writer that writes to the cell. */ @@ -190,8 +211,11 @@ class MainWriter implements DataWriter { private final DataWriter nextWriter; + private final DataOutControl dataOutControl; + public MainWriter() throws DataException { - this.nextWriter = nextWriterFor(new VoidOut()); + this.dataOutControl = childDataOut(); + this.nextWriter = nextWriterFor(dataOutControl.dataOut()); } @Override @@ -201,14 +225,21 @@ public boolean write(Object object) throws DataException { return true; } - if (isWrittenTo()) { + if (isWrittenTo() || dataOutControl.isWrittenTo()) { + dataOutControl.resetWrittenTo(); resetWrittenTo(); return write(object); } - T value = value(); + T value = dataOutControl.value(); + if (value == null) { + value = value(); + } + else { + value(value); + } columnOut.setData(value); @@ -229,6 +260,31 @@ public void close() throws DataException { } } + protected DataOutControl childDataOut() { + + return new DataOutControl() { + + @Override + public T value() { + return null; + } + + @Override + public boolean isWrittenTo() { + return false; + } + + @Override + public void resetWrittenTo() { + } + + @Override + public DataOut dataOut() { + return new VoidOut(); + } + }; + } + @SuppressWarnings("unchecked") @Override public DataWriter writerFor(DataOut dataOut) throws DataException { diff --git a/src/java/org/oddjob/dido/poi/layouts/TextCell.java b/src/java/org/oddjob/dido/poi/layouts/TextCell.java index 1176f70..ef38e89 100644 --- a/src/java/org/oddjob/dido/poi/layouts/TextCell.java +++ b/src/java/org/oddjob/dido/poi/layouts/TextCell.java @@ -1,6 +1,11 @@ package org.oddjob.dido.poi.layouts; import org.apache.poi.ss.usermodel.Cell; +import org.oddjob.dido.DataIn; +import org.oddjob.dido.DataOut; +import org.oddjob.dido.Layout; +import org.oddjob.dido.text.StringTextIn; +import org.oddjob.dido.text.StringTextOut; public class TextCell extends DataCell { @@ -14,15 +19,50 @@ public int getCellType() { return Cell.CELL_TYPE_STRING; } + public void setOf(int index, Layout child) { + addOrRemoveChild(index, child); + } + @Override public String extractCellValue(Cell cell) { return cell.getStringCellValue(); } + @Override + protected DataIn childDataIn() { + return new StringTextIn(value()); + } + @Override public void insertValueInto(Cell cell, String value) { cell.setCellValue(value); } + + @Override + public DataOutControl childDataOut() { + + return new DataOutControl() { + + StringTextOut textOut = new StringTextOut(); + + @Override + public DataOut dataOut() { + return textOut; + } + @Override + public boolean isWrittenTo() { + return textOut.isMultiLine(); + } + @Override + public void resetWrittenTo() { + textOut.resetWrittenTo(); + } + @Override + public String value() { + return textOut.toText(); + } + }; + } public String getValue() { return this.value(); diff --git a/test/java/org/oddjob/dido/poi/layouts/TextCellOfNamedValues.xml b/test/java/org/oddjob/dido/poi/layouts/TextCellOfNamedValues.xml new file mode 100644 index 0000000..ee4f440 --- /dev/null +++ b/test/java/org/oddjob/dido/poi/layouts/TextCellOfNamedValues.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/oddjob/dido/poi/layouts/TextCellTest.java b/test/java/org/oddjob/dido/poi/layouts/TextCellTest.java new file mode 100644 index 0000000..f6dd780 --- /dev/null +++ b/test/java/org/oddjob/dido/poi/layouts/TextCellTest.java @@ -0,0 +1,41 @@ +package org.oddjob.dido.poi.layouts; + +import java.io.File; + +import junit.framework.TestCase; + +import org.oddjob.Oddjob; +import org.oddjob.OddjobLookup; +import org.oddjob.arooa.convert.ArooaConversionException; +import org.oddjob.arooa.reflect.ArooaPropertyException; +import org.oddjob.state.ParentState; + +public class TextCellTest extends TestCase { + + public void testWriteAndRead() throws ArooaPropertyException, ArooaConversionException { + + File file = new File(getClass().getResource( + "TextCellOfNamedValues.xml").getFile()); + + Oddjob oddjob = new Oddjob(); + oddjob.setFile(file); + + oddjob.run(); + + assertEquals(ParentState.COMPLETE, + oddjob.lastStateEvent().getState()); + + OddjobLookup lookup = new OddjobLookup(oddjob); + + String[] expected = lookup.lookup("text-read.data.input", String[].class); + + String[] result = lookup.lookup("text-write.data.output", String[].class); + + assertEquals(expected[0], result[0]); + assertEquals(expected[1], result[1]); + assertEquals(expected[2], result[2]); + + assertEquals(expected.length, result.length); + } + +}