Utilities.java revision 688633f95faa52515b090ff00440b1eebdaad7d9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* A static class that provides miscellaneous functions.
*/
public class Utilities
{
private static File rootDirectory;
private static File instanceRootDirectory;
private static final String[] binarySyntaxOIDs = {
};
private static ImageIcon warningIcon;
private static ImageIcon requiredIcon;
private static LocalizableMessage NO_VALUE_SET =
private static LocalizableMessage NOT_IMPLEMENTED =
/**
* Creates a combo box.
* @return a combo box.
*/
public static JComboBox createComboBox()
{
if (isMacOS())
{
}
return combo;
}
/**
* Creates a frame.
* @return a frame.
*/
public static JFrame createFrame()
{
frame.setResizable(true);
return frame;
}
/**
* Returns <CODE>true</CODE> if an attribute value must be obfuscated because
* it contains sensitive information (like passwords) and <CODE>false</CODE>
* otherwise.
* @param attrName the attribute name.
* @param schema the schema of the server.
* @return <CODE>true</CODE> if an attribute value must be obfuscated because
* it contains sensitive information (like passwords) and <CODE>false</CODE>
* otherwise.
*/
{
{
}
{
{
return true;
}
}
return false;
}
/**
* Derives a color by adding the specified offsets to the base color's
* hue, saturation, and brightness values. The resulting hue, saturation,
* and brightness values will be contrained to be between 0 and 1.
* @param base the color to which the HSV offsets will be added
* @param dH the offset for hue
* @param dS the offset for saturation
* @param dB the offset for brightness
* @return Color with modified HSV values
*/
{
return Color.getHSBColor(
}
/**
* Displays an error dialog that contains a set of error messages.
* @param parentComponent the parent component relative to which the dialog
* will be displayed.
* @param errors the set of error messages that the dialog must display.
*/
{
/*
ErrorPanel panel = new ErrorPanel("Error", errors);
GenericDialog dlg = new GenericDialog(null, panel);
dlg.setModal(true);
Utilities.centerGoldenMean(dlg, Utilities.getParentDialog(this));
dlg.setVisible(true);
*/
{
}
}
/**
* Displays a confirmation dialog. Returns <CODE>true</CODE> if the user
* accepts the message and <CODE>false</CODE> otherwise.
* @param parentComponent the parent component relative to which the dialog
* will be displayed.
* @param title the title of the dialog.
* @param msg the message to be displayed.
* @return <CODE>true</CODE> if the user accepts the message and
* <CODE>false</CODE> otherwise.
*
*/
{
null, // don't use a custom Icon
null, // the titles of buttons
null); // default button title
}
/**
* Displays a warning dialog.
* @param parentComponent the parent component relative to which the dialog
* will be displayed.
* @param title the title of the dialog.
* @param msg the message to be displayed.
*/
{
}
/**
* Creates a JEditorPane that displays a message.
* @param text the message of the editor pane in HTML format.
* @param font the font to be used in the message.
* @return a JEditorPane that displays a message.
*/
{
{
}
pane.setEditable(false);
pane.setFocusCycleRoot(false);
return pane;
}
/**
* Creates a JEditorPane that displays a message.
* @param text the message of the editor pane in plain text format.
* @param font the font to be used in the message.
* @return a JEditorPane that displays a message.
*/
{
{
}
pane.setEditable(false);
pane.setFocusCycleRoot(false);
return pane;
}
/**
* Returns the HTML style representation for the given font.
* @param font the font for which we want to get an HTML style representation.
* @return the HTML style representation for the given font.
*/
{
{
}
{
}
}
/**
* Creates a titled border.
* @param msg the message to be displayed in the titled border.
* @return the created titled border.
*/
{
return border;
}
/**
* Returns a JScrollPane that contains the provided component. The scroll
* pane will not contain any border.
* @param comp the component contained in the scroll pane.
* @return a JScrollPane that contains the provided component. The scroll
* pane will not contain any border.
*/
{
return scroll;
}
/**
* Returns a JScrollPane that contains the provided component.
* @param comp the component contained in the scroll pane.
* @return a JScrollPane that contains the provided component.
*/
{
return scroll;
}
/**
* Creates a button.
* @param text the message to be displayed by the button.
* @return the created button.
*/
{
return button;
}
/**
* Creates a radio button.
* @param text the message to be displayed by the radio button.
* @return the created radio button.
*/
{
return button;
}
/**
* Creates a check box.
* @param text the message to be displayed by the check box.
* @return the created check box.
*/
{
return cb;
}
/**
* Creates a menu item with the provided text.
* @param msg the text.
* @return a menu item with the provided text.
*/
{
}
/**
* Creates a menu with the provided text.
* @param msg the text.
* @param description the accessible description.
* @return a menu with the provided text.
*/
{
description.toString());
return menu;
}
/**
* Creates a label of type 'primary' (with bigger font than usual) with no
* text.
* @return the label of type 'primary' (with bigger font than usual) with no
* text.
*/
public static JLabel createPrimaryLabel()
{
}
/**
* Creates a label of type 'primary' (with bigger font than usual).
* @param text the message to be displayed by the label.
* @return the label of type 'primary' (with bigger font than usual).
*/
{
return label;
}
/**
* Creates a label of type 'inline help' (with smaller font).
* @param text the message to be displayed by the label.
* @return the label of type 'inline help' (with smaller font).
*/
{
return label;
}
/**
* Creates a label of type 'title' (with bigger font).
* @param text the message to be displayed by the label.
* @return the label of type 'title' (with bigger font).
*/
{
return label;
}
/**
* Creates a label (with default font) with no text.
* @return the label (with default font) with no text.
*/
public static JLabel createDefaultLabel()
{
}
/**
* Creates a label (with default font).
* @param text the message to be displayed by the label.
* @return the label (with default font).
*/
{
return label;
}
/**
* Returns a table created with the provided model and renderers.
* @param tableModel the table model.
* @param renderer the cell renderer.
* @return a table created with the provided model and renderers.
*/
{
table.setShowGrid(true);
if (isMacOS())
{
}
if (isWindows())
{
}
{
}
public void mouseClicked(MouseEvent e) {
}
}
};
return table;
}
/**
* Creates a text area with borders similar to the ones of a text field.
* @param text the text of the text area.
* @param rows the rows of the text area.
* @param cols the columns of the text area.
* @return a text area with borders similar to the ones of a text field.
*/
int cols)
{
{
}
return ta;
}
/**
* Creates a non-editable text area.
* @param text the text of the text area.
* @param rows the rows of the text area.
* @param cols the columns of the text area.
* @return a non-editable text area.
*/
int cols)
{
ta.setEditable(false);
return ta;
}
/**
* Creates a text area.
* @param text the text of the text area.
* @param rows the rows of the text area.
* @param cols the columns of the text area.
* @return a text area.
*/
int cols)
{
return ta;
}
/**
* Creates a text field.
* @param text the text of the text field.
* @param cols the columns of the text field.
* @return the created text field.
*/
{
return tf;
}
/**
* Creates a short text field.
* @return the created text field.
*/
public static JTextField createShortTextField()
{
return tf;
}
/**
* Creates a medium sized text field.
* @return the created text field.
*/
public static JTextField createMediumTextField()
{
return tf;
}
/**
* Creates a long text field.
* @return the created text field.
*/
public static JTextField createLongTextField()
{
return tf;
}
/**
* Creates a text field with the default size.
* @return the created text field.
*/
public static JTextField createTextField()
{
return tf;
}
/**
* Creates a pasword text field.
* @return the created password text field.
*/
public static JPasswordField createPasswordField()
{
return pf;
}
/**
* Creates a pasword text field.
* @param cols the columns of the password text field.
* @return the created password text field.
*/
{
return pf;
}
/**
* Sets the border in a given component. If the component already has a
* border, creates a compound border.
* @param comp the component.
* @param border the border to be set.
*/
{
{
}
else
{
}
}
/**
* Checks the size of the table and of the scroll bar where it is contained,
* and depending on it updates the auto resize mode.
* @param scroll the scroll pane containing the table.
* @param table the table.
*/
{
{
}
else
{
}
}
/**
* Updates the size of the table rows according to the size of the
* rendered component.
* @param table the table to handle.
*/
{
}
/**
* Updates the size of the table rows according to the size of the
* rendered component.
* @param table the table to handle.
* @param rows the maximum rows to be displayed (-1 for unlimited)
*/
{
int headerMaxHeight = 5;
int headerMaxWidth = 0;
{
{
{
}
{
// There are some issues on Mac OS and sometimes the preferred size
// is too big.
colHeight = 0;
}
}
}
{
int colMaxWidth = 8;
{
}
{
}
{
colMaxWidth = 8;
}
{
}
}
{
}
{
{
{
colHeight = 0;
}
}
}
{
}
if (rows == -1)
{
}
else
{
}
}
/**
* Returns a String that contains the html passed as parameter with a span
* applied. The span style corresponds to the Font specified as parameter.
* The goal of this method is to be able to specify a font for an HTML string.
*
* @param html the original html text.
* @param font the font to be used to generate the new HTML.
* @return a string that represents the original HTML with the font specified
* as parameter.
*/
{
}
/**
* Returns an ImageIcon or <CODE>null</CODE> if the path was invalid.
* @param path the path of the image.
* @param loader the class loader to use to load the image. If
* <CODE>null</CODE> this class class loader will be used.
* @return an ImageIcon or <CODE>null</CODE> if the path was invalid.
*/
{
}
}
/**
* Returns an ImageIcon or <CODE>null</CODE> if the path was invalid.
* @param path the path of the image.
* @return an ImageIcon or <CODE>null</CODE> if the path was invalid.
*/
}
/**
* Creates an image icon using an array of bytes that contain the image and
* specifying the maximum height of the image.
* @param bytes the byte array.
* @param maxHeight the maximum height of the image.
* @param description the description of the image.
* @param useFast whether a fast algorithm must be used to transform the image
* or an algorithm with a better result.
* @return an image icon using an array of bytes that contain the image and
* specifying the maximum height of the image.
*/
{
{
return icon;
}
return new ImageIcon(scaledImage);
}
/**
* Updates the preferred size of an editor pane.
* @param pane the panel to be updated.
* @param nCols the number of columns that the panel must have.
* @param plainText the text to be displayed (plain text).
* @param font the font to be used.
* to the text or not.
*/
{
if (applyBackground)
{
}
{
}
}
/**
* Strips any potential HTML markup from a given string.
* @param s string to strip
* @return resulting string
*/
if (s != null) {
// This is not a comprehensive solution but addresses
// the few tags that we have in Resources.properties
// at the moment. Note that the following might strip
// out more than is intended for non-tags like
// '<your name here>' or for funky tags like
// '<tag attr="1 > 0">'. See test class for cases that
// might cause problems.
}
return o;
}
/**
* Wraps the contents of the provided message using the specified number of
* columns.
* @param msg the message to be wrapped.
* @param nCols the number of columns.
* @return the wrapped message.
*/
{
int lastOpenTag = -1;
boolean inTag = false;
int lastSpace = -1;
int lastLineLengthInLastSpace = 0;
int lastLineLength = 0;
for (int i=0; i<s.length() ; i++)
{
boolean isNormalChar = false;
char c = s.charAt(i);
if (c == '<')
{
inTag = true;
lastOpenTag = i;
}
else if (c == '>')
{
if (lastOpenTag != -1)
{
inTag = false;
lastOpenTag = -1;
if (isLineBreakTag(tag))
{
lastLineLength = 0;
lastSpace = -1;
}
}
else
{
isNormalChar = true;
}
}
else if (inTag)
{
}
{
{
+ HTML_SPACE.length())))
{
if (lastLineLength < nCols)
{
// Only count as 1 space
lastLineLength ++;
}
else
{
// Insert a line break
lastLineLength = 0;
lastSpace = -1;
}
}
else
{
isNormalChar = true;
}
}
else
{
isNormalChar = true;
}
}
else if (c == ' ')
{
if (lastLineLength < nCols)
{
// Only count as 1 space
lastLineLength ++;
}
else
{
// Insert a line break
lastLineLength = 0;
lastSpace = -1;
}
}
else
{
isNormalChar = true;
}
if (isNormalChar)
{
if (lastLineLength < nCols)
{
lastLineLength ++;
}
else
{
// Check where to insert a line break
if (lastSpace != -1)
{
lastSpace = -1;
}
else
{
// Force the line break.
lastLineLength = 1;
}
}
}
}
{
}
}
{
}
/**
* Center the component location based on its preferred size. The code
* considers the particular case of 2 screens and puts the component on the
* center of the left screen
*
* @param comp the component to be centered.
*/
{
if (multipleScreen)
{
} else
{
}
}
/**
* Center the component location of the ref component.
*
* @param comp the component to be centered.
* @param ref the component to be used as reference.
*
*/
{
// Apply the golden mean
{
// Check that the new window will be fully visible
{
}
}
}
/**
* Returns the parent frame of a component. <CODE>null</CODE> if this
* component is not contained in any frame.
* @param comp the component.
* @return the parent frame of a component. <CODE>null</CODE> if this
* component is not contained in any frame.
*/
{
{
}
}
/**
* Returns the parent dialog of a component. <CODE>null</CODE> if this
* component is not contained in any dialog.
* @param comp the component.
* @return the parent dialog of a component. <CODE>null</CODE> if this
* component is not contained in any dialog.
*/
{
{
{
}
}
return null;
}
/**
* Unescapes UTF-8 text and generates a String from it.
* @param v the string in UTF-8 format.
* @return the string with unescaped characters.
*/
{
try
{
int pos = 0;
{
if (stringBytes[i] == '\\'
{
// Convert hex-encoded UTF-8 to 16-bit chars.
byte b;
byte escapedByte1 = stringBytes[++i];
switch (escapedByte1)
{
case '0':
b = (byte) 0x00;
break;
case '1':
b = (byte) 0x10;
break;
case '2':
b = (byte) 0x20;
break;
case '3':
b = (byte) 0x30;
break;
case '4':
b = (byte) 0x40;
break;
case '5':
b = (byte) 0x50;
break;
case '6':
b = (byte) 0x60;
break;
case '7':
b = (byte) 0x70;
break;
case '8':
b = (byte) 0x80;
break;
case '9':
b = (byte) 0x90;
break;
case 'a':
case 'A':
b = (byte) 0xA0;
break;
case 'b':
case 'B':
b = (byte) 0xB0;
break;
case 'c':
case 'C':
b = (byte) 0xC0;
break;
case 'd':
case 'D':
b = (byte) 0xD0;
break;
case 'e':
case 'E':
b = (byte) 0xE0;
break;
case 'f':
case 'F':
b = (byte) 0xF0;
break;
default:
}
byte escapedByte2 = stringBytes[++i];
switch (escapedByte2)
{
case '0':
break;
case '1':
b |= 0x01;
break;
case '2':
b |= 0x02;
break;
case '3':
b |= 0x03;
break;
case '4':
b |= 0x04;
break;
case '5':
b |= 0x05;
break;
case '6':
b |= 0x06;
break;
case '7':
b |= 0x07;
break;
case '8':
b |= 0x08;
break;
case '9':
b |= 0x09;
break;
case 'a':
case 'A':
b |= 0x0A;
break;
case 'b':
case 'B':
b |= 0x0B;
break;
case 'c':
case 'C':
b |= 0x0C;
break;
case 'd':
case 'D':
b |= 0x0D;
break;
case 'e':
case 'E':
b |= 0x0E;
break;
case 'f':
case 'F':
b |= 0x0F;
break;
default:
}
decodedBytes[pos++] = b;
}
else {
}
}
}
catch (UnsupportedEncodingException uee)
{
// This is a bug, UTF-8 should be supported always by the JVM
}
}
/**
* Returns <CODE>true</CODE> if the the provided strings represent the same
* DN and <CODE>false</CODE> otherwise.
* @param dn1 the first dn to compare.
* @param dn2 the second dn to compare.
* @return <CODE>true</CODE> if the the provided strings represent the same
* DN and <CODE>false</CODE> otherwise.
*/
{
try
{
{
return false;
}
}
/**
* Gets the RDN string for a given attribute name and value.
* @param attrName the attribute name.
* @param attrValue the attribute value.
* @return the RDN string for the attribute name and value.
*/
{
}
/**
* Returns the attribute name with no options (or subtypes).
* @param attrName the complete attribute name.
* @return the attribute name with no options (or subtypes).
*/
{
if (index != -1)
{
}
return attrName;
}
/**
* Strings any potential "separator" from a given string.
* @param s string to strip
* @param separator the separator string to remove
* @return resulting string
*/
{
if (s != null)
{
}
return o;
}
/** The pattern for control characters. */
/**
* Checks if a string contains control characters.
* @param s : the string to check
* @return true if s contains control characters, false otherwise
*/
{
return m.find();
}
/**
* This is a helper method that gets a String representation of the elements
* in the Collection. The String will display the different elements separated
* by the separator String.
*
* @param col
* the collection containing the String.
* @param separator
* the separator String to be used.
* @return the String representation for the collection.
*/
{
{
{
}
}
}
/**
* Commodity method to get the Name object representing a dn.
* It is preferable to use Name objects when doing JNDI operations to avoid
* problems with the '/' character.
* @param dn the DN as a String.
* @return a Name object representing the DN.
* @throws InvalidNameException if the provided DN value is not valid.
*
*/
{
}
return name;
}
/**
* Returns a String representing an LDIF file from a set of lines.
* @param lines the lines of the LDIF file.
* @return a String representing an LDIF file from a set of lines.
*/
{
}
// Append an extra line so we can append LDIF Strings.
}
/**
* Returns the HTML representation of the 'Done' string.
* @param progressFont the font to be used.
* @return the HTML representation of the 'Done' string.
*/
{
}
/**
* Returns the HTML representation of a message to which some points have
* been appended.
* @param plainText the plain text.
* @param progressFont the font to be used.
* @return the HTML representation of a message to which some points have
* been appended.
*/
{
applyFont(" ..... ",
}
/**
* Returns the HTML representation of an error for a given text.
* @param title the title.
* @param titleFont the font for the title.
* @param details the details.
* @param detailsFont the font to be used for the details.
* @return the HTML representation of an error for the given text.
*/
{
{
}
"</form>";
}
/**
* Returns the HTML representation of a success for a given text.
* @param title the title.
* @param titleFont the font for the title.
* @param details the details.
* @param detailsFont the font to be used for the details.
* @return the HTML representation of a success for the given text.
*/
{
{
}
"</form>";
}
/**
* Returns the HTML representation of a confirmation for a given text.
* @param title the title.
* @param titleFont the font for the title.
* @param details the details.
* @param detailsFont the font to be used for the details.
* @return the HTML representation of a confirmation for the given text.
*/
{
{
}
}
/**
* Returns the HTML representation of a warning for a given text.
* @param title the title.
* @param titleFont the font for the title.
* @param details the details.
* @param detailsFont the font to be used for the details.
* @return the HTML representation of a success for the given text.
*/
{
{
}
"</form>";
}
/**
* Sets the not available text to a label and associates a help icon and
* a tooltip explaining that the data is not available because the server is
* down.
* @param l the label.
*/
public static void setNotAvailableBecauseServerIsDown(LabelWithHelpIcon l)
{
l.setHelpIconVisible(true);
}
/**
* Sets the not available text to a label and associates a help icon and
* a tooltip explaining that the data is not available because authentication
* is required.
* @param l the label.
*/
public static void setNotAvailableBecauseAuthenticationIsRequired(
{
l.setHelpIconVisible(true);
}
/**
* Sets the not available text to a label and associates a help icon and
* a tooltip explaining that the data is not available because the server is
* down.
* @param l the label.
*/
public static void setNotAvailableBecauseServerIsDown(
{
l.setHelpIconVisible(true);
}
/**
* Sets the not available text to a label and associates a help icon and
* a tooltip explaining that the data is not available because authentication
* is required.
* @param l the label.
*/
public static void setNotAvailableBecauseAuthenticationIsRequired(
{
l.setHelpIconVisible(true);
}
/**
* Updates a label by setting a warning icon and a text.
* @param l the label to be updated.
* @param text the text to be set on the label.
*/
{
if (warningIcon == null)
{
}
l.setIcon(warningIcon);
}
/**
* Sets the not available text to a label with no icon nor tooltip.
* @param l the label.
*/
public static void setNotAvailable(LabelWithHelpIcon l)
{
l.setHelpIconVisible(false);
l.setHelpTooltip(null);
}
/**
* Sets the a text to a label with no icon nor tooltip.
* @param l the label.
* @param text the text.
*/
{
l.setHelpIconVisible(false);
l.setHelpTooltip(null);
}
/**
* Sets the not available text to a label with no icon nor tooltip.
* @param l the label.
*/
public static void setNotAvailable(SelectableLabelWithHelpIcon l)
{
l.setHelpIconVisible(false);
l.setHelpTooltip(null);
}
/**
* Sets the a text to a label with no icon nor tooltip.
* @param l the label.
* @param text the text.
*/
{
l.setHelpIconVisible(false);
l.setHelpTooltip(null);
}
/**
* Returns the server root directory (the path where the server is installed).
* @return the server root directory (the path where the server is installed).
*/
public static File getServerRootDirectory()
{
if (rootDirectory == null)
{
// This allows testing of configuration components when the OpenDJ.jar
// in the classpath does not necessarily point to the server's
if (installRoot == null) {
}
}
return rootDirectory;
}
/**
* Returns the instance root directory (the path where the instance is
* installed).
* @param installPath The installRoot path.
* @return the instance root directory (the path where the instance is
* installed).
*/
{
if (instanceRootDirectory == null)
{
instanceRootDirectory = new File(
}
return instanceRootDirectory;
}
/**
* Returns the path of the installation of the directory server. Note that
* this method assumes that this code is being run locally.
* @return the path of the installation of the directory server.
*/
public static String getInstallPathFromClasspath()
{
/* Get the install path from the Class Path */
/*
* Do a best effort to avoid having a relative representation (for
* instance to avoid having ../../../).
*/
try
{
}
catch (IOException ioe)
{
// Best effort
}
}
return installPath;
}
{
{
{
return classPath;
}
}
return null;
}
/**
* Returns <CODE>true</CODE> if the server located in the provided path
* is running and <CODE>false</CODE> otherwise.
* @param serverRootDirectory the path where the server is installed.
* @return <CODE>true</CODE> if the server located in the provided path
* is running and <CODE>false</CODE> otherwise.
*/
{
try {
{
return false;
}
return true;
}
catch (Throwable t) {
// Assume that if we cannot acquire the lock file the
// server is running.
return true;
}
}
private static final String VALID_SCHEMA_SYNTAX =
"abcdefghijklmnopqrstuvwxyz0123456789-";
/**
* Returns <CODE>true</CODE> if the provided string can be used as objectclass
* name and <CODE>false</CODE> otherwise.
* @param s the string to be analyzed.
* @return <CODE>true</CODE> if the provided string can be used as objectclass
* name and <CODE>false</CODE> otherwise.
*/
public static boolean isValidObjectclassName(String s)
{
{
return false;
}
while (c != CharacterIterator.DONE)
{
{
return false;
}
}
return true;
}
/**
* Returns <CODE>true</CODE> if the provided string can be used as attribute
* name and <CODE>false</CODE> otherwise.
* @param s the string to be analyzed.
* @return <CODE>true</CODE> if the provided string can be used as attribute
* name and <CODE>false</CODE> otherwise.
*/
public static boolean isValidAttributeName(String s)
{
return isValidObjectclassName(s);
}
/**
* Returns the representation of the VLV index as it must be used in the
* command-line.
* @param index the VLV index.
* @return the representation of the VLV index as it must be used in the
* command-line.
*/
{
}
/**
* Returns a string representing the VLV index in a cell.
* @param index the VLV index to be represented.
* @return the string representing the VLV index in a cell.
*/
{
}
private static final String[] standardSchemaFileNames =
{
"00-core.ldif", "01-pwpolicy.ldif", "03-changelog.ldif",
"03-uddiv3.ldif", "05-solaris.ldif"
};
private static final String[] configurationSchemaOrigins =
{
"OpenDJ Directory Server", "OpenDS Directory Server",
"Sun Directory Server", "Microsoft Active Directory"
};
private static final String[] standardSchemaOrigins =
{
"Sun Java System Directory Server", "Solaris Specific", "X.501"
};
private static final String[] configurationSchemaFileNames =
{
"02-config.ldif", "06-compat.ldif"
};
/**
* Returns <CODE>true</CODE> if the provided schema element is part of the
* standard and <CODE>false</CODE> otherwise.
* @param fileElement the schema element.
* @return <CODE>true</CODE> if the provided schema element is part of the
* standard and <CODE>false</CODE> otherwise.
*/
{
{
}
else if (fileElement instanceof CommonSchemaElements)
{
{
return contains(standardSchemaOrigins, xOrigin) || xOrigin.startsWith("RFC ") || xOrigin.startsWith("draft-");
}
}
return false;
}
/**
* Returns <CODE>true</CODE> if the provided schema element is part of the
* configuration and <CODE>false</CODE> otherwise.
* @param fileElement the schema element.
* @return <CODE>true</CODE> if the provided schema element is part of the
* configuration and <CODE>false</CODE> otherwise.
*/
{
{
}
else if (fileElement instanceof CommonSchemaElements)
{
{
}
}
return false;
}
{
{
{
return true;
}
}
return false;
}
/**
* Returns the origin of the provided schema element.
* @param element the schema element.
* @return the origin of the provided schema element.
*/
{
}
/**
* Returns the string representation of an attribute syntax.
* @param syntax the attribute syntax.
* @return the string representation of an attribute syntax.
*/
{
if (syntaxName != null)
{
}
return syntaxOID;
}
/**
* Returns <CODE>true</CODE> if the provided attribute has image syntax and
* <CODE>false</CODE> otherwise.
* @param attrName the name of the attribute.
* @param schema the schema.
* @return <CODE>true</CODE> if the provided attribute has image syntax and
* <CODE>false</CODE> otherwise.
*/
{
{
return true;
}
// Check all the attributes that we consider binaries.
{
{
}
}
return false;
}
/**
* Returns <CODE>true</CODE> if the provided attribute has binary syntax and
* <CODE>false</CODE> otherwise.
* @param attrName the name of the attribute.
* @param schema the schema.
* @return <CODE>true</CODE> if the provided attribute has binary syntax and
* <CODE>false</CODE> otherwise.
*/
{
}
/**
* Returns <CODE>true</CODE> if the provided attribute has password syntax and
* <CODE>false</CODE> otherwise.
* @param attrName the name of the attribute.
* @param schema the schema.
* @return <CODE>true</CODE> if the provided attribute has password syntax and
* <CODE>false</CODE> otherwise.
*/
{
}
{
{
{
}
}
return false;
}
/**
* Returns the string representation of a matching rule.
* @param matchingRule the matching rule.
* @return the string representation of a matching rule.
*/
{
{
// This is the name only
}
return oid;
}
/**
* Returns the InitialLdapContext to connect to the administration connector
* of the server using the information in the ControlCenterInfo object (which
* provides the host and administration connector port to be used) and some
* LDAP credentials.
* It also tests that the provided credentials have enough rights to read the
* configuration.
* @param controlInfo the object which provides the connection parameters.
* @param bindDN the base DN to be used to bind.
* @param pwd the password to be used to bind.
* @return the InitialLdapContext connected to the server.
* @throws NamingException if there was a problem connecting to the server
* or the provided credentials do not have enough rights.
* @throws ConfigReadException if there is an error reading the configuration.
*/
public static InitialLdapContext getAdminDirContext(
throws NamingException, ConfigReadException
{
{
throw new ConfigReadException(
}
// Search for the config to check that it is the directory manager.
return ctx;
}
/**
* Returns the InitialLdapContext to connect to the server using the
* information in the ControlCenterInfo object (which provides the host, port
* and protocol to be used) and some LDAP credentials. It also tests that
* the provided credentials have enough rights to read the configuration.
* @param controlInfo the object which provides the connection parameters.
* @param bindDN the base DN to be used to bind.
* @param pwd the password to be used to bind.
* @return the InitialLdapContext connected to the server.
* @throws NamingException if there was a problem connecting to the server
* or the provided credentials do not have enough rights.
* @throws ConfigReadException if there is an error reading the configuration.
*/
public static InitialLdapContext getUserDataDirContext(
{
if (controlInfo.connectUsingStartTLS())
{
{
throw new ConfigReadException(
}
}
else if (controlInfo.connectUsingLDAPS())
{
{
throw new ConfigReadException(
}
}
else
{
{
throw new ConfigReadException(
}
}
return ctx;
}
/**
* Checks that the provided connection can read cn=config.
* @param ctx the connection to be tested.
* @throws NamingException if an error occurs while reading cn=config.
*/
throws NamingException
{
// Search for the config to check that it is the directory manager.
try
{
{
}
}
finally
{
}
}
/**
* Ping the specified InitialLdapContext.
* This method sends a search request on the root entry of the DIT
* and forward the corresponding exception (if any).
* @param ctx the InitialLdapContext to be "pinged".
* @throws NamingException if the ping could not be performed.
*/
throws NamingException {
0, // count limit
0, // time limit
false, // Don't return bound object
false // Don't dereference link
);
}
/**
* Deletes a configuration subtree using the provided configuration handler.
* @param confHandler the configuration handler to be used to delete the
* subtree.
* @param dn the DN of the subtree to be deleted.
* @throws OpenDsException if an error occurs.
* @throws ConfigException if an error occurs.
*/
throws OpenDsException, ConfigException
{
{
// Copy the values to avoid problems with this recursive method.
{
}
}
}
/**
* Sets the required icon to the provided label.
* @param label the label to be updated.
*/
{
if (requiredIcon == null)
{
}
}
/**
* Updates the scrolls with the provided points.
* This method uses SwingUtilities.invokeLater so it can be also called
* outside the event thread.
* @param pos the scroll and points.
*/
{
{
public void run()
{
{
}
}
});
}
/**
* Gets the view positions object for the provided component. This includes
* all the scroll panes inside the provided component.
* @param comp the component.
* @return the view positions for the provided component.
*/
{
{
}
return pos;
}
/**
* Returns the scrolpane where the provided component is contained.
* <CODE>null</CODE> if the component is not contained in any scrolpane.
* @param comp the component.
* @return the scrolpane where the provided component is contained.
*/
{
{
if (parent instanceof JScrollPane)
{
}
else
{
}
}
return scroll;
}
{
if (comp instanceof JScrollPane)
{
}
else
{
{
{
}
}
}
}
{
{
{
try
{
}
{
try
{
}
{
// Cannot convert it, just return it
return o;
}
}
}
}
return null;
}
/**
* Returns the first value as a String for a given attribute in the provided
* entry.
*
* @param sr
* the entry. It may be <CODE>null</CODE>.
* @param attrName
* the attribute name.
* @return the first value as a String for a given attribute in the provided
* entry.
*/
{
{
{
if (o != null)
{
}
}
}
return null;
}
/**
* Returns the monitoring value in a String form to be displayed to the user.
* @param attr the attribute to analyze.
* @param monitoringEntry the monitoring entry.
* @return the monitoring value in a String form to be displayed to the user.
*/
{
if (monitoringValue == null)
{
return NO_VALUE_SET.toString();
}
{
return NOT_IMPLEMENTED.toString();
}
else if (attr.isNumericDate())
{
{
return NO_VALUE_SET.toString();
}
}
{
{
return NO_VALUE_SET.toString();
}
return monitoringValue;
}
{
try
{
}
catch (Throwable t)
{
return monitoringValue;
}
}
else if (attr.isValueInBytes())
{
}
return monitoringValue;
}
/**
* Returns <CODE>true</CODE> if the provided monitoring value represents the
* non implemented label and <CODE>false</CODE> otherwise.
* @param attr the attribute to analyze.
* @param monitoringEntry the monitoring entry.
* @return <CODE>true</CODE> if the provided monitoring value represents the
* non implemented label and <CODE>false</CODE> otherwise.
*/
{
{
try
{
return false;
}
catch (Throwable t)
{
return true;
}
}
return false;
}
/**
* Adds a click tool tip listener to the provided component.
* @param comp the component.
*/
{
}
/**
* Updates a combo box model with a number of items.
* The method assumes that is being called from the event thread.
* @param newElements the new items for the combo box model.
* @param model the combo box model to be updated.
*/
{
}
/**
* Updates a combo box model with a number of items.
* The method assumes that is being called from the event thread.
* @param newElements the new items for the combo box model.
* @param model the combo box model to be updated.
* @param comparator the object that will be used to compare the objects in
* the model. If <CODE>null</CODE>, the equals method will be used.
*/
{
if (!changed)
{
int i = 0;
{
if (comparator != null)
{
changed =
}
else
{
}
if (changed)
{
break;
}
i++;
}
}
if (changed)
{
boolean selectDefault = false;
{
}
{
{
}
else
{
selectDefault = true;
}
}
else
{
selectDefault = true;
}
if (selectDefault)
{
{
if (o instanceof CategorizedComboBoxElement
{
continue;
}
model.setSelectedItem(o);
break;
}
}
}
}
/**
* Indicates if the provided matching rule is an equality matching rule.
*
* @param matchingRule
* The matching rule.
* @return {@code true} if this matching rule is an equality mathing rule.
*/
return false;
}
/**
* Indicates if the provided matching rule is an approximate matching rule.
*
* @param matchingRule
* The matching rule.
* @return {@code true} if this matching rule is an approximate mathing rule.
*/
return false;
}
/**
* Indicates if the provided matching rule is a substring matching rule.
*
* @param matchingRule
* The matching rule.
* @return {@code true} if this matching rule is a substring mathing rule.
*/
return false;
}
/**
* Indicates if the provided matching rule is an ordering matching rule.
*
* @param matchingRule
* The matching rule.
* @return {@code true} if this matching rule is an ordering mathing rule.
*/
return false;
}
/**
* Computes the possible comparison results for monitoring information.
*
* @param monitor1
* the first monitor to compare
* @param monitor2
* the second monitor to compare
* @param possibleResults
* where possible results are output
* @param attrNames
* the names for which to compute possible comparison results
*/
public static void computeMonitoringPossibleResults(CustomSearchResult monitor1, CustomSearchResult monitor2,
{
{
int possibleResult;
{
{
possibleResult = 0;
}
else
{
possibleResult = -1;
}
}
{
possibleResult = 1;
}
else
{
{
{
possibleResult = 0;
}
else
{
possibleResult = -1;
}
}
{
possibleResult = 1;
}
{
{
{
{
possibleResult = 1;
}
{
possibleResult = -1;
}
else
{
possibleResult = 0;
}
}
else
{
{
possibleResult = 1;
}
{
possibleResult = -1;
}
else
{
possibleResult = 0;
}
}
}
else
{
possibleResult = 1;
}
}
{
possibleResult = -1;
}
else
{
}
}
}
}
{
{
{
}
}
return null;
}
/**
* Throw the first exception of the list (if any).
*
* @param <E>
* The exception type
* @param exceptions
* A list of exceptions.
* @throws E
* The first element of the provided list (if the list is not
* empty).
*/
{
if (!exceptions.isEmpty())
{
}
}
}