导入浏览器书签
This commit is contained in:
@ -29,6 +29,10 @@ public class Const {
|
||||
|
||||
public static int COOKIE_TIMEOUT= 30*24*60*60;
|
||||
|
||||
public static String MenuIocURL= "https://up.raindrop.io/collection/templates/social-media-logos-6/47social.png";
|
||||
//已修改父级id的书签
|
||||
public static String BOOKMARK_STATE_FLAG= "666";
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,109 @@
|
||||
package com.ruoyi.common.utils.bookmarkhtml;
|
||||
|
||||
|
||||
|
||||
public class HtmlName implements Cloneable,Comparable<HtmlName>{
|
||||
|
||||
private String id; //id
|
||||
private String parentId; //父级id
|
||||
private String title; //标题
|
||||
private String description; //简介
|
||||
private String state;//状态 0目录 1书签
|
||||
private String url;//书签地址
|
||||
private String urls;//官网
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUrls() {
|
||||
return urls;
|
||||
}
|
||||
|
||||
public void setUrls(String urls) {
|
||||
this.urls = urls;
|
||||
}
|
||||
|
||||
public HtmlName() {
|
||||
super();
|
||||
}
|
||||
public HtmlName(String id, String parentId, String title, String description, String state,String url) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.parentId = parentId;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.state = state;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HtmlName{" +
|
||||
"id='" + id + '\'' +
|
||||
", parentId='" + parentId + '\'' +
|
||||
", title='" + title + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", state='" + state + '\'' +
|
||||
", url='" + url + '\'' +
|
||||
", urls='" + urls + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HtmlName clone() throws CloneNotSupportedException {
|
||||
return (HtmlName) super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(HtmlName o) {
|
||||
return Integer.parseInt(this.getId()) - Integer.parseInt(o.getId());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -10,12 +10,15 @@ import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Auther: Wang
|
||||
@ -25,6 +28,7 @@ import java.util.regex.Pattern;
|
||||
public class ImportHtml {
|
||||
|
||||
public static Logger logger = LoggerFactory.getLogger(ImportHtml.class);
|
||||
static int id = 1;
|
||||
/**
|
||||
* @param url
|
||||
* @return
|
||||
@ -359,4 +363,88 @@ public class ImportHtml {
|
||||
String host = url.getHost();// 获取主机名
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*获取导入书签的所有数据
|
||||
*/
|
||||
public static List<HtmlName> addMenuAndBookmark(InputStream inputStream) {
|
||||
Document doc = null;
|
||||
List<HtmlName> list =null;
|
||||
try {
|
||||
doc = Jsoup.parse(inputStream, "UTF-8", "");
|
||||
Element metasdt = doc.selectFirst("dl");
|
||||
Elements metasdts = new Elements();
|
||||
metasdts.add(metasdt);
|
||||
list = Htmlurl(metasdts, new ArrayList<HtmlName>(), "0");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dt1s
|
||||
* @param list
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
public static List<HtmlName> Htmlurl(Elements dt1s, List<HtmlName> list, String parentId) {
|
||||
for (Element dt1 : dt1s) {
|
||||
if ("h3".equalsIgnoreCase(dt1.nodeName())) {
|
||||
int a = id++;
|
||||
list.add(new HtmlName(a + "", parentId, dt1.text(), dt1.text(), "0",""));
|
||||
parentId = a + "";
|
||||
} else if ("dl".equalsIgnoreCase(dt1.nodeName())) {
|
||||
Elements dts = dt1.children();
|
||||
for (Element dt11 : dts) {
|
||||
if ("dt".equals(dt11.nodeName())) {
|
||||
if ("a".equals(dt11.child(0).nodeName())) {
|
||||
String url = dt11.child(0).attr("href");
|
||||
if (url.startsWith("http")) {
|
||||
list.add(new HtmlName((id++) + "", parentId,
|
||||
dt11.child(0) == null ? "" : dt11.child(0).text(),
|
||||
dt11.child(0) == null ? "" : dt11.child(0).text(), "1",url));
|
||||
}
|
||||
}
|
||||
if ("h3".equalsIgnoreCase(dt11.child(0).nodeName())) {
|
||||
Htmlurl(dt11.children(), list, parentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
static Element htmlReplace(Element metasdt, String str) {
|
||||
String metasdtStr = metasdt.toString();
|
||||
while (metasdtStr.indexOf(str) != -1) {
|
||||
metasdtStr = metasdtStr.replace(str, "");
|
||||
}
|
||||
return metasdt.after(metasdtStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改父级id
|
||||
* @return
|
||||
*/
|
||||
public static List<HtmlName> listFilter(List<HtmlName> list,Long parentId,String htmlid){
|
||||
for (HtmlName h : list) {
|
||||
if (h.getParentId().equals(htmlid)) {
|
||||
h.setParentId(parentId.toString());
|
||||
if (!h.getState().equals("0"))
|
||||
h.setState(Const.BOOKMARK_STATE_FLAG);//标识符
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user