1 package org.apache.maven.doxia.module.xdoc; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.io.IOException; 23 import java.io.StringReader; 24 import java.io.StringWriter; 25 26 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; 27 import org.codehaus.plexus.util.xml.XMLWriter; 28 import org.codehaus.plexus.util.xml.XmlUtil; 29 30 /** 31 * A Doxia Sink which produces an xdoc document. 32 * 33 * @author juan <a href="mailto:james@jamestaylor.org">James Taylor</a> 34 * @author Juan F. Codagnone (replaced println with XmlWriterXdocSink) 35 * @version $Id: XmlWriterXdocSink.java 746992 2009-02-23 12:35:59Z vsiveton $ 36 * @deprecated Since 1.1, this sink is not more supported. If you are looking for a <code>Sink</code> which produces 37 * pretty formatted XML, you could use the {@link XdocSink#XdocSink(java.io.Writer)} as usual and reformat the 38 * <code>Sink</code> content produced with {@link XmlUtil#prettyFormat(java.io.Reader, java.io.Writer)}. 39 */ 40 public class XmlWriterXdocSink 41 extends XdocSink 42 { 43 /** Writer used by Xdoc */ 44 private StringWriter xdocWriter; 45 46 private XMLWriter xmlWriter; 47 48 private XmlWriterXdocSink( StringWriter out, String encoding ) 49 { 50 super( out, encoding ); 51 this.xdocWriter = out; 52 this.xmlWriter = new PrettyPrintXMLWriter( out ); 53 } 54 55 /** 56 * <p>Constructor for XmlWriterXdocSink.</p> 57 * 58 * @param out the wanted XML Writer. 59 * @deprecated since 1.1 60 */ 61 public XmlWriterXdocSink( XMLWriter out ) 62 { 63 this( new StringWriter(), "UTF-8" ); 64 this.xmlWriter = out; 65 } 66 67 /** {@inheritDoc} */ 68 public void close() 69 { 70 super.close(); 71 72 String xdocContent = xdocWriter.toString(); 73 if ( getLog().isDebugEnabled() ) 74 { 75 getLog().debug( "Xdoc content: " + xdocContent ); 76 } 77 StringWriter formattedContent = new StringWriter(); 78 try 79 { 80 XmlUtil.prettyFormat( new StringReader( xdocContent ), formattedContent ); 81 } 82 catch ( IOException e ) 83 { 84 if ( getLog().isDebugEnabled() ) 85 { 86 getLog().error( "IOException: " + e.getMessage(), e ); 87 } 88 formattedContent = new StringWriter(); 89 formattedContent.write( xdocContent ); 90 } 91 xmlWriter.writeMarkup( formattedContent.toString() ); 92 } 93 }