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

📄 jxplorer.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
package com.ca.directory.jxplorer;

import com.ca.commons.cbutil.*;
import com.ca.commons.jndi.JNDIOps;
import com.ca.commons.jndi.JndiSocketFactory;
import com.ca.commons.naming.*;
import com.ca.commons.security.cert.CertViewer;
import com.ca.directory.BuildNumber;
import com.ca.directory.jxplorer.broker.*;
import com.ca.directory.jxplorer.event.*;
import com.ca.directory.jxplorer.search.SearchBar;
import com.ca.directory.jxplorer.tree.*;
import com.ca.directory.jxplorer.viewer.AttributeDisplay;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.*;
import java.security.Provider;
import java.security.Security;
import java.util.*;
import java.util.logging.*;

/**
 * Does the main setup for JXplorer.
 */
public class
        JXplorer extends JFrame         			// Applet
        implements JXplorerEventGenerator
{
    static String version = BuildNumber.value;

    private static JFrame rootFrame;                 	// convenience variables to avoid
    Container mainPane;                      			// calling get methods all the time.

    transient JXplorerListener jxplorerListener;

    EventListenerList eventListeners = new EventListenerList();

    JScrollPane explorePanel;                   // contains mr tree
    JScrollPane resultsPanel;                   // contains search tree
    JScrollPane schemaPanel;                    // contains schema tree

    JTabbedPane treeTabPane;

    JPanel userViewPanel;

    CBPanel topPanel;                        	// the top panel, containing the tool bars.
    JToolBar searchBar;                      	// the quick search toolbar.
    ButtonBar buttonBar;                     	// the graphic button bar.

    public static Properties myProperties;   	// global variables for the browser, read from...
    public static String propertyFile;       	// ...a user configurable file storing default properties.
    public static String localDir;           	// local directory the browser is being run from...

    public static JFrame jx;

    JNDIBroker jndiBroker = null;      	// the JNDIBroker intermediary class through which requests pass
    JNDIBroker searchBroker = null;      	// another JNDIBroker used for searching, and the search tree.
    OfflineBroker offlineBroker = null;      	// provides a gateway to ldif files.
    SchemaBroker schemaBroker = null;      	// provides access to an artificaial 'schema tree'

    SmartTree mrTree = null;      	// the display tree
    SmartTree searchTree = null;      	// the search results tree
    SmartTree schemaTree = null;      	// the schema display tree

    AttributeDisplay mainViewer;				// the main display panel

    CBPanel statusDisplay;
    JLabel displayLabel;

    boolean workOffline = false;

    public static boolean debug = false;
    public static int debugLevel = 0;

    protected Stack statusStack = new Stack();

    protected MainMenu mainMenu;

    protected static ButtonRegister buttonRegister = null;      //TE: Object that is used by JXplorer to register all its buttons and menu items.

    protected CBHelpSystem helpSystem;

    protected StopMonitor stopMonitor;

    public Thread jndiThread, schemaThread, searchThread, offlineThread;

    public String url = "Disconnected";         //TE: an anchor for the LDAP/DSML url.

    CBResourceLoader resourceLoader;  			// loads files 'n stuff from zip/jar archives.
    CBClassLoader classLoader;        			// loads classes from zip/jar archives.

    /*
     *    Constants that define which security property elements to use.
     */

    public static final String CLIENT_TYPE_PROPERTY = "keystoreType.clientcerts";
    public static final String CA_TYPE_PROPERTY = "keystoreType.cacerts";
    public static final String CLIENT_PATH_PROPERTY = "option.ssl.clientcerts";
    public static final String CA_PATH_PROPERTY = "option.ssl.cacerts";
    public static final String ALLOW_CONNECTION_CERT_IMPORT = "option.ssl.import.cert.during.connection";

    private static Logger log = Logger.getLogger(JXplorer.class.getName());  // ...It's round it's heavy it's wood... It's better than bad, it's good...

    /**
     * Constructor for the JXplorer object, which is in fact the whole browser.
     */

    // PROG NOTE: Many of these methods are order dependant - don't change the
    //            order they are called without checking!

    boolean connected = false;  //TE: a vague flag that is set to true if the user hits the connect button, false if user hits disconnect button.  This is for changing the state of the buttons when flicking between tabs.

    public JXplorer()
    {
        super();

        JWindow splash = new JWindow();

        showSplashScreen(splash);

        rootFrame = this;
        mainPane = rootFrame.getContentPane();
        mrTree = null;

        loadProperties(myProperties);

        setupLogger();  // requires properties to be loaded first

        initUtilityFtns(this);

        setupResourceFiles();

        CBIntText.init("language.JX", classLoader);   // i18n support.


        if (checkFileEnvironment() == false) return;

        initJNDIBroker();

        initSearchBroker();

        initSchemaBroker();

        initOfflineBroker();

        initStopMonitor();

        buttonRegister = new ButtonRegister();

        setupGUI();

        setStatus(CBIntText.get("Not Connected"));

        setBackground(Color.white);

        setVisible(true);

        splash.dispose();
    }

    public static void printTime(String msg)
    {
        long time = System.currentTimeMillis();
        log.info(msg + "\nTIME: " + new Date().toString() + "  (" + (time % 1000) + ")\n");
    }

    /**
     * The main class, from whence all else proceeds.
     * (Obviously, this is not used if the browser is
     * run as an applet instead...)
     *
     * @param args Not currently used.
     */

    public static void main(String[] args)
    {
        printTime("main start");

        log.fine("running JXplorer version " + version);

        if (checkJavaEnvironment() == false)
            System.exit(-1);

        new JXplorer();

        printTime("main end");
    }

    /**
     * Failback routine for if we can't find proper log parameters... setup a console logger
     */

    protected static void setupBackupLogger()
    {
        Logger mainLogger = LogManager.getLogManager().getLogger("com.ca");

        // property default value is 'WARNING'
        mainLogger.setLevel(Level.parse(getProperty("java.util.logging.ConsoleHandler.level")));
        Handler handler = new ConsoleHandler();
        handler.setLevel(Level.ALL);
        mainLogger.addHandler(handler);
    }

    /**
     * Initialises the log manager using log configuration set in the properties file
     */
    protected static void setupLogger()
    {
        // REQUIRES loadProperties() to have been called.

        log.info("setting up logger");

        try
        {
            // Sun logging system weird.  Cascading log levels only work if you pre-create exact loggers. whatever.
            Logger.getLogger("com");
            Logger.getLogger("com.ca");
            Logger.getLogger("com.ca.directory");
            Logger.getLogger("com.ca.directory.jxplorer");

            // XXX Have to reinitialise 'log' here, because Sun logging system is too stupid to do the cascading trick
            // XXX unless the 'parent' loggers have been already created.
            log = Logger.getLogger(JXplorer.class.getName());

            LogManager logManager = LogManager.getLogManager();
            logManager.reset();

            /* DEBUG
            Enumeration names = logManager.getLoggerNames();
            while (names.hasMoreElements())
                System.out.println("LOGGER: " + names.nextElement());

            System.out.println("JX: " + JXplorer.class.getName());
            System.out.println("JX: " + JXplorer.class.getName());
            */

            logManager.readConfiguration(new FileInputStream(propertyFile));
            System.out.println("XXX logging initially level " + CBUtility.getTrueLogLevel(log) + " with " + log.getHandlers().length + " parents=" + log.getUseParentHandlers());

            log.info("Using configuration file: " + propertyFile);
            log.info("logging initialised to global level " + CBUtility.getTrueLogLevel(log));

            // DEBUG BLOCK
            /*
            log.severe("ENABLED");
            log.warning("ENABLED");
            log.info("ENABLED");
            log.fine("ENABLED");
            log.finer("ENABLED");
            log.finest("ENABLED");
             */
            if (false) throw new IOException();
        }
        catch (IOException e)
        {
            log.log(Level.SEVERE, "Unable to load log configuration from config file: " + propertyFile, e);
            System.err.println("Unable to load log configuration from config file: " + propertyFile);
            e.printStackTrace();
            setupBackupLogger();

        }

        int currentLogLevel = CBUtility.getTrueLogLevel(log).intValue();

        // XXX 'ALL' is a very, very large negatice number, because Sun are fucked in the head.

        if (currentLogLevel <= Level.FINE.intValue())
        {
            Vector sortedKeys = new Vector();
            Enumeration baseKeys = myProperties.keys();
            while (baseKeys.hasMoreElements())
            {
                String key = (String) baseKeys.nextElement();
                sortedKeys.addElement(key);
            }
            Collections.sort(sortedKeys);

            Enumeration propNames = sortedKeys.elements();

            StringBuffer propertyData = new StringBuffer();
            String propName;

            while (propNames.hasMoreElements())
            {
                propName = (String) propNames.nextElement();
                propertyData.append("property: ").append(propName).append(" = ").append(myProperties.getProperty(propName)).append("\n");
            }

            log.fine("property:\n" + propertyData.toString());
        }

        /*  Never did get this stuff working properly... log4j xml config file.
        try
        {
            final String DEFAULT_XML_LOG_FILE_TEXT =
                "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
                "    <!DOCTYPE log4j:configuration SYSTEM \"log4j.dtd\">\n" +
                "    <log4j:configuration xmlns:log4j=\"http://jakarta.apache.org/log4j/\"> \n" +
                "  \n" +
                "        <appender name=\"JX\" class=\"org.apache.log4j.FileAppender\"> \n" +
                "                <param name=\"File\"   value=\"JX.log\" /> \n" +
                "                <param name=\"Append\" value=\"false\" />\n" +
                "                <layout class=\"org.apache.log4j.PatternLayout\"> \n" +
                "                    <param name=\"ConversionPattern\" value=\"%t %-5p %c{2} - %m%n\"/> \n" +
                "                </layout>\n" +
                "        </appender>  \n" +
                "  \n" +
                "        <category name=\"org.apache.log4j.xml\"> \n" +
                "          <priority value=\"info\" /> \n" +
                "          <appender-ref ref=\"JX\" /> \n" +
                "        </category> \n" +
                " \n" +
                "        <root> \n" +
                "           <priority value =\"info\" /> \n" +
                "           <appender-ref ref=\"JX\" /> \n" +
                "        </root>\n" +
                " \n" +
                "    </log4j:configuration> \n";

            String logFileName = getProperty("log4j.config", "log4j.xml");
            File logFile = new File(logFileName);
            if (logFile.exists() == false)
            {
                FileWriter writer = new FileWriter(logFile);
                writer.write(DEFAULT_XML_LOG_FILE_TEXT);
                writer.close();
            }
            DOMConfigurator.configure(logFile.getPath());
        }
        catch (IOException e)
        {
            System.err.println("Unable to write/read log config file: " + e.toString());
        }
        catch (Exception e2)
        {
            System.err.println("Unexpected error setting up log file.");
            e2.printStackTrace();
        }
        */
    }

    /**
     * Set up some common utility ftns for logging and error reporting.
     */
    public void initUtilityFtns(JFrame rootFrame)
    {

        CBUtility.initDefaultDisplay(rootFrame);
    }

    /**
     *    A common start point.  This  method is where the JXplorer object
     *    is created and initialised, and should be called by the main
     *    method, the applet initialiser, or by external programs wishing
     *    to incorporate JXplorer.
     *
     */

⌨️ 快捷键说明

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