Bladeren bron

wip cleanup

Fabio Dalle Ave 2 maanden geleden
bovenliggende
commit
26a7b44c9c

+ 0 - 136
src/main/java/commons/utility/BrowserVersion.java

@@ -1,136 +0,0 @@
-package commons.utility;
-
-import jakarta.servlet.http.HttpServletRequest;
-
-import commons.utility.database.NullValue;
-
-public class BrowserVersion {
-	private boolean dipendente = false;
-
-	private boolean operatore = false;
-
-	private HttpServletRequest req = null;
-
-	public BrowserVersion(HttpServletRequest req) {
-		super();
-		this.req = req;
-	}
-
-	public void check() {
-
-		String agt = NullValue.STRING;
-		String majorS=NullValue.STRING;;
-
-		try {
-			agt = req.getHeader("user-agent");
-			if (agt != null)
-				agt = agt.toLowerCase();
-			else
-				return;
-
-			boolean firefx = (agt.indexOf("firefox") != -1);
-			if (firefx) {
-				operatore = true;
-				dipendente = true;
-			} else {
-				boolean ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
-
-				// int minor = Integer.parseInt(minorS);
-
-				if (ie) {
-					majorS = agt.substring(agt.indexOf("msie") + 5, agt.indexOf("msie") + 5 + 1);
-					int major = Integer.parseInt(majorS);
-					boolean ie3 = (major < 4);
-					boolean ie4 = (major == 4 && (agt.indexOf("msie 4") != -1));
-					boolean ie4up = (major >= 4);
-					boolean ie5 = (major == 5 && (agt.indexOf("msie 5.0") != -1));
-					boolean ie5_5 = (major == 5 && (agt.indexOf("msie 5.5") != -1));
-					boolean ie5up = (major >= 5 && !ie3 && !ie4 && !ie5);
-					boolean ie5_5up = (major >= 5 && !ie3 && !ie4 && !ie5 && !ie5_5);
-					boolean ie6 = (major == 6 && (agt.indexOf("msie 6.0") != -1));
-					boolean ie6up = (major >= 6 && !ie3 && !ie4 && !ie5 && !ie5_5 && !ie6);
-
-					if (ie5_5 || ie5_5up) {
-						dipendente = true;
-					}
-
-					if (ie6 || ie6up) {
-						operatore = true;
-						dipendente = true;
-					}
-				}
-			}
-		} catch (Exception er) {
-			
-			if (agt == null) {
-				System.out.println("*************************************** USER-AGENT ***************************");
-				System.out.println("USER-AGENT NULLO " + er.getMessage());
-				er.printStackTrace();
-				System.out.println("*************************************** USER-AGENT ***************************");
-			}
-			if (req == null) {
-				
-				System.out.println("*************************************** USER-AGENT ***************************");
-				System.out.println("Request NULLA " + er.getMessage());
-				er.printStackTrace();
-				System.out.println("*************************************** USER-AGENT ***************************");
-			}
-
-			if (agt.length() == 0) {
-				
-				System.out.println("*************************************** USER-AGENT ***************************");
-				System.out.println("Agent == blank" + er.getMessage());
-				er.printStackTrace();
-				System.out.println("*************************************** USER-AGENT ***************************");
-			}
-			 if (er instanceof NumberFormatException) {
-					System.out.println("*************************************** USER-AGENT ***************************");
-					System.out.println("NumberFormatException");
-					System.out.println("Valore= "+majorS);
-					System.out.println(er.getMessage());
-					er.printStackTrace();
-					System.out.println("*************************************** USER-AGENT ***************************");
-			}
-			
-			System.out.println("*************************************** USER-AGENT ***************************");
-			System.out.println("GENERAL");
-			System.out.println("agt= " +agt);
-			System.out.println("majorS= "+majorS);
-			System.out.println("");
-			System.out.println(er.getMessage());
-			er.printStackTrace();
-			System.out.println("*************************************** USER-AGENT ***************************");
-			
-			
-			operatore = false;
-			dipendente = true;
-		}
-
-	}
-
-	public boolean isDipendente() {
-		return dipendente;
-	}
-
-	public boolean isOperatore() {
-		return operatore;
-	}
-
-	
-	public String recoverRemoteAddress() {
-		String retVal = req.getRemoteAddr(); 
-		return (!StringUtility.empty(retVal) && retVal.length() > 30)?retVal.substring(0,30):retVal;
-	}
-
-	public String recoverHost() {
-		String retVal = req.getHeader("host"); 
-		return (!StringUtility.empty(retVal) && retVal.length() > 50)?retVal.substring(0,50):retVal;
-	}
-
-	public String recoverUserAgent() {
-		String retVal = req.getHeader("user-agent"); 
-		return (!StringUtility.empty(retVal) && retVal.length() > 100)?retVal.substring(0,100):retVal;
-	}
-
-
-}

+ 0 - 150
src/main/java/commons/utility/CryptedCookie.java

@@ -1,150 +0,0 @@
-package commons.utility;
-
-import jakarta.servlet.http.Cookie;
-
-public class CryptedCookie extends Cookie
-{
-
-	private Cookie ck = null;
-	
-	public CryptedCookie(Cookie ck) {
-		super(ck.getName(), "");
-		this.ck = ck;
-	}
-	
-	public CryptedCookie(String name, String value) {
-		this(new Cookie(name, ""));
-		this.setValue(value);
-	}
-
-	public Cookie getCk()
-	{
-		return ck;
-	}
-
-	public void setCk(Cookie ck)
-	{
-		this.ck = ck;
-	}
-
-	public Object clone()
-	{
-		return ck.clone();
-	}
-
-	public boolean equals(Object o)
-	{
-		return ck.equals(o);
-	}
-
-	public String getComment()
-	{
-		return ck.getComment();
-	}
-
-	public String getDomain()
-	{
-		return ck.getDomain();
-	}
-
-	public int getMaxAge()
-	{
-		return ck.getMaxAge();
-	}
-
-	public String getName()
-	{
-		return ck.getName();
-	}
-
-	public String getPath()
-	{
-		return ck.getPath();
-	}
-
-	public boolean getSecure()
-	{
-		return ck.getSecure();
-	}
-
-	public String getValue()
-	{
-		try
-		{
-			return Crypto.decrypt(ck.getValue());
-		}
-		catch(Exception e)
-		{
-			setValue("");
-			return "";
-		}
-	}
-
-	public int getVersion()
-	{
-		return ck.getVersion();
-	}
-
-	public int hashCode()
-	{
-		return ck.hashCode();
-	}
-
-	public void setComment(String arg0)
-	{
-		ck.setComment(arg0);
-		super.setComment(arg0);
-	}
-
-	public void setDomain(String arg0)
-	{
-		ck.setDomain(arg0);
-		super.setDomain(arg0);
-	}
-
-	public void setMaxAge(int arg0)
-	{
-		ck.setMaxAge(arg0);
-		super.setMaxAge(arg0);
-	}
-
-	public void setPath(String arg0)
-	{
-		ck.setPath(arg0);
-		super.setPath(arg0);
-	}
-
-	public void setSecure(boolean arg0)
-	{
-		ck.setSecure(arg0);
-		super.setSecure(arg0);
-	}
-
-	public void setValue(String arg0)
-	{
-		try
-		{
-			ck.setValue(Crypto.encrypt(arg0));
-			super.setValue(ck.getValue());
-		}
-		catch(Exception e)
-		{
-			ck.setValue("");
-			super.setValue("");
-		}
-	}
-
-	public void setVersion(int arg0)
-	{
-		ck.setVersion(arg0);
-		super.setVersion(arg0);
-	}
-
-	public String toString()
-	{
-		return ck.toString();
-	}
-	
-	
-
-}

+ 0 - 190
src/main/java/commons/utility/Crypto.java

@@ -1,190 +0,0 @@
-package commons.utility;
-
-import commons.exception.ZCryptoException;
-
-
-
-public class Crypto {
-  private static String KEY="Zucchetti2004";
-
-  public static String encrypt(String input) throws ZCryptoException{
-      if (input == null || (input != null && input.length() < 3))
-          return input;
-      return encrypt(input, KEY);
-  }
-
-  private static String encrypt(String input,String key) throws ZCryptoException{
-      if (input == null)
-        return input;
-
-      String output = "";
-      int y = 3;
-      int k = 0;
-      int x = 0;
-      char[] chKey = key.toCharArray();
-      char[] tmp = input.toCharArray();
-      long chk = 100;
-      String strChk = "";
-      //Random rdm1 = new Random(((int)new Date().getTime()));
-      //String randomKey = "" + Math.round((rdm1.nextDouble() * 700) + 123);
-	  String randomKey = "" + ((Math.random() * 700) + 123);
-      char[] chRandomKey = randomKey.toCharArray();
-      for (int i = 0; i < 3; i++) {
-        output += ((char)((chRandomKey[i]+chKey[k])-(80+y)));
-        y++;
-        if (y > 7)
-          y = 0;
-        k++;
-        if (k >= chKey.length)
-          k = 0;
-      }
-      for (int i = 0; i < tmp.length; i++)
-        chk += tmp[i];
-      chk = chk * tmp.length;
-      strChk = "000" + chk;
-      strChk = strChk.substring((strChk.length()-3));
-      input = input + strChk;
-      char[] tmp1 = input.toCharArray();
-      int iTmp = 0;
-      for (int i = 0; i < tmp1.length; i++) {
-        iTmp = ((tmp1[i]+chKey[k])-(80+y)+chRandomKey[x]-(35 + x));
-        if (iTmp > 255)
-          iTmp -= 255;
-        else if (iTmp < 0)
-          iTmp += 255;
-        output += ((char)iTmp);
-        y++;
-        if (y > 7)
-          y = 0;
-        k++;
-        if (k >= chKey.length)
-          k = 0;
-        x++;
-        if (x > 2)
-          x = 0;
-      }
-      output = adjustCrypt(output);
-      return output;
-  }
-
-
-  private static String adjustCrypt(String input) throws ZCryptoException{
-    String output = "";
-    String sTmp = "";
-    char[] tmp = input.toCharArray();
-    for (int i=0; i<tmp.length; i++)
-    {
-            sTmp = "" + (tmp[i] + 0);
-            sTmp =  Integer.toHexString(tmp[i]);
-            sTmp = padLeft(sTmp,2,'0');
-            output += sTmp;
-
-    }
-    return output;
-  }
-
-  private static String padLeft(String str, int w, char c) throws ZCryptoException{
-    if (str.length() >= w) return str;
-    StringBuffer sb=new StringBuffer();
-    for (int i = w - str.length(); i > 0; --i) sb.append(c);
-    sb.append(str);
-    return new String(sb);
-  }
-
-
-  private static String adjustDecrypt(String input) throws ZCryptoException{
-    String output = "";
-    String sTmp = "";
-
-    for (int i=0; i<(input.length()); i += 2)
-    {
-            sTmp = input.substring(i,i+2);
-            if(sTmp.startsWith("0"))
-            {
-                    sTmp = sTmp.substring(1);
-                    if(sTmp.startsWith("0"))
-                            sTmp = "0";
-            }
-            output += "" + ((char)(Integer.parseInt(sTmp,16)));
-    }
-    return output;
-  }
-
-  public static String decrypt(String input) throws ZCryptoException{
-      if (input == null || (input != null && input.length() < 3))
-          return input;
-      return decrypt(input,KEY);
-  }
-
-  private static String decrypt(String input,String key) throws ZCryptoException{
-    if (input == null)
-      return input;
-
-    char[] chKey = key.toCharArray();
-    input = adjustDecrypt(input);
-
-    String output = "";
-    int y = 3;
-    int k = 0;
-    int x = 0;
-    char[] tmp = input.toCharArray();
-    long chk = 100;
-    String strChk = "";
-    String strChk1 = "";
-    String randomKey = "";
-    for (int i = 0; i < 3; i++) {
-      randomKey += ((char)((tmp[i]-chKey[k])+(80+y)));
-      y++;
-      if (y > 7)
-        y = 0;
-      k++;
-      if (k >= chKey.length)
-        k = 0;
-    }
-    char[] chRandomKey = randomKey.toCharArray();
-
-    int iTmp = 0;
-    for (int i = 3; i < tmp.length; i++) {
-      iTmp = ( (tmp[i] - chKey[k]) + (80 + y) - chRandomKey[x] + (35 + x));
-      if (iTmp < 0)
-        iTmp += 255;
-      else if (iTmp > 255)
-        iTmp -= 255;
-
-      output += ( (char) iTmp);
-      y++;
-      if (y > 7)
-        y = 0;
-      k++;
-      if (k >= chKey.length)
-        k = 0;
-      x++;
-      if (x > 2)
-        x = 0;
-    }
-    strChk = output.substring( (output.length() - 3));
-    output = output.substring(0, (output.length() - 3));
-    char[] tmp1 = output.toCharArray();
-    for (int i = 0; i < tmp1.length; i++)
-      chk += tmp1[i];
-    chk = chk * tmp1.length;
-    strChk1 = "000" + chk;
-    strChk1 = strChk1.substring( (strChk1.length() - 3));
-    if (!strChk.equals(strChk1)) {
-       throw new ZCryptoException();
-    }
-    return output;
-  }
-}
-
-
-
-
-
-
-
-
-
-
-
-

+ 0 - 180
src/main/java/commons/utility/FileUtility.java

@@ -1,180 +0,0 @@
-package commons.utility;
-
-import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.channels.FileChannel;
-import java.util.Date;
-
-import javax.imageio.ImageIO;
-
-import commons.utility.database.NullValue;
-
-
-public class FileUtility {
-	
-    public static byte[] fromFileToByte(String pathFile) throws IOException 
-    {
-		File file = new File(pathFile);
-		InputStream is = new FileInputStream(file);
-		long length = file.length();
-		byte[] bytes = new byte[(int)length];
-		// Read in the bytes
-		int offset = 0;
-		int numRead = 0;
-		while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
-			offset += numRead;
-		}
-		// Ensure all the bytes have been read in
-		if (offset < bytes.length) {
-			is.close();
-			throw new IOException("Impossibile leggere il file " + file.getName());
-		}
-		// Close the input stream and return bytes
-		is.close();
-		return bytes;
-	}
-    
-	public static void fromByteToFile(byte[] bytes,
-	                                  File file)
-	{
-		BufferedOutputStream bos = null;
-
-		try
-		{
-			//create an object of FileOutputStream
-			FileOutputStream fos = new FileOutputStream(file);
-			//create an object of BufferedOutputStream
-			bos = new BufferedOutputStream(fos);
-
-			/*
-			 * To write byte array to file use,
-			 * public void write(byte[] b) method of BufferedOutputStream
-			 * class.
-			 */
-			bos.write(bytes);
-		}
-		catch (FileNotFoundException fnfe)
-		{
-			fnfe.printStackTrace();
-		}
-		catch (IOException ioe)
-		{
-			ioe.printStackTrace();
-		}
-		finally
-		{
-			if (bos != null)
-			{
-				try
-				{
-					//flush the BufferedOutputStream
-					bos.flush();
-					//close the BufferedOutputStream
-					bos.close();
-				}
-				catch (Exception e)
-				{
-				}
-			}
-		}
-	}
-
-    //Elimina una cartella e le sue sottocartelle compresi i file
-    public static boolean deleteDir(File dir) {
-        if (dir.isDirectory()) {
-            String[] children = dir.list();
-            for (int i=0; i<children.length; i++) {
-                boolean success = deleteDir(new File(dir, children[i]));
-                if (!success) {
-                    return false;
-                }
-            }
-        }
-
-        // The directory is now empty so delete it
-        return dir.delete();
-    }
-
-    //Copia file
-    public static void copy(File source, File dest) throws IOException {
-        FileChannel in = null, out = null;
-        try {
-             in = new FileInputStream(source).getChannel();
-             out = new FileOutputStream(dest).getChannel();
-
-             in.transferTo( 0, in.size(), out);
-        } finally {
-             if (in != null)
-                 in.close();
-             if (out != null)
-                 out.close();
-        }
-   }
-    
-    public static String getFileNameFromPath(String path)
-    {
- 	   File file = new File(path);
- 	   return file.getName();
-    }
-    
-    public static String getExtension(String fileName)
-    {
- 	   String ext = NullValue.STRING;
- 	   if(!StringUtility.empty(fileName, true))
- 		   ext = fileName.substring(fileName.lastIndexOf(".") + 1);
- 	   return ext;
-    }
-    
-    public static String getContentType(String tipoFile)
-  	{
-  		if(tipoFile.equals("pdf"))
-  			return "application/pdf";
-  		else if(tipoFile.equals("zip"))
-  			return "application/zip";
-  		else if(tipoFile.equals("rar"))
-  			return "application/rar";
-  		else if(tipoFile.equals("doc"))
-  			return "application/msword";
-  		else if(tipoFile.equals("jpg"))
-  			return "image/jpg";
-  		else if(tipoFile.equals("jpeg"))
-  			return "image/jpeg";
-  		else if(tipoFile.equals("bmp"))
-  			return "imgae/bmp";
-  		else if(tipoFile.equals("tif"))
-  			return "image/tif";
-  		else if(tipoFile.equals("tiff"))
-  			return "imgae/tiff";
-  		else if(tipoFile.equals("gif"))
-  			return "image/gif";
-  		else if(tipoFile.equals("png"))
-  			return "imgae/png";
-  		else
-  			return "application/octet-stream";
-  	}
-    
-    public static byte[] resizeImage(File fileUploaded) throws IOException
-    {
-    	final int IMG_WIDTH = 130;
-    	final int IMG_HEIGHT = 130;
-    	BufferedImage originalImage = ImageIO.read(fileUploaded);
-		int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
-    	
-		BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
-    	Graphics2D g = resizedImage.createGraphics();
-    	g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
-    	g.dispose();
-     
-    	File file = new File(new Date().getTime() + "");
-    	ImageIO.write(resizedImage, "jpg", file); 
-    	
-    	return fromFileToByte(file.getAbsolutePath());
-        }
-}