📄 jxplorer.java
字号:
searchTree.setRoot(SmartTree.NODATA);
if (schemaTree == null) return;
schemaTree.clearTree();
schemaTree.setRoot(SmartTree.NODATA);
// TODO: maybe restart jndibroker thread somehow?
}
/**
* Perform necessary setup after a connection has been established.
* This will link up the trees with their respective data
* brokers.<p>
* <p/>
* This does quite a bit of work, including trying to find the default
* base naming context(s), and registering schema.
*/
public boolean postConnectionSetup(JNDIBroker.DataConnectionQuery request)
{
searchTree.clearTree();
if (workOffline == true)
{
workOffline = false;
offlineBroker.clear();
//mrTree.registerDataSource(jxplorer.jndiBroker, new DN(SmartTree.NODATA));
}
String baseDN = request.conData.baseDN;
DN base = new DN(baseDN);
DN[] namingContexts = null;
int ldapV = request.conData.version;
try
{
if (base == null || base.size() == 0 || jndiBroker.getDirOp().exists(base) == false)
{
if (ldapV == 2)
{
if (jndiBroker.getDirOp().exists(base) == false) // bail out if we can't find the base DN for ldap v2
{
CBUtility.error("Error opening ldap v2 connection - bad base DN '" + ((base == null) ? "*null*" : base.toString()) + "' ");
disconnect();
return false;
}
}
else // for ldap v3, try to find a valid base.
{
if (base != null && base.size() > 0)
log.warning("The Base DN '" + base + "' cannot be found.");
base = null; // set base to a known state.
namingContexts = jndiBroker.readFallbackRoot(); // may return null, but that's o.k.
if (baseDN.trim().length() > 0)
{
// Change from user error message to log message CBErrorWin errWin = new CBErrorWin(this, CBIntText.get("The DN you are trying to access cannot be found or does not exist. The fall back DN is ") + namingContexts[0].toString(), "DN Not Found"); //TE: user info.
if (namingContexts != null && namingContexts[0] != null)
log.warning("Cannot find the user-specified Base DN - Using the fall back DN '" + namingContexts[0].toString() + "'");
else
log.warning("WARNING: Cannot find the user-specified Base DN, and cannot read alternative from directory. Leaving unset for the present.");
}
if (namingContexts != null && namingContexts.length == 1) // if we only have one context...
base = namingContexts[0]; // ... make it our base
}
}
mrTree.clearTree();
mrTree.registerDataSource(jndiBroker);
}
catch (Exception ex) // wierd things can go wrong here; especially if ldap v2
{
if (ldapV != 2)
{
CBUtility.error("Possible errors occurred while opening connection.", ex); // if not ldap v2, try to carry on anyway
}
else // if ldap v2, just bail out.
{
CBUtility.error("Error opening ldap v2 connection (possibly bad base DN?) ", ex);
disconnect();
return false;
}
}
//
// Set up the initial state of the tree, either with the base DN given, or with
// a set of Naming Contexts read from 'jndiBroker.readFallbackRoot()', or by
// trying to expand a blank DN (i.e. by doing a list on "").
//
if (base != null) // We've got a single base DN - use it to set the tree root...
{
mrTree.setRoot(base);
if (base.size() == 0)
{
mrTree.expandRoot();
mrTree.getRootNode().setAlwaysRefresh(true);
}
else
{
mrTree.expandDN(base);
makeDNAutoRefreshing(base);
}
}
else if (namingContexts != null) // We've got multiple naming contexts - add them all.
{
mrTree.setRoot("");
for (int i = 0; i < namingContexts.length; i++) // for each context
{
DN namingContext = namingContexts[i]; // get the 'base' DN
SmartNode node = mrTree.addNode(namingContext); // add that to the tree as a node
// *Amazing* but harmless Hack for Mr John Q. Birrell
if (node.getChildCount() == 0) // if nothing is there already (might be if server mis-configured)
node.add(new SmartNode()); // make that node expandable
}
for (int i = 0; i < namingContexts.length; i++) // for each context
{
mrTree.expandDN(namingContexts[i]); // and make the node visible.
makeDNAutoRefreshing(namingContexts[i]);
}
}
else // no information; try to expand an empty dn and see what we get!
{
mrTree.expandRoot();
mrTree.getRootNode().setAlwaysRefresh(true);
}
searchTree.clearTree();
searchBroker.registerDirectoryConnection(jndiBroker);
searchTree.registerDataSource(searchBroker);
searchTree.setRoot(new DN(SmartTree.NODATA));
schemaTree.clearTree();
if (Integer.toString(ldapV) != null && ldapV > 2)
{
schemaBroker.registerDirectoryConnection(jndiBroker);
schemaTree.registerDataSource(schemaBroker);
schemaTree.setRoot(new DN("cn=schema"));
DXAttribute.setDefaultSchema(jndiBroker.getSchemaOps());
DXAttributes.setDefaultSchema(jndiBroker.getSchemaOps());
}
else
{
DXAttribute.setDefaultSchema(null);
DXAttributes.setDefaultSchema(null);
}
if (base != null)
{
jndiBroker.getEntry(base); // read first entry.
JXplorer.setDefaultProperty("baseDN", base.toString());
url = request.conData.url;
setStatus(CBIntText.get("Connected To ''{0}''", new String[]{url}));
}
getButtonRegister().setConnectedState();
mainMenu.setConnected(true);
setConnected(true);
return true;
}
protected void makeDNAutoRefreshing(DN dn)
{
try
{
TreePath path = ((SmartModel) mrTree.getModel()).getPathForDN(dn);
if (path == null) throw new Exception("null path returned");
Object[] nodes = path.getPath();
for (int j = 0; j < nodes.length - 1; j++)
{
((SmartNode) nodes[j]).setAlwaysRefresh(true); // XXX hack for x500/ldap server compatibility - force refreshing if certain magic nodes are expanded.
}
}
catch (Exception e)
{
log.info("INFO: messed up setting auto-expanding nodes for context '" + dn + "'");
}
}
/**
* Disables/enables the menu and button bar items to reflect a disconnected state.
* Clears the Explore, Results and Schema trees and also sets the status message
* to disconnected.
*/
public void disconnect()
{
jndiBroker.disconnect();
mrTree.clearTree();
schemaTree.clearTree();
searchTree.clearTree();
searchTree.setNumOfResults(0);
getButtonRegister().setDisconnectState();
mainMenu.setDisconnected();
setConnected(false);
setStatus(CBIntText.get("Disconnected"));
}
/**
* Disables/enables the menu and button bar items to reflect a disconnected state.
* Also sets the status message to disconnected.
*/
public void setDisconnectView()
{
mainMenu.setDisconnected();
getButtonRegister().setDisconnectState();
setStatus(CBIntText.get("Disconnected"));
}
//
// Make JXplorer into an event generating object, that can
// register ActionListeners and trigger actionEvents.
//
/**
* Add the specified JXplorer listener to receive JXplorer events from
* JXplorer. Currently,the only JXplorer event occurs when a user selects a DN.
* If l is null, no exception is thrown and no JXplorer is performed.
*
* @param l the JXplorer listener
* @see #removeJXplorerListener
*/
public synchronized void addJXplorerListener(JXplorerListener l)
{
if (l != null)
eventListeners.add(JXplorerListener.class, l);
}
/**
* Remove the specified JXplorer listener so that it no longer
* receives JXplorer events from this button. JXplorer events occur
* when a user presses or releases the mouse over this button.
* If l is null, no exception is thrown and no JXplorer is performed.
*
* @param l the JXplorer listener
* @see #addJXplorerListener
*/
public synchronized void removeJXplorerListener(JXplorerListener l)
{
if (l != null)
eventListeners.remove(JXplorerListener.class, l);
}
/**
* Creates JXplorer events
* by dispatching them to any registered
* <code>JXplorerListener</code> objects.
* (Implements the JXplorerEventGenerator interface)
* <p/>
*
* @param e the JXplorer event.
* @see com.ca.directory.jxplorer.event.JXplorerEventGenerator
* @see com.ca.directory.jxplorer.event.JXplorerListener
* @see com.ca.directory.jxplorer.JXplorer#addJXplorerListener
*/
public void fireJXplorerEvent(JXplorerEvent e)
{
Object[] list = eventListeners.getListenerList();
for (int index = list.length - 2; index >= 0; index -= 2)
{
if (list[index] == JXplorerListener.class)
{
((JXplorerListener) list[index + 1]).JXplorerDNSelected(e);
}
}
}
/**
* Displays a splash screen with a thin black border in the center of the screen.
* Splash screen auto-sizes to be very slightly larger than the templates/JXsplash.gif image.
*/
public void showSplashScreen(JWindow splash)
{
ImageIcon splashIcon = new ImageIcon("templates" + File.separator + "JXsplash.gif");
int width = splashIcon.getIconWidth();
int height = splashIcon.getIconHeight();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
splash.setBounds((screen.width - width) / 2, (screen.height - height) / 2, width, height);
JLabel pic = new JLabel(splashIcon);
JPanel content = (JPanel) splash.getContentPane();
content.add(pic);
splash.setVisible(true);
}
/**
* A variety of plugin possibilities exist in JXplorer. To make distribution easier, it
* is possible to package up class files, as well as image/text/etc. files, and use a
* custom resource loader to access these zipped/jarred resources. This sets it all up,
* as well as adding any custom security providers...
*/
public void setupResourceFiles()
{
resourceLoader = new CBResourceLoader();
classLoader = new CBClassLoader(resourceLoader);
String pluginPath = JXplorer.getProperty("dir.plugins");
String[] pluginFiles = CBUtility.readFilteredDirectory(pluginPath, new String[]{"zip", "jar"});
if (pluginFiles == null)
{
log.warning("Unable to access plugins directory: '" + pluginPath + "'");
return;
}
for (int i = 0; i < pluginFiles.length; i++)
resourceLoader.addResource(new CBJarResource(pluginPath + pluginFiles[i]));
setupSecurityProviders();
setupGSSAPIConfig();
}
/**
* This sets up the inital GSSAPI config file if it does not already exist, and sets the
* login config system property.
*/
protected void setupGSSAPIConfig()
{
try
{
String sep = System.getProperty("line.separator");
// the default gssapi.conf file (provided by Vadim Tarassov).
String defaultFileText = "com.ca.commons.jndi.JNDIOps {" + sep +
" com.sun.security.auth.module.Krb5LoginModule required client=TRUE" + sep +
" \t\t\t\t\t\t\t\t\t\t\t\t\t\tuseTicketCache=TRUE;" + sep +
"};";
String configFile = CBUtility.getPropertyConfigPath("gssapi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -