当前位置: 首页 > news >正文

湛江网站设计公司/搜索引擎优化包括哪些

湛江网站设计公司,搜索引擎优化包括哪些,做任务免费得晋江币网站,php网站建设教程为什么80%的码农都做不了架构师?>>> 平时我比较喜欢XML和java对象之间互转,同时每天要经常处理XML,所以我比较喜欢jaxb技术。下面是我对一些常用的简单封装。 package com.geostar.common.util;import java.io.File; import java…

为什么80%的码农都做不了架构师?>>>   hot3.png

平时我比较喜欢XML和java对象之间互转,同时每天要经常处理XML,所以我比较喜欢jaxb技术。下面是我对一些常用的简单封装。

 

package com.geostar.common.util;import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.net.URL;import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.util.ValidationEventCollector;
import javax.xml.transform.sax.SAXSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;import org.apache.log4j.Logger;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
/*** @author likehua* @  工具类* */
public class JaxbUtil {private JaxbUtil(){};private  static Logger logger=Logger.getLogger(JaxbUtil.class);//from object 2  xmlpublic static Object   Xml2Object(Class<?> clazz,File file)throws JAXBException{JAXBContext context=JAXBContext.newInstance(clazz);Unmarshaller localUnmarshaller=context.createUnmarshaller();return  localUnmarshaller.unmarshal(file);//return null;};public  static  Object Xml2Object(Class<?> clazz,File file,String schema)throws SAXException,JAXBException{Object obj = null ;try{ValidationEventCollector vec = new  ValidationEventCollector();  SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);   Schema sch = sf.newSchema(new  File(schema)); JAXBContext jc = JAXBContext.newInstance(clazz.getPackage().getName());   Unmarshaller u = jc.createUnmarshaller();   u.setSchema(sch);   u.setEventHandler(vec);   obj = u.unmarshal(file);}catch(SAXException e){logger.error(e);throw  e;}catch(JAXBException e){logger.error(e);throw e;}return obj;		 };//from  xml  2  objectpublic  static  void  Object2Xml(Object paramObject, NamespacePrefixMapper paramNamespacePrefixMapper, OutputStream paramOutputStream)throws JAXBException{Class localClass = paramObject.getClass();JAXBContext localJAXBContext = JAXBContext.newInstance(new Class[] { localClass });Marshaller localMarshaller = localJAXBContext.createMarshaller();localMarshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", paramNamespacePrefixMapper);localMarshaller.setProperty("jaxb.formatted.output", Boolean.valueOf(true));localMarshaller.marshal(paramObject, paramOutputStream);};//xml  2  objectpublic static  Object Xml2Object(Class<?> clazz,InputStream is)throws JAXBException{JAXBContext context=JAXBContext.newInstance(clazz);Unmarshaller localUnmarshaller=context.createUnmarshaller();	return localUnmarshaller.unmarshal(is);//return null;};public  static  Object Xml2Object(Class<?> clazz,InputStream is,String schema)throws SAXException,JAXBException{Object obj = null ;try{ValidationEventCollector vec = new  ValidationEventCollector();  SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);  Schema sch = sf.newSchema(new  File(schema)); JAXBContext jc = JAXBContext.newInstance(clazz.getPackage().getName());   Unmarshaller u = jc.createUnmarshaller();   u.setSchema(sch);   u.setEventHandler(vec);   obj = u.unmarshal(is);}catch(SAXException e){logger.error(e);throw e;}catch(JAXBException e){logger.error(e);throw e;}return obj;		};//使用schema的url来验证jaxbpublic  static  Object Xml2Object(Class<?> clazz,InputStream is,URL  schema)throws SAXException,JAXBException{Object obj = null ;try{ValidationEventCollector vec = new  ValidationEventCollector();  SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);  //InputSource inSource=new InputSource(schema);//SAXSource sax=new SAXSource(inSource);Schema sch = sf.newSchema(schema); JAXBContext jc = JAXBContext.newInstance(clazz.getPackage().getName());   Unmarshaller u = jc.createUnmarshaller();   u.setSchema(sch);   u.setEventHandler(vec);   obj = u.unmarshal(is);}catch(SAXException e){logger.error(e);throw e;}catch(JAXBException e){logger.error(e);throw e;}return obj;		};//通过流来判断public  static  Object Xml2Object(Class<?> clazz,InputStream is,InputStream  schema)throws SAXException,JAXBException{Object obj = null ;try{ValidationEventCollector vec = new  ValidationEventCollector();  SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);  InputSource inSource=new InputSource(schema);SAXSource sax=new SAXSource(inSource);Schema sch = sf.newSchema(sax); JAXBContext jc = JAXBContext.newInstance(clazz.getPackage().getName());   Unmarshaller u = jc.createUnmarshaller();   u.setSchema(sch);   u.setEventHandler(vec);   obj = u.unmarshal(is);}catch(SAXException e){logger.error(e);throw e;}catch(JAXBException e){logger.error(e);throw e;}return obj;		};// 	xml  2  objectpublic  static  Object  XML2Obejct(Class<?> clazz,Reader reader)throws JAXBException{JAXBContext context=JAXBContext.newInstance(new Class[]{clazz});Unmarshaller localMarshaller=context.createUnmarshaller();return localMarshaller.unmarshal(reader);};public  static  Object XML2Object(Class<?> clazz,Reader reader,InputStream schema)throws SAXException,JAXBException{//ssObject obj = null ;try{ValidationEventCollector vec = new  ValidationEventCollector();  SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);   InputSource inSource=new InputSource(schema);SAXSource sax=new SAXSource(inSource);Schema sch = sf.newSchema(sax); JAXBContext jc = JAXBContext.newInstance(clazz.getPackage().getName());   Unmarshaller u = jc.createUnmarshaller();   u.setSchema(sch);   u.setEventHandler(vec);   obj = u.unmarshal(reader);}catch(SAXException e){logger.error(e);throw e;}catch(JAXBException e){logger.error(e);throw e;}return obj;	};public  static  Object  XML2Obejct(Class<?> clazz,Reader reader,String schema)throws SAXException,JAXBException{Object obj = null ;try{ValidationEventCollector vec = new  ValidationEventCollector();  SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);   Schema sch = sf.newSchema(new  File(schema)); JAXBContext jc = JAXBContext.newInstance(clazz.getPackage().getName());   Unmarshaller u = jc.createUnmarshaller();   u.setSchema(sch);   u.setEventHandler(vec);   obj = u.unmarshal(reader);}catch(SAXException e){logger.error(e);throw e;}catch(JAXBException e){logger.error(e);throw e;}return obj;		};// 	xml  2  objectpublic static  void   Object2Xml(Object ob,OutputStream  os)throws JAXBException{Class local=ob.getClass();JAXBContext context=JAXBContext.newInstance(new Class[]{local});Marshaller marshaller=context.createMarshaller();marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);marshaller.marshal(ob, os);		};
//	from object 2 xml  filepublic static  void Object2XmlFile(Object ob, String path)throws JAXBException,FileNotFoundException {Class local=ob.getClass();JAXBContext context=JAXBContext.newInstance(new Class[]{local});Marshaller marshaller=context.createMarshaller();//marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", paramNamespacePrefixMapper);//marshaller.setProperty("jaxb.formatted.output", Boolean.valueOf(true));marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);marshaller.marshal(ob, new FileOutputStream(new File(path)));		};
//	from object 2 xml  filepublic static  void Object2XmlFile(Object ob,NamespacePrefixMapper paramNamespacePrefixMapper, String path)throws JAXBException,FileNotFoundException {Class local=ob.getClass();JAXBContext context=JAXBContext.newInstance(new Class[]{local});Marshaller marshaller=context.createMarshaller();marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", paramNamespacePrefixMapper);marshaller.setProperty("jaxb.formatted.output", Boolean.valueOf(true));//.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);marshaller.marshal(ob, new FileOutputStream(new File(path)));//marshaller.marshal(ob, new File(path));};public static  void main(String[] args)throws FileNotFoundException,JAXBException,SAXException{
//		UpdateCSW cswRequest=(UpdateCSW)JaxbUtil.Xml2Object(UpdateCSW.class, new FileInputStream("C:\\request.xml"), UpdateCSW.class.getResourceAsStream("UpdateCSW.xsd"));
//		System.out.println("通过");};
}

转载于:https://my.oschina.net/lkh/blog/38653

http://www.lbrq.cn/news/1299241.html

相关文章:

  • 景德镇网站网站建设/优化设计七年级下册数学答案
  • 成都科技网站建设联系/seo系统
  • 枣阳建网站/软文案例200字
  • 无锡网站制作建设/河南seo快速排名
  • 建设公司营销网站/重庆百度推广seo
  • 怎样做展会推广网站/网上销售平台怎么做
  • 网站做电商销售需要注册吗/公司网站设计需要多少钱
  • 免费的求职简历模板网站/软件开发公司网站
  • 北湖区网站建设/app推广渠道在哪接的单子
  • 交互设计网站推荐/湖南网站建设seo
  • 廊坊做网站价格/网页seo搜索引擎优化
  • 闵行网站开发/seo关键词优化报价价格
  • 图书拍卖网站开发遇到的问题/爱站工具查询
  • 网站建设补贴/识别关键词软件
  • 网站版建设/汽车推广软文
  • 宿州网站建设工作室/搜索引擎提交入口大全
  • 网站建设要什么证件/seo优化方向
  • 免费网站知乎/seo在哪学
  • 如何做网站内容管理/百度权重查询工具
  • 网站制作书籍/百度官方客户端
  • 网站开发的最后5个阶段/如何在google上免费推广
  • 长沙建网站联系电话/东莞外贸优化公司
  • 物流网站前端模板下载/知名网络营销推广
  • 衢州高级网站设计/微信搜一搜seo优化
  • 个人可以做几个网站吗/淘宝推广怎么推
  • 浙江省建设工程质量管理协会网站/泰州seo
  • 在网站做网管工作都做什么/百度竞价推广怎么收费
  • 电商型企业网站建设/济南seo全网营销
  • 做网站有前景吗/泰安seo推广
  • 山东房和城乡建设厅网站首页/网络推广工具
  • 黑马点评系列问题之p70postman报错“服务器异常”
  • [MarkdownGithub] 使用块引用高亮显示“注意“和“警告“和其他注意方式的选项
  • 上网行为管理-web认证服务
  • HarmonyOS-ArkUI Web控件基础铺垫4--TCP协议- 断联-四次挥手解析
  • nastools继任者?极空间部署影视自动化订阅系统『MediaMaster』
  • RS485转PROFIBUS DP网关写入命令让JRT激光测距传感器开启慢速模式连续测量