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 org.fcrepo.kernel.api.RdfLexicon.DESCRIBES; 020import static org.fcrepo.kernel.api.RdfLexicon.DESCRIBED_BY; 021 022import org.fcrepo.kernel.api.models.NonRdfSourceDescription; 023import org.fcrepo.kernel.api.models.FedoraBinary; 024import org.fcrepo.kernel.api.models.FedoraResource; 025import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 026 027import com.hp.hpl.jena.graph.Node; 028import com.hp.hpl.jena.rdf.model.Resource; 029 030/** 031 * @author cabeer 032 * @author ajs6f 033 * @since 10/16/14 034 */ 035public class ContentRdfContext extends NodeRdfContext { 036 /** 037 * Default constructor. 038 * 039 * @param resource the resource 040 * @param idTranslator the idTranslator 041 */ 042 public ContentRdfContext(final FedoraResource resource, 043 final IdentifierConverter<Resource, FedoraResource> idTranslator) { 044 super(resource, idTranslator); 045 046 // if there's an accessible jcr:content node, include information about it 047 if (resource instanceof NonRdfSourceDescription) { 048 final FedoraResource contentNode = ((NonRdfSourceDescription) resource()).getDescribedResource(); 049 final Node subject = uriFor(resource()); 050 final Node contentSubject = uriFor(contentNode); 051 // add triples representing parent-to-content-child relationship 052 concat(create(subject, DESCRIBES.asNode(), contentSubject)); 053 054 } else if (resource instanceof FedoraBinary) { 055 final FedoraResource description = ((FedoraBinary) resource).getDescription(); 056 concat(create(uriFor(resource), DESCRIBED_BY.asNode(), uriFor(description))); 057 } 058 } 059}