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

网站的二级网页关键词跨境经验分享

网站的二级网页关键词,跨境经验分享,wordpress密码邮箱,网站管理后台文章排序一、ofd格式介绍 国家发布过一份关于ofd编码格式的资料#xff0c;本来我想传上去的发现资源重复了#xff0c;你们可以找找看#xff0c;没有的话留个邮箱#xff0c;我看到会发给你们的 ofd本质上其实是一个压缩文件#xff0c;咱们把他当做一个压缩包来处理就好了本来我想传上去的发现资源重复了你们可以找找看没有的话留个邮箱我看到会发给你们的 ofd本质上其实是一个压缩文件咱们把他当做一个压缩包来处理就好了思路是先解压对解压后的文件进行解析处理解压后是xml文件java有很多处理xml的类这里我推荐dom4j原因是相对来说功能全、速度快处理完后再进行压缩保存为ofd格式即可 ofd的阅读器我也有只是是公司的不方便共享了大家可以找网上在线阅读器   二、xml处理工具类 import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Collectors;import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.OutputFormat; import org.dom4j.io.SAXReader; import org.dom4j.io.XMLWriter;/** DOM4J类DOM4J定义了几个Java类。以下是最常见的类Document - 表示整个XML文档。文档Document对象是通常被称为DOM树。Element - 表示一个XML元素。 Element对象有方法来操作其子元素它的文本属性和名称空间。Attribute - 表示元素的属性。属性有方法来获取和设置属性的值。它有父节点和属性类型。Node - 代表元素属性或处理指令常见DOM4J的方法当使用DOM4J还有经常用到的几种方法SAXReader.read(xmlSource)() - 构建XML源的DOM4J文档。Document.getRootElement() - 得到的XML的根元素。Element.node(index) - 获得在元素特定索引XML节点。Element.attributes() - 获取一个元素的所有属性。Node.valueOf(Name) - 得到元件的给定名称的属性的值。* * */ public class OfdXmlUtil {public static String ids ;public static String getAttributeIdByPath(String path,String attribute) throws Exception {ListXmlEntity xmlList readXmlByPath(path);int mediaId 0;for (XmlEntity xml : xmlList) {if (xml.getNode().equals(attribute) xml.getAttributes().get(ID) ! null) {mediaId mediaIdInteger.parseInt(xml.getAttributes().get(ID))?mediaId:Integer.parseInt(xml.getAttributes().get(ID));}}String idString.valueOf(mediaId1);return id;}public static String getId(Element node, String element) {if(node.getName().equals(element)) {ids node.valueOf(id);}// 当前节点下面子节点迭代器IteratorElement it node.elementIterator();// 递归遍历while (it.hasNext()) {// 获取某个子节点对象Element e it.next();// 对子节点进行遍历getId(e, element);}return ids;}public static String getLastIdByElement(String path, String element) throws Exception {File file new File(path);// 创建saxReader对象SAXReader reader new SAXReader();Document document reader.read(file);// 获取根节点元素对象Element node document.getRootElement();String str getId(node, element);return str;}/*** * param path* return* throws Exception*/public static ListXmlEntity readXmlByPath(String path) throws Exception {File file new File(path);ListXmlEntity xmlEntities readXmlByFile(file);return xmlEntities;}/*** param file* return* throws Exception*/public static ListXmlEntity readXmlByFile(File file) throws Exception {// 创建saxReader对象SAXReader reader new SAXReader();Document document reader.read(file);// 获取根节点元素对象Element node document.getRootElement();ListXmlEntity xmlEntities new ArrayListXmlEntity();listNodes(node, xmlEntities);return xmlEntities;}/*** 遍历当前节点元素下面的所有(元素的)子节点* * param node*/public static void listNodes(Element node, ListXmlEntity xmlEntities) {XmlEntity xmlEntity new XmlEntity();xmlEntity.setNode(node.getName());// 获取当前节点的所有属性节点ListAttribute list node.attributes();// 遍历属性节点MapString, String attributeMap list.stream().collect(Collectors.toMap(Attribute::getName, Attribute::getValue));xmlEntity.setAttributes(attributeMap);if (!(node.getTextTrim().equals())) {xmlEntity.setContent(node.getText());}xmlEntities.add(xmlEntity);// 当前节点下面子节点迭代器IteratorElement it node.elementIterator();// 递归遍历while (it.hasNext()) {// 获取某个子节点对象Element e it.next();// 对子节点进行遍历listNodes(e, xmlEntities);}}// 递归获取当前节点下最后一个节点的元素public static Element getLastElement(Element node) throws Exception {Element node2 getNextElement(node, 0);if (node2.elements().size() 0) {node2 getNextElement(node2, 0);}return node2;}// 获取当前节点下第i个节点的元素public static Element getNextElement(Element e, int i) {e e.elements().get(i);return e;}/*** 根据节点名获取节点* * param node*/public static ListElement getAllEle(Element node, ListElement elems) {elems.add(node);ListElement listElement node.elements();// 所有一级子节点的listfor (Element e : listElement) {// 遍历所有一级子节点getAllEle(e, elems);// 递归}return elems;}/*** 修改、增加xml属性值 元素无重复 不能修改根元素 String elem 需要修改的标签名, String key属性名, String* value修改后的值* * return* throws Exception*/public static boolean edit(Document doc, String elem, String key, String value, String outUrl) throws Exception {Element element doc.getRootElement();// 当前节点下面子节点迭代器Element tmpEle doc.getRootElement();ListElement elems new ArrayListElement();ListElement listElement getAllEle(element, elems);if (listElement.size() ! 0) {for (Element e : listElement) {// 遍历所有一级子节点if (e.getName().equals(elem)) {tmpEle e;}}}if (tmpEle.isRootElement()) {return false;} else {// 2.通过增加同名属性的方法修改属性值tmpEle.addAttribute(key, value); // key相同覆盖不存在key则添加// 指定文件输出的位置writer(doc, outUrl);return true;}}/*** 把document对象写入新的文件* * param document* throws Exception*/public static void writer(Document document, String url) throws Exception {// 紧凑的格式// OutputFormat format OutputFormat.createCompactFormat();// 排版缩进的格式OutputFormat format OutputFormat.createPrettyPrint();// 设置编码format.setEncoding(UTF-8);// 创建XMLWriter对象,指定了写出文件及编码格式// XMLWriter writer new XMLWriter(new FileWriter(new// File(src//a.xml)),format);XMLWriter writer new XMLWriter(new OutputStreamWriter(new FileOutputStream(new File(url)), UTF-8), format);// 写入writer.setEscapeText(false);writer.write(document);// 立即写入writer.flush();// 关闭操作writer.close();}public static void createSignaturesXml(String signs,String signTmp) throws Exception {Document doc1 new SAXReader().read(new File(signs /Signatures.xml));Element Signatures doc1.getRootElement();Element Signature Signatures.addElement(ofd:Signature);Signature.addAttribute(ID, 1);Signature.addAttribute(Type, Seal);Signature.addAttribute(BaseLoc, signTmp.substring(signTmp.length()-6) /Signature.xml);OfdXmlUtil.writer(doc1, signs /Signatures.xml);} } 三、压缩解压缩处理工具类 import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream;public class ZipUtil {private ZipUtil() {}public static void doCompress(String srcFile, String zipFile) throws Exception {String rootdDirectory srcFile.split(/)[srcFile.split(/).length - 1]; // 获取根目录名称doCompress(new File(srcFile), new File(zipFile), rootdDirectory);}/*** 文件压缩* * param srcFile 目录或者单个文件* param zipFile 压缩后的ZIP文件*/public static void doCompress(File srcFile, File zipFile, String rootdDirectory) throws Exception {ZipOutputStream out null;try {out new ZipOutputStream(new FileOutputStream(zipFile));doCompress(srcFile, out, rootdDirectory);} catch (Exception e) {throw e;} finally {out.close();// 记得关闭资源}}public static void doCompress(File file, ZipOutputStream out, String rootdDirectory) throws IOException {doCompress(file, out, , rootdDirectory);}public static void doCompress(File inFile, ZipOutputStream out, String dir, String rootdDirectory)throws IOException {if (inFile.isDirectory()) {File[] files inFile.listFiles();if (files ! null files.length 0) {for (File file : files) {String name inFile.getName();if (!.equals(dir)) {name dir / name;}ZipUtil.doCompress(file, out, name, rootdDirectory);}}} else {// 将根目录干掉否则无法打开OFD文件dir dir.replaceAll(rootdDirectory, );ZipUtil.doZip(inFile, out, dir);}}public static void doZip(File inFile, ZipOutputStream out, String dir) throws IOException {String entryName null;if (!.equals(dir)) {dir dir.substring(1, dir.length());entryName dir / inFile.getName();} else {entryName inFile.getName();}ZipEntry entry new ZipEntry(entryName);out.putNextEntry(entry);int len 0;byte[] buffer new byte[1024 * 1024];FileInputStream fis new FileInputStream(inFile);while ((len fis.read(buffer)) 0) {out.write(buffer, 0, len);out.flush();}out.closeEntry();fis.close();} } package com.koalii.oes.util;import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile;/*** 项目名称meter* 类名称ZipTools * 类描述采用zip压缩文件* 创建人meter* 创建时间2018年5月4日 上午10:25:09* 版权Copyright2018.All Rights Reserved* version v1.0*/ public class UnzipUtil {/*** 读写zip文件*/private static void write(InputStream inputStream,OutputStream outStream) throws IOException{byte[] datanew byte[4096];int length0;while((lengthinputStream.read(data)) ! -1){outStream.write(data,0,length);}outStream.flush();//刷新输出流inputStream.close();//关闭输入流}public static void unzip(String zipFile, String destDir) throws IOException {unzip(new File(zipFile), new File(destDir));}/*** 解压文件n */public static void unzip(File zipFile, File destDir) throws IOException {ZipFile zipOutFile new ZipFile(zipFile);Enumeration? extends ZipEntry entries zipOutFile.entries();while (entries.hasMoreElements()) {ZipEntry entry entries.nextElement();if(entry.isDirectory()){File tempFile new File(destDir.getAbsolutePath()File.separatorentry.getName());if (!tempFile.exists()) {tempFile.mkdirs();}}else{File tempFilenew File(destDir.getAbsolutePath()File.separatorentry.getName());checkParentDir(tempFile);FileOutputStream fileOutStreamnew FileOutputStream(tempFile);BufferedOutputStream bufferOutStream new BufferedOutputStream(fileOutStream);write(zipOutFile.getInputStream(entry),bufferOutStream);bufferOutStream.close();fileOutStream.close();}}zipOutFile.close();//关闭zip文件}/*** 验证父目录是否存在否则创建*/private static void checkParentDir(File file){if(!file.getParentFile().exists()){file.getParentFile().mkdirs();}}}
http://www.yutouwan.com/news/341237/

相关文章:

  • 网站开发有什么软件有哪些使用django做网站
  • 上海建设局官方网站群晖如何做网站服务器
  • 如何建网站卖东西网页设计的实训报告
  • 免费作图网站都有哪些国外扁平化网站
  • 网站首页的布局设计自创字 网站
  • 奉节做网站php网站如何上传数据库
  • 手机网站改app山东网络建站推广
  • 手机商城app开发公司郑州seo竞价
  • 网站logo是什么意思wordpress连接自己的域名
  • 广州 网站备案下载并安装app
  • 做网站需要什么学专业网站建设 数据分析
  • 成华区门户网站深圳网站建设便捷
  • 南京建设网站方案wordpress汉化插件下载
  • o2o网站系统建设设计工作一般多少工资
  • 驻马店网站优化手机视频网站建设
  • 淘宝网站内搜索引擎优化怎么做各种网站
  • 西安市长安区建设局网站官网整站优化
  • 响应式设计网站怎么做做竞价托管的公司
  • 网站备案如何查询国外 wordpress 免费空间
  • 卖汽车的网站怎么做的上海网站定制团队
  • 网站文章添加做网站怎样上传文件
  • 昆山设计网站公司成都建设局网站首页
  • dedecms网站乱码wordpress显示多少页
  • 策划书模板免费下载的网站室内设计公司和装修公司的区别
  • h5网站模板下载798艺术区
  • 免费h5生成网站app定制多少钱
  • 响应式网站预览网站 ip地址是什么
  • 最权威的排行榜网站wordpress标签
  • 切图做网站福建省建设厅网站职业资格
  • 昆山城市建设网站wordpress怎么编辑网站