001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.kernel.api.rdf; 019 020import java.io.File; 021import java.io.IOException; 022import java.util.HashMap; 023import java.util.Map; 024 025import org.fcrepo.kernel.api.utils.AutoReloadingConfiguration; 026 027import com.fasterxml.jackson.core.type.TypeReference; 028import com.fasterxml.jackson.databind.ObjectMapper; 029import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 030 031/** 032 * Registry of RDF namespaces 033 * 034 * @author bbpennel 035 */ 036public class RdfNamespaceRegistry extends AutoReloadingConfiguration { 037 038 private Map<String, String> namespaces; 039 040 /** 041 * Load the namespace prefix to URI configuration file 042 */ 043 @Override 044 protected synchronized void loadConfiguration() throws IOException { 045 final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); 046 final TypeReference<HashMap<String, String>> typeRef = new TypeReference<HashMap<String, String>>() {}; 047 namespaces = mapper.readValue(new File(configPath), typeRef); 048 } 049 050 /** 051 * Get the mapping of namespace prefixes to URIs 052 * 053 * @return map of namespace prefixes to URIs, or an empty map if no mapping was provided. 054 */ 055 public Map<String, String> getNamespaces() { 056 if (namespaces == null) { 057 namespaces = new HashMap<>(); 058 } 059 return namespaces; 060 } 061 062 /** 063 * Set the mapping of namespace prefixes to URIs 064 * 065 * @param namespaces mapping of namespaces 066 */ 067 public void setNamespaces(final Map<String, String> namespaces) { 068 this.namespaces = namespaces; 069 } 070}