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