001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.http.commons.domain; 019 020import static javax.ws.rs.core.Variant.mediaTypes; 021import static org.apache.jena.riot.WebContent.contentTypeN3; 022import static org.apache.jena.riot.WebContent.contentTypeN3Alt2; 023import static org.apache.jena.riot.WebContent.contentTypeNTriples; 024import static org.apache.jena.riot.WebContent.contentTypeRDFXML; 025import static org.apache.jena.riot.WebContent.contentTypeTurtle; 026import static org.apache.jena.riot.WebContent.contentTypeTurtleAlt2; 027 028import java.util.List; 029 030import javax.ws.rs.core.MediaType; 031import javax.ws.rs.core.Variant; 032 033/** 034 * This is a convenience class carrying the various RDF content-type values as 035 * Strings and MediaTypes, after the fashion of the constants available on 036 * javax.ws.rs.core.MediaType 037 * 038 * @author ba2213 039 */ 040public abstract class RDFMediaType extends MediaType { 041 042 public static final String N3 = contentTypeN3; 043 044 public static final MediaType N3_TYPE = typeFromString(N3); 045 046 public static final String N3_ALT2 = contentTypeN3Alt2; 047 048 public static final MediaType N3_ALT2_TYPE = typeFromString(N3_ALT2); 049 050 public static final String TURTLE = contentTypeTurtle; 051 052 public static final MediaType TURTLE_TYPE = typeFromString(TURTLE); 053 054 public static final String TURTLE_X = contentTypeTurtleAlt2; 055 056 public static final MediaType TURTLE_X_TYPE = typeFromString(TURTLE_X); 057 058 public static final String RDF_XML = contentTypeRDFXML; 059 060 public static final MediaType RDF_XML_TYPE = typeFromString(RDF_XML); 061 062 public static final String NTRIPLES = contentTypeNTriples; 063 064 public static final MediaType NTRIPLES_TYPE = typeFromString(NTRIPLES); 065 066 public final static String JSON_LD = "application/ld+json"; 067 068 public final static MediaType JSON_LD_TYPE = typeFromString(JSON_LD); 069 070 public static final List<Variant> POSSIBLE_RDF_VARIANTS = mediaTypes( 071 RDF_XML_TYPE, TURTLE_TYPE, N3_TYPE, N3_ALT2_TYPE, NTRIPLES_TYPE, APPLICATION_XML_TYPE, 072 TEXT_PLAIN_TYPE, TURTLE_X_TYPE, JSON_LD_TYPE).add().build(); 073 074 public static final String POSSIBLE_RDF_RESPONSE_VARIANTS_STRING[] = { 075 TURTLE, N3, N3_ALT2, RDF_XML, NTRIPLES, TEXT_PLAIN, APPLICATION_XML, TURTLE_X, JSON_LD }; 076 077 private static MediaType typeFromString(final String type) { 078 return new MediaType(type.split("/")[0], type.split("/")[1]); 079 } 080 081}