import jp.sfjp.jindolf.view.WindowManager;
import jp.sourceforge.jindolf.corelib.VillageState;
import jp.sourceforge.jovsonz.JsObject;
+import org.xml.sax.SAXException;
/**
* いわゆるMVCでいうとこのコントローラ。
private final TopView topView;
+ private final JFileChooser xmlFileChooser = buildFileChooser();
+
private final VillageTreeWatcher treeVillageWatcher =
new VillageTreeWatcher();
private final ChangeListener tabPeriodWatcher =
return;
}
+ /**
+ * XMLファイルを選択するためのChooserを生成する。
+ *
+ * @return Chooser
+ */
+ private static JFileChooser buildFileChooser(){
+ JFileChooser chooser = new JFileChooser();
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+
+ FileFilter filter;
+ filter = new FileNameExtensionFilter("XML files (*.xml)", "xml", "XML");
+ chooser.setFileFilter(filter);
+
+ chooser.setDialogTitle("アーカイブXMLファイルを開く");
+
+ return chooser;
+ }
+
/**
* ウィンドウマネジャを返す。
return;
}
+ this.xmlFileChooser.updateUI();
+
LOGGER.log(Level.INFO,
"Look&Feelが[{0}]に変更されました。", className );
* ローカルなXMLファイルを読み込む。
*/
private void actionOpenXml(){
- JFileChooser chooser = new JFileChooser();
- chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
-
- FileFilter filter;
- filter = new FileNameExtensionFilter("XML files (*.xml)", "xml", "XML");
- chooser.setFileFilter(filter);
-
- int result = chooser.showOpenDialog(getTopFrame());
+ int result = this.xmlFileChooser.showOpenDialog(getTopFrame());
if(result != JFileChooser.APPROVE_OPTION) return;
- File selected = chooser.getSelectedFile();
+ File selected = this.xmlFileChooser.getSelectedFile();
submitHeavyBusyTask(() -> {
Village village;
+
try{
village = VillageLoader.parseVillage(selected);
}catch(IOException e){
- System.out.println(e);
+ String warnMsg = MessageFormat.format(
+ "XMLファイル[ {0} ]を読み込むことができません",
+ selected.getPath()
+ );
+ warnDialog("XML I/O error", warnMsg, e);
+ return;
+ }catch(SAXException e){
+ String warnMsg = MessageFormat.format(
+ "XMLファイル[ {0} ]の形式が不正なため読み込むことができません",
+ selected.getPath()
+ );
+ warnDialog("XML form error", warnMsg, e);
return;
}
+
village.setLocalArchive(true);
AvatarPics avatarPics = village.getAvatarPics();
this.appSetting.applyLocalImage(avatarPics);
* @param xmlFile XMLファイル
* @return 村
* @throws IOException I/Oエラー
+ * @throws SAXException XMLの形式エラー
*/
- public static Village parseVillage(File xmlFile) throws IOException{
+ public static Village parseVillage(File xmlFile)
+ throws IOException, SAXException{
Objects.nonNull(xmlFile);
boolean isNormal;
&& xmlFile.exists()
&& xmlFile.canRead();
if(!isNormal){
- return null;
+ throw new IOException(xmlFile.getPath() + "を読み込むことができません");
}
Path path = xmlFile.toPath();
* @param path XMLファイルのPath
* @return 村
* @throws IOException I/Oエラー
+ * @throws SAXException XMLの形式エラー
*/
- public static Village parseVillage(Path path) throws IOException{
+ public static Village parseVillage(Path path)
+ throws IOException, SAXException{
Objects.nonNull(path);
path = path.normalize();
&& Files.isRegularFile(path)
&& Files.isReadable(path);
if(!isNormal){
- return null;
+ throw new IOException(path.toString() + "を読み込むことができません");
}
Village result;
* @param istream XML入力
* @return 村
* @throws IOException I/Oエラー
+ * @throws SAXException XMLの形式エラー
*/
- public static Village parseVillage(InputStream istream) throws IOException{
+ public static Village parseVillage(InputStream istream)
+ throws IOException, SAXException{
InputSource isource = new InputSource(istream);
Village result = parseVillage(isource);
return result;
* @param isource XML入力
* @return 村
* @throws IOException I/Oエラー
+ * @throws SAXException XMLの形式エラー
*/
- public static Village parseVillage(InputSource isource) throws IOException{
+ public static Village parseVillage(InputSource isource)
+ throws IOException, SAXException{
XMLReader reader = buildReader();
VillageHandler handler = new VillageHandler();
reader.setContentHandler(handler);
- try{
- reader.parse(isource);
- }catch(SAXException e){
- System.out.println(e);
- return null;
- }
+ reader.parse(isource);
Village result = handler.getVillage();
return result;