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