Project

General

Profile

« Previous | Next » 

Revision 7671

adjust action=zip behavior to use full docids and entity names (data files) for the zip entry. Also uses the given qformat to render the metadata. https://projects.ecoinformatics.org/ecoinfo/issues/3816

View differences:

src/edu/ucsb/nceas/metacat/MetacatHandler.java
565 565
            }
566 566
            // Create a DBuery to handle export
567 567
            queryObj = new DBQuery();
568
            String qformat = null;
569
            if (params.containsKey("qformat")) {
570
                qformat = params.get("qformat")[0];
571
                queryObj.setQformat(qformat);
572
            }
568 573
            // Get the docid
569 574
            docId = docs[0];
570 575
            // Make sure the client specify docid
......
582 587
                return;
583 588
            }
584 589
            // Get output stream
590
            response.setContentType("application/zip"); //MIME type
591
            response.setHeader("Content-Disposition",
592
                    "attachment; filename="
593
                    + docId + ".zip"); // Set the name of the zip file
585 594
            out = response.getOutputStream();            
586 595
            zOut = new ZipOutputStream(out);
587 596
            zOut = queryObj
588 597
                    .getZippedPackage(docId, out, user, groups, passWord);
589 598
            zOut.finish(); //terminate the zip file
590

  
591
            response.setContentType("application/zip"); //MIME type
592
            response.setHeader("Content-Disposition",
593
                    "attachment; filename="
594
                    + docId + ".zip"); // Set the name of the zip file
595 599
            zOut.close(); //close the zip stream
596 600
            
597 601
        } catch (Exception e) {
......
772 776
                    withInlineData = false;
773 777
                }
774 778
            }*/
779
            // handle special case where the PID was given
780
            if (params.containsKey("pid")) {
781
                docs = params.get("pid");
782
            	for (int i = 0; i < docs.length; i++) {
783
            		String pid = docs[i];
784
            		// look up the pid if we have it
785
            		String localId = IdentifierManager.getInstance().getLocalId(pid);
786
            		docs[i] = localId;
787
            	}
788
            	// put docid in parms for downstream methods to use
789
            	params.put("docid", docs);
790
            }
791
            
775 792
            if ((docs.length > 1) || qformat.equals("zip")) {
776 793
                zip = true;
777 794
                out = response.getOutputStream();
src/edu/ucsb/nceas/metacat/DBQuery.java
2058 2058
		this.operator = operator;
2059 2059
	}
2060 2060

  
2061
	public String getQformat() {
2062
		return qformat;
2063
	}
2064

  
2065
	public void setQformat(String qformat) {
2066
		this.qformat = qformat;
2067
	}
2068

  
2061 2069
	/**
2062 2070
     * Check if the user has the permission to export data package
2063 2071
     *
......
2147 2155

  
2148 2156
        byteString = docImpl.getBytes();
2149 2157
        //use docId as the zip entry's name
2150
        zEntry = new ZipEntry(packageZipEntry + "/metadata/"
2151
                + docImpl.getDocID());
2158
        String fullDocId = docImpl.getDocID() + PropertyService.getProperty("document.accNumSeparator") + docImpl.getRev();
2159
		zEntry = new ZipEntry(packageZipEntry + "/metadata/" + fullDocId );
2152 2160
        zEntry.setSize(byteString.length);
2153 2161
        zipOut.putNextEntry(zEntry);
2154 2162
        zipOut.write(byteString, 0, byteString.length);
......
2285 2293
        if (!filePath.endsWith("/")) {
2286 2294
            filePath += "/";
2287 2295
        }
2288
        String fileName = filePath + docImpl.getDocID();
2289
        zEntry = new ZipEntry(packageZipEntry + "/data/" + docImpl.getDocID());
2296
        String fileName = docImpl.getDocID() + PropertyService.getProperty("document.accNumSeparator") + docImpl.getRev();
2297
        String entityName = docImpl.getDocname();
2298
        filePath = filePath + fileName;
2299
        zEntry = new ZipEntry(packageZipEntry + "/data/" + fileName + "-" + entityName);
2290 2300
        zipOut.putNextEntry(zEntry);
2291 2301
        FileInputStream fin = null;
2292 2302
        try {
2293
            fin = new FileInputStream(fileName);
2303
            fin = new FileInputStream(filePath);
2294 2304
            byte[] buf = new byte[4 * 1024]; // 4K buffer
2295 2305
            int b = fin.read(buf);
2296 2306
            while (b != -1) {
......
2353 2363
                htmlDoc.append("</h2>");
2354 2364
                //do the actual transform
2355 2365
                StringWriter docString = new StringWriter();
2356
                xmlToHtml.transformXMLDocument(((DocumentImpl) docImplList
2357
                        .elementAt(i)).toString(), "-//NCEAS//eml-generic//EN",
2358
                        "-//W3C//HTML//EN", "html", docString, null, null);
2366
                xmlToHtml.transformXMLDocument(
2367
                		((DocumentImpl) docImplList.elementAt(i)).toString(), 
2368
                		((DocumentImpl) docImplList.elementAt(i)).getDoctype(), //"-//NCEAS//eml-generic//EN",
2369
                        "-//W3C//HTML//EN", 
2370
                        qformat,
2371
                        docString, 
2372
                        null, 
2373
                        null);
2359 2374
                htmlDoc.append(docString.toString());
2360 2375
                htmlDoc.append("<br><br><hr><br><br>");
2361 2376
            }//if

Also available in: Unified diff