first version
commit
71ec3f4e2e
|
@ -0,0 +1,12 @@
|
|||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = false
|
||||
insert_final_newline = false
|
|
@ -0,0 +1,2 @@
|
|||
See here for details:
|
||||
https://github.com/moezbhatti/qksms/issues/1664#issuecomment-743362709
|
|
@ -0,0 +1,49 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>yg</groupId>
|
||||
<artifactId>silence-xml-to-qksms-json</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.16</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.12.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/CP</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,11 @@
|
|||
package yg;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Backup {
|
||||
private int messageCount;
|
||||
private List<Message> messages;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package yg;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Message {
|
||||
private int protocol;
|
||||
private String address;
|
||||
private long date;
|
||||
private long dateSent;
|
||||
private int type;
|
||||
private String body;
|
||||
private boolean read;
|
||||
private int status;
|
||||
private boolean locked;
|
||||
private int subId = -1;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package yg;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class Smses2Json {
|
||||
private static final ObjectMapper JACKSON = new ObjectMapper();
|
||||
private static final Pattern XML_ENTITY_PATTERN = Pattern.compile("&#(\\d+);");
|
||||
|
||||
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
|
||||
List<XmlMessage> messages = Arrays.asList(JACKSON.readValue(new File(args[0]), XmlMessage[].class));
|
||||
|
||||
Backup backup = new Backup();
|
||||
backup.setMessages(messages
|
||||
.stream()
|
||||
.map(x -> new Message(
|
||||
x.getProtocol(), x.getAddress(), x.getDate(),
|
||||
x.getType() == 1 ? x.getDate() : 0, // a date for an SMS received; 0 for an SMS sent
|
||||
x.getType(), x.getBody(), x.getRead() == 1, x.getStatus(), x.getLocked() == 1,
|
||||
x.getType() == 1 ? 1 : -1)) // 1 for an SMS received; −1 for an SMS sent
|
||||
.peek(msg -> {
|
||||
Matcher matcher = XML_ENTITY_PATTERN.matcher(msg.getBody());
|
||||
msg.setBody(matcher.replaceAll(match -> {
|
||||
return new StringBuilder().appendCodePoint(Integer.valueOf(match.group(1))).toString();
|
||||
}));
|
||||
})
|
||||
.collect(Collectors.toList()));
|
||||
backup.setMessageCount(backup.getMessages().size());
|
||||
|
||||
if (args.length == 1) {
|
||||
JACKSON.writeValue(System.out, backup);
|
||||
} else {
|
||||
JACKSON.writeValue(new File(args[1]), backup);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package yg;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class XmlMessage {
|
||||
private int protocol;
|
||||
private String address;
|
||||
private long date;
|
||||
private int type;
|
||||
private String body;
|
||||
private String service_center;
|
||||
private int read;
|
||||
private int status;
|
||||
private int locked;
|
||||
|
||||
// useless:
|
||||
private String subject;
|
||||
private String toa;
|
||||
private String sc_toa;
|
||||
}
|
Loading…
Reference in New Issue