updated SibaManager

This commit is contained in:
Didier Clermonté 2016-05-25 18:10:34 +02:00
parent 4fbf01f8a0
commit 60ab1f52a3
11 changed files with 77 additions and 44 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,9 +1,21 @@
/*
* Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
*
* This file is part of Siba.
*
* Siba is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.dclermonte.siba;
@ -15,7 +27,9 @@ package org.dclermonte.siba;
*/
public class SibaException extends Exception
{
/**
*
*/
private static final long serialVersionUID = 2909630770291570845L;
public SibaException()
@ -23,22 +37,29 @@ public class SibaException extends Exception
super();
}
/**
*
* @param message
*/
public SibaException(final String message)
{
super(message);
}
/**
*
* @param message
* @param cause
*/
public SibaException(final String message, final Throwable cause)
{
super(message, cause);
}
protected SibaException(final String message, final Throwable cause, final boolean enableSuppression,
final boolean writableStackTrace)
{
super(message, cause, enableSuppression, writableStackTrace);
}
/**
*
* @param cause
*/
public SibaException(final Throwable cause)
{
super(cause);

View File

@ -131,8 +131,7 @@ public class SibaCLI
}
else
{
System.out.println(BUNDLE.getString("badUsage.text"));
help();
throw new SibaException(BUNDLE.getString("ToManyParameter.text")); //$NON-NLS-1$
}
}
else if (StringUtils.equals(args[0], "check"))
@ -161,8 +160,7 @@ public class SibaCLI
}
else
{
System.out.println(BUNDLE.getString("badUsage.text"));
help();
throw new SibaException(BUNDLE.getString("ToManyParameter.text")); //$NON-NLS-1$
}
}
else
@ -180,6 +178,7 @@ public class SibaCLI
{
System.err.println("SibaException chainée = " + sibaException.getCause().getMessage());
}
help();
}
}

View File

@ -9,4 +9,5 @@ directoryNotExist.text = one of the directories does not exist
missingFileToCheck.text = Missing the file to check
missingTargetFile.text=missing target file
NotDirectorySource.text=Source is not a directory
SibaManageralgorithm.text=Algorithm error in sibaManagerexception
SibaManageralgorithm.text=Algorithm error in sibaManagerexception
ToManyParameter.text= Bad number of parameters

View File

@ -9,4 +9,5 @@ directoryNotExist.text = L'un des r
missingFileToCheck.text = Il manque le fichier à vérifier
missingTargetFile.text=Le répertoire destination n'existe pas
NotDirectorySource.text=La source n'est pas un répertoire
SibaManageralgorithm.text=Erreur d'algorithme dans sibaManager
SibaManageralgorithm.text=Erreur d'algorithme dans sibaManager
ToManyParameter.text= Trop de paramètres

View File

@ -171,8 +171,6 @@ public class BackupPanel extends JPanel
panel_2.add(verticalStrut);
btnNewButton_2.addActionListener(new ActionListener()
{
private Object e1;
@Override
public void actionPerformed(final ActionEvent e)
{
@ -196,10 +194,16 @@ public class BackupPanel extends JPanel
}
}
catch (SibaException e1)
catch (SibaException sibaException)
{
// TODO Auto-generated catch block
((Throwable) this.e1).printStackTrace();
String dataMissing = sibaException.getMessage();
if (!(sibaException.getCause() == null))
{
dataMissing.concat(sibaException.getCause().getMessage());
}
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@ -134,18 +134,14 @@ public class CheckPanel extends JPanel
+ BUNDLE.getString("CheckPanel.confirmDialogBad.text");
JOptionPane.showMessageDialog(null, message, titre, JOptionPane.INFORMATION_MESSAGE);
}
}
else
{
String dataMissing = BUNDLE.getString("BackupPanel.dataMissing.text");
String titleWarning = BUNDLE.getString("BackupPanel.TitleWarning.text");
JOptionPane.showMessageDialog(null, dataMissing, titleWarning, JOptionPane.INFORMATION_MESSAGE);
}
}
catch (SibaException exception)
{
// TODO Auto-generated catch block

View File

@ -27,6 +27,7 @@ import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
@ -151,6 +152,8 @@ public class SibaGUI
private void initialize() throws SibaException
{
this.frmSimpleBackup = new JFrame();
this.frmSimpleBackup.setIconImage(Toolkit.getDefaultToolkit()
.getImage(SibaGUI.class.getResource("/org/dclermonte/siba/Cat-Box-256.png")));
this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400));
this.frmSimpleBackup.getContentPane().setBackground(new Color(173, 255, 47));

View File

@ -20,6 +20,7 @@
package org.dclermonte.siba.model;
import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -60,18 +61,30 @@ public class SibaManager
*/
public static File backup(final File fileToSave, File target) throws SibaException
{
File result = null;
File result;
try
{
if (!(fileToSave == null) && fileToSave.exists())
if ((fileToSave == null) || !(fileToSave.exists()))
{
if (fileToSave.isDirectory())
throw new SibaException(BUNDLE.getString("sourceNotExist.text"));
}
else
{
if (!(fileToSave.isDirectory()))
{
throw new SibaException(BUNDLE.getString("NotDirectorySource.text"));
}
else
{
if ((target == null))
{
target = new File(System.getProperty("user.dir"));
}
if (target.isDirectory())
if (!(target.isDirectory()))
{
throw new SibaException(BUNDLE.getString("NotDirectoryTarget.text"));
}
else
{
int pathLength = fileToSave.getParentFile().getAbsolutePath().length();
LocalDateTime date = LocalDateTime.now();
@ -87,27 +100,20 @@ public class SibaManager
out.close();
fileCheckMD5(result, target + "/" + outputFileNameWithoutExtension + ".tgz.md5");
}
else
{
throw new SibaException(BUNDLE.getString("NotDirectoryTarget.text"));
}
}
else
{
throw new SibaException(BUNDLE.getString("NotDirectorySource.text"));
}
}
else
{
throw new SibaException(BUNDLE.getString("sourceNotExist.text"));
}
}
catch (IOException ioExceptionBackup)
{
throw new SibaException(BUNDLE.getString("ioExceptionBackup.text"), ioExceptionBackup); //$NON-NLS-1$
}
finally
{
Closeable out = null;
IOUtils.closeQuietly(out);
}
//
return result;
}
/**
@ -119,7 +125,7 @@ public class SibaManager
*/
public static boolean check(final File choosenFile) throws SibaException
{
boolean result = false;
boolean result;
try
{
if (choosenFile.exists() && (choosenFile.length() > 32))
@ -173,6 +179,7 @@ public class SibaManager
{
throw new SibaException(BUNDLE.getString("ioExceptionCheck.text"), ioExceptionCheck); //$NON-NLS-1$
}
//
return result;
}
@ -252,7 +259,7 @@ public class SibaManager
{
throw new SibaException(BUNDLE.getString("ioExceptionFileMD5.text"), ioExceptionFileMD5); //$NON-NLS-1$
}
//
return result;
}
@ -303,6 +310,7 @@ public class SibaManager
throw new SibaException(BUNDLE.getString("ioExceptionMD5.text"), ioException); //$NON-NLS-1$
}
result = hashString.toString();
//
return result;
}