Project

General

Profile

« Previous | Next » 

Revision 7316

improve content type handling during the get() calls
https://redmine.dataone.org/issues/3070

View differences:

src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
905 905
                
906 906
            SystemMetadata sm = MNodeService.getInstance(request).getSystemMetadata(session, id);
907 907
            
908
            //set the content type
909
            if (sm.getFormatId().getValue().trim().equals(
910
            		ObjectFormatCache.getInstance().getFormat("text/csv").getFormatId().getValue()))
911
            {
912
                response.setContentType("text/csv");
913
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
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");
914 921
            }
915
            else if (sm.getFormatId().getValue().trim().equals(
916
            		ObjectFormatCache.getInstance().getFormat("text/plain").getFormatId().getValue()))
917
            {
918
                response.setContentType("text/plain");
919
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
920
            } 
921
            else if (sm.getFormatId().getValue().trim().equals(
922
            		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFormatId().getValue()))
923
            {
924
                response.setContentType("application/octet-stream");
925
            }
926
            else
927
            {
928
                response.setContentType("text/xml");
929
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".xml");
930
            }
931 922
            
932 923
            InputStream data = MNodeService.getInstance(request).get(session, id);
933 924

  
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
537 537
        SystemMetadata sm = CNodeService.getInstance(request)
538 538
                .getSystemMetadata(session, id);
539 539

  
540
        // set the content type
541
        if (sm.getFormatId()
542
                .getValue()
543
                .trim()
544
                .equals(ObjectFormatCache.getInstance().getFormat("text/csv")
545
                        .getFormatId().getValue())) {
546
            response.setContentType("text/csv");
547
            response.setHeader("Content-Disposition",
548
                    "inline; filename=" + id.getValue() + ".csv");
549
        } else if (sm
550
                .getFormatId()
551
                .getValue()
552
                .trim()
553
                .equals(ObjectFormatCache.getInstance().getFormat("text/plain")
554
                        .getFormatId().getValue())) {
555
            response.setContentType("text/plain");
556
            response.setHeader("Content-Disposition",
557
                    "inline; filename=" + id.getValue() + ".txt");
558
        } else if (sm
559
                .getFormatId()
560
                .getValue()
561
                .trim()
562
                .equals(ObjectFormatCache.getInstance()
563
                        .getFormat("application/octet-stream").getFormatId()
564
                        .getValue())) {
565
            response.setContentType("application/octet-stream");
566
        } else {
567
            response.setContentType("text/xml");
568
            response.setHeader("Content-Disposition",
569
                    "inline; filename=" + id.getValue() + ".xml");
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");
570 553
        }
571 554

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

Also available in: Unified diff