package de.retest.recheck.persistence.xml.util;

import javax.xml.bind.Marshaller;

import de.retest.recheck.ui.descriptors.IdentifyingAttributesAdapter;
import de.retest.recheck.ui.descriptors.RenderContainedElementsAdapter;
import de.retest.recheck.ui.descriptors.StateAttributesAdapter;

public class XmlUtil {

	private XmlUtil() {}

	public static String clean( final Object input ) {
		if ( input == null ) {
			return null;
		}
		String result = input.toString().trim();
		result = result.replaceAll( "&", "&amp;" );
		result = result.replaceAll( "<", "&lt;" );
		result = result.replaceAll( ">", "&gt;" );
		result = result.replaceAll( "\"", "'" );
		return result;
	}

	public static void addLightWeightAdapter( final Marshaller marshaller ) {
		marshaller.setAdapter( new RenderContainedElementsAdapter( true ) );
		marshaller.setAdapter( new StateAttributesAdapter( true ) );
		marshaller.setAdapter( new IdentifyingAttributesAdapter( true ) );
	}
}

@@ -496,19 +496,16 @@
 .replace
-All
 ( %22&%22, %22
@@ -539,19 +539,16 @@
 .replace
-All
 ( %22%3C%22, %22
@@ -581,19 +581,16 @@
 .replace
-All
 ( %22%3E%22, %22
@@ -627,11 +627,8 @@
 lace
-All
 ( %22%5C

Replace `replaceAll` with `replace` for better perfomance