mirror of https://github.com/apache/archiva.git
Adding XMLWriter
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@529613 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
01b7555594
commit
8e01424163
|
@ -37,11 +37,27 @@
|
||||||
<groupId>dom4j</groupId>
|
<groupId>dom4j</groupId>
|
||||||
<artifactId>dom4j</artifactId>
|
<artifactId>dom4j</artifactId>
|
||||||
<version>1.6.1</version>
|
<version>1.6.1</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>xom</groupId>
|
||||||
|
<artifactId>xom</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jaxen</groupId>
|
<groupId>jaxen</groupId>
|
||||||
<artifactId>jaxen</artifactId>
|
<artifactId>jaxen</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.1</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>jdom</groupId>
|
||||||
|
<artifactId>jdom</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>xom</groupId>
|
||||||
|
<artifactId>xom</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package org.apache.maven.archiva.xml;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.io.OutputFormat;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XMLWriter
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class XMLWriter
|
||||||
|
{
|
||||||
|
public static void write( Document doc, Writer writer )
|
||||||
|
throws XMLException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OutputFormat outputFormat = OutputFormat.createPrettyPrint();
|
||||||
|
org.dom4j.io.XMLWriter xmlwriter = new org.dom4j.io.XMLWriter( writer, outputFormat );
|
||||||
|
xmlwriter.write( doc );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new XMLException( "Unable to write xml contents to writer: " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<basic>
|
<basic>
|
||||||
<names>
|
<names>
|
||||||
<name>Trygve Laugstøl</name>
|
<name>Trygve Laugstøl</name>
|
||||||
<name>The ∞ Archiva</name>
|
<name>The ∞ Archiva</name>
|
||||||
</names>
|
</names>
|
||||||
</basic>
|
</basic>
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
package org.apache.maven.archiva.xml;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
import org.dom4j.Document;
|
||||||
|
import org.dom4j.DocumentHelper;
|
||||||
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XMLWriterTest
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class XMLWriterTest
|
||||||
|
extends AbstractArchivaXmlTestCase
|
||||||
|
{
|
||||||
|
public void testWrite()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
String expectedResults = FileUtils.fileRead( getExampleXml( "prolog-with-utf8.xml" ) );
|
||||||
|
|
||||||
|
Element basic = DocumentHelper.createElement( "basic" );
|
||||||
|
Document doc = DocumentHelper.createDocument( basic );
|
||||||
|
|
||||||
|
Element names = basic.addElement( "names" );
|
||||||
|
names.addElement( "name" ).setText( "Trygve Laugst\u00f8l" );
|
||||||
|
names.addElement( "name" ).setText( "The \u221e Archiva" );
|
||||||
|
|
||||||
|
StringWriter actual = new StringWriter();
|
||||||
|
XMLWriter.write( doc, actual );
|
||||||
|
|
||||||
|
assertEquals( "Comparision of contents:", expectedResults, actual.toString() );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue