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.jena; 019 020import org.apache.jena.atlas.io.IndentedWriter; 021import org.apache.jena.graph.Graph; 022import org.apache.jena.riot.system.PrefixMap; 023import org.apache.jena.riot.writer.TurtleWriter; 024import org.apache.jena.sparql.util.Context; 025 026/** 027 * @author awoods 028 * @since 2017/01/03 029 */ 030public class FedoraTurtleWriter extends TurtleWriter { 031 032 @Override 033 protected void output(final IndentedWriter iOut, 034 final Graph graph, 035 final PrefixMap prefixMap, 036 final String baseURI, 037 final Context context) { 038 final FedoraTurtleWriter.TurtleWriter$ w = 039 new FedoraTurtleWriter.TurtleWriter$(iOut, prefixMap, baseURI, context) ; 040 w.write(graph) ; 041 } 042 043 private static class TurtleWriter$ extends CopyOfTurtleShell { 044 045 /** 046 * 047 * @param out 048 * @param prefixMap 049 * @param baseURI 050 * @param context 051 */ 052 public TurtleWriter$(final IndentedWriter out, 053 final PrefixMap prefixMap, 054 final String baseURI, 055 final Context context) { 056 super(out, prefixMap, baseURI, context) ; 057 } 058 059 private void write(final Graph graph) { 060 writeBase(baseURI) ; 061 writePrefixes(prefixMap) ; 062 if ( !prefixMap.isEmpty() && !graph.isEmpty() ) { 063 out.println(); 064 } 065 writeGraphTTL(graph) ; 066 } 067 } 068 069}