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

📄 extensionstoredescriptor.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 *  SSL-Explorer
 *
 *  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
			
package com.sslexplorer.extensions.store;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

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

import com.sslexplorer.boot.VersionInfo;
import com.sslexplorer.extensions.ExtensionBundle;

public class ExtensionStoreDescriptor {

  URL descriptor;

  final static Log log = LogFactory.getLog(ExtensionStoreDescriptor.class);

  String store;
  HashMap applicationBundles;
  List applicationBundlesList;
  Document doc;

  public static final String UNDEFINED_PARAMETER = "UNDEFINED";

  public ExtensionStoreDescriptor(URL descriptor) throws JDOMException, IOException {
    this.descriptor = descriptor;
    load();
  }

  public URL getDescriptorLocation() {
    return descriptor;
  }

  public List getExtensionBundles() {
    return applicationBundlesList;
  }

  public String getStore() {
    return store;
  }

  public void load() throws JDOMException, IOException {
	if (log.isInfoEnabled())
	  log.info("Loading application descriptor " + descriptor.toExternalForm());

    SAXBuilder sax = new SAXBuilder();
    doc = sax.build(descriptor);

    if (!doc.getRootElement().getName().equalsIgnoreCase("applications")) {
      throw new JDOMException("Application root element must be <applications>");
    }

    store = doc.getRootElement().getAttribute("store").getValue();
    if (store == null) {
      throw new JDOMException("<applications> element requires attribute 'store'");
    }

    applicationBundles = new HashMap();
    applicationBundlesList = new ArrayList();
    for (Iterator it = doc.getRootElement().getChildren().iterator(); it.hasNext();) {
      Element e = (Element) it.next();
      if (e.getName().equalsIgnoreCase("install") || e.getName().equalsIgnoreCase("configure")) {
        String id = e.getAttributeValue("id");
        if(id == null || id.equals("")) {
          throw new JDOMException("<" + e.getName() +"> requires an 'id' attribute." );
        }
        String name = e.getAttributeValue("name");
        if(id == null || id.equals("")) {
          throw new JDOMException("<" + e.getName() +"> requires a 'name' attribute." );
        }
        String license = e.getAttributeValue("license");
        String productURL = e.getAttributeValue("productURL");
        String instructionsURL = e.getAttributeValue("instructionsURL");
        String description = e.getText();
        String depends = e.getAttributeValue("depends");
        String category = e.getAttributeValue("category");
        
        if(e.getName().equalsIgnoreCase("configure") && (instructionsURL == null || instructionsURL.equals(""))) {
          throw new JDOMException("The instructionsURL is mandatory to applications of type <configure>.");
        }
        String ver = e.getAttributeValue("version");
        if(ver == null || ver.equals("")) {
          throw new JDOMException("<" + e.getName() +"> requires a 'version' attribute." );
        }
        String requiredHostVersionText = e.getAttributeValue("requiredHostVersion");
        VersionInfo.Version requiredHostVersion = null;
        if(requiredHostVersionText != null && !requiredHostVersionText.equals("")) {
            requiredHostVersion = new VersionInfo.Version(requiredHostVersionText);
        }
        VersionInfo.Version version = new VersionInfo.Version(ver);        
        ExtensionBundle bundle = new ExtensionBundle(version, e.getName().equalsIgnoreCase("install") ? ExtensionBundle.TYPE_INSTALLABLE : ExtensionBundle.TYPE_CONFIGUREABLE,
            id, name, description, license, productURL, instructionsURL, requiredHostVersion, depends, category);
        
        if(applicationBundles.put(id, bundle) != null) {
          throw new JDOMException("Duplicate application bundle id.");
        }
        applicationBundlesList.add(bundle);
      } else {
        throw new JDOMException("Unknown element '" + e.getName() + "'.");
      }
    }
    
    Collections.sort(applicationBundlesList);

  }

  public Document getDescriptor() throws IOException {
    return (Document) doc.clone();
  }

  public ExtensionBundle getApplicationBundle(String id) {
    return (ExtensionBundle)applicationBundles.get(id);
  }
}

⌨️ 快捷键说明

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