if(result != JFileChooser.APPROVE_OPTION) return;
File selected = chooser.getSelectedFile();
- Village village;
- try{
- village = VillageLoader.parseVillage(selected);
- }catch(IOException e){
- System.out.println(e);
- return;
- }
-
- selectedVillage(village);
+ submitHeavyBusyTask(() -> {
+ Village village;
+ try{
+ village = VillageLoader.parseVillage(selected);
+ }catch(IOException e){
+ System.out.println(e);
+ return;
+ }
+ EventQueue.invokeLater(() -> {
+ selectedVillage(village);
+ });
+ }, "XML読み込み中", "XML読み込み完了");
return;
}
--- /dev/null
+/*
+ * village XML file element tags
+ *
+ * License : The MIT License
+ * Copyright(c) 2020 olyutorskii
+ */
+
+package jp.sfjp.jindolf.data.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * XMLファイルのタグ要素名デコーダ。
+ */
+public enum ElemTag {
+
+ VILLAGE("village"),
+ AVATAR("avatar"),
+ PERIOD("period"),
+ TALK("talk"),
+ LI("li"),
+ ;
+
+
+ private final String name;
+
+
+ /**
+ * constructor.
+ *
+ * @param name element name
+ */
+ ElemTag(String name){
+ this.name = name;
+ return;
+ }
+
+
+ /**
+ * get ElemTag map with name-space Prefixed key.
+ *
+ * @param pfx prefix
+ * @return ElemTag
+ */
+ public static Map<String, ElemTag> getQNameMap(String pfx){
+ Map<String, ElemTag> result = new HashMap<>();
+
+ String lead;
+ if(pfx.isEmpty()){
+ lead = "";
+ }else{
+ lead = pfx + ":";
+ }
+
+ for(ElemTag tag : values()){
+ String key = lead + tag.name;
+ key = key.intern();
+ result.put(key, tag);
+ }
+
+ return result;
+ }
+
+}
private final StringBuilder content = new StringBuilder(250);
private final Map<String, Avatar> idAvatarMap = new HashMap<>();
+ private Map<String, ElemTag> qNameMap = ElemTag.getQNameMap("");
/**
return result;
}
+ /**
+ * decode ElemTag.
+ *
+ * @param uri URI of namespace
+ * @param localName local name
+ * @param qName Qname
+ * @return
+ */
+ private ElemTag decodeElemTag(String uri,
+ String localName,
+ String qName){
+ ElemTag result = this.qNameMap.get(qName);
+ return result;
+ }
/**
* パースした結果のVillageを返す。
throws SAXException {
if(NS_JINARCHIVE.equals(uri)){
this.nsPfx = prefix;
+ this.qNameMap = ElemTag.getQNameMap(this.nsPfx);
}
return;
}
String qName,
Attributes atts)
throws SAXException {
- if( ! NS_JINARCHIVE.equals(uri)){
- return;
- }
+ ElemTag tag = decodeElemTag(uri, localName, qName);
+ if(tag == null) return;
- switch(localName){
- case "village":
+ switch(tag){
+ case VILLAGE:
startVillage(atts);
break;
- case "avatar":
+ case AVATAR:
startAvatar(atts);
break;
- case "period":
+ case PERIOD:
startPeriod(atts);
break;
- case "talk":
+ case TALK:
startTalk(atts);
break;
- case "li":
+ case LI:
startLi(atts);
break;
default:
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
- if( ! NS_JINARCHIVE.equals(uri)){
- return;
- }
- switch(localName){
- case "talk":
+ ElemTag tag = decodeElemTag(uri, localName, qName);
+ if(tag == null) return;
+
+ switch(tag){
+ case TALK:
endTalk();
break;
- case "li":
+ case LI:
endLi();
break;
default: