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.kernel.modeshape.rdf.impl; 019 020import static org.apache.jena.graph.Triple.create; 021import static org.apache.jena.vocabulary.RDF.type; 022import static org.fcrepo.kernel.api.FedoraTypes.FEDORA_CONTAINER; 023import static org.fcrepo.kernel.api.RdfLexicon.BASIC_CONTAINER; 024import static org.fcrepo.kernel.api.RdfLexicon.CONTAINER; 025import static org.fcrepo.kernel.api.RdfLexicon.NON_RDF_SOURCE; 026import static org.fcrepo.kernel.api.RdfLexicon.RDF_SOURCE; 027 028import java.util.stream.Stream; 029import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 030import org.fcrepo.kernel.api.models.Container; 031import org.fcrepo.kernel.api.models.FedoraResource; 032import org.fcrepo.kernel.api.models.NonRdfSourceDescription; 033import org.apache.jena.graph.Triple; 034import org.apache.jena.rdf.model.Resource; 035 036/** 037 * @author cabeer 038 * @since 9/16/14 039 */ 040public class LdpRdfContext extends NodeRdfContext { 041 042 043 /** 044 * Default constructor. 045 * 046 * @param resource the resource 047 * @param idTranslator the id translator 048 */ 049 public LdpRdfContext(final FedoraResource resource, 050 final IdentifierConverter<Resource, FedoraResource> idTranslator) { 051 super(resource, idTranslator); 052 053 final Stream.Builder<Triple> builder = Stream.builder(); 054 055 if (resource instanceof NonRdfSourceDescription) { 056 builder.accept(nonRdfSourceContext()); 057 } else { 058 builder.accept(typeContext()); 059 } 060 061 if (resource instanceof Container) { 062 builder.accept(containerContext()); 063 064 if (!resource.hasType(FEDORA_CONTAINER)) { 065 builder.accept(defaultContainerContext()); 066 } 067 } 068 concat(builder.build()); 069 } 070 071 private Triple typeContext() { 072 return create(subject(), type.asNode(), RDF_SOURCE.asNode()); 073 } 074 075 private Triple containerContext() { 076 return create(subject(), type.asNode(), CONTAINER.asNode()); 077 } 078 079 private Triple defaultContainerContext() { 080 return create(subject(), type.asNode(), BASIC_CONTAINER.asNode()); 081 } 082 083 private Triple nonRdfSourceContext() { 084 return create(subject(), type.asNode(), NON_RDF_SOURCE.asNode()); 085 } 086}