PluginJar.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.monitor.engine.dynamic;

  21. import java.io.File;
  22. import java.io.IOException;
  23. import java.io.Serializable;
  24. import java.net.MalformedURLException;
  25. import java.net.URL;
  26. import java.util.Date;

  27. import org.openspcoop2.utils.UtilsException;
  28. import org.openspcoop2.utils.regexp.RegExpException;
  29. import org.openspcoop2.utils.regexp.RegExpNotFoundException;
  30. import org.openspcoop2.utils.regexp.RegExpNotValidException;
  31. import org.openspcoop2.utils.regexp.RegularExpressionEngine;
  32. import org.openspcoop2.utils.resources.FileSystemUtilities;

  33. /**
  34.  * Plugin
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */
  40. public class PluginJar implements Serializable {

  41.     /**
  42.      *
  43.      */
  44.     private static final long serialVersionUID = 1L;

  45.     private String nome;
  46.     private Date date; // data salvata sulla configurazione
  47.    
  48.     //private byte[] content; // occupa spazio inutile
  49.     private File fContent;
  50.    
  51.     private String url;
  52.    
  53.     private URL resourceURL;
  54.    
  55.     public PluginJar(String nome, Date data, byte[] contenuto) throws UtilsException, IOException {
  56.         this.nome = nome;
  57.         this.date = data;
  58.         /**this.content = contenuto;*/
  59.         this.fContent = FileSystemUtilities.createTempFile("plugin_"+this.nome, ".raw");
  60.         FileSystemUtilities.writeFile(this.fContent, contenuto);
  61.         this.resourceURL = this.fContent.toURI().toURL();
  62.     }
  63.     public PluginJar(String nome, Date data, String url) throws RegExpException, RegExpNotValidException, RegExpNotFoundException, MalformedURLException {
  64.         this.nome = nome;
  65.         this.date = data;
  66.         this.url = url;
  67.        
  68.         String uriPattern = ".+://.+";
  69.         boolean matchUri = RegularExpressionEngine.isMatch(this.url, uriPattern);
  70.         if(matchUri) {
  71.             this.resourceURL = new URL(this.url);
  72.         }
  73.         else {
  74.             File f = new File(this.url);
  75.             if(f.exists()) {
  76.                 this.resourceURL = f.toURI().toURL();
  77.             }
  78.             else {
  79.                 this.resourceURL = new URL(this.url);
  80.             }
  81.         }
  82.     }
  83.    
  84.     public void close() {
  85.         if(this.fContent!=null) {
  86.             FileSystemUtilities.deleteFile(this.fContent);
  87.         }
  88.     }
  89.    
  90.     public String getNome() {
  91.         return this.nome;
  92.     }
  93.     public Date getDate() {
  94.         return this.date;
  95.     }
  96.     public URL getResourceURL() {
  97.         return this.resourceURL;
  98.     }
  99. }