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

com.jianggujin.http.response.JXmlResponse Maven / Gradle / Ivy

package com.jianggujin.http.response;

import java.io.IOException;
import java.io.InputStream;

import com.jianggujin.http.util.JDataUtils;

/**
 * XML响应
 * 
 * @author jianggujin
 *
 */
public class JXmlResponse extends JAbstractResponse {
   private Class target = null;
   private String charset;
   private static JXmlResolver resolver = null;

   public JXmlResponse(Class target) {
      this.target = target;
   }

   public JXmlResponse(Class target, String charset) {
      this.charset = charset;
      this.target = target;
   }

   @Override
   protected void dealData(InputStream stream) throws IOException {
      String charset = (this.charset == null || this.charset.length() == 0)
            ? JDataUtils.getCharsetFromContentType(this.getHeader("Content-Type"))
            : this.charset;
      this.data = resolver != null ? resolver.resolve(target, stream, charset) : null;
   }

   /**
    * 设置解析器
    * 
    * @param resolver
    */
   public static void setResolver(JXmlResolver resolver) {
      JXmlResponse.resolver = resolver;
   }

   /**
    * XML解析器
    * 
    * @author jianggujin
    *
    */
   public static interface JXmlResolver {
      Object resolve(Class clazz, InputStream stream, String charset);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy