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