import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@SpringBootApplication
@MapperScan("com.aaa.mapper") // 这里替换为你的mapper接口所在的包名
public class MyApplication implements CommandLineRunner {
@Autowired
private FileContentService fileContentService;
public static void main(String[] args) {
SpringApplication.run(PgTestApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
// read data
final List<FileContent> all = fileContentService.findAll();
System.out.println(all.size());
for (FileContent fileContent : all) {
final String path = fileContent.getPath();
if(path.contains("process")) {
final String content = fileContent.getContent();
// System.out.println(content);
if(null != content && content.startsWith("[")) {
final JSONArray objects = JSONUtil.parseArray(content);
objects.forEach(o -> {
JSONObject jsonObject = (JSONObject) o;
String name = jsonObject.getStr("name");
if(name.equalsIgnoreCase("w3wp.exe")) {
String commandLine = jsonObject.getStr("commandline");
System.out.println("=====================" + commandLine);
Pattern pattern = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
Matcher matcher = pattern.matcher(commandLine);
while (matcher.find()) {
if (matcher.group(1) != null) {
System.out.println(matcher.group(1));
} else if (matcher.group(2) != null) {
System.out.println(matcher.group(2));
} else {
System.out.println(matcher.group());
}
}
}
});
}
}
if(path.contains("SConfig.xml")) {
final String content = fileContent.getContent();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
// Document doc = dBuilder.parse(inputFile);
InputSource is = new InputSource(new StringReader(content));
Document doc = dBuilder.parse(is);
doc.getDocumentElement().normalize();
System.out.println("Root element: " + doc.getDocumentElement().getNodeName());
XMLParser.traverseNodes(doc.getDocumentElement(), 0); // 从根节点开始遍历
}
}
}
}
正则表达式[^\\s\"']+|\"([^\"]*)\"|'([^']*)'
用于匹配不包含空格、单引号和双引号的字符串,或者包含在单引号或双引号中的字符串。