From a473a5c7af8d33a931510dec4c93413a341da1d9 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Tue, 4 Oct 2011 17:11:16 +0000 Subject: [PATCH] Improve CSV and tabular git-svn-id: https://svn.argeo.org/commons/trunk@4797 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../jcr/tabular/JcrTabularRowIterator.java | 34 +++++++++---------- .../argeo/jcr/tabular/JcrTabularWriter.java | 15 +++++--- .../org/argeo/jcr/tabular/JcrTabularTest.java | 2 +- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularRowIterator.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularRowIterator.java index 238e7d26c..8223e1d48 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularRowIterator.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularRowIterator.java @@ -15,7 +15,6 @@ import javax.jcr.RepositoryException; import org.apache.commons.io.IOUtils; import org.argeo.ArgeoException; import org.argeo.jcr.ArgeoTypes; -import org.argeo.jcr.JcrUtils; import org.argeo.util.CsvParser; import org.argeo.util.tabular.ArrayTabularRow; import org.argeo.util.tabular.TabularColumn; @@ -46,7 +45,8 @@ public class JcrTabularRowIterator implements TabularRowIterator { if (node.isNodeType(ArgeoTypes.ARGEO_COLUMN)) { Integer type = PropertyType.valueFromName(node.getProperty( Property.JCR_REQUIRED_TYPE).getString()); - TabularColumn tc = new TabularColumn(node.getName(), type); + TabularColumn tc = new TabularColumn(node.getProperty( + Property.JCR_TITLE).getString(), type); header.add(tc); // } else if (node.getName().equals(Property.JCR_CONTENT)) { // contentNode = node; @@ -66,7 +66,7 @@ public class JcrTabularRowIterator implements TabularRowIterator { // TODO Auto-generated catch block e.printStackTrace(); } - //textLines.add(tokens); + // textLines.add(tokens); if (hasNext == null) { hasNext = true; synchronized (JcrTabularRowIterator.this) { @@ -127,20 +127,20 @@ public class JcrTabularRowIterator implements TabularRowIterator { return true; // (parsingCompleted && textLines.isEmpty()) - return false; - -// if (!hasNext && textLines.isEmpty()) { -// if (in != null) { -// IOUtils.closeQuietly(in); -// in = null; -// } -// if (binary != null) { -// JcrUtils.closeQuietly(binary); -// binary = null; -// } -// return false; -// } else -// return true; + return false; + + // if (!hasNext && textLines.isEmpty()) { + // if (in != null) { + // IOUtils.closeQuietly(in); + // in = null; + // } + // if (binary != null) { + // JcrUtils.closeQuietly(binary); + // binary = null; + // } + // return false; + // } else + // return true; } public synchronized TabularRow next() { diff --git a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularWriter.java b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularWriter.java index cd6feb565..0727b784e 100644 --- a/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularWriter.java +++ b/server/runtime/org.argeo.server.jcr/src/main/java/org/argeo/jcr/tabular/JcrTabularWriter.java @@ -30,10 +30,17 @@ public class JcrTabularWriter implements TabularWriter { String contentNodeType) { try { for (TabularColumn column : columns) { - Node columnNode = tableNode.addNode(column.getName(), + String normalized = JcrUtils.replaceInvalidChars(column + .getName()); + Node columnNode = tableNode.addNode(normalized, ArgeoTypes.ARGEO_COLUMN); - columnNode.setProperty(Property.JCR_REQUIRED_TYPE, - PropertyType.nameFromValue(column.getType())); + columnNode.setProperty(Property.JCR_TITLE, column.getName()); + if (column.getType() != null) + columnNode.setProperty(Property.JCR_REQUIRED_TYPE, + PropertyType.nameFromValue(column.getType())); + else + columnNode.setProperty(Property.JCR_REQUIRED_TYPE, + PropertyType.TYPENAME_STRING); } contentNode = tableNode.addNode(Property.JCR_CONTENT, contentNodeType); @@ -48,7 +55,7 @@ public class JcrTabularWriter implements TabularWriter { } } - public void appendRow(List row) { + public void appendRow(Object[] row) { csvWriter.writeLine(row); } diff --git a/server/runtime/org.argeo.server.jcr/src/test/java/org/argeo/jcr/tabular/JcrTabularTest.java b/server/runtime/org.argeo.server.jcr/src/test/java/org/argeo/jcr/tabular/JcrTabularTest.java index 3df80ca04..7bb8e90bc 100644 --- a/server/runtime/org.argeo.server.jcr/src/test/java/org/argeo/jcr/tabular/JcrTabularTest.java +++ b/server/runtime/org.argeo.server.jcr/src/test/java/org/argeo/jcr/tabular/JcrTabularTest.java @@ -67,7 +67,7 @@ public class JcrTabularTest extends AbstractJcrTestCase { for (int j = 0; j < columnCount; j++) { objs.add(stringValue); } - writer.appendRow(objs); + writer.appendRow(objs.toArray()); } writer.close(); session().save(); -- 2.39.2