Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
xml=application/xml,text/xml
json=application/json
xml=application/xml,text/xml,application/*+xml
json=application/json,application/*+json
text=text/plain
csv=text/csv
avro=avro/binary,application/avro-binary,application/avro+binary
yaml=text/x-yaml,text/yaml,text/yml,application/x-yaml,application/x-yml,application/yaml,application/yml
yaml=text/x-yaml,text/yaml,text/yml,application/x-yaml,application/x-yml,application/yaml,application/yml,application/*+yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export class ContentViewerComponent implements OnInit, OnDestroy {
const supportedContentViewer = this.supportedContentViewerLookup.get(supportedMimeTypeId);
if (supportedContentViewer) {
const supportsMimeType = supportedContentViewer.supportedMimeTypes.mimeTypes.some(
(supportedMimeType) => mimeType.startsWith(supportedMimeType)
(supportedMimeType) => this.isMediaTypeCompatible(mimeType, supportedMimeType)
);

if (supportsMimeType) {
Expand All @@ -269,6 +269,34 @@ export class ContentViewerComponent implements OnInit, OnDestroy {
return null;
}

/**
* Checks if a MIME type is compatible with a supported media type pattern.
* Supports patterns like "application/*+xml" which match "application/fhir+xml".
*/
private isMediaTypeCompatible(mimeType: string, supportedMimeType: string): boolean {
// Check for exact match or startsWith match
if (mimeType === supportedMimeType || mimeType.startsWith(supportedMimeType)) {
return true;
}

// Check for wildcard patterns like "application/*+xml"
if (supportedMimeType.includes('/*+')) {
// Parse pattern: "application/*+xml" -> type="application", suffix="+xml"
const patternMatch = supportedMimeType.match(/^([^/]+)\/\*(\+.+)$/);
if (patternMatch) {
const [, patternType, patternSuffix] = patternMatch;
// Parse mimeType: "application/fhir+xml" -> type="application", suffix="+xml"
const mimeMatch = mimeType.match(/^([^/]+)\/[^+]+(\+.+)$/);
if (mimeMatch) {
const [, mimeTypeType, mimeTypeSuffix] = mimeMatch;
return patternType === mimeTypeType && patternSuffix === mimeTypeSuffix;
}
}
}

return false;
}

viewAsChanged(event: MatSelectChange): void {
this.loadContentViewer(Number(event.value));
}
Expand Down
Loading