
org.nbnResolving.converters.RdfXmlConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resolver-core Show documentation
Show all versions of resolver-core Show documentation
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 RdfXmlConverter
*
* 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
**********************************************************************/
package org.nbnResolving.converters;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nbnResolving.common.URNUtils;
import org.nbnResolving.pidef.PidefDocument;
import org.nbnResolving.pidef.ResolvingInfoType;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.DCTerms;
/**
*
* @author Thomas Haidlas, German National Library
*/
public class RdfXmlConverter {
private static final Log LOGGER = LogFactory.getLog(RdfXmlConverter.class);
/**
* @param rdfModel
* @param document
* @return A RDF Model
*/
@SuppressWarnings("static-method")
public Model addRecordToModel(Model rdfModel, PidefDocument document){
org.nbnResolving.pidef.HeaderType header = document.getPidef().getHeader();
org.nbnResolving.pidef.DataType data = document.getPidef().getData();
String aboutUrl = header.getRequest();
Resource resource = rdfModel.createResource(aboutUrl);
resource.addProperty(DCTerms.mediator, header.getSource());
resource.addProperty(DCTerms.date, header.getTimestamp().toString());
if (data != null) {
String notSet = "";
ResolvingInfoType rit = data.getResolvingInformation();
if (rit != null) {
LOGGER.debug("RdfXmlConverter() found. Listing detailed information");
org.nbnResolving.pidef.UrlInfoType[] uit = rit.getUrlInfoArray();
resource.addProperty(DCTerms.publisher, rit.getPiInfo().getOwner().getName());
for (int i=0; i < uit.length; i++) {
String url = uit[i].getUrl();
if (url != null && !url.isEmpty()) {
resource.addProperty(DCTerms.identifier, URNUtils.correctUrlString(url, false, false));
}
}
resource.addProperty(DCTerms.isPartOf, notSet);
resource.addProperty(DCTerms.replaces, notSet);
resource.addProperty(DCTerms.isReplacedBy, notSet);
if (rit.getPiInfo().getCreated() != null) {
resource.addProperty(DCTerms.created, rit.getPiInfo().getCreated().toString());
}
if (rit.getPiInfo().getLastModified() != null) {
resource.addProperty(DCTerms.modified, rit.getPiInfo().getLastModified().toString());
}
} else {
//resolving information does not exist. try section
if (data.getLinks() != null) {
//loop all the links and write them in RDF
for (int i=0; i < data.getLinks().sizeOfLinkArray(); i++) {
String url = data.getLinks().getLinkArray(i);
if (url != null && !url.isEmpty()) {
//getFrontpage()?; Primary?
resource.addProperty(DCTerms.identifier, URNUtils.correctUrlString(url, false, false));
}
}
}
}
}
return rdfModel;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy