Project

General

Profile

« Previous | Next » 

Revision 7412

use ObjectFormatInfo libclient utility to look up mimeType and filename extension during get() calls. Configurable mapping file is deployed by default to /var/metacat/dataone where it can then be augmented as needed. This location is controlled in the metacat.properties file (which is injected into the DataONE Settings values during weapp intitialization).
https://redmine.dataone.org/issues/3309

View differences:

lib/metacat.properties.metadata.xml
450 450
		<description> </description>
451 451
		<helpFile> </helpFile>
452 452
	</config>
453
	<config>
454
	    <key>D1Client.resourcesDir</key>
455
	    <label>Configurable DataONE Resources Directory</label>
456
	    <group>6</group>
457
	    <index>12</index>                
458
		<fieldType>hidden</fieldType>
459
		<description> </description>
460
		<helpFile> </helpFile>
461
	</config>
453 462
	
454 463
	
464
	
465
	
455 466
</metadataConfig>
lib/metacat.properties
503 503
D1Client.CN_URL=https://cn.dataone.org/cn
504 504
# Configure the Member Node client certificate location
505 505
D1Client.certificate.file=/var/metacat/certs/METACAT1.pem
506
# Client resources
507
D1Client.resourcesDir=/var/metacat/dataone
506 508
# Member Node configuration
507 509
dataone.nodeId=
508 510
dataone.subject=CN=METACAT1, DC=dataone, DC=org
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
46 46
import org.apache.commons.io.IOUtils;
47 47
import org.apache.log4j.Logger;
48 48
import org.dataone.client.ObjectFormatCache;
49
import org.dataone.client.formats.ObjectFormatInfo;
49 50
import org.dataone.mimemultipart.MultipartRequest;
50 51
import org.dataone.mimemultipart.MultipartRequestResolver;
51 52
import org.dataone.service.exceptions.BaseException;
......
905 906
                
906 907
            SystemMetadata sm = MNodeService.getInstance(request).getSystemMetadata(session, id);
907 908
            
908
            // set the content type, default to octet-stream
909
            response.setContentType("application/octet-stream");
910
            response.setHeader("Content-Disposition",
911
                    "inline; filename=" + id.getValue());
912
            // TODO: use objectFormat MIME type when we add that information
913
            if (sm.getFormatId().getValue().startsWith("text")) {
914
                response.setContentType(sm.getFormatId().getValue());
915
            } else if (sm.getFormatId().getValue().startsWith("image")) {
916
            	response.setContentType(sm.getFormatId().getValue());
917
            } else if (sm.getFormatId().getValue().startsWith("application")) {
918
            	response.setContentType(sm.getFormatId().getValue());
919
            } else if (ObjectFormatCache.getInstance().getFormat(sm.getFormatId()).getFormatType().equals("METADATA")) {
920
            	response.setContentType("text/xml");
909
            // set the headers for the content
910
            String mimeType = ObjectFormatInfo.instance().getMimeType(sm.getFormatId().getValue());
911
            if (mimeType == null) {
912
            	mimeType = "application/octet-stream";
921 913
            }
914
            String extension = ObjectFormatInfo.instance().getExtension(sm.getFormatId().getValue());
915
            String filename = id.getValue();
916
            if (extension != null) {
917
            	filename = id.getValue() + extension;
918
            }
919
            response.setContentType(mimeType);
920
            response.setHeader("Content-Disposition", "inline; filename=" + filename);
922 921
            
923 922
            InputStream data = MNodeService.getInstance(request).get(session, id);
924 923

  
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
40 40
import org.apache.commons.io.IOUtils;
41 41
import org.apache.log4j.Logger;
42 42
import org.dataone.client.ObjectFormatCache;
43
import org.dataone.client.formats.ObjectFormatInfo;
43 44
import org.dataone.service.exceptions.BaseException;
44 45
import org.dataone.service.exceptions.IdentifierNotUnique;
45 46
import org.dataone.service.exceptions.InsufficientResources;
......
537 538
        SystemMetadata sm = CNodeService.getInstance(request)
538 539
                .getSystemMetadata(session, id);
539 540

  
540
        // set the content type, default to octet-stream
541
        response.setContentType("application/octet-stream");
542
        response.setHeader("Content-Disposition",
543
                "inline; filename=" + id.getValue());
544
        // TODO: use objectFormat MIME type when we add that information
545
        if (sm.getFormatId().getValue().startsWith("text")) {
546
            response.setContentType(sm.getFormatId().getValue());
547
        } else if (sm.getFormatId().getValue().startsWith("image")) {
548
        	response.setContentType(sm.getFormatId().getValue());
549
        } else if (sm.getFormatId().getValue().startsWith("application")) {
550
        	response.setContentType(sm.getFormatId().getValue());
551
        } else if (ObjectFormatCache.getInstance().getFormat(sm.getFormatId()).getFormatType().equals("METADATA")) {
552
        	response.setContentType("text/xml");
541
        // set the headers for the content
542
        String mimeType = ObjectFormatInfo.instance().getMimeType(sm.getFormatId().getValue());
543
        if (mimeType == null) {
544
        	mimeType = "application/octet-stream";
553 545
        }
546
        String extension = ObjectFormatInfo.instance().getExtension(sm.getFormatId().getValue());
547
        String filename = id.getValue();
548
        if (extension != null) {
549
        	filename = id.getValue() + extension;
550
        }
551
        response.setContentType(mimeType);
552
        response.setHeader("Content-Disposition", "inline; filename=" + filename);
554 553

  
555 554
        InputStream data = CNodeService.getInstance(request).get(session, id);
556 555

  

Also available in: Unified diff