Revision 4685
Added by walbridge almost 16 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
1767 | 1767 |
// if we decide to use "application/octet-stream" for all data |
1768 | 1768 |
// returns |
1769 | 1769 |
// response.setContentType("application/octet-stream"); |
1770 |
|
|
1770 |
|
|
1771 |
// check for the existence of a metadatadocid parameter, |
|
1772 |
// if this is sent, then send a filename which contains both |
|
1773 |
// the metadata docid and the data docid, so the link with |
|
1774 |
// metadata is explicitly encoded in the filename. |
|
1775 |
String metadatadocid = null; |
|
1776 |
Vector<String> nameparts = new Vector<String>(); |
|
1777 |
|
|
1778 |
if(params.containsKey("metadatadocid")) { |
|
1779 |
metadatadocid = params.get("metadatadocid")[0]; |
|
1780 |
} |
|
1781 |
if (metadatadocid != null && !metadatadocid.equals("")) { |
|
1782 |
nameparts.add(metadatadocid); |
|
1783 |
} |
|
1784 |
// we'll always have the docid, include it in the name |
|
1785 |
String doctype = doc.getDoctype(); |
|
1786 |
// TODO: fix this to lookup the associated FGDC metadata document, |
|
1787 |
// and grab the doctype tag for it. These should be set to something |
|
1788 |
// consistent, not 'metadata' as it stands... |
|
1789 |
//if (!doctype.equals("metadata")) { |
|
1790 |
// nameparts.add(docid); |
|
1791 |
//} |
|
1792 |
nameparts.add(docid); |
|
1771 | 1793 |
// Set the name of the data file to the entity name plus docid, |
1772 | 1794 |
// or if that is unavailable, use the docid alone |
1773 | 1795 |
String docname = doc.getDocname(); |
1774 |
if (docname == null || docname.equals("")) { |
|
1775 |
docname = docid; |
|
1776 |
} else { |
|
1777 |
docname = docid + "-" + docname; |
|
1796 |
if (docname != null && !docname.equals("")) { |
|
1797 |
nameparts.add(docname); |
|
1778 | 1798 |
} |
1799 |
// combine the name elements with a dash, using a 'join' equivalent |
|
1800 |
String outputname = null; |
|
1801 |
String delimiter = "-"; |
|
1802 |
Iterator<String> iter = nameparts.iterator(); |
|
1803 |
StringBuffer buffer = new StringBuffer(iter.next()); |
|
1804 |
while (iter.hasNext()) buffer.append(delimiter).append(iter.next()); |
|
1805 |
outputname = buffer.toString(); |
|
1806 |
|
|
1779 | 1807 |
response.setHeader("Content-Disposition", |
1780 |
"attachment; filename=\"" + docname + "\"");
|
|
1808 |
"attachment; filename=\"" + outputname + "\"");
|
|
1781 | 1809 |
|
1782 | 1810 |
try { |
1783 | 1811 |
ServletOutputStream out = response.getOutputStream(); |
Also available in: Unified diff
Robustly handle file naming as per bug #2566 and the feedback of the scientific programmers (http://tinyurl.com/4n4jve).