gwtipstricks:idxtipstricks:doc_mapping_xml

Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.

Link a questa pagina di confronto

Entrambe le parti precedenti la revisione Revisione precedente
Prossima revisione
Revisione precedente
gwtipstricks:idxtipstricks:doc_mapping_xml [2021/03/17 16:27]
francesco.rosati
gwtipstricks:idxtipstricks:doc_mapping_xml [2021/04/02 17:52] (versione attuale)
francesco.rosati
Linea 39: Linea 39:
  
 //1) recupero dei dati //1) recupero dei dati
-String keyColumn = "id_contractor"; +String keyColumn = "id_test"; 
-String ​id_contractor ​= (String) item.get(keyColumn);​ +String ​itemId ​= (String) item.get(keyColumn);​ 
 + 
 HashMap<​String,​ Object> valuesMapQuery = new HashMap<​String,​ Object>​();​ HashMap<​String,​ Object> valuesMapQuery = new HashMap<​String,​ Object>​();​
-valuesMapQuery.put(keyColumn,​id_contractor);+valuesMapQuery.put(keyColumn,​itemId)
 + 
 +String xmlValue ="​questo è un test";
  
 //​1.1)RECUPERRO DEL VALORE DI UN CAMPO DAL DB //​1.1)RECUPERRO DEL VALORE DI UN CAMPO DAL DB
Linea 87: Linea 89:
      </​Liste>​      </​Liste>​
  </​RelazioneTrimestrale>""";​  </​RelazioneTrimestrale>""";​
-//3)+ 
 +//3) recupero del template Doc
 ///////////////////////////////////////////////////////////////////​ ///////////////////////////////////////////////////////////////////​
-String classNameTemplate = "​nome_classe_template";​+// classe TEMPLATE DOC 
 +String classNameTemplate ​  ​= "​nome_classe_template";​
 String attributeColumnName = "​nome_attributo_document_template";​ String attributeColumnName = "​nome_attributo_document_template";​
 ///////////////////////////////////////////////////////////////////​ ///////////////////////////////////////////////////////////////////​
-//String itemId  +GwBeanDocument gwBeanDocument = services.gwDocumentDataService.getDocumentBeanByItemIdAndAttributeColumnName(classNameTemplate,​itemId,​attributeColumnName);​
- +
-GwBeanDocument gwBeanDocument = gwDocumentDataService.getDocumentBeanByItemIdAndAttributeColumnName(classNameTemplate,​itemId,​attributeColumnName ​ ); +
-//noime della cartella per i file temporanei +
-String tempDestDirName = "​gwdocxmltemp";​ +
-String tempFilePath ="";​ +
-if(gwBeanDocument!=null && gwBeanDocument.getIs()!=null ){ +
- +
-    File tempDir = new File(System.getProperty("​java.io.tmpdir"​),​ tempDestDirName);​ +
-    String tempDirPath = tempDir.getPath();​  +
-    log.debug("​GEOWEB_DEBUG:​ Trying to create a new File instance with this path "​+tempDirPath);​  +
-    log.debug("​GEOWEB_DEBUG:​ If doesn'​t already exist, trying to create the directory named by this pathname "​+tempDir);​  +
-    if (!tempDir.exists()) { +
-       if (!tempDir.mkdir())  +
-   throw new IOException("​Could not create directory: " + tempDirPath);​ +
-       ​else +
-          log.debug("​GEOWEB_DEBUG:​ (FileManagerService) - The folder in the path " + tempDirPath + " was created"​);​ +
-    } +
- +
-    File tempFile = new File(tempDir,​gwBeanDocument.getName());​ +
-    tempFilePath = tempFile.getPath();​ +
-    FileOutputStream output = new FileOutputStream(tempFile);​ +
-    IOUtils.copy(gwBeanDocument.getIs() , output); +
-}else{ +
-    throw new RuntimeException("​Template doc non trovato"​);​ +
-+
- +
-////4) CREAZIONE DEL DOC AGGIORNATO:​ +
-//INPUT: PATH sul SERVER dove memorizzare temporaneamente il file +
-//OUTPUT: il doc aggiornato +
-GwBeanDocument gwBeanDocument = services.gwDocumentDataService.getDocumentBeanByItemIdAndAttributeColumnName(classNameTemplate,​itemId,​attributeColumnName ​ );+
 //nome della cartella per i file temporanei //nome della cartella per i file temporanei
 String tempDestDirName = "​gwdocxmltemp";​ String tempDestDirName = "​gwdocxmltemp";​
 File tempFile = null; File tempFile = null;
 if(gwBeanDocument!=null && gwBeanDocument.getIs()!=null ){ if(gwBeanDocument!=null && gwBeanDocument.getIs()!=null ){
-  + File tempDir = new File(System.getProperty("​java.io.tmpdir"​),​ tempDestDirName);​ 
-    ​File tempDir = new File(System.getProperty("​java.io.tmpdir"​),​ tempDestDirName);​ +    String tempDirPath = tempDir.getPath();​ 
-    String tempDirPath = tempDir.getPath();  +    log.debug("​GEOWEB_DEBUG:​ If doesn'​t already exist, trying to create the directory named by this path:"+tempDirPath);
-    log.debug("​GEOWEB_DEBUG:​ Trying to create a new File instance with this path " + tempDirPath);  +
-    log.debug("​GEOWEB_DEBUG:​ If doesn'​t already exist, trying to create the directory named by this pathname ​" + tempDir); +
     if (!tempDir.exists()) {     if (!tempDir.exists()) {
        if (!tempDir.mkdir())         if (!tempDir.mkdir())
-   ​throw new IOException("​Could not create directory: " + tempDirPath);​+       throw new IOException("​Could not create directory: " + tempDirPath);​
        else        else
           log.debug("​GEOWEB_DEBUG:​ (FileManagerService) - The folder in the path " + tempDirPath + " was created"​);​           log.debug("​GEOWEB_DEBUG:​ (FileManagerService) - The folder in the path " + tempDirPath + " was created"​);​
     }     }
-  + tempFile = new File(tempDir,​gwBeanDocument.getName());​ 
-  ​tempFile = new File(tempDir,​gwBeanDocument.getName());​ + FileOutputStream output = new FileOutputStream(tempFile);​ 
-  FileOutputStream output = new FileOutputStream(tempFile);​ + IOUtils.copy(gwBeanDocument.getIs() , output);
-  IOUtils.copy(gwBeanDocument.getIs() , output);+
 }else{ }else{
     throw new RuntimeException("​Template doc non trovato"​);​     throw new RuntimeException("​Template doc non trovato"​);​
 } }
    
-////4) SERVIZIO PER LA CREAZIONE DEL DOC AGGIORNATO:​ +//4) SERVIZIO PER LA CREAZIONE DEL DOC AGGIORNATO: 
 +String contentDisposition ="​attachment";​ 
 + 
 +//esempi di content type: 
 +//​.doc ​     application/​msword 
 +//​.docx ​    ​application/​vnd.openxmlformats-officedocument.wordprocessingml.document 
 +//​.xls ​     application/​vnd.ms-excel 
 +//​.xlsx ​    ​application/​vnd.openxmlformats-officedocument.spreadsheetml.sheet 
 +String contentType ="​application/​vnd.openxmlformats-officedocument.wordprocessingml.document";​ 
 +httpServletResponse.setContentType(contentType ); 
 +httpServletResponse.setHeader("​Content-Disposition",​contentDisposition+";​filename=\""​+gwBeanDocument.getName()+"​\""​);​
 ZipFile zipFile = new ZipFile(tempFile);​ ZipFile zipFile = new ZipFile(tempFile);​
 OutputStream out = httpServletResponse.getOutputStream();​ OutputStream out = httpServletResponse.getOutputStream();​
 ZipOutputStream zos = new ZipOutputStream(out);​ ZipOutputStream zos = new ZipOutputStream(out);​
 + 
 for(Enumeration e = zipFile.entries();​ e.hasMoreElements();​ ) { for(Enumeration e = zipFile.entries();​ e.hasMoreElements();​ ) {
     ZipEntry entryIn = (ZipEntry) e.nextElement();​     ZipEntry entryIn = (ZipEntry) e.nextElement();​
  • gwtipstricks/idxtipstricks/doc_mapping_xml.1615994870.txt.gz
  • Ultima modifica: 2021/03/17 16:27
  • da francesco.rosati