first pass at creating a csv download option. TODO icons on page, debug failing load
This commit is contained in:
parent
1b890a3767
commit
96bed7ce03
4 changed files with 52 additions and 3 deletions
|
@ -70,6 +70,7 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
protected static final int DEFAULT_MAX_HIT_COUNT = 1000;
|
||||
|
||||
private static final String PARAM_XML_REQUEST = "xml";
|
||||
private static final String PARAM_CSV_REQUEST = "csv";
|
||||
private static final String PARAM_START_INDEX = "startIndex";
|
||||
private static final String PARAM_HITS_PER_PAGE = "hitsPerPage";
|
||||
private static final String PARAM_CLASSGROUP = "classgroup";
|
||||
|
@ -79,7 +80,7 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
protected static final Map<Format,Map<Result,String>> templateTable;
|
||||
|
||||
protected enum Format {
|
||||
HTML, XML;
|
||||
HTML, XML, CSV;
|
||||
}
|
||||
|
||||
protected enum Result {
|
||||
|
@ -101,9 +102,10 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
throws IOException, ServletException {
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
boolean wasXmlRequested = isRequestedFormatXml(vreq);
|
||||
if( ! wasXmlRequested ){
|
||||
boolean wasCSVRequested = isRequestedFormatCSV(vreq);
|
||||
if( !wasXmlRequested && !wasCSVRequested){
|
||||
super.doGet(vreq,response);
|
||||
}else{
|
||||
}else if (wasXMLRequested){
|
||||
try {
|
||||
ResponseValues rvalues = processRequest(vreq);
|
||||
|
||||
|
@ -113,6 +115,16 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
}else if (wasCSVRequested){
|
||||
try {
|
||||
ResponseValues rvalues = processRequest(vreq);
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("text/csv;charset=UTF-8");
|
||||
writeTemplate(rvalues.getTemplateName(), rvalues.getMap(), request, response);
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,9 +685,24 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean isRequestedFormatCSV(VitroRequest req){
|
||||
if( req != null ){
|
||||
String param = req.getParameter(PARAM_CSV_REQUEST);
|
||||
if( param != null && "1".equals(param)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected Format getFormat(VitroRequest req){
|
||||
if( req != null && req.getParameter("xml") != null && "1".equals(req.getParameter("xml")))
|
||||
return Format.XML;
|
||||
else if ( req != null && req.getParameter("csv") != null && "1".equals(req.getParameter("csv")))
|
||||
return Format.CSV;
|
||||
else
|
||||
return Format.HTML;
|
||||
}
|
||||
|
@ -705,9 +732,20 @@ public class PagedSearchController extends FreemarkerHttpServlet {
|
|||
resultsToTemplates = new HashMap<Result,String>();
|
||||
resultsToTemplates.put(Result.PAGED, "search-xmlResults.ftl");
|
||||
resultsToTemplates.put(Result.ERROR, "search-xmlError.ftl");
|
||||
|
||||
// resultsToTemplates.put(Result.BAD_QUERY, "search-xmlBadQuery.ftl");
|
||||
templateTable.put(Format.XML, Collections.unmodifiableMap(resultsToTemplates));
|
||||
|
||||
|
||||
// set up CSV format
|
||||
resultsToTemplates = new HashMap<Result,String>();
|
||||
resultsToTemplates.put(Result.PAGED, "search-csvResults.ftl");
|
||||
resultsToTemplates.put(Result.ERROR, "search-csvError.ftl");
|
||||
|
||||
// resultsToTemplates.put(Result.BAD_QUERY, "search-xmlBadQuery.ftl");
|
||||
templateTable.put(Format.CSV, Collections.unmodifiableMap(resultsToTemplates));
|
||||
|
||||
|
||||
return Collections.unmodifiableMap(templateTable);
|
||||
}
|
||||
}
|
||||
|
|
BIN
webapp/web/images/share-uri-icon.png
Normal file
BIN
webapp/web/images/share-uri-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -0,0 +1,5 @@
|
|||
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
URI,Name
|
||||
<#list individuals as individual>
|
||||
${individual.uri?xml},${individual.name?xml}
|
||||
</#list>
|
|
@ -8,8 +8,14 @@
|
|||
<#if classGroupName?has_content>limited to type '${classGroupName}'</#if>
|
||||
<#if typeName?has_content>limited to type '${typeName}'</#if>
|
||||
</#escape>
|
||||
<span id="downloadResults">
|
||||
<img src="images/share-uri-icon.png" alt="XML/RDF Results" />
|
||||
|
||||
</span>
|
||||
</h2>
|
||||
|
||||
<span id="searchHelp"><a href="${urls.base}/searchHelp" title="search help">Not the results you expected?</a></span>
|
||||
|
||||
<div class="contentsBrowseGroup">
|
||||
|
||||
<#-- Refinement links -->
|
||||
|
|
Loading…
Add table
Reference in a new issue