55
66import javax .xml .parsers .ParserConfigurationException ;
77
8+ import org .dataone .service .types .v2 .SystemMetadata ;
89import org .xml .sax .SAXException ;
910
1011/**
@@ -17,24 +18,28 @@ public class MetadataDialectFactory {
1718 /**
1819 * Creates a MetadataDialect implementation based on the provided content type.
1920 *
20- * @param contentType the format identifier of the metadata (e.g., "xml" or "json")
21+ * @param contentType the format identifier of the metadata (e.g., "xml" or
22+ * "json")
2123 * @param metadataContent an InputStream of the metadata content to be parsed
22- * @return The appropriate concrete implementation of the MetadataDialect according to content type.
24+ * @return The appropriate concrete implementation of the MetadataDialect
25+ * according to content type.
2326 * @throws IllegalArgumentException
2427 * @throws SAXException
2528 * @throws IOException
2629 * @throws ParserConfigurationException
2730 */
28- public static MetadataDialect createDialect (String contentType , InputStream metadataContent )
31+ public static MetadataDialect createDialect (SystemMetadata sysMeta , InputStream metadataContent )
2932 throws IllegalArgumentException , SAXException , IOException , ParserConfigurationException {
30- switch (contentType .toLowerCase ()) {
31- case "xml" :
32- return new XMLDialect (metadataContent );
33- case "json" :
34- return new JSONDialect (metadataContent );
35- default :
36- throw new IllegalArgumentException ("Unsupported content type: " + contentType );
33+
34+ // detect either json or xml, default xml
35+ String formatId = sysMeta .getFormatId ().getValue ();
36+
37+ if (formatId .contains ("json" )) {
38+ return new JSONDialect (metadataContent );
39+ } else {
40+ return new XMLDialect (metadataContent );
3741 }
42+
3843 }
3944
4045}
0 commit comments