public static Datastream setDatastreamDefaults(Datastream ds)
            throws ObjectIntegrityException {

        if ((ds.DSMIME == null || ds.DSMIME.isEmpty())
                && ds.DSControlGrp.equalsIgnoreCase("X")) {
            ds.DSMIME = "text/xml";
        }

        if (ds.DSState == null || ds.DSState.isEmpty()) {
            ds.DSState = "A";
        }

        // For METS backward compatibility
        if (ds.DSInfoType == null || ds.DSInfoType.isEmpty()
                || ds.DSInfoType.equalsIgnoreCase("OTHER")) {
            ds.DSInfoType = "UNSPECIFIED";
        }

        // LOOK! For METS backward compatibility:
        // If we have a METS MDClass value, and DSFormatURI isn't already
        // assigned, preserve MDClass and MDType in a DSFormatURI.
        // Note that the system is taking over the DSFormatURI in this case.
        // Therefore, if a client subsequently modifies the DSFormatURI
        // this METS legacy informatin will be lost, in which case the inline
        // datastream will default to amdSec/techMD in a subsequent METS export.
        if (ds.DSControlGrp.equalsIgnoreCase("X")) {
            if (((DatastreamXMLMetadata) ds).DSMDClass != 0
                    && ds.DSFormatURI == null) {
                String mdClassName = "";
                String mdType = ds.DSInfoType;
                String otherType = "";
                if (((DatastreamXMLMetadata) ds).DSMDClass == 1) {
                    mdClassName = "techMD";
                } else if (((DatastreamXMLMetadata) ds).DSMDClass == 2) {
                    mdClassName = "sourceMD";
                } else if (((DatastreamXMLMetadata) ds).DSMDClass == 3) {
                    mdClassName = "rightsMD";
                } else if (((DatastreamXMLMetadata) ds).DSMDClass == 4) {
                    mdClassName = "digiprovMD";
                } else if (((DatastreamXMLMetadata) ds).DSMDClass == 5) {
                    mdClassName = "descMD";
                }
                if (!mdType.equals("MARC") && !mdType.equals("EAD")
                        && !mdType.equals("DC") && !mdType.equals("NISOIMG")
                        && !mdType.equals("LC-AV") && !mdType.equals("VRA")
                        && !mdType.equals("TEIHDR") && !mdType.equals("DDI")
                        && !mdType.equals("FGDC")) {
                    mdType = "OTHER";
                    otherType = ds.DSInfoType;
                }
                ds.DSFormatURI =
                        "info:fedora/fedora-system:format/xml.mets."
                                + mdClassName + "." + mdType + "." + otherType;
            }
        }
        return ds;
    }
public static Datastream setDatastreamDefaults ( Datastream ds ) throws ObjectIntegrityException { if ( ( ds . DSMIME == null || ds . DSMIME . isEmpty ( ) ) && ds . DSControlGrp . equalsIgnoreCase ( "X" ) ) { ds . DSMIME = "text/xml" ; } if ( ds . DSState == null || ds . DSState . isEmpty ( ) ) { ds . DSState = "A" ; } if ( ds . DSInfoType == null || ds . DSInfoType . isEmpty ( ) || ds . DSInfoType . equalsIgnoreCase ( "OTHER" ) ) { ds . DSInfoType = "UNSPECIFIED" ; } if ( ds . DSControlGrp . equalsIgnoreCase ( "X" ) ) { if ( ( ( DatastreamXMLMetadata ) ds ) . DSMDClass != 0 && ds . DSFormatURI == null ) { String mdClassName = "" ; String mdType = ds . DSInfoType ; String otherType = "" ; if ( ( ( DatastreamXMLMetadata ) ds ) . DSMDClass == 1 ) { mdClassName = "techMD" ; } else if ( ( ( DatastreamXMLMetadata ) ds ) . DSMDClass == 2 ) { mdClassName = "sourceMD" ; } else if ( ( ( DatastreamXMLMetadata ) ds ) . DSMDClass == 3 ) { mdClassName = "rightsMD" ; } else if ( ( ( DatastreamXMLMetadata ) ds ) . DSMDClass == 4 ) { mdClassName = "digiprovMD" ; } else if ( ( ( DatastreamXMLMetadata ) ds ) . DSMDClass == 5 ) { mdClassName = "descMD" ; } if ( ! mdType . equals ( "MARC" ) && ! mdType . equals ( "EAD" ) && ! mdType . equals ( "DC" ) && ! mdType . equals ( "NISOIMG" ) && ! mdType . equals ( "LC-AV" ) && ! mdType . equals ( "VRA" ) && ! mdType . equals ( "TEIHDR" ) && ! mdType . equals ( "DDI" ) && ! mdType . equals ( "FGDC" ) ) { mdType = "OTHER" ; otherType = ds . DSInfoType ; } ds . DSFormatURI = "info:fedora/fedora-system:format/xml.mets." + mdClassName + "." + mdType + "." + otherType ; } } return ds ; }
Check for null values in attributes and set them to empty string so
'null' does not appear in XML attribute values. This helps in XML
validation of required attributes. If 'null' is the attribute value then
validation would incorrectly consider in a valid non-empty value. Also,
we set some other default values here.

@param ds
The Datastream object to work on.
@return The Datastream value with default set.
@throws ObjectIntegrityException