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