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 RDF/XML (standard XML notation). 021 * 022 * <p> 023 * Produces human-readable RDF/XML output suitable for interchange and debugging. 024 * 025 * <h5 class='figure'>Examples:</h5> 026 * <p class='bjava'> 027 * <jc>// Serialize a bean to RDF/XML string.</jc> 028 * Person <jv>person</jv> = <jk>new</jk> Person(<js>"Alice"</js>, 30); 029 * String <jv>rdfXml</jv> = RdfXmlSerializer.<jsf>DEFAULT</jsf>.write(<jv>person</jv>); 030 * </p> 031 * <p class='bjava'> 032 * <jc>// Or use the RdfXml marshaller for convenience.</jc> 033 * String <jv>rdfXml</jv> = RdfXml.<jsf>DEFAULT</jsf>.write(<jv>person</jv>); 034 * </p> 035 * <p class='bjava'> 036 * <jc>// Custom serializer with swaps.</jc> 037 * RdfXmlSerializer <jv>s</jv> = RdfXmlSerializer.create().swaps(DateSwap.<jk>class</jk>).build(); 038 * String <jv>rdfXml</jv> = <jv>s</jv>.write(<jv>bean</jv>); 039 * </p> 040 * 041 * <h5 class='figure'>Example output (bean with name/age):</h5> 042 * <p class='bxml'> 043 * <xt><rdf:RDF></xt> 044 * <xt><rdf:Description rdf:about=</xt><xs>"..."</xs><xt>></xt> 045 * <xt><j:name></xt>Alice<xt></j:name></xt> 046 * <xt><j:age></xt>30<xt></j:age></xt> 047 * <xt></rdf:Description></xt> 048 * <xt></rdf:RDF></xt> 049 * </p> 050 * 051 * <h5 class='figure'>Complex (nested address + array):</h5> 052 * <p class='bxml'> 053 * <xt><rdf:RDF></xt> 054 * <xt><rdf:Description rdf:about=</xt><xs>"..."</xs><xt>></xt> 055 * <xt><j:name></xt>Alice<xt></j:name></xt> 056 * <xt><j:age></xt>30<xt></j:age></xt> 057 * <xt><j:address rdf:resource=</xt><xs>".../address"</xs><xt>/></xt> 058 * <xt><j:tags rdf:resource=</xt><xs>".../tags"</xs><xt>/></xt> 059 * <xt></rdf:Description></xt> 060 * <xt><rdf:Description rdf:about=</xt><xs>".../address"</xs><xt>></xt> 061 * <xt><j:street></xt>123 Main St<xt></j:street></xt> 062 * <xt><j:city></xt>Boston<xt></j:city></xt> 063 * <xt><j:state></xt>MA<xt></j:state></xt> 064 * <xt></rdf:Description></xt> 065 * <xt></rdf:RDF></xt> 066 * </p> 067 * 068 * <h5 class='section'>Notes:</h5><ul> 069 * <li class='note'>This class is thread safe and reusable. 070 * </ul> 071 * 072 * <h5 class='section'>See Also:</h5><ul> 073 * <li class='link'>{doc jmr.RdfDetails} 074 * </ul> 075 */ 076@SuppressWarnings({ 077 "java:S110" // Deep inheritance inherent to the RDF serializer hierarchy. 078}) 079public class RdfXmlSerializer extends RdfSerializer { 080 081 /** Default RDF/XML serializer, all default settings.*/ 082 public static final RdfXmlSerializer DEFAULT = new RdfXmlSerializer(create()); 083 084 /** 085 * Creates a new builder for this object. 086 * 087 * @return A new builder. 088 */ 089 @SuppressWarnings({ 090 "java:S1452", // Builder<?> wildcard return intentional; callers chain via fluent API without needing the concrete type 091 "java:S9149" // Public Juneau DSL factory; hiding parent create() is intentional. 092 }) 093 public static RdfSerializer.Builder<?> create() { 094 return RdfSerializer.create().xml(); 095 } 096 097 /** 098 * Constructor. 099 * 100 * @param builder The builder for this object. 101 * <br>Cannot be <jk>null</jk>. 102 */ 103 public RdfXmlSerializer(RdfSerializer.Builder<?> builder) { 104 super(builder.xml()); 105 } 106}