Example usage for org.springframework.beans.factory.xml XmlBeanDefinitionStoreException getMessage

List of usage examples for org.springframework.beans.factory.xml XmlBeanDefinitionStoreException getMessage

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml XmlBeanDefinitionStoreException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:it.cilea.osd.jdyna.web.controller.ImportAnagraficaObject.java

/** Performa l'import da file xml di configurazioni di oggetti;
 *  Sull'upload del file la configurazione dell'oggetto viene caricato come contesto di spring
 *  e salvate su db.//from   w  w w. j  av  a2s  . c o m
 */
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object,
        BindException errors) throws RuntimeException, IOException {

    FileUploadConfiguration bean = (FileUploadConfiguration) object;
    MultipartFile file = (CommonsMultipartFile) bean.getFile();
    File a = null;

    //creo il file temporaneo che sara' caricato come contesto di spring per caricare la configurazione degli oggetti
    a = File.createTempFile("jdyna", ".xml", new File(path));
    file.transferTo(a);

    ApplicationContext context = null;
    try {
        context = new FileSystemXmlApplicationContext(new String[] { "file:" + a.getAbsolutePath() });
    } catch (XmlBeanDefinitionStoreException exc) {
        //cancello il file dalla directory temporanea
        logger.warn("Error during the configuration import from file: " + file.getOriginalFilename(), exc);
        a.delete();
        saveMessage(request, getText("action.file.nosuccess.upload", new Object[] { exc.getMessage() },
                request.getLocale()));
        return new ModelAndView(getErrorView());
    }
    //cancello il file dalla directory temporanea
    a.delete();
    String[] tpDefinitions = context.getBeanDefinitionNames(); //getBeanNamesForType(tpClass);
    AnagraficaObject<P, TP> anagraficaObject = null;

    String idStringAnagraficaObject = request.getParameter("id");
    Integer pkey = Integer.parseInt(idStringAnagraficaObject);
    anagraficaObject = applicationService.get(modelClass, pkey);

    //la variabile i conta le tipologie caricate con successo
    int i = 0;
    //la variabile j conta le tipologie non caricate
    int j = 0;

    for (String tpNameDefinition : tpDefinitions) {
        try {
            ImportPropertyAnagraficaUtil importBean = (ImportPropertyAnagraficaUtil) context
                    .getBean(tpNameDefinition);
            anagraficaUtils.importProprieta(anagraficaObject, importBean);
        } catch (Exception ecc) {
            saveMessage(request, getText("action.file.nosuccess.metadato.upload",
                    new Object[] { ecc.getMessage() }, request.getLocale()));
            j++;
            i--;
        }
        i++;
    }
    //pulisco l'anagrafica
    anagraficaObject.pulisciAnagrafica();
    applicationService.saveOrUpdate(modelClass, anagraficaObject);

    saveMessage(request,
            getText("action.file.success.upload", new Object[] { new String("Totale Oggetti Caricati:" + (i + j)
                    + "" + "[" + i + " caricate con successo/" + j + " fallito caricamento]") },
                    request.getLocale()));

    return new ModelAndView(getDetailsView());
}

From source file:it.cilea.osd.jdyna.web.controller.ImportConfigurazione.java

/** Performa l'import da file xml di configurazioni di oggetti;
 *  Sull'upload del file la configurazione dell'oggetto viene caricato come contesto di spring
 *  e salvate su db.//from   ww w .  j a  va  2s  .  c  om
 */
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object,
        BindException errors) throws RuntimeException, IOException {

    FileUploadConfiguration bean = (FileUploadConfiguration) object;
    MultipartFile file = (CommonsMultipartFile) bean.getFile();
    File a = null;

    //creo il file temporaneo che sara' caricato come contesto di spring per caricare la configurazione degli oggetti
    a = File.createTempFile("jdyna", ".xml", new File(path));
    file.transferTo(a);

    ApplicationContext context = null;
    try {
        context = new FileSystemXmlApplicationContext(new String[] { "file:" + a.getAbsolutePath() },
                getApplicationContext());

    } catch (XmlBeanDefinitionStoreException exc) {
        //cancello il file dalla directory temporanea
        logger.warn("Errore nell'importazione della configurazione dal file: " + file.getOriginalFilename(),
                exc);
        a.delete();
        saveMessage(request, getText("action.file.nosuccess.upload", new Object[] { exc.getMessage() },
                request.getLocale()));
        return new ModelAndView(getErrorView());
    }
    //cancello il file dalla directory temporanea
    a.delete();
    String[] tpDefinitions = context.getBeanNamesForType(tpClass);
    //la variabile i conta le tipologie caricate con successo
    int i = 0;
    //la variabile j conta le tipologie non caricate
    int j = 0;
    for (String tpNameDefinition : tpDefinitions) {
        try {
            TP tipologiaDaImportare = (TP) context.getBean(tpNameDefinition);
            applicationService.saveOrUpdate(tpClass, tipologiaDaImportare);
        } catch (Exception ecc) {
            saveMessage(request, getText("action.file.nosuccess.metadato.upload",
                    new Object[] { ecc.getMessage() }, request.getLocale()));
            j++;
            i--;
        }
        i++;
    }

    String[] areeDefinitions = context.getBeanNamesForType(areaClass);
    int w = 0;
    int v = 0;
    for (String areaNameDefinition : areeDefinitions) {
        try {
            A areaDaImportare = (A) context.getBean(areaNameDefinition);
            applicationService.saveOrUpdate(areaClass, areaDaImportare);
        } catch (Exception ecc) {
            saveMessage(request, getText("action.file.nosuccess.metadato.upload",
                    new Object[] { ecc.getMessage() }, request.getLocale()));
            v++;
            w--;
        }
        w++;
    }
    // check sulla tipologia poiche' ci sono oggetti che non hanno la tipologia tipo Opera e Parte
    if (typeClass != null) {
        String[] typeDefinitions = context.getBeanNamesForType(typeClass);
        int r = 0;
        int t = 0;
        for (String typeDefinition : typeDefinitions) {
            try {
                TY tipologiaDaImportare = (TY) context.getBean(typeDefinition);
                applicationService.saveOrUpdate(typeClass, tipologiaDaImportare);
            } catch (Exception ecc) {
                saveMessage(request, getText("action.file.nosuccess.metadato.upload",
                        new Object[] { ecc.getMessage() }, request.getLocale()));
                t++;
                r--;
            }
            r++;
        }

        saveMessage(request,
                getText("action.file.success.upload.tipologie",
                        new Object[] { new String("Totale Tipologie:" + (t + r) + " [" + r
                                + "caricate con successo/" + t + " fallito caricamento]") },
                        request.getLocale()));

    }

    saveMessage(request,
            getText("action.file.success.upload",
                    new Object[] {
                            new String("Totale TP:" + (i + j) + "" + "[" + i + " caricate con successo/" + j
                                    + " fallito caricamento]"),
                            new String("Totale Aree:" + (w + v) + " [" + w + "caricate con successo/" + v
                                    + " fallito caricamento]") },
                    request.getLocale()));

    return new ModelAndView(getDetailsView());
}