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