Package com.dotmarketing.plugin.business

Examples of com.dotmarketing.plugin.business.PluginAPI


  public void loadPlugins(String rootPath, String pluginPath) {
    List<File> pluginJars = PluginUtil.getPluginJars(rootPath, pluginPath);
    List<String> pluginIds = new ArrayList<String>();
   
    //initialize the pluginAPI
    PluginAPI pluginAPI = APILocator.getPluginAPI();
    pluginAPI.setDeployedPluginOrder(pluginIds);
    try {
      pluginAPI.setPluginJarDir(new File(pluginPath));
    } catch (IOException e) {
      Logger.fatal(this, "ERROR : while initializing pluginAPI", e);
      return;
    }
   
    List<Plugin> plugins = null;
    try {
      plugins = pluginAPI.findPlugins();
    } catch (DotDataException e) {
      Logger.fatal(this, "ERROR : when loading the installed plugins", e);
      return;
    }
   
    for (File f : pluginJars) {
      String id = f.getName();
      try{
        id = PluginUtil.getPluginNameFromJar(f.getName())
        Plugin plugin = null;
       
        if (plugins != null) {
          for (Plugin tempPlugin: plugins) {
            if (tempPlugin.getId().equals(id)) {
              plugin = tempPlugin;
              break;
            }
          }
        }
       
        boolean newPlugin = false;
        JarFile jar;
        Manifest mf;
        try {
          jar = new JarFile(f.getPath());
          mf=jar.getManifest();
        } catch (IOException e1) {
          Logger.fatal(this, "Method loadPlugins : Error deploying plugin id:" + id, e1);
          continue;
        }
        Attributes attrs=mf.getMainAttributes();
        if(plugin == null || !UtilMethods.isSet(plugin.getId())){
          plugin = new Plugin();
          newPlugin = true;
          plugin.setFirstDeployedDate(Calendar.getInstance().getTime());
          plugin.setId(id);
        }
        String version = attrs.getValue("Plugin-Version");
        if(!UtilMethods.isSet(version)){
          Logger.fatal(this, "Method loadPlugins : Error deploying plugin id:" + id);
          continue;
        }
        if(!newPlugin){
          if(plugin.getPluginVersion().equalsIgnoreCase(version)){
            setUpHooks(id);
            loadPluginProperties(jar, plugin.getId());
            pluginIds.add(id);
            pluginAPI.setDeployedPluginOrder(pluginIds);
            continue;
          }
        }
       
        plugin.setPluginVersion(version);
        String oldVersion = plugin.getPluginVersion();
        plugin.setLastDeployedDate(Calendar.getInstance().getTime());
        String pluginName = attrs.getValue("Plugin-Name") ==  null ? "":attrs.getValue("Plugin-Name");
        String author = attrs.getValue("Author") ==  null ? "":attrs.getValue("Author");
        plugin.setAuthor(author);
        plugin.setPluginName(pluginName);
        try{
          pluginAPI.save(plugin);
        } catch (DotDataException e2) {
          Logger.fatal(this, "Method loadPlugins : Error deploying plugin id:" + id, e2);
          continue;
        }
        loadPluginProperties(jar, plugin.getId());
        String deployClass = attrs.getValue("Deploy-Class");
        PluginDeployer deployer=null;
        if (deployClass!=null && deployClass.length()>0) {
          try {
            Object o=Class.forName(deployClass).newInstance();
            if (o instanceof PluginDeployer) {
              deployer=(PluginDeployer)o;
              if(newPlugin)
                deployer.deploy();
              else
                deployer.redeploy(oldVersion);
            }
          } catch (InstantiationException e) {
            Logger.debug(PluginLoader.class,"InstantiationException: " + id + " " + e.getMessage(),e);
            continue;
          } catch (IllegalAccessException e) {
            Logger.debug(PluginLoader.class,"IllegalAccessException: " + id + " " + e.getMessage(),e);
            continue;
          } catch (ClassNotFoundException e) {
            Logger.debug(PluginLoader.class,"ClassNotFoundException: " + id + " " + e.getMessage(),e);
            continue;
          }
        }
        setUpHooks(id);
        pluginIds.add(id);
        pluginAPI.setDeployedPluginOrder(pluginIds);
        pluginAPI.loadBackEndFiles(plugin.getId());
       
      }catch (Exception e) {
        Logger.fatal(this, "ERROR DEPLOYING A PLUGIN : " + id, e);
      }
    }
View Full Code Here


    }
  }
 
  private void setUpHooks(String pluginId) throws InstantiationException, IllegalAccessException, ClassNotFoundException, DotDataException{

    PluginAPI pluginAPI = APILocator.getPluginAPI();
    Interceptor conI = (Interceptor)APILocator.getContentletAPIntercepter();
    String conPreHooks = pluginAPI.loadPluginConfigProperty(pluginId, "contentletapi.prehooks");
    String conPostHooks = pluginAPI.loadPluginConfigProperty(pluginId, "contentletapi.posthooks");
    if(UtilMethods.isSet(conPreHooks)){
      String[] pres = conPreHooks.split(",");
      for (String string : pres) {
        conI.addPreHook(string);
      }
View Full Code Here



  private static void getPluginsHBM(String type,Configuration cfg) {
    Logger.debug(HibernateUtil.class, "Loading Hibernate Mappings from plugins ");
    PluginAPI pAPI=APILocator.getPluginAPI();

    File pluginDir=pAPI.getPluginJarDir();
    if (pluginDir==null) {
    return;
    }
    File[] plugins=pluginDir.listFiles(new FilenameFilter(){
View Full Code Here

         set.add("^/api/");
         set.add("^/DOTLESS/");
         set.add("^/DOTSASS/");

         //Load exclusions from plugins
         PluginAPI pAPI=APILocator.getPluginAPI();
         List<String> pluginList=pAPI.getDeployedPluginOrder();
         if (pluginList!=null) {
           for (String pluginID:pluginList) {
             try {
           String list=pAPI.loadPluginConfigProperty(pluginID, "cmsfilter.servlet.exclusions");
           Logger.info(CMSFilter.class,"plugin "+pluginID+" cmsfilter.servlet.exclusions="+list);
           if (list!=null) {
             String[] items=list.split(",");
             if (items!=null && items.length>0) {
               for (String item:items) {
View Full Code Here

TOP

Related Classes of com.dotmarketing.plugin.business.PluginAPI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.