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

com.github.gkutiel.flip.web.XmlResponse Maven / Gradle / Ivy

package com.github.gkutiel.flip.web;

import java.text.MessageFormat;

import org.w3c.dom.Document;

import com.github.gkutiel.flip.processor.pub.Responce;
import com.github.gkutiel.flip.utils.Utils;

public class XmlResponse implements Responce {

	@Override
	public byte[] getBytes(final Object result, final String... xsl) {
		try {
			final Document doc = Utils.Xml.toXml(result);
			if (xsl != null && xsl.length > 0) {
				final String stylesheet = MessageFormat.format("type=''text/xsl'' href=''/{0}''", xsl[0]);
				doc.insertBefore(doc.createProcessingInstruction("xml-stylesheet", stylesheet), doc.getDocumentElement());
			}
			return Utils.Xml.toString(doc).getBytes();
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy