package saccubus.conv;
import java.io.*;
+import java.util.EnumSet;
+import java.util.Set;
import org.xml.sax.*;
import javax.xml.parsers.*;
private ConvertToVideoHook() {
}
+ @Deprecated
public static void convert(File file, File out, String ng_id, String ng_word) throws IOException {
+ convert(EnumSet.allOf(NicoXMLReader.ProcessType.class), file, out, ng_id, ng_word);
+ }
+
+ public static void convert(Set<NicoXMLReader.ProcessType> types, File file, File out, String ng_id, String ng_word)
+ throws IOException {
try {
final Packet packet = new Packet();
// SAXパーサーファクトリを生成
// SAXパーサーを生成
final SAXParser parser = spfactory.newSAXParser();
// XMLファイルを指定されたデフォルトハンドラーで処理します
- final NicoXMLReader nico_reader = new NicoXMLReader(packet, ng_id, ng_word);
+ final NicoXMLReader nico_reader = new NicoXMLReader(types, packet, ng_id, ng_word);
parser.parse(file, nico_reader);
} catch (IOException | SAXException | ParserConfigurationException ex) {
throw new IOException("コメント変換に失敗。ファイル名に使用できない文字が含まれているか正規表現の間違い?", ex);
}
- }
+ }
}
package saccubus.conv;
+import java.util.EnumSet;
+import java.util.Set;
import java.util.regex.Pattern;
import org.xml.sax.helpers.DefaultHandler;
*/
public class NicoXMLReader extends DefaultHandler {
+ private final Set<ProcessType> processTypes;
private final Packet packet;
private final Pattern ngWord;
private final Pattern ngId;
private Chat item;
private boolean itemKicked;
- public NicoXMLReader(Packet packet, String ng_id, String ng_word) {
+ public enum ProcessType {
+
+ NORMAL, OWNER;
+ }
+
+ public NicoXMLReader(Set<ProcessType> types, Packet packet, String ng_id, String ng_word) {
+ this.processTypes = EnumSet.copyOf(types);
this.packet = packet;
this.ngWord = makePattern(ng_word);
this.ngId = makePattern(ng_id);
// System.out.println("----------");
item = new Chat();
itemKicked = false;
+
+ // 通常コメントを処理するか, 投稿者コメントを処理するか
+ final String fork = attributes.getValue("fork");
+ final boolean isOwner = "1".equals(fork);
+ if (isOwner) {
+ if (!processTypes.contains(ProcessType.OWNER)) {
+ itemKicked = true;
+ }
+ } else {
+ if (!processTypes.contains(ProcessType.NORMAL)) {
+ itemKicked = true;
+ }
+ }
+
//マイメモリ削除対象
final String deleted = attributes.getValue("deleted");
if (deleted != null && deleted.equalsIgnoreCase("1")) {