Refactor exporter interface along same lines as importer
git-svn-id: http://google-refine.googlecode.com/svn/trunk@1547 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
9858849198
commit
083abd4329
@ -15,6 +15,8 @@ import com.google.refine.commands.Command;
|
||||
import com.google.refine.exporters.CsvExporter;
|
||||
import com.google.refine.exporters.Exporter;
|
||||
import com.google.refine.exporters.ExporterRegistry;
|
||||
import com.google.refine.exporters.StreamExporter;
|
||||
import com.google.refine.exporters.WriterExporter;
|
||||
import com.google.refine.model.Project;
|
||||
|
||||
public class ExportRowsCommand extends Command {
|
||||
@ -50,11 +52,15 @@ public class ExportRowsCommand extends Command {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("Content-Type", exporter.getContentType());
|
||||
|
||||
if (exporter.takeWriter()) {
|
||||
if (exporter instanceof WriterExporter) {
|
||||
PrintWriter writer = response.getWriter();
|
||||
exporter.export(project, options, engine, writer);
|
||||
((WriterExporter) exporter).export(project, options, engine, writer);
|
||||
} else if (exporter instanceof StreamExporter) {
|
||||
((StreamExporter) exporter).export(project, options, engine, response.getOutputStream());
|
||||
} else if (exporter instanceof StreamExporter) {
|
||||
((StreamExporter) exporter).export(project, options, engine, response.getOutputStream());
|
||||
} else {
|
||||
exporter.export(project, options, engine, response.getOutputStream());
|
||||
respondException(response, new RuntimeException("Unknown exporter type"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
respondException(response, e);
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.google.refine.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.util.Properties;
|
||||
|
||||
@ -17,7 +16,7 @@ import com.google.refine.model.Column;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.model.Row;
|
||||
|
||||
public class CsvExporter implements Exporter{
|
||||
public class CsvExporter implements WriterExporter{
|
||||
|
||||
final static Logger logger = LoggerFactory.getLogger("CsvExporter");
|
||||
char separator;
|
||||
@ -30,12 +29,6 @@ public class CsvExporter implements Exporter{
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export(Project project, Properties options, Engine engine, OutputStream outputStream)
|
||||
throws IOException {
|
||||
throw new RuntimeException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export(Project project, Properties options, Engine engine, Writer writer) throws IOException {
|
||||
boolean printColumnHeader = true;
|
||||
@ -107,9 +100,4 @@ public class CsvExporter implements Exporter{
|
||||
return "application/x-unknown";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takeWriter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,19 +1,9 @@
|
||||
package com.google.refine.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.model.Project;
|
||||
|
||||
public interface Exporter {
|
||||
/**
|
||||
* @return MIME content type handled by exporter
|
||||
*/
|
||||
public String getContentType();
|
||||
|
||||
public boolean takeWriter();
|
||||
|
||||
public void export(Project project, Properties options, Engine engine, OutputStream outputStream) throws IOException;
|
||||
|
||||
public void export(Project project, Properties options, Engine engine, Writer writer) throws IOException;
|
||||
}
|
||||
|
15
main/src/com/google/refine/exporters/StreamExporter.java
Normal file
15
main/src/com/google/refine/exporters/StreamExporter.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.google.refine.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.model.Project;
|
||||
|
||||
|
||||
public interface StreamExporter extends Exporter {
|
||||
|
||||
public void export(Project project, Properties options, Engine engine, OutputStream outputStream) throws IOException;
|
||||
|
||||
}
|
16
main/src/com/google/refine/exporters/UrlExporter.java
Normal file
16
main/src/com/google/refine/exporters/UrlExporter.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.google.refine.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.model.Project;
|
||||
|
||||
|
||||
public interface UrlExporter extends Exporter {
|
||||
|
||||
|
||||
public void export(Project project, Properties options, Engine engine, URL url) throws IOException;
|
||||
|
||||
}
|
15
main/src/com/google/refine/exporters/WriterExporter.java
Normal file
15
main/src/com/google/refine/exporters/WriterExporter.java
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
package com.google.refine.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.model.Project;
|
||||
|
||||
public interface WriterExporter extends Exporter {
|
||||
|
||||
public void export(Project project, Properties options, Engine engine, Writer writer) throws IOException;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user