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