Added support for creating a project by pointing to a data file URL.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@1139 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
f411dc9104
commit
3bda9d035d
@ -15,6 +15,9 @@ Features:
|
||||
- In CSV and TSV importers, added support for ignoring quotation marks
|
||||
- Regexp groups capturing GEL function
|
||||
- Text facet's choice count limit is now configurable through preference page
|
||||
- Select All and Unselect All buttons in History Extract dialog
|
||||
- Schema skeleton: support for multiple cells per cell-as nodes, and for conditional links
|
||||
- Added support for creating a project by pointing to a data file URL.
|
||||
|
||||
Fixes:
|
||||
- TSV/CSV exporter bug: Gridworks crashed when there were empty cells.
|
||||
|
@ -173,7 +173,8 @@ public class CreateProjectCommand extends Command {
|
||||
) throws Exception {
|
||||
|
||||
ServletFileUpload upload = new ServletFileUpload();
|
||||
String url = null;
|
||||
String url = options.getProperty("url");
|
||||
boolean imported = false;
|
||||
|
||||
FileItemIterator iter = upload.getItemIterator(request);
|
||||
while (iter.hasNext()) {
|
||||
@ -185,25 +186,29 @@ public class CreateProjectCommand extends Command {
|
||||
Reader reader = new InputStreamReader(stream,"UTF-8");
|
||||
try {
|
||||
internalInvokeImporter(project, new TsvCsvImporter(), options, reader);
|
||||
imported = true;
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} else if (name.equals("url")) {
|
||||
} else if (name.equals("project-url")) {
|
||||
url = Streams.asString(stream);
|
||||
} else {
|
||||
options.put(name, Streams.asString(stream));
|
||||
}
|
||||
} else {
|
||||
String fileName = item.getName().toLowerCase();
|
||||
try {
|
||||
internalImportFile(project, options, fileName, stream);
|
||||
} finally {
|
||||
stream.close();
|
||||
if (fileName.length() > 0) {
|
||||
try {
|
||||
internalImportFile(project, options, fileName, stream);
|
||||
imported = true;
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (url != null && url.length() > 0) {
|
||||
if (!imported && url != null && url.length() > 0) {
|
||||
internalImportURL(request, project, options, url);
|
||||
}
|
||||
}
|
||||
@ -230,7 +235,7 @@ public class CreateProjectCommand extends Command {
|
||||
protected void internalImportFile(
|
||||
Project project,
|
||||
Properties options,
|
||||
String fileName,
|
||||
String fileName,
|
||||
InputStream inputStream
|
||||
) throws Exception {
|
||||
|
||||
@ -413,7 +418,6 @@ public class CreateProjectCommand extends Command {
|
||||
Importer importer = guessUrlImporter(url);
|
||||
if (importer instanceof UrlImporter) {
|
||||
((UrlImporter) importer).read(url, project, options);
|
||||
return;
|
||||
} else {
|
||||
// If we couldn't find one, try opening URL and treating as a stream
|
||||
try {
|
||||
@ -432,10 +436,9 @@ public class CreateProjectCommand extends Command {
|
||||
}
|
||||
|
||||
try {
|
||||
importer = guessImporter(connection.getContentType(),
|
||||
url.getPath());
|
||||
internalInvokeImporter(project, importer, options, inputStream,
|
||||
connection.getContentEncoding());
|
||||
importer = guessImporter(connection.getContentType(), url.getPath());
|
||||
|
||||
internalInvokeImporter(project, importer, options, inputStream, connection.getContentEncoding());
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class ImporterUtilities {
|
||||
if (options.containsKey(name)) {
|
||||
String s = options.getProperty(name);
|
||||
try {
|
||||
value = Boolean.parseBoolean(s);
|
||||
value = s.equalsIgnoreCase("on") || s.equals("1") || Boolean.parseBoolean(s);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class TsvCsvImporter implements ReaderImporter,StreamImporter {
|
||||
@Override
|
||||
public void read(Reader reader, Project project, Properties options) throws ImportException {
|
||||
boolean splitIntoColumns = ImporterUtilities.getBooleanOption("split-into-columns", options, true);
|
||||
|
||||
|
||||
String sep = options.getProperty("separator"); // auto-detect if not present
|
||||
int ignoreLines = ImporterUtilities.getIntegerOption("ignore", options, -1);
|
||||
int headerLines = ImporterUtilities.getIntegerOption("header-lines", options, 1);
|
||||
|
@ -31,7 +31,6 @@ public class ParsingUtilities {
|
||||
if (query.startsWith("?")) {
|
||||
query = query.substring(1);
|
||||
}
|
||||
|
||||
parseParameters(options,query);
|
||||
}
|
||||
return options;
|
||||
|
@ -64,6 +64,9 @@
|
||||
<tr><td><span class="field-label">Data File</span>:</td>
|
||||
<td><input type="file" id="project-file-input" name="project-file" /></td>
|
||||
</tr>
|
||||
<tr><td><span class="field-label">Or Data File URL</span>:</td>
|
||||
<td><input id="project-url-input" name="project-url" size="50" /></td>
|
||||
</tr>
|
||||
<tr><td><span class="field-label">Project Name</span>:</td>
|
||||
<td><input type="text" size="30" id="project-name-input" name="project-name" /></td></tr>
|
||||
<tr><td></td>
|
||||
@ -109,7 +112,7 @@
|
||||
|
||||
<div class="field-group">
|
||||
<div><input id="ignore-quotes-input" name="ignore-quotes" type="checkbox" />Ignore Quotation Marks </div>
|
||||
<div class="field-hint">Ignore quotation marks, using all newlines and separators</div>
|
||||
<div class="field-hint">Ignore quotation marks,<br/>using all newlines and separators</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr></table>
|
||||
|
@ -1,22 +1,24 @@
|
||||
function onClickUploadFileButton(evt) {
|
||||
var projectName = $("#project-name-input")[0].value;
|
||||
var dataURL = $.trim($("#project-url-input")[0].value);
|
||||
if (! $.trim(projectName).length) {
|
||||
window.alert("You must specify a project name.");
|
||||
|
||||
} else if ($("#project-file-input")[0].files.length === 0) {
|
||||
window.alert("You must specify select a file to upload.");
|
||||
} else if ($("#project-file-input")[0].files.length === 0 && ! dataURL.length) {
|
||||
window.alert("You must specify a data file to upload or a URL to retrieve.");
|
||||
|
||||
} else {
|
||||
$("#file-upload-form").attr("action",
|
||||
"/command/create-project-from-upload?" + [
|
||||
"url=" + escape(dataURL),
|
||||
"split-into-columns=" + $("#split-into-columns-input")[0].checked,
|
||||
"separator=" + $("#separator-input")[0].value,
|
||||
"ignore=" + $("#ignore-input")[0].value,
|
||||
"header-lines=" + $("#header-lines-input")[0].value,
|
||||
"skip=" + $("#skip-input")[0].value,
|
||||
"limit=" + $("#limit-input")[0].value,
|
||||
"guess-value-type=" + $("#guess-value-type-input")[0].checked,
|
||||
"ignore-quotes=" + $("#ignore-quotes-input")[0].checked
|
||||
"separator=" + $("#separator-input")[0].value,
|
||||
"ignore=" + $("#ignore-input")[0].value,
|
||||
"header-lines=" + $("#header-lines-input")[0].value,
|
||||
"skip=" + $("#skip-input")[0].value,
|
||||
"limit=" + $("#limit-input")[0].value,
|
||||
"guess-value-type=" + $("#guess-value-type-input")[0].checked,
|
||||
"ignore-quotes=" + $("#ignore-quotes-input")[0].checked
|
||||
].join("&"));
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user