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 com.hp.hpl.jena.rdf.model.Resource; 019 020import org.fcrepo.kernel.api.models.FedoraResource; 021import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 022 023import javax.jcr.Node; 024import javax.jcr.RepositoryException; 025 026import java.util.Iterator; 027import java.util.List; 028import static java.util.Arrays.asList; 029import static org.fcrepo.kernel.modeshape.identifiers.NodeResourceConverter.nodeConverter; 030 031/** 032 * @author cabeer 033 * @author ajs6f 034 * @since 10/9/14 035 */ 036public class HashRdfContext extends NodeRdfContext { 037 038 039 private static final List<Class<? extends NodeRdfContext>> contexts = asList(TypeRdfContext.class, 040 PropertiesRdfContext.class, SkolemNodeRdfContext.class); 041 042 /** 043 * Default constructor. 044 * 045 * @param resource the resource 046 * @param idTranslator the id translator 047 * @throws javax.jcr.RepositoryException if repository exception occurred 048 */ 049 public HashRdfContext(final FedoraResource resource, 050 final IdentifierConverter<Resource, FedoraResource> idTranslator) 051 throws RepositoryException { 052 super(resource, idTranslator); 053 054 final Node node = resource().getNode(); 055 if (node.hasNode("#")) { 056 @SuppressWarnings("unchecked") 057 final Iterator<Node> hashChildrenNodes = node.getNode("#").getNodes(); 058 concat(flatMap(hashChildrenNodes, n -> nodeConverter.convert(n).getTriples(idTranslator, contexts))); 059 } 060 } 061}