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.xml;
018
019import static org.apache.juneau.commons.utils.AssertionUtils.*;
020
021/**
022 * Serializes POJOs to HTTP responses as XML.
023 *
024 * <h5 class='topic'>Media types</h5>
025 *
026 * Handles <c>Accept</c> types:  <bc>text/xml</bc>
027 * <p>
028 * Produces <c>Content-Type</c> types:  <bc>text/xml</bc>
029 *
030 * <h5 class='topic'>Description</h5>
031 *
032 * Same as {@link XmlSerializer}, except prepends <code><xt>&lt;?xml</xt> <xa>version</xa>=<xs>'1.0'</xs>
033 * <xa>encoding</xa>=<xs>'UTF-8'</xs><xt>?&gt;</xt></code> to the response to make it a valid XML document.
034 *
035 * <h5 class='section'>Notes:</h5><ul>
036 *    <li class='note'>This class is thread safe and reusable.
037 * </ul>
038 *
039 * <h5 class='section'>See Also:</h5><ul>
040 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/XmlBasics">XML Basics</a>
041 * </ul>
042 */
043public class XmlDocSerializer extends XmlSerializer {
044   /** Default serializer without namespaces. */
045   public static class Ns extends XmlDocSerializer {
046
047      /**
048       * Constructor.
049       *
050       * @param builder The builder for this object.
051       *    <br>Cannot be <jk>null</jk>.
052       */
053      public Ns(XmlSerializer.Builder builder) {
054         super(assertArgNotNull("builder", builder).enableNamespaces());
055      }
056   }
057
058   /**
059    * Creates a new builder for this object.
060    *
061    * @return A new builder.
062    */
063   public static Builder create() {
064      return new Builder().type(XmlDocSerializer.class);
065   }
066
067   /**
068    * Constructor.
069    *
070    * @param builder The builder for this object.
071    *    <br>Cannot be <jk>null</jk>.
072    */
073   public XmlDocSerializer(XmlSerializer.Builder builder) {
074      super(assertArgNotNull("builder", builder));
075   }
076
077   @Override /* Overridden from Context */
078   public Builder copy() {
079      return new Builder(this);
080   }
081
082   @Override /* Overridden from Context */
083   public XmlDocSerializerSession.Builder createSession() {
084      return XmlDocSerializerSession.create(this);
085   }
086
087   @Override /* Overridden from Context */
088   public XmlDocSerializerSession getSession() { return createSession().build(); }
089}