Exemple #1
0
 public FileCache build() {
   if (userHome == null) {
     String path = System.getenv("SONAR_USER_HOME");
     if (path == null) {
       // Default
       path = FileUtils.getUserDirectoryPath() + File.separator + ".sonar";
     }
     userHome = new File(path);
   }
   File cacheDir = new File(userHome, "cache");
   return FileCache.create(cacheDir, log);
 }
 @SuppressWarnings("unchecked")
 private void exportBtnActionPerformed(java.awt.event.ActionEvent evt) {
   toggle(false);
   JFileChooser fc = new JFileChooser();
   String path =
       FileUtils.getUserDirectoryPath() + File.separator + treeViewNode.getText() + ".csv";
   fc.setSelectedFile(new File(path));
   fc.showSaveDialog(this);
   File target = fc.getSelectedFile();
   int row = model.getRowCount();
   try {
     boolean written;
     try (FileOutputStream fos = new FileOutputStream(target)) {
       while (--row > -1) {
         Vector v = (Vector) model.getDataVector().get(row);
         for (int i = 0; i < v.size(); i++) {
           if (v.get(i).toString().contains(",")) {
             v.set(i, ST.format("\"<%1>\"", v.get(i)));
           }
         }
         String line = ST.format("<%1:{ x |, <x>}>", v).substring(2);
         fos.write(line.getBytes(CHARSET));
         fos.write(Character.LINE_SEPARATOR);
       }
       written = true;
     }
     if (written) {
       LogEmitter.factory
           .get()
           .emit(
               this,
               Core.ALERT.INFO,
               ST.format("<%1> hosts written to <%2>", model.getRowCount(), target.getPath()));
     } else {
       LogEmitter.factory
           .get()
           .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
     }
   } catch (FileNotFoundException ex) {
     Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex);
     LogEmitter.factory
         .get()
         .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
   } catch (IOException ex) {
     Logger.getLogger(ConnectionDialog.class.getName()).log(Level.SEVERE, null, ex);
     LogEmitter.factory
         .get()
         .emit(this, Core.ALERT.DANGER, ST.format("Failed to export <%1>", target.getPath()));
   }
   toggle(true);
 }
Exemple #3
0
 @SuppressWarnings("unchecked")
 private void initUI() {
   paramExport = new ParamExport(mainFrame);
   paramExport.load();
   Internal internal =
       BookUtil.get(
           mainFrame,
           SbConstants.BookKey.EXPORT_DIRECTORY,
           EnvUtil.getDefaultExportDir(mainFrame));
   txFolder.setText(internal.getStringValue());
   if (txFolder.getText().isEmpty()) txFolder.setText(FileUtils.getUserDirectoryPath());
   cbReport.removeAllItems();
   for (ExportData export : exports) {
     cbReport.addItem(export);
   }
   cbReport.setSelectedIndex(0);
   cbFormat.removeAllItems();
   for (String zformat : formats) {
     cbFormat.addItem(zformat);
   }
   cbFormat.setSelectedItem("html");
 }