[Devel] reimplementing using visitor pattern
Changing to the visitor pattern will make it easier to implement a SAX reader and writer
This commit is contained in:
parent
3310a8d471
commit
0605dd784f
332
pom.xml
332
pom.xml
|
@ -1,115 +1,73 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>ch.eitchnet</groupId>
|
<groupId>ch.eitchnet</groupId>
|
||||||
<artifactId>ch.eitchnet.xmlpers</artifactId>
|
<artifactId>ch.eitchnet.xmlpers</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>ch.eitchnet.xmlpers</name>
|
<name>ch.eitchnet.xmlpers</name>
|
||||||
<url>https://github.com/eitch/ch.eitchnet.xmlpers</url>
|
<url>https://github.com/eitch/ch.eitchnet.xmlpers</url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- POM Reference: http://maven.apache.org/pom.html#Licenses -->
|
<!-- POM Reference: http://maven.apache.org/pom.html#Licenses -->
|
||||||
|
|
||||||
<inceptionYear>2011</inceptionYear>
|
<inceptionYear>2011</inceptionYear>
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>GNU Lesser General Public License</name>
|
<name>GNU Lesser General Public License</name>
|
||||||
<url>http://www.gnu.org/licenses/lgpl.html</url>
|
<url>http://www.gnu.org/licenses/lgpl.html</url>
|
||||||
<distribution>repo</distribution>
|
<distribution>repo</distribution>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
<organization>
|
<organization>
|
||||||
<name>eitchnet.ch</name>
|
<name>eitchnet.ch</name>
|
||||||
<url>http://blog.eitchnet.ch</url>
|
<url>http://blog.eitchnet.ch</url>
|
||||||
</organization>
|
</organization>
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
<id>eitch</id>
|
<id>eitch</id>
|
||||||
<name>Robert von Vurg</name>
|
<name>Robert von Vurg</name>
|
||||||
<email>eitch@eitchnet.ch</email>
|
<email>eitch@eitchnet.ch</email>
|
||||||
<url>http://blog.eitchnet.ch</url>
|
<url>http://blog.eitchnet.ch</url>
|
||||||
<organization>eitchnet.ch</organization>
|
<organization>eitchnet.ch</organization>
|
||||||
<organizationUrl>http://blog.eitchnet.ch</organizationUrl>
|
<organizationUrl>http://blog.eitchnet.ch</organizationUrl>
|
||||||
<roles>
|
<roles>
|
||||||
<role>architect</role>
|
<role>architect</role>
|
||||||
<role>developer</role>
|
<role>developer</role>
|
||||||
</roles>
|
</roles>
|
||||||
<timezone>+1</timezone>
|
<timezone>+1</timezone>
|
||||||
<properties>
|
<properties>
|
||||||
<picUrl>http://localhost</picUrl>
|
<picUrl>http://localhost</picUrl>
|
||||||
</properties>
|
</properties>
|
||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<issueManagement>
|
<issueManagement>
|
||||||
<system>Github Issues</system>
|
<system>Github Issues</system>
|
||||||
<url>https://github.com/eitch/ch.eitchnet.xmlpers/issues</url>
|
<url>https://github.com/eitch/ch.eitchnet.xmlpers/issues</url>
|
||||||
</issueManagement>
|
</issueManagement>
|
||||||
|
|
||||||
<!--
|
<!-- <ciManagement> <system>continuum</system> <url>http://127.0.0.1:8080/continuum</url> <notifiers> <notifier> <type>mail</type>
|
||||||
<ciManagement>
|
<sendOnError>true</sendOnError> <sendOnFailure>true</sendOnFailure> <sendOnSuccess>false</sendOnSuccess> <sendOnWarning>false</sendOnWarning>
|
||||||
<system>continuum</system>
|
<configuration><address>continuum@127.0.0.1</address></configuration> </notifier> </notifiers> </ciManagement> <mailingLists>
|
||||||
<url>http://127.0.0.1:8080/continuum</url>
|
<mailingList> <name>User List</name> <subscribe>user-subscribe@127.0.0.1</subscribe> <unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe>
|
||||||
<notifiers>
|
<post>user@127.0.0.1</post> <archive>http://127.0.0.1/user/</archive> <otherArchives> <otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
|
||||||
<notifier>
|
</otherArchives> </mailingList> </mailingLists> -->
|
||||||
<type>mail</type>
|
|
||||||
<sendOnError>true</sendOnError>
|
|
||||||
<sendOnFailure>true</sendOnFailure>
|
|
||||||
<sendOnSuccess>false</sendOnSuccess>
|
|
||||||
<sendOnWarning>false</sendOnWarning>
|
|
||||||
<configuration><address>continuum@127.0.0.1</address></configuration>
|
|
||||||
</notifier>
|
|
||||||
</notifiers>
|
|
||||||
</ciManagement>
|
|
||||||
|
|
||||||
<mailingLists>
|
<scm>
|
||||||
<mailingList>
|
<connection>scm:git:https://github.com/eitch/ch.eitchnet.xmlpers.git</connection>
|
||||||
<name>User List</name>
|
<developerConnection>scm:git:git@github.com:eitch/ch.eitchnet.xmlpers.git</developerConnection>
|
||||||
<subscribe>user-subscribe@127.0.0.1</subscribe>
|
<url>https://github.com/eitch/ch.eitchnet.xmlpers</url>
|
||||||
<unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe>
|
</scm>
|
||||||
<post>user@127.0.0.1</post>
|
|
||||||
<archive>http://127.0.0.1/user/</archive>
|
|
||||||
<otherArchives>
|
|
||||||
<otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
|
|
||||||
</otherArchives>
|
|
||||||
</mailingList>
|
|
||||||
</mailingLists>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<scm>
|
<!-- <repositories> <repository> <releases> <enabled>false</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>warn</checksumPolicy>
|
||||||
<connection>scm:git:https://github.com/eitch/ch.eitchnet.xmlpers.git</connection>
|
</releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>fail</checksumPolicy>
|
||||||
<developerConnection>scm:git:git@github.com:eitch/ch.eitchnet.xmlpers.git</developerConnection>
|
</snapshots> <id>codehausSnapshots</id> <name>Codehaus Snapshots</name> <url>http://snapshots.maven.codehaus.org/maven2</url>
|
||||||
<url>https://github.com/eitch/ch.eitchnet.xmlpers</url>
|
<layout>default</layout> </repository> </repositories> <pluginRepositories> ... </pluginRepositories> -->
|
||||||
</scm>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<releases>
|
|
||||||
<enabled>false</enabled>
|
|
||||||
<updatePolicy>always</updatePolicy>
|
|
||||||
<checksumPolicy>warn</checksumPolicy>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
<updatePolicy>never</updatePolicy>
|
|
||||||
<checksumPolicy>fail</checksumPolicy>
|
|
||||||
</snapshots>
|
|
||||||
<id>codehausSnapshots</id>
|
|
||||||
<name>Codehaus Snapshots</name>
|
|
||||||
<url>http://snapshots.maven.codehaus.org/maven2</url>
|
|
||||||
<layout>default</layout>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
<pluginRepositories>
|
|
||||||
...
|
|
||||||
</pluginRepositories>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>deployment</id>
|
<id>deployment</id>
|
||||||
|
@ -123,93 +81,93 @@
|
||||||
</snapshotRepository>
|
</snapshotRepository>
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.10</version>
|
<version>4.10</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.eitchnet</groupId>
|
<groupId>ch.eitchnet</groupId>
|
||||||
<artifactId>ch.eitchnet.utils</artifactId>
|
<artifactId>ch.eitchnet.utils</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.2</version>
|
<version>1.7.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
<version>1.7.2</version>
|
<version>1.7.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-eclipse-plugin</artifactId>
|
|
||||||
<version>2.9</version>
|
|
||||||
<configuration>
|
|
||||||
<downloadJavadocs>true</downloadJavadocs>
|
|
||||||
<downloadSources>true</downloadSources>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-eclipse-plugin</artifactId>
|
||||||
<version>2.3.2</version>
|
<version>2.9</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.6</source>
|
<downloadJavadocs>true</downloadJavadocs>
|
||||||
<target>1.6</target>
|
<downloadSources>true</downloadSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
<version>2.1.2</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-sources</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar-no-fork</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.4</version>
|
<version>2.3.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<source>1.6</source>
|
||||||
<manifest>
|
<target>1.6</target>
|
||||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
</configuration>
|
||||||
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
</plugin>
|
||||||
<!--mainClass>ch.eitchnet.App</mainClass-->
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-site-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>2.3</version>
|
<version>2.1.2</version>
|
||||||
<configuration>
|
<executions>
|
||||||
<outputEncoding>UTF-8</outputEncoding>
|
<execution>
|
||||||
</configuration>
|
<id>attach-sources</id>
|
||||||
</plugin>
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
<plugin>
|
||||||
</build>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||||
|
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
|
||||||
|
<!--mainClass>ch.eitchnet.App</mainClass -->
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>2.3</version>
|
||||||
|
<configuration>
|
||||||
|
<outputEncoding>UTF-8</outputEncoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,432 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package ch.eitchnet.xmlpers;
|
||||||
|
|
||||||
|
import javax.xml.namespace.NamespaceContext;
|
||||||
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public class FormattingXmlStreamWriter implements XMLStreamWriter {
|
||||||
|
|
||||||
|
private final XMLStreamWriter writer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param writer
|
||||||
|
*/
|
||||||
|
public FormattingXmlStreamWriter(XMLStreamWriter writer) {
|
||||||
|
this.writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start of elements
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeStartDocument()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeStartDocument() throws XMLStreamException {
|
||||||
|
preStart();
|
||||||
|
this.writer.writeStartDocument();
|
||||||
|
postStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void preStart() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void postStart() throws XMLStreamException {
|
||||||
|
//this.writer.writeCharacters(new char[] { '\n' }, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void preEnd() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void postEnd() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param version
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeStartDocument(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeStartDocument(String version) throws XMLStreamException {
|
||||||
|
preStart();
|
||||||
|
this.writer.writeStartDocument(version);
|
||||||
|
postStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param encoding
|
||||||
|
* @param version
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeStartDocument(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
|
||||||
|
preStart();
|
||||||
|
this.writer.writeStartDocument(encoding, version);
|
||||||
|
postStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param localName
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeStartElement(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeStartElement(String localName) throws XMLStreamException {
|
||||||
|
preStart();
|
||||||
|
this.writer.writeStartElement(localName);
|
||||||
|
postStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param namespaceURI
|
||||||
|
* @param localName
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeStartElement(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
|
||||||
|
preStart();
|
||||||
|
this.writer.writeStartElement(namespaceURI, localName);
|
||||||
|
postStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix
|
||||||
|
* @param localName
|
||||||
|
* @param namespaceURI
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeStartElement(java.lang.String, java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
|
||||||
|
preStart();
|
||||||
|
this.writer.writeStartElement(prefix, localName, namespaceURI);
|
||||||
|
postStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// End of elements
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeEndElement()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeEndElement() throws XMLStreamException {
|
||||||
|
preStart();
|
||||||
|
this.writer.writeEndElement();
|
||||||
|
postStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeEndDocument()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeEndDocument() throws XMLStreamException {
|
||||||
|
preStart();
|
||||||
|
this.writer.writeEndDocument();
|
||||||
|
postStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Empty elements
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param namespaceURI
|
||||||
|
* @param localName
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeEmptyElement(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
|
||||||
|
preEnd();
|
||||||
|
this.writer.writeEmptyElement(namespaceURI, localName);
|
||||||
|
postEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix
|
||||||
|
* @param localName
|
||||||
|
* @param namespaceURI
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeEmptyElement(java.lang.String, java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
|
||||||
|
preEnd();
|
||||||
|
this.writer.writeEmptyElement(prefix, localName, namespaceURI);
|
||||||
|
postEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param localName
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeEmptyElement(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeEmptyElement(String localName) throws XMLStreamException {
|
||||||
|
this.writer.writeEmptyElement(localName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// attributes
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param localName
|
||||||
|
* @param value
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeAttribute(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeAttribute(String localName, String value) throws XMLStreamException {
|
||||||
|
this.writer.writeAttribute(localName, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix
|
||||||
|
* @param namespaceURI
|
||||||
|
* @param localName
|
||||||
|
* @param value
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeAttribute(java.lang.String, java.lang.String, java.lang.String,
|
||||||
|
* java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
|
||||||
|
throws XMLStreamException {
|
||||||
|
this.writer.writeAttribute(prefix, namespaceURI, localName, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param namespaceURI
|
||||||
|
* @param localName
|
||||||
|
* @param value
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeAttribute(java.lang.String, java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
|
||||||
|
this.writer.writeAttribute(namespaceURI, localName, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// other
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeComment(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeComment(String data) throws XMLStreamException {
|
||||||
|
this.writer.writeComment(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param target
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeProcessingInstruction(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeProcessingInstruction(String target) throws XMLStreamException {
|
||||||
|
this.writer.writeProcessingInstruction(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param target
|
||||||
|
* @param data
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeProcessingInstruction(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
|
||||||
|
this.writer.writeProcessingInstruction(target, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeCData(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeCData(String data) throws XMLStreamException {
|
||||||
|
this.writer.writeCData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dtd
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeDTD(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeDTD(String dtd) throws XMLStreamException {
|
||||||
|
this.writer.writeDTD(dtd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix
|
||||||
|
* @param namespaceURI
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeNamespace(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
|
||||||
|
this.writer.writeNamespace(prefix, namespaceURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param namespaceURI
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeDefaultNamespace(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
|
||||||
|
this.writer.writeDefaultNamespace(namespaceURI);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeEntityRef(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeEntityRef(String name) throws XMLStreamException {
|
||||||
|
this.writer.writeEntityRef(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param text
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeCharacters(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeCharacters(String text) throws XMLStreamException {
|
||||||
|
this.writer.writeCharacters(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param text
|
||||||
|
* @param start
|
||||||
|
* @param len
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#writeCharacters(char[], int, int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
|
||||||
|
this.writer.writeCharacters(text, start, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param uri
|
||||||
|
* @return
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#getPrefix(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getPrefix(String uri) throws XMLStreamException {
|
||||||
|
return this.writer.getPrefix(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix
|
||||||
|
* @param uri
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#setPrefix(java.lang.String, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setPrefix(String prefix, String uri) throws XMLStreamException {
|
||||||
|
this.writer.setPrefix(prefix, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param uri
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#setDefaultNamespace(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setDefaultNamespace(String uri) throws XMLStreamException {
|
||||||
|
this.writer.setDefaultNamespace(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param context
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#setNamespaceContext(javax.xml.namespace.NamespaceContext)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
|
||||||
|
this.writer.setNamespaceContext(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#getNamespaceContext()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public NamespaceContext getNamespaceContext() {
|
||||||
|
return this.writer.getNamespaceContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name
|
||||||
|
* @return
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#getProperty(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object getProperty(String name) throws IllegalArgumentException {
|
||||||
|
return this.writer.getProperty(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#close()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close() throws XMLStreamException {
|
||||||
|
this.writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws XMLStreamException
|
||||||
|
* @see javax.xml.stream.XMLStreamWriter#flush()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void flush() throws XMLStreamException {
|
||||||
|
this.writer.flush();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package ch.eitchnet.xmlpers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
|
||||||
|
import javax.xml.stream.XMLOutputFactory;
|
||||||
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
|
XMLOutputFactory factory = XMLOutputFactory.newInstance();
|
||||||
|
|
||||||
|
File file = new File("output.xml");
|
||||||
|
XMLStreamWriter writer = factory.createXMLStreamWriter(new FileWriter(file));
|
||||||
|
System.out.println("writer: " + writer.getClass().getName());
|
||||||
|
|
||||||
|
//writer = new com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter(writer);
|
||||||
|
writer = new FormattingXmlStreamWriter(writer);
|
||||||
|
|
||||||
|
writer.writeStartDocument();
|
||||||
|
writer.writeStartElement("document");
|
||||||
|
writer.writeStartElement("data");
|
||||||
|
writer.writeAttribute("name", "value");
|
||||||
|
writer.writeEndElement();
|
||||||
|
writer.writeEndElement();
|
||||||
|
writer.writeEndDocument();
|
||||||
|
|
||||||
|
writer.flush();
|
||||||
|
writer.close();
|
||||||
|
System.out.println("Wrote to " + file.getAbsolutePath());
|
||||||
|
|
||||||
|
//Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
//Result outputTarget = new StaxR;
|
||||||
|
//Source xmlSource;
|
||||||
|
//transformer.transform(xmlSource, outputTarget);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package ch.eitchnet.xmlpers;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface XmlSaxWriter {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue