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