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

io.github.nichetoolkit.rest.util.XmlUtils Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package io.github.nichetoolkit.rest.util;

import io.github.nichetoolkit.rest.error.often.XmlMarshalException;
import io.github.nichetoolkit.rest.error.often.XmlReadException;
import io.github.nichetoolkit.rest.error.often.XmlWriteException;
import io.github.nichetoolkit.rest.helper.XmlHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXB;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 

XmlUtils

* @author Cyan ([email protected]) * @version v1.0.0 */ @Slf4j public class XmlUtils { public static void encode(String filename, HttpServletResponse response) { XmlHelper.encode(filename,response); } public static Marshaller marshaller(Class clazz) { try { return XmlHelper.marshaller(clazz); } catch (XmlMarshalException exception) { log.error("It is failed when data write to create marshal! {}", exception.getMessage()); exception.printStackTrace(); return null; } } public static Unmarshaller unmarshaller(Class clazz) { try { return XmlHelper.unmarshaller(clazz); } catch (XmlMarshalException exception) { log.error("It is failed when data write to create marshal! {}", exception.getMessage()); exception.printStackTrace(); return null; } } public static T read(MultipartFile xmlFile, Class clazz) { try { return XmlHelper.read(xmlFile, clazz); } catch (XmlReadException exception) { log.error("It is failed when xml read! {}", exception.getMessage()); exception.printStackTrace(); return null; } } public static T read(File xmlFile, Class clazz) { try { return XmlHelper.read(xmlFile, clazz); } catch (XmlReadException exception) { log.error("It is failed when xml file read! {}", exception.getMessage()); exception.printStackTrace(); return null; } } public static T read(Unmarshaller unmarshaller, InputStream inputStream, Class clazz) { try { return XmlHelper.read(unmarshaller,inputStream, clazz); } catch (XmlReadException exception) { log.error("It is failed when unmarshaller inputStream read! {}", exception.getMessage()); exception.printStackTrace(); return null; } } public static T read(InputStream inputStream, Class clazz) { try { return XmlHelper.read(inputStream, clazz); } catch (XmlReadException exception) { log.error("It is failed when inputStream read! {}", exception.getMessage()); exception.printStackTrace(); return null; } } public static void write(Marshaller marshaller, T xmlObject, String filename, HttpServletResponse response) { try { XmlHelper.write(marshaller, xmlObject, filename,response); } catch (XmlWriteException exception) { log.error("It is failed when xml read! {}", exception.getMessage()); exception.printStackTrace(); } } public static void write(Marshaller marshaller, T xmlObject, HttpServletResponse response) { try { XmlHelper.write(marshaller, xmlObject, response); } catch (XmlWriteException exception) { log.error("It is failed when xml read! {}", exception.getMessage()); exception.printStackTrace(); } } public static void write(Marshaller marshaller, T xmlObject, OutputStream outputStream) { try { XmlHelper.write(marshaller, xmlObject, outputStream); } catch (XmlWriteException exception) { log.error("It is failed when xml read! {}", exception.getMessage()); exception.printStackTrace(); } } public static void write(T xmlObject, String filename, HttpServletResponse response) { try { XmlHelper.write(xmlObject, filename, response); } catch (XmlWriteException exception) { log.error("It is failed when xml read! {}", exception.getMessage()); exception.printStackTrace(); } } public static void write(T xmlObject, HttpServletResponse response) { try { XmlHelper.write(xmlObject, response); } catch (XmlWriteException exception) { log.error("It is failed when xml read! {}", exception.getMessage()); exception.printStackTrace(); } } public static void write(T xmlObject, OutputStream outputStream) { JAXB.marshal(xmlObject,outputStream); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy