jndioption.java
来自「Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI」· Java 代码 · 共 157 行
JAVA
157 行
/*--------------------------------------------------------------------------*
| Copyright (C) 2006 Christopher Kohlhaas |
| |
| 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. A copy of the license has been included with |
| these distribution in the COPYING file, if not go to www.fsf.org |
| |
| As a special exception, you are granted the permissions to link this |
| program with every library, which license fulfills the Open Source |
| Definition as published by the Open Source Initiative (OSI). |
*--------------------------------------------------------------------------*/
package org.rapla.plugin.jndi;
import java.awt.BorderLayout;
import java.util.Locale;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.rapla.components.layout.TableLayout;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;
import org.rapla.gui.DefaultPluginOption;
import org.rapla.gui.OptionPanel;
public class JNDIOption extends DefaultPluginOption implements OptionPanel {
TableLayout tableLayout;
JPanel content;
JTextField digest;
JTextField connectionName;
JTextField connectionPassword;
JTextField connectionURL;
JTextField contextFactory;
JTextField userPassword;
JTextField userMail;
JTextField userCn;
JTextField userSearch;
JTextField userBase;
public JNDIOption(RaplaContext sm) throws RaplaException {
super(sm);
}
protected JPanel createPanel() throws RaplaException {
digest = new JTextField();
connectionName = new JTextField();
connectionPassword = new JTextField();
connectionURL = new JTextField();
contextFactory= new JTextField();
userPassword = new JTextField();
userMail = new JTextField();
userCn = new JTextField();
userSearch = new JTextField();
userBase = new JTextField();
JPanel panel = super.createPanel();
content = new JPanel();
tableLayout = new TableLayout();
tableLayout.insertColumn( 0, TableLayout.PREFERRED);
tableLayout.insertColumn( 1, 5);
tableLayout.insertColumn( 2, TableLayout.FILL);
tableLayout.insertColumn( 3, 5);
content.setLayout(tableLayout);
tableLayout.insertRow( 0, TableLayout.PREFERRED);
content.add( new JLabel("WARNING! Only enable plugin, if you have a LDAP Server running!"), "0,0,2,0");
addRow("connectionName", connectionName);
addRow("connectionPassword", connectionPassword );
addRow("connectionURL", connectionURL );
addRow("contextFactory", contextFactory);
addRow( "digest", digest);
addRow("userPassword", userPassword );
addRow("userMail", userMail );
addRow("userCn", userCn );
addRow("userSearch", userSearch );
addRow("userBase", userBase );
panel.add( content, BorderLayout.CENTER);
return panel;
}
private void addRow(String title, JComponent component) {
int row = tableLayout.getNumRow();
tableLayout.insertRow( row, TableLayout.PREFERRED);
content.add(new JLabel(title), "0," + row);
content.add( component, "2," + row);
tableLayout.insertRow( row + 1, 5);
}
protected void addChildren( DefaultConfiguration newConfig) {
setAttribute(newConfig,"digest", digest);
setAttribute(newConfig,"connectionName", connectionName);
setAttribute(newConfig,"connectionPassword", connectionPassword );
setAttribute(newConfig,"connectionURL", connectionURL );
setAttribute(newConfig,"contextFactory", contextFactory);
setAttribute(newConfig,"userPassword", userPassword );
setAttribute(newConfig,"userMail", userMail );
setAttribute(newConfig,"userCn", userCn );
setAttribute(newConfig,"userSearch", userSearch );
setAttribute(newConfig,"userBase", userBase );
}
public void setAttribute( DefaultConfiguration newConfig, String attributeName, JTextField text) {
String value = text.getText().trim();
if ( value.length() > 0)
newConfig.setAttribute( attributeName, value);
}
public void readAttribute( String attributeName, JTextField text) {
readAttribute( attributeName, text, "");
}
public void readAttribute( String attributeName, JTextField text, String defaultValue) {
text.setText(config.getAttribute(attributeName, defaultValue));
}
protected void readConfig( Configuration config) {
super.readConfig( config );
readAttribute("digest", digest);
readAttribute("connectionName", connectionName, "cn=Manager,dc=mycompany,dc=com" );
readAttribute("connectionPassword", connectionPassword, "secret" );
readAttribute("connectionURL", connectionURL, "ldap://localhost:389");
readAttribute("contextFactory", contextFactory, "com.sun.jndi.ldap.LdapCtxFactory");
readAttribute("userPassword", userPassword,"userPassword" );
readAttribute("userMail", userMail,"mail" );
readAttribute("userCn", userCn,"cn" );
readAttribute("userSearch", userSearch,"(uid={0})" );
readAttribute("userBase", userBase,"ou=people,dc=mycompany,dc=com" );
}
public void show() throws RaplaException {
super.show();
}
public void commit() throws RaplaException {
super.commit();
}
/**
* @see org.rapla.gui.DefaultPluginOption#getDescriptorClassName()
*/
public String getDescriptorClassName() {
return JNDIPlugin.class.getName();
}
public String getName(Locale locale) {
return JNDIPlugin.PLUGIN_NAME;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?