java110
2022-04-26 fd7eafe5b15a59728edd5d31c018590bd626ea83
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
package com.java110.code;
 
import com.alibaba.fastjson.JSONObject;
 
import java.io.*;
 
/**
 * @ClassName DealHtml
 * @Description TODO
 * @Author wuxw
 * @Date 2022/4/20 22:18
 * @Version 1.0
 * add by wuxw 2022/4/20
 **/
public class DealVc18nAddSpanHtml {
 
    public static void main(String[] args) throws Exception {
        File file = new File("C:\\project\\vip\\MicroCommunityWeb\\public\\pages");
        JSONObject js = new JSONObject();
        listFiles(file, js);
        System.out.println("js = " + js.toJSONString());
    }
 
    public static void listFiles(File file, JSONObject js) throws Exception {
        if (file.isFile()) {
            if (file.getName().endsWith(".html")) {
                doDealHtml(file, js);
            }
            return;
        }
 
        File[] files = file.listFiles();
 
        for (File tmpFile : files) {
            listFiles(tmpFile, js);
        }
    }
 
    private static void doDealHtml(File tmpFile, JSONObject js) throws Exception {
 
        String fileName = tmpFile.getName().replace(".html", "");
        System.out.println("fileName=" + fileName + ",dir=" + tmpFile.getPath());
        BufferedReader in = new BufferedReader(new FileReader(tmpFile));
        String str;
        String context = "";
        JSONObject fileNameObj = new JSONObject();
        while ((str = in.readLine()) != null) {
            //doDealHtmlNode(str,fileName);
            context += doDealHtmlNode(str+"\n", fileName, fileNameObj);
 
        }
        System.out.println(context);
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(tmpFile));
        bufferedWriter.write(context);
        bufferedWriter.close();
 
 
    }
 
    private static String doDealHtmlNode(String str, String fileName, JSONObject fileNameObj) {
        String vcStr = "<vc:i18n";
        if (!str.contains(vcStr)) {
            return str;
        }
 
 
        String endStr = "</vc:i18n>";
        String name = "";
 
        str = str.replaceAll(vcStr,"<span>"+vcStr);
        str = str.replaceAll(endStr,endStr+"</span>");
 
 
        return str;
    }
}