001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.marshall.jena; 018 019/** 020 * Subclass of {@link RdfSerializer} for serializing POJOs to Turtle format. 021 * 022 * <p> 023 * Produces compact, human-readable RDF in W3C Turtle syntax. Turtle is widely used for RDF 024 * interchange and is often more readable than RDF/XML. 025 * 026 * <h5 class='figure'>Examples:</h5> 027 * <p class='bjava'> 028 * <jc>// Serialize a bean to Turtle string.</jc> 029 * Person <jv>person</jv> = <jk>new</jk> Person(<js>"Alice"</js>, 30); 030 * String <jv>turtle</jv> = TurtleSerializer.<jsf>DEFAULT</jsf>.write(<jv>person</jv>); 031 * </p> 032 * <p class='bjava'> 033 * <jc>// Or use the Turtle marshaller for convenience.</jc> 034 * String <jv>turtle</jv> = Turtle.<jsf>DEFAULT</jsf>.write(<jv>person</jv>); 035 * </p> 036 * <p class='bjava'> 037 * <jc>// Custom serializer with swaps.</jc> 038 * TurtleSerializer <jv>s</jv> = TurtleSerializer.create().swaps(DateSwap.<jk>class</jk>).build(); 039 * String <jv>turtle</jv> = <jv>s</jv>.write(<jv>bean</jv>); 040 * </p> 041 * 042 * <h5 class='figure'>Example output (bean with name/age):</h5> 043 * <p class='bcode'> 044 * @prefix j: <...> . 045 * <...> a j:Person ; j:name "Alice" ; j:age 30 . 046 * </p> 047 * 048 * <h5 class='figure'>Complex (nested address + array):</h5> 049 * <p class='bcode'> 050 * @prefix j: <...> . 051 * <...> a j:Person ; j:name "Alice" ; j:age 30 ; 052 * j:address <.../address> ; j:tags <.../tags> . 053 * <.../address> a j:Address ; j:street "123 Main St" ; 054 * j:city "Boston" ; j:state "MA" . 055 * <.../tags> j:member "a", "b", "c" . 056 * </p> 057 * 058 * <h5 class='section'>Notes:</h5><ul> 059 * <li class='note'>This class is thread safe and reusable. 060 * </ul> 061 * 062 * <h5 class='section'>See Also:</h5><ul> 063 * <li class='link'>{doc jmr.RdfDetails} 064 * </ul> 065 */ 066@SuppressWarnings({ 067 "java:S110" // Deep inheritance inherent to the RDF serializer hierarchy. 068}) 069public class TurtleSerializer extends RdfSerializer { 070 071 /** Default Turtle serializer, all default settings.*/ 072 public static final TurtleSerializer DEFAULT = new TurtleSerializer(create()); 073 074 /** 075 * Creates a new builder for this object. 076 * 077 * @return A new builder. 078 */ 079 @SuppressWarnings({ 080 "java:S1452", // Builder<?> wildcard return intentional; callers chain via fluent API without needing the concrete type 081 "java:S9149" // Public Juneau DSL factory; hiding parent create() is intentional. 082 }) 083 public static RdfSerializer.Builder<?> create() { 084 return RdfSerializer.create().turtle(); 085 } 086 087 /** 088 * Constructor. 089 * 090 * @param builder The builder for this object. 091 * <br>Cannot be <jk>null</jk>. 092 */ 093 public TurtleSerializer(RdfSerializer.Builder<?> builder) { 094 super(builder.turtle()); 095 } 096}