Helius
2022-08-31 39a322c380ac88874760b4b9a28def18c0b7753a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.xcong.farmer.cms;
 
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.xcong.farmer.cms.modules.core.service.ICmsCoreService;
import com.xcong.farmer.cms.modules.system.service.IReleaseService;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2022-07-09
 **/
@SpringBootTest
public class TemplateTest {
 
    String baseUrl = "http://120.27.238.55:8000/cms/static/";
 
    @Test
    public void staticFileTest() throws IOException {
        // /Users/helius/Desktop/template-online/template/ahrnfy/test.html
        // /Users/helius/Desktop/template-online/template/ahrnfy/test.html
        File file = new File("/Users/helius/Desktop/template-online/template/ahrnfy/test.html");
        Document parse = Jsoup.parse(file, "utf-8");
 
        System.out.println(111);
//        staticPathParser(parse, "img", "src");
//        staticPathParser(parse, "href", "link");
//        staticPathParser(parse, "script", "src");
//
//        FileOutputStream outputStream = new FileOutputStream(file);
//        outputStream.write(parse.html().getBytes());
//        outputStream.close();
    }
 
    public void staticPathParser(Document document, String tagName, String attrKey) {
        Elements elements = document.getElementsByTag(tagName);
        if (elements.isEmpty()) {
            return;
        }
 
        for (Element element : elements) {
            String attr = element.attr(attrKey);
            if (StrUtil.isNotBlank(attr) && !attr.contains("http://") && !attr.contains("https://")) {
                element.attr(attrKey, baseUrl + attr);
            }
        }
    }
 
    @Autowired
    private IReleaseService releaseService;
 
    @Test
    public void columnTest() {
        releaseService.releaseColumn(135L, 1, 26L);
    }
 
 
    @Autowired
    private ICmsCoreService cmsCoreService;
 
    @Test
    public void parserTest() {
        Map<String, Object> map = new HashMap<>();
        map.put("companyId", 24L);
        map.put("id", 81L);
        map.put("templateType", "article");
        cmsCoreService.columnProcess(map, "test.html");
    }
}