⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plugintype.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 */
package com.sslexplorer.extensions.types;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Element;
import org.jdom.JDOMException;

import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.extensions.ExtensionDescriptor;
import com.sslexplorer.extensions.ExtensionType;
import com.sslexplorer.plugin.PluginDefinition;

public class PluginType implements ExtensionType {

    final static Log log = LogFactory.getLog(PluginType.class);
    
    final static String TYPE = "plugin";

    public void load(ExtensionDescriptor descriptor, Element element) throws JDOMException, IOException {

        if(element.getName().equals(TYPE)) {

                // Plugin name
                  String name = element.getAttributeValue("name");
                  if(name == null || name.equals("")) {
                      throw new JDOMException("The name attribute must be supplied for <plugin> elements.");
                  }

                  // Plugin classname
                  String className = element.getAttributeValue("class");
                  if(className == null || className.equals("")) {
                      throw new JDOMException("The class attribute must be supplied for <plugin> elements.");
                  }

                  // Required host version
                  String requiredHostVersion = element.getAttributeValue("hostVersion");
                  if(requiredHostVersion == null || requiredHostVersion.equals("")) {
                      throw new JDOMException("The hostVersion attribute must be supplied for <plugin> elements.");
                  }

                  // Order
                  String orderText  = element.getAttributeValue("order");
                  int order = 999;
                  if(orderText != null && !orderText.equals("")) {
                      order = Integer.parseInt(orderText);
                  }

                  // Optional
                  String dependencies = element.getAttributeValue("dependencies");
                  if(dependencies != null) {
                      log.warn("DEPRECATED. dependencies attribute in plugin definition in " + descriptor.getApplicationBundle().getFile().getAbsolutePath() + " should now use 'depends'.");
                  }
                  else {
                      dependencies = element.getAttributeValue("depends");
                  }

                  PluginDefinition def = new PluginDefinition(descriptor);

                  // Required
                  def.setClassName(className);
                  def.setRequiredHostVersion(requiredHostVersion);

                  // Optional
                  def.setDependencies(dependencies);
                  def.setOrder(order);

                  for(Iterator i  = element.getChildren().iterator(); i.hasNext(); ) {
                      Element el = (Element)i.next();
                      if(el.getName().equals("classpath")) {
                          String path = el.getText();
                          if(path != null && !path.equals("")) {
                              File f = new File(descriptor.getApplicationBundle().getBaseDir(),
                                              path);
                              if(f.exists()) {
                                  URL u = f.toURL();
                                  if (log.isInfoEnabled())
                                	  log.info("Adding " + u + " to classpath");
                                  def.addClassPath(u);
                              }
                              else {
                                  if(!"true".equals(System.getProperty("sslexplorer.useDevConfig"))) {
                                      log.warn("Plugin classpath element " + f.getAbsolutePath() + " does not exist.");
                                  }
                              }
                          }
                      }
                      else if(el.getName().equals("resources")) {
                          File f = new File(descriptor.getApplicationBundle().getBaseDir(), el.getText());
                          if(f.exists() && f.isDirectory()) {
                              def.addResourceBase(f.getCanonicalFile().toURL());
                          }
                          else {
                        	  if (log.isInfoEnabled())
                        		  log.info("<resources> element does not point to a valid directory.");
                          }
                      }
                      else if(el.getName().equals("native")) {
                          File f = new File(descriptor.getApplicationBundle().getBaseDir(), el.getText());
                          if(f.exists() && f.isDirectory()) {
                              def.addNativeDirectory(f.getCanonicalFile());
                          }
                          else {
                        	  if (log.isInfoEnabled())
                        		  log.info("<native> element does not point to a valid directory.");
                          }
                      }
                      else {
                          throw new JDOMException("The <plugin> element only supports the nested <classpath>, <resources> or <native> elements");
                      }
                  }
                  CoreServlet.getServlet().getPluginManager().addPluginDefinition(def);
        }


      }

      public void verifyRequiredElements() throws JDOMException {

      }    
      
      public boolean isHidden() {
          return true;
      }          
  
      public String getType() {
          return TYPE;
      }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -