All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nbnResolving.views.RdfXmlView Maven / Gradle / Ivy

Go to download

Java classes providing resolving functionality for Persistent Identifiers. Main focus is on National Bibliography Numbers, but some other known systems are also supported. See the official URN:NBN Resolver http://nbn-resolving.org or http://persid.org

The newest version!
/* *********************************************************************
 * Class RdfXmlView
 * 
 * Copyright (c) 2011-2012, German National Library/Deutsche Nationalbibliothek
 * Adickesallee 1, D-60322 Frankfurt am Main, Federal Republic of Germany 
 *
 * This program is free software.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Thomas Haidlas -- German National Library
 * Kadir Karaca Kocer -- German National Library
 **********************************************************************/

/* ********************************************************************
 * CHANGELOG:
 * 
 * 2012-04-03 Port to Maven by Timo Heck & Karaca Kocer
 * 2011-12-12 Licence information and JavaDocs by Karaca Kocer
 * Created on 2011-12-08 by Thomas Haidlas -- German National Library
 ********************************************************************/

package org.nbnResolving.views;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nbnResolving.converters.RdfXmlConverter;
import org.nbnResolving.pidef.PidefDocument;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.vocabulary.DCTerms;

/**
 * Renders all UrnRecord to RDF/XML.
 * 
 * @author Thomas Haidlas
 */

public final class RdfXmlView extends BaseView {

	private static final Map PREFIXES = new HashMap();
	private static final String RDF_FORMAT = "RDF/XML-ABBREV";
	
	private RdfXmlConverter rdfConverter;

	static{
		PREFIXES.put("dcterms", DCTerms.NS);
		PREFIXES.put("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
		PREFIXES.put("owl", com.hp.hpl.jena.vocabulary.OWL.NS);				
	}
	
	/** Constructor */
	public RdfXmlView(){
		setContentType("application/rdf+xml");		
	}
	
	/**
	 * @return RDF/XML converter
	 */
	public RdfXmlConverter getRdfConverter() {
		return this.rdfConverter;
	}

	/**
	 * @param converter Converter to set
	 */
	public void setRdfConverter(final RdfXmlConverter converter) {
		this.rdfConverter = converter;
	}

	@Override
	protected void renderMergedOutputModel(final Map model,
			final HttpServletRequest request, final HttpServletResponse response)
			throws Exception {
		//final String identifier = (String) model.get("identifier");
		final Model rdfModel = ModelFactory.createDefaultModel();
		rdfModel.setNsPrefixes(PREFIXES);
		
		for (Map.Entry entry : model.entrySet()) {
			if(entry.getValue() instanceof PidefDocument){
				final PidefDocument record = (PidefDocument) entry.getValue();
				this.rdfConverter.addRecordToModel(rdfModel, record);
			}
		}

		rdfModel.write(response.getOutputStream(), RDF_FORMAT);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy