public static String findMediaType(final String uri) { Optional<RDFFormat> format = RDFFormat.matchFileName(uri, null); if (!format.isPresent()) { throw new IllegalArgumentException("no matching media type for " + uri); } List<String> types = format.get().getMIMETypes(); if (0 == types.size()) { throw new IllegalStateException("RDF format has no media type(s): " + format); } return types.iterator().next(); }
public static String findMediaType(final String uri) { Optional<RDFFormat> format = RDFFormat.matchFileName(uri, null); if (!format.isPresent()) { throw new IllegalArgumentException("no matching media type for " + uri); } List<String> types = format.get().getMIMETypes(); if (0 == types.size()) { throw new IllegalStateException("RDF format has no media type(s): " + format); } return types.iterator().next(); }
/** * Tries to match the extension of a file name against the list of RDF * formats that can be parsed. * * @param fileName * A file name. * @return An RDFFormat object if a match was found, or * {@link Optional#empty()} otherwise. * @see #getParserFormatForFileName(String, RDFFormat) */ public static Optional<RDFFormat> getParserFormatForFileName(String fileName) { return RDFFormat.matchFileName(fileName, RDFParserRegistry.getInstance().getKeys()); }
/** * Tries to match the extension of a file name against the list of RDF * formats that can be written. * * @param fileName * A file name. * @return An RDFFormat object if a match was found, or * {@link Optional#empty()} otherwise. * @see #getWriterFormatForFileName(String, RDFFormat) */ public static Optional<RDFFormat> getWriterFormatForFileName(String fileName) { return RDFFormat.matchFileName(fileName, RDFWriterRegistry.getInstance().getKeys()); }
@Get public Representation get(final Variant variant) { selfURI = this.getRequest().getResourceRef().toString(); int i = selfURI.lastIndexOf("."); if (i > 0) { format = RDFFormat.matchFileName(selfURI, null); } if (!format.isPresent()) { webResourceCategory = WebResourceCategory.NON_INFORMATION_RESOURCE; getVariants().addAll(RDFMediaTypes.getRDFVariants()); } else { webResourceCategory = WebResourceCategory.INFORMATION_RESOURCE; getVariants().add(RDFMediaTypes.findVariant(format.get())); hostIdentifier = this.getRequest().getResourceRef().getHostIdentifier(); baseRef = this.getRequest().getResourceRef().getBaseRef().toString(); subjectResourceURI = selfURI.substring(0, i); typeSpecificId = subjectResourceURI.substring(baseRef.length()); datasetURI = LinkedDataServer.getInstance().getDatasetURI(); sail = LinkedDataServer.getInstance().getSail(); } MediaType type = variant.getMediaType(); switch (webResourceCategory) { case INFORMATION_RESOURCE: return representInformationResource(); case NON_INFORMATION_RESOURCE: return representNonInformationResource(type); default: throw new IllegalStateException("no such resource type: " + webResourceCategory); } }