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