From f5618c87e63deb99920710787f6dcd34d4b17425 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 13 Apr 2016 18:41:29 +0200 Subject: (WiP) Global image sync --- .../java/org/openslx/imagemaster/util/Util.java | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/openslx/imagemaster/util') diff --git a/src/main/java/org/openslx/imagemaster/util/Util.java b/src/main/java/org/openslx/imagemaster/util/Util.java index e9146e0..f8d9248 100644 --- a/src/main/java/org/openslx/imagemaster/util/Util.java +++ b/src/main/java/org/openslx/imagemaster/util/Util.java @@ -7,6 +7,7 @@ import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.util.Arrays; import java.util.Random; +import java.util.UUID; import org.apache.log4j.Logger; @@ -120,7 +121,7 @@ public class Util public static boolean isEmpty( String str ) { - return str != null && !str.isEmpty(); + return str == null || str.isEmpty(); } public static boolean isEmpty( String str, String message, Logger logger ) @@ -217,4 +218,30 @@ public class Util return Arrays.equals( k1.getEncoded(), k2.getEncoded() ); } + public static String getRelativePath( File absolutePath, File parentDir ) + { + String file; + String dir; + try { + file = absolutePath.getCanonicalPath(); + dir = parentDir.getCanonicalPath() + File.separator; + } catch ( Exception e ) { + LOGGER.error( "Could not get relative path for " + absolutePath.toString(), e ); + return null; + } + if ( !file.startsWith( dir ) ) + return null; + return file.substring( dir.length() ); + } + + public static boolean isUUID( String id ) + { + try { + UUID.fromString( id ); + } catch ( Exception e ) { + return false; + } + return true; + } + } -- cgit v1.2.3-55-g7522