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

📄 javatype.java

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

import java.io.IOException;
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.boot.Util;
import com.sslexplorer.extensions.ApplicationLauncherType;
import com.sslexplorer.extensions.ApplicationShortcutItem;
import com.sslexplorer.extensions.ExtensionDescriptor;
import com.sslexplorer.extensions.ExtensionType;

/**
 * Implementation of an
 * {@link com.sslexplorer.extensions.ApplicationLauncherType} that allows
 * execution of Java applications using a running VPN client.
 * <p>
 * This launcher will provide links to launch the VPN client if it is not
 * running before launching the applicaiton itself.
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.14 $
 */
public class JavaType implements ApplicationLauncherType {

    static Log log = LogFactory.getLog(JavaType.class);
    
    final static String TYPE = "java";
    
    // Private instance variables
    private String jre;
    private ExtensionDescriptor descriptor;

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.extensions.ExtensionType#load(com.sslexplorer.extensions.ExtensionDescriptor,
     *      org.jdom.Element)
     */
    public void load(ExtensionDescriptor descriptor, Element element) throws JDOMException, IOException {
        this.descriptor = descriptor;
        if (element.getName().equals(TYPE)) {
            
            jre = element.getAttribute("jre").getValue();

            if (jre == null) {
                throw new JDOMException("<application> element requires attribute 'jre'");
            }

            try {
                ExtensionDescriptor.getVersion(jre);
            } catch (Throwable ex) {
                throw new JDOMException("Invalid value '" + jre + "' specified for 'jre' attribute");
            }

            for (Iterator it = element.getChildren().iterator(); it.hasNext();) {
                Element e = (Element) it.next();

                if (e.getName().equalsIgnoreCase("classpath")) {
                    verifyClasspath(e);
                } else if (e.getName().equalsIgnoreCase("main")) {
                    verifyMain(e);
                } else {
                    throw new JDOMException("Unexpected element <" + e.getName() + "> found in <application>");
                }
            }


        }

    }

    public void verifyRequiredElements() throws JDOMException {

    }


    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.extensions.ApplicationLauncherType#getLink(com.sslexplorer.extensions.ApplicationShortcutItem,
     *      java.lang.String)
     */
    public String getLink(ApplicationShortcutItem shortcut, String referer) {
        String redirect = "&path=" + Util.urlEncode(referer);
        String path = "http://localhost:" + shortcut.getClientPort() + "/launchApplication?name="
                        + shortcut.getExtensionDescriptor().getId() + "&id=" + shortcut.getResource().getResourceId() + redirect;
        if (shortcut.getClientPort() == -1) {
            path = "/launchVPNClient.do?returnTo=" + Util.urlEncode(path);
        }
        return path;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.sslexplorer.extensions.ApplicationLauncherType#getOnClick(com.sslexplorer.extensions.ApplicationShortcutItem)
     */
    public String getOnClick(ApplicationShortcutItem shortcut) {
        return null;
    }

    private void verifyClasspath(Element element) throws IOException {
        for (Iterator it = element.getChildren().iterator(); it.hasNext();) {            Element e = (Element) it.next();

            if (e.getName().equalsIgnoreCase("jar")) {
                descriptor.processFile(e);
            } else if (e.getName().equals("if")) {
                verifyClasspath(e);
            } else {
                throw new IOException("Invalid element <" + e.getName() + "> found in <classpath>");
            }
        }
    }

    private void verifyMain(Element element) throws JDOMException, IOException {
        for (Iterator it = element.getChildren().iterator(); it.hasNext();) {
            Element e = (Element) it.next();
            if (e.getName().equalsIgnoreCase("if")) {
                verifyMain(e);
            } else if (!e.getName().equalsIgnoreCase("arg") && !e.getName().equalsIgnoreCase("jvm")) {
                throw new JDOMException("Unexpected element <" + e.getName() + "> found in <main>");
            }
        }
    }
    
    public boolean isHidden() {
        return false;
    }
    
    public String getType() {
        return TYPE;
    }
}

⌨️ 快捷键说明

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