All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.conqat.lib.commons.xml.XMLWriter Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) CQSE GmbH
 *
 * Licensed 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.
 */

package org.conqat.lib.commons.xml;

import static org.conqat.lib.commons.string.StringUtils.LINE_SEPARATOR;
import static org.conqat.lib.commons.string.StringUtils.SPACE;

import java.io.Closeable;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.EmptyStackException;
import java.util.HashSet;
import java.util.Stack;

import org.conqat.lib.commons.filesystem.FileSystemUtils;
import org.conqat.lib.commons.string.StringUtils;

/**
 * Utility class for creating XML documents. Please consult test case XMLWriterTest to see how this
 * class is intended to be used.
 */
public class XMLWriter, A extends Enum> implements Closeable {

	/** Describes the states of the writer. */
	private enum EState {

		/** Indicates that we are at the beginning of the document. */
		DOCUMENT_START,

		/** Started a tag but did not close it yet. */
		INSIDE_TAG,

		/** Inside a text element. */
		INSIDE_TEXT,

		/**
		 * Indicates that we are between two tags but not within a text element.
		 */
		OUTSIDE_TAG
	}

	/** XML comment end symbol. */
	private static final String COMMENT_END = " -->";

	/** XML comment start symbol. */
	private static final String COMMENT_START = "
            
    
            


© 2015 - 2024 Weber Informatics LLC | Privacy Policy