Author: fdesbois Date: 2009-10-14 17:41:51 +0200 (Wed, 14 Oct 2009) New Revision: 2718 Modified: trunk/lima-main/src/main/java/org/chorem/lima/imports/XMLImport.java trunk/lima-main/src/main/java/org/chorem/lima/ui/ProgressBarImpl.java trunk/lima-main/src/main/resources/i18n/lima-main-fr_FR.properties Log: Problem when default_pcg.xml is in jar : change XMLImport method to take InputStream Modified: trunk/lima-main/src/main/java/org/chorem/lima/imports/XMLImport.java =================================================================== --- trunk/lima-main/src/main/java/org/chorem/lima/imports/XMLImport.java 2009-10-14 14:02:42 UTC (rev 2717) +++ trunk/lima-main/src/main/java/org/chorem/lima/imports/XMLImport.java 2009-10-14 15:41:51 UTC (rev 2718) @@ -111,6 +111,15 @@ return result; } + public String importAccount(InputStream stream) { + if (log.isDebugEnabled()) { + log.debug("Load Account XML "); + } + // Chargement du fichier + LoadFile(stream, InputStream.class); + return importAccount(); + } + /** * Import Account * @param file @@ -121,12 +130,15 @@ if (log.isDebugEnabled()) { log.debug("Load Account XML "); } + LoadFile(file, String.class); + return importAccount(); + } + + private String importAccount() { // Variables - accountServ = Main.getContext().getDataManager().getAccountModel(); + accountServ = Main.getContext().getDataManager().getAccountModel(); String result = ServiceHelper.RESPOND_ERROR; boolean existError = false; - // Chargement du fichier - LoadFile(file); try { // Recherche de la racine racine = document.getRootElement(); @@ -143,7 +155,7 @@ String label = noeudCourant.getAttribute("label").getValue(); String accountNumber = noeudCourant.getAttribute("accountNumber").getValue(); String masterAccount = noeudCourant.getAttribute("masterAccount").getValue(); - String type = noeudCourant.getAttribute("type").getValue(); + String type = noeudCourant.getAttribute("type").getValue(); // Création bdd // Si il n'a pas de compte père, alors on rattache le compte au compte '0' master. if ( masterAccount.equals("0") ) @@ -184,12 +196,14 @@ return result; } - + private void LoadFile(String file) { + LoadFile(file, String.class); + } /** * * @param file */ - private void LoadFile (String file) + private <T> void LoadFile(T file, Class<T> fileClass) { /** * Chargement du fichier et construction du Dom @@ -200,7 +214,11 @@ try { /* On crée une instance de SAXBuilder */ SAXBuilder sxb = new SAXBuilder(); - document = sxb.build(file); + if (fileClass.equals(String.class)) { + document = sxb.build((String)file); + } else if (fileClass.equals(InputStream.class)){ + document = sxb.build((InputStream)file); + } } catch (IOException e) { log.error("Erreur lors de la lecture du fichier " + e.getMessage() ); Modified: trunk/lima-main/src/main/java/org/chorem/lima/ui/ProgressBarImpl.java =================================================================== --- trunk/lima-main/src/main/java/org/chorem/lima/ui/ProgressBarImpl.java 2009-10-14 14:02:42 UTC (rev 2717) +++ trunk/lima-main/src/main/java/org/chorem/lima/ui/ProgressBarImpl.java 2009-10-14 15:41:51 UTC (rev 2718) @@ -19,6 +19,7 @@ package org.chorem.lima.ui; +import java.io.IOException; import java.net.URL; import javax.swing.JOptionPane; import static org.nuiton.i18n.I18n._; @@ -58,7 +59,14 @@ } public void loadDefaultAccount(AccountDTO accountRoot) { + if (log.isDebugEnabled()) { + log.debug("Account root : " + accountRoot); + } if (accountRoot.getChildren().isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("No existing accounts"); + } + String[] response = {_("lima.response.yes"), _("lima.response.no")}; int n = JOptionPane.showOptionDialog(this, _("lima.question.load.accounts"), @@ -71,7 +79,11 @@ if (n == JOptionPane.YES_OPTION) { XMLImport imports = new XMLImport(); URL urlFile = ProgressBarImpl.class.getResource("/import/default_pcg.xml"); - imports.importAccount(urlFile.getFile()); + try { + imports.importAccount(urlFile.openStream()); + } catch (IOException eee) { + log.error("Erreur chargement du fichier 'default_pcg.xml'", eee); + } } else { Main.getContext().getDataManager().resetAccountModel(); } Modified: trunk/lima-main/src/main/resources/i18n/lima-main-fr_FR.properties =================================================================== --- trunk/lima-main/src/main/resources/i18n/lima-main-fr_FR.properties 2009-10-14 14:02:42 UTC (rev 2717) +++ trunk/lima-main/src/main/resources/i18n/lima-main-fr_FR.properties 2009-10-14 15:41:51 UTC (rev 2718) @@ -93,6 +93,8 @@ lima.error.account.not.master=Ce compte ne poss\u00E8de pas de compte principal lima.error.account.with.entries=Ce compte poss\u00E8de des entr\u00E9es comptables lima.error.at.least.one.criteria=Au moins un crit\u00E8re doit +lima.error.entry.not.exist= +lima.error.entry.not.remove= lima.error.journal.double=Un journal poss\u00E8de d\u00E9j\u00E0 ce nom lima.error.journal.not.exist=Ce journal n'existe pas lima.error.journal.with.transactions=Ce journal poss\u00E8de des transactions comptables