Class Utilities
- java.lang.Object
-
- org.opends.guitools.controlpanel.util.Utilities
-
public class Utilities extends Object
A static class that provides miscellaneous functions.
-
-
Constructor Summary
Constructors Constructor Description Utilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddClickTooltipListener(JComponent comp)Adds a click tool tip listener to the provided component.static StringapplyFont(CharSequence html, Font font)Returns a String that contains the html passed as parameter with a span applied.static voidcenterGoldenMean(Window comp, Component ref)Center the component location of the ref component.static voidcenterOnScreen(Component comp)Center the component location based on its preferred size.static voidcomputeMonitoringPossibleResults(SearchResultEntry monitor1, SearchResultEntry monitor2, List<Integer> possibleResults, Collection<String> attrNames)Computes the possible comparison results for monitoring information.static JScrollPanecreateBorderLessScrollBar(Component comp)Returns a JScrollPane that contains the provided component.static JButtoncreateButton(org.forgerock.i18n.LocalizableMessage text)Creates a button.static JCheckBoxcreateCheckBox(org.forgerock.i18n.LocalizableMessage text)Creates a check box.static <T> JComboBox<T>createComboBox()Creates a combo box.static JLabelcreateDefaultLabel()Creates a label (with default font) with no text.static JLabelcreateDefaultLabel(org.forgerock.i18n.LocalizableMessage text)Creates a label (with default font).static JFramecreateFrame()Creates a frame.static ImageIconcreateImageIcon(byte[] bytes, int maxHeight, org.forgerock.i18n.LocalizableMessage description, boolean useFast)Creates an image icon using an array of bytes that contain the image and specifying the maximum height of the image.static ImageIconcreateImageIcon(String path)Returns an ImageIcon ornullif the path was invalid.static ImageIconcreateImageIcon(String path, ClassLoader loader)Returns an ImageIcon ornullif the path was invalid.static JLabelcreateInlineHelpLabel(org.forgerock.i18n.LocalizableMessage text)Creates a label of type 'inline help' (with smaller font).static JTextFieldcreateLongTextField()Creates a long text field.static JTextFieldcreateMediumTextField()Creates a medium sized text field.static JMenucreateMenu(org.forgerock.i18n.LocalizableMessage msg, org.forgerock.i18n.LocalizableMessage description)Creates a menu with the provided text.static JMenuItemcreateMenuItem(org.forgerock.i18n.LocalizableMessage msg)Creates a menu item with the provided text.static JTextAreacreateNonEditableTextArea(org.forgerock.i18n.LocalizableMessage text, int rows, int cols)Creates a non-editable text area.static JPasswordFieldcreatePasswordField()Creates a password text field.static JPasswordFieldcreatePasswordField(int cols)Creates a password text field.static JLabelcreatePrimaryLabel()Creates a label of type 'primary' (with bigger font than usual) with no text.static JLabelcreatePrimaryLabel(org.forgerock.i18n.LocalizableMessage text)Creates a label of type 'primary' (with bigger font than usual).static JRadioButtoncreateRadioButton(org.forgerock.i18n.LocalizableMessage text)Creates a radio button.static JScrollPanecreateScrollPane(Component comp)Returns a JScrollPane that contains the provided component.static JTextFieldcreateShortTextField()Creates a short text field.static JTablecreateSortableTable(SortableTableModel tableModel, TableCellRenderer renderer)Returns a table created with the provided model and renderers.static JTextAreacreateTextArea(org.forgerock.i18n.LocalizableMessage text, int rows, int cols)Creates a text area.static JTextAreacreateTextAreaWithBorder(org.forgerock.i18n.LocalizableMessage text, int rows, int cols)Creates a text area with borders similar to the ones of a text field.static JTextFieldcreateTextField()Creates a text field with the default size.static JTextFieldcreateTextField(String text, int cols)Creates a text field.static JLabelcreateTitleLabel(org.forgerock.i18n.LocalizableMessage text)Creates a label of type 'title' (with bigger font).static voiddeleteConfigSubtree(ConfigurationHandler confHandler, DN dn)Deletes a configuration subtree using the provided configuration handler.static ColorderiveColorHSB(Color base, float dH, float dS, float dB)Derives a color by adding the specified offsets to the base color's hue, saturation, and brightness values.static booleandisplayConfirmationDialog(Component parentComponent, org.forgerock.i18n.LocalizableMessage title, org.forgerock.i18n.LocalizableMessage msg)Displays a confirmation dialog.static voiddisplayErrorDialog(Component parentComponent, Collection<org.forgerock.i18n.LocalizableMessage> errors)Displays an error dialog that contains a set of error messages.static voiddisplayWarningDialog(Component parentComponent, org.forgerock.i18n.LocalizableMessage title, org.forgerock.i18n.LocalizableMessage msg)Displays a warning dialog.static ConnectionWrappergetAdminConnection(ControlPanelInfo controlInfo, DN bindDN, String pwd)Returns the connection 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.static StringgetAttributeConfigName(SchemaElement element)Returns the name of configuration attribute corresponding to the provided element.static StringgetAttributeNameWithoutOptions(String attrDesc)Returns the attribute name with no options (or subtypes).static JScrollPanegetContainingScroll(Component comp)Returns the scrollpane where the provided component is contained.static StringgetElementNameOrOID(SchemaElement element)Returns the name or OID of provided element.static StringgetElementOID(SchemaElement element)Returns the OID of provided element.static StringgetFirstValueAsString(Entry sr, String attrName)Returns the first value as a String for a given attribute in the provided entry.static StringgetFormattedConfirmation(org.forgerock.i18n.LocalizableMessage title, Font titleFont, org.forgerock.i18n.LocalizableMessage details, Font detailsFont)Returns the HTML representation of a confirmation for a given text.static StringgetFormattedError(org.forgerock.i18n.LocalizableMessage title, Font titleFont, org.forgerock.i18n.LocalizableMessage details, Font detailsFont)Returns the HTML representation of an error for a given text.static StringgetFormattedSuccess(org.forgerock.i18n.LocalizableMessage title, Font titleFont, org.forgerock.i18n.LocalizableMessage details, Font detailsFont)Returns the HTML representation of a success for a given text.static StringgetFormattedWarning(org.forgerock.i18n.LocalizableMessage title, Font titleFont, org.forgerock.i18n.LocalizableMessage details, Font detailsFont)Returns the HTML representation of a warning for a given text.static JFramegetFrame(Component comp)Returns the parent frame of a component.static StringgetInstallPathFromClasspath()Returns the path of the installation of the directory server.static FilegetInstanceRootDirectory(String installPath)Returns the instance root directory (the path where the instance is installed).static StringgetMatchingRuleText(MatchingRule matchingRule)Returns the string representation of a matching rule.static StringgetMonitoringValue(MonitoringAttributes attr, SearchResultEntry monitoringEntry)Returns the monitoring value in a String form to be displayed to the user.static AttributeTypegetNewAttributeTypeWithNewSuperiorType(AttributeType attributeType, AttributeType newSuperiorType)Return a new attribute type with the provided new superior type.static WindowgetParentDialog(Component comp)Returns the parent dialog of a component.static StringgetProgressDone(Font progressFont)Returns the HTML representation of the 'Done' string.static StringgetProgressWithPoints(org.forgerock.i18n.LocalizableMessage plainText, Font progressFont)Returns the HTML representation of a message to which some points have been appended.static FilegetServerRootDirectory()Returns the server root directory (the path where the server is installed).static StringgetStringFromCollection(Collection<String> col, String separator)This is a helper method that gets a String representation of the elements in the Collection.static StringgetSyntaxText(Syntax syntax)Returns the string representation of an attribute syntax.static ConnectionWrappergetUserDataConnection(ControlPanelInfo controlInfo, DN bindDN, String pwd)Returns the connection 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.static ViewPositionsgetViewPositions(Component comp)Gets the view positions object for the provided component.static StringgetVLVNameInCellRenderer(VLVIndexDescriptor index)Returns a string representing the VLV index in a cell.static StringgetVLVNameInCommandLine(VLVIndexDescriptor index)Returns the representation of the VLV index as it must be used in the command-line.static booleanhasBinarySyntax(String attrName, Schema schema)Returns whether the provided attribute has binary syntax.static booleanhasControlCharaters(String s)Checks if a string contains control characters.static booleanhasImageSyntax(String attrName, Schema schema)Returns whether the provided attribute has image syntax.static booleanhasPasswordSyntax(String attrName, Schema schema)Returns whether the provided attribute has password syntax.static voidinitializeConfigurationFramework()Initialize the configuration framework.static booleanisAttributeType(SchemaElement element)Test whether provided schema element is an attribute type.static booleanisConfiguration(SchemaElement fileElement)Returns whether the provided schema element is part of the configuration.static booleanisServerRunning(File serverRootDirectory)Returns whether the server located in the provided path is running.static booleanisStandard(SchemaElement fileElement)Returns whether the provided schema element is part of the standard.static booleanisValidAttributeName(String s)Returns whether the provided string can be used as attribute name.static JEditorPanemakeHtmlPane(CharSequence text, Font font)Creates a JEditorPane that displays a message.static JEditorPanemakePlainTextPane(String text, Font font)Creates a JEditorPane that displays a message.static BordermakeTitledBorder(org.forgerock.i18n.LocalizableMessage msg)Creates a titled border.static booleanmustObfuscate(String attrName, Schema schema)Returns whether an attribute value must be obfuscated because it contains sensitive information (like passwords).static voidping(ConnectionWrapper connWrapper)Ping the specified connection.static voidsetBorder(JComponent comp, Border border)Sets the border in a given component.static voidsetNotAvailable(LabelWithHelpIcon l)Sets the not available text to a label with no icon nor tooltip.static voidsetNotAvailable(SelectableLabelWithHelpIcon l)Sets the not available text to a label with no icon nor tooltip.static voidsetNotAvailableBecauseAuthenticationIsRequired(LabelWithHelpIcon l)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.static voidsetNotAvailableBecauseAuthenticationIsRequired(SelectableLabelWithHelpIcon l)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.static voidsetNotAvailableBecauseServerIsDown(LabelWithHelpIcon l)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.static voidsetNotAvailableBecauseServerIsDown(SelectableLabelWithHelpIcon l)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.static voidsetRequiredIcon(JLabel label)Sets the required icon to the provided label.static voidsetTextValue(LabelWithHelpIcon l, String text)Sets the a text to a label with no icon nor tooltip.static voidsetTextValue(SelectableLabelWithHelpIcon l, String text)Sets the a text to a label with no icon nor tooltip.static voidsetWarningLabel(JLabel l, org.forgerock.i18n.LocalizableMessage text)Updates a label by setting a warning icon and a text.static StringstripHtmlToSingleLine(String s)Strips any potential HTML markup from a given string.static <E extends Exception>
voidthrowFirstFrom(List<? extends E> exceptions)Throw the first exception of the list (if any).static StringunescapeUtf8(String v)Unescapes UTF-8 text and generates a String from it.static voidupdateComboBoxModel(Collection<?> newElements, DefaultComboBoxModel model)Updates a combo box model with a number of items.static voidupdateComboBoxModel(Collection<?> newElements, DefaultComboBoxModel model, Comparator<Object> comparator)Updates a combo box model with a number of items.static voidupdatePreferredSize(JEditorPane pane, int nCols, String plainText, Font font, boolean applyBackground)Updates the preferred size of an editor pane.static SchemaElementupdateSchemaElementExtraPropertyMultiplesValues(ServerContext serverContext, SchemaElement element, String property, List<String> values)Updates an extra property of provided schema element with several values.static SchemaElementupdateSchemaElementExtraPropertySingleValue(ServerContext serverContext, SchemaElement element, String property, String value)Updates an extra property of provided schema element with a single value.static voidupdateScrollMode(JScrollPane scroll, JTable table)Checks the size of the table and of the scroll bar where it is contained, and depending on it updates the auto resize mode.static voidupdateTableSizes(JTable table)Updates the size of the table rows according to the size of the rendered component.static voidupdateTableSizes(JTable table, int rows)Updates the size of the table rows according to the size of the rendered component.static voidupdateViewPositions(ViewPositions pos)Updates the scrolls with the provided points.static org.forgerock.i18n.LocalizableMessagewrapHTML(org.forgerock.i18n.LocalizableMessage msg, int nCols)Wraps the contents of the provided message using the specified number of columns.
-
-
-
Method Detail
-
createComboBox
public static <T> JComboBox<T> createComboBox()
Creates a combo box.- Type Parameters:
T- The combo box data type.- Returns:
- a combo box.
-
createFrame
public static JFrame createFrame()
Creates a frame.- Returns:
- a frame.
-
mustObfuscate
public static boolean mustObfuscate(String attrName, Schema schema)
Returns whether an attribute value must be obfuscated because it contains sensitive information (like passwords).- Parameters:
attrName- the attribute name.schema- the schema of the server.- Returns:
trueif an attribute value must be obfuscated because it contains sensitive information (like passwords) andfalseotherwise.
-
deriveColorHSB
public static Color deriveColorHSB(Color base, float dH, float dS, float dB)
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 constrained to be between 0 and 1.- Parameters:
base- the color to which the HSV offsets will be addeddH- the offset for huedS- the offset for saturationdB- the offset for brightness- Returns:
- Color with modified HSV values
-
displayErrorDialog
public static void displayErrorDialog(Component parentComponent, Collection<org.forgerock.i18n.LocalizableMessage> errors)
Displays an error dialog that contains a set of error messages.- Parameters:
parentComponent- the parent component relative to which the dialog will be displayed.errors- the set of error messages that the dialog must display.
-
displayConfirmationDialog
public static boolean displayConfirmationDialog(Component parentComponent, org.forgerock.i18n.LocalizableMessage title, org.forgerock.i18n.LocalizableMessage msg)
Displays a confirmation dialog.- Parameters:
parentComponent- the parent component relative to which the dialog will be displayed.title- the title of the dialog.msg- the message to be displayed.- Returns:
trueif the user accepts the message,falseotherwise.
-
displayWarningDialog
public static void displayWarningDialog(Component parentComponent, org.forgerock.i18n.LocalizableMessage title, org.forgerock.i18n.LocalizableMessage msg)
Displays a warning dialog.- Parameters:
parentComponent- the parent component relative to which the dialog will be displayed.title- the title of the dialog.msg- the message to be displayed.
-
makeHtmlPane
public static JEditorPane makeHtmlPane(CharSequence text, Font font)
Creates a JEditorPane that displays a message.- Parameters:
text- the message of the editor pane in HTML format.font- the font to be used in the message.- Returns:
- a JEditorPane that displays a message.
-
makePlainTextPane
public static JEditorPane makePlainTextPane(String text, Font font)
Creates a JEditorPane that displays a message.- Parameters:
text- the message of the editor pane in plain text format.font- the font to be used in the message.- Returns:
- a JEditorPane that displays a message.
-
makeTitledBorder
public static Border makeTitledBorder(org.forgerock.i18n.LocalizableMessage msg)
Creates a titled border.- Parameters:
msg- the message to be displayed in the titled border.- Returns:
- the created titled border.
-
createBorderLessScrollBar
public static JScrollPane createBorderLessScrollBar(Component comp)
Returns a JScrollPane that contains the provided component. The scroll pane will not contain any border.- Parameters:
comp- the component contained in the scroll pane.- Returns:
- a JScrollPane that contains the provided component. The scroll pane will not contain any border.
-
createScrollPane
public static JScrollPane createScrollPane(Component comp)
Returns a JScrollPane that contains the provided component.- Parameters:
comp- the component contained in the scroll pane.- Returns:
- a JScrollPane that contains the provided component.
-
createButton
public static JButton createButton(org.forgerock.i18n.LocalizableMessage text)
Creates a button.- Parameters:
text- the message to be displayed by the button.- Returns:
- the created button.
-
createRadioButton
public static JRadioButton createRadioButton(org.forgerock.i18n.LocalizableMessage text)
Creates a radio button.- Parameters:
text- the message to be displayed by the radio button.- Returns:
- the created radio button.
-
createCheckBox
public static JCheckBox createCheckBox(org.forgerock.i18n.LocalizableMessage text)
Creates a check box.- Parameters:
text- the message to be displayed by the check box.- Returns:
- the created check box.
-
createMenuItem
public static JMenuItem createMenuItem(org.forgerock.i18n.LocalizableMessage msg)
Creates a menu item with the provided text.- Parameters:
msg- the text.- Returns:
- a menu item with the provided text.
-
createMenu
public static JMenu createMenu(org.forgerock.i18n.LocalizableMessage msg, org.forgerock.i18n.LocalizableMessage description)
Creates a menu with the provided text.- Parameters:
msg- the text.description- the accessible description.- Returns:
- a menu with the provided text.
-
createPrimaryLabel
public static JLabel createPrimaryLabel()
Creates a label of type 'primary' (with bigger font than usual) with no text.- Returns:
- the label of type 'primary' (with bigger font than usual) with no text.
-
createPrimaryLabel
public static JLabel createPrimaryLabel(org.forgerock.i18n.LocalizableMessage text)
Creates a label of type 'primary' (with bigger font than usual).- Parameters:
text- the message to be displayed by the label.- Returns:
- the label of type 'primary' (with bigger font than usual).
-
createInlineHelpLabel
public static JLabel createInlineHelpLabel(org.forgerock.i18n.LocalizableMessage text)
Creates a label of type 'inline help' (with smaller font).- Parameters:
text- the message to be displayed by the label.- Returns:
- the label of type 'inline help' (with smaller font).
-
createTitleLabel
public static JLabel createTitleLabel(org.forgerock.i18n.LocalizableMessage text)
Creates a label of type 'title' (with bigger font).- Parameters:
text- the message to be displayed by the label.- Returns:
- the label of type 'title' (with bigger font).
-
createDefaultLabel
public static JLabel createDefaultLabel()
Creates a label (with default font) with no text.- Returns:
- the label (with default font) with no text.
-
createDefaultLabel
public static JLabel createDefaultLabel(org.forgerock.i18n.LocalizableMessage text)
Creates a label (with default font).- Parameters:
text- the message to be displayed by the label.- Returns:
- the label (with default font).
-
createSortableTable
public static JTable createSortableTable(SortableTableModel tableModel, TableCellRenderer renderer)
Returns a table created with the provided model and renderers.- Parameters:
tableModel- the table model.renderer- the cell renderer.- Returns:
- a table created with the provided model and renderers.
-
createTextAreaWithBorder
public static JTextArea createTextAreaWithBorder(org.forgerock.i18n.LocalizableMessage text, int rows, int cols)
Creates a text area with borders similar to the ones of a text field.- Parameters:
text- the text of the text area.rows- the rows of the text area.cols- the columns of the text area.- Returns:
- a text area with borders similar to the ones of a text field.
-
createNonEditableTextArea
public static JTextArea createNonEditableTextArea(org.forgerock.i18n.LocalizableMessage text, int rows, int cols)
Creates a non-editable text area.- Parameters:
text- the text of the text area.rows- the rows of the text area.cols- the columns of the text area.- Returns:
- a non-editable text area.
-
createTextArea
public static JTextArea createTextArea(org.forgerock.i18n.LocalizableMessage text, int rows, int cols)
Creates a text area.- Parameters:
text- the text of the text area.rows- the rows of the text area.cols- the columns of the text area.- Returns:
- a text area.
-
createTextField
public static JTextField createTextField(String text, int cols)
Creates a text field.- Parameters:
text- the text of the text field.cols- the columns of the text field.- Returns:
- the created text field.
-
createShortTextField
public static JTextField createShortTextField()
Creates a short text field.- Returns:
- the created text field.
-
createMediumTextField
public static JTextField createMediumTextField()
Creates a medium sized text field.- Returns:
- the created text field.
-
createLongTextField
public static JTextField createLongTextField()
Creates a long text field.- Returns:
- the created text field.
-
createTextField
public static JTextField createTextField()
Creates a text field with the default size.- Returns:
- the created text field.
-
createPasswordField
public static JPasswordField createPasswordField()
Creates a password text field.- Returns:
- the created password text field.
-
createPasswordField
public static JPasswordField createPasswordField(int cols)
Creates a password text field.- Parameters:
cols- the columns of the password text field.- Returns:
- the created password text field.
-
setBorder
public static void setBorder(JComponent comp, Border border)
Sets the border in a given component. If the component already has a border, creates a compound border.- Parameters:
comp- the component.border- the border to be set.
-
updateScrollMode
public static void updateScrollMode(JScrollPane scroll, JTable table)
Checks the size of the table and of the scroll bar where it is contained, and depending on it updates the auto resize mode.- Parameters:
scroll- the scroll pane containing the table.table- the table.
-
updateTableSizes
public static void updateTableSizes(JTable table)
Updates the size of the table rows according to the size of the rendered component.- Parameters:
table- the table to handle.
-
updateTableSizes
public static void updateTableSizes(JTable table, int rows)
Updates the size of the table rows according to the size of the rendered component.- Parameters:
table- the table to handle.rows- the maximum rows to be displayed (-1 for unlimited)
-
applyFont
public static String applyFont(CharSequence html, Font font)
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.- Parameters:
html- the original html text.font- the font to be used to generate the new HTML.- Returns:
- a string that represents the original HTML with the font specified as parameter.
-
createImageIcon
public static ImageIcon createImageIcon(String path, ClassLoader loader)
Returns an ImageIcon ornullif the path was invalid.- Parameters:
path- the path of the image.loader- the class loader to use to load the image. Ifnullthis class class loader will be used.- Returns:
- an ImageIcon or
nullif the path was invalid.
-
createImageIcon
public static ImageIcon createImageIcon(String path)
Returns an ImageIcon ornullif the path was invalid.- Parameters:
path- the path of the image.- Returns:
- an ImageIcon or
nullif the path was invalid.
-
createImageIcon
public static ImageIcon createImageIcon(byte[] bytes, int maxHeight, org.forgerock.i18n.LocalizableMessage description, boolean useFast)
Creates an image icon using an array of bytes that contain the image and specifying the maximum height of the image.- Parameters:
bytes- the byte array.maxHeight- the maximum height of the image.description- the description of the image.useFast- whether a fast algorithm must be used to transform the image or an algorithm with a better result.- Returns:
- an image icon using an array of bytes that contain the image and specifying the maximum height of the image.
-
updatePreferredSize
public static void updatePreferredSize(JEditorPane pane, int nCols, String plainText, Font font, boolean applyBackground)
Updates the preferred size of an editor pane.- Parameters:
pane- the panel to be updated.nCols- the number of columns that the panel must have.plainText- the text to be displayed (plain text).font- the font to be used.applyBackground- whether an error/warning background must be applied to the text or not.
-
stripHtmlToSingleLine
public static String stripHtmlToSingleLine(String s)
Strips any potential HTML markup from a given string.- Parameters:
s- string to strip- Returns:
- resulting string
-
wrapHTML
public static org.forgerock.i18n.LocalizableMessage wrapHTML(org.forgerock.i18n.LocalizableMessage msg, int nCols)Wraps the contents of the provided message using the specified number of columns.- Parameters:
msg- the message to be wrapped.nCols- the number of columns.- Returns:
- the wrapped message.
-
centerOnScreen
public static void centerOnScreen(Component comp)
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- Parameters:
comp- the component to be centered.
-
centerGoldenMean
public static void centerGoldenMean(Window comp, Component ref)
Center the component location of the ref component.- Parameters:
comp- the component to be centered.ref- the component to be used as reference.
-
getFrame
public static JFrame getFrame(Component comp)
Returns the parent frame of a component.nullif this component is not contained in any frame.- Parameters:
comp- the component.- Returns:
- the parent frame of a component.
nullif this component is not contained in any frame.
-
getParentDialog
public static Window getParentDialog(Component comp)
Returns the parent dialog of a component.nullif this component is not contained in any dialog.- Parameters:
comp- the component.- Returns:
- the parent dialog of a component.
nullif this component is not contained in any dialog.
-
unescapeUtf8
public static String unescapeUtf8(String v)
Unescapes UTF-8 text and generates a String from it.- Parameters:
v- the string in UTF-8 format.- Returns:
- the string with unescaped characters.
-
getAttributeNameWithoutOptions
public static String getAttributeNameWithoutOptions(String attrDesc)
Returns the attribute name with no options (or subtypes).Note: normal code should use
AttributeDescription.valueOf(attrName).getNameOrOID()However this method is used by UI code which sometimes receives strings which are not valid attribute descriptions.
- Parameters:
attrDesc- the complete attribute name.- Returns:
- the attribute name with no options (or subtypes).
-
hasControlCharaters
public static boolean hasControlCharaters(String s)
Checks if a string contains control characters.- Parameters:
s- : the string to check- Returns:
- true if s contains control characters, false otherwise
-
getStringFromCollection
public static String getStringFromCollection(Collection<String> col, String separator)
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.- Parameters:
col- the collection containing the String.separator- the separator String to be used.- Returns:
- the String representation for the collection.
-
getProgressDone
public static String getProgressDone(Font progressFont)
Returns the HTML representation of the 'Done' string.- Parameters:
progressFont- the font to be used.- Returns:
- the HTML representation of the 'Done' string.
-
getProgressWithPoints
public static String getProgressWithPoints(org.forgerock.i18n.LocalizableMessage plainText, Font progressFont)
Returns the HTML representation of a message to which some points have been appended.- Parameters:
plainText- the plain text.progressFont- the font to be used.- Returns:
- the HTML representation of a message to which some points have been appended.
-
getFormattedError
public static String getFormattedError(org.forgerock.i18n.LocalizableMessage title, Font titleFont, org.forgerock.i18n.LocalizableMessage details, Font detailsFont)
Returns the HTML representation of an error for a given text.- Parameters:
title- the title.titleFont- the font for the title.details- the details.detailsFont- the font to be used for the details.- Returns:
- the HTML representation of an error for the given text.
-
getFormattedSuccess
public static String getFormattedSuccess(org.forgerock.i18n.LocalizableMessage title, Font titleFont, org.forgerock.i18n.LocalizableMessage details, Font detailsFont)
Returns the HTML representation of a success for a given text.- Parameters:
title- the title.titleFont- the font for the title.details- the details.detailsFont- the font to be used for the details.- Returns:
- the HTML representation of a success for the given text.
-
getFormattedConfirmation
public static String getFormattedConfirmation(org.forgerock.i18n.LocalizableMessage title, Font titleFont, org.forgerock.i18n.LocalizableMessage details, Font detailsFont)
Returns the HTML representation of a confirmation for a given text.- Parameters:
title- the title.titleFont- the font for the title.details- the details.detailsFont- the font to be used for the details.- Returns:
- the HTML representation of a confirmation for the given text.
-
getFormattedWarning
public static String getFormattedWarning(org.forgerock.i18n.LocalizableMessage title, Font titleFont, org.forgerock.i18n.LocalizableMessage details, Font detailsFont)
Returns the HTML representation of a warning for a given text.- Parameters:
title- the title.titleFont- the font for the title.details- the details.detailsFont- the font to be used for the details.- Returns:
- the HTML representation of a success for the given text.
-
setNotAvailableBecauseServerIsDown
public static void setNotAvailableBecauseServerIsDown(LabelWithHelpIcon l)
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.- Parameters:
l- the label.
-
setNotAvailableBecauseAuthenticationIsRequired
public static void setNotAvailableBecauseAuthenticationIsRequired(LabelWithHelpIcon l)
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.- Parameters:
l- the label.
-
setNotAvailableBecauseServerIsDown
public static void setNotAvailableBecauseServerIsDown(SelectableLabelWithHelpIcon l)
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.- Parameters:
l- the label.
-
setNotAvailableBecauseAuthenticationIsRequired
public static void setNotAvailableBecauseAuthenticationIsRequired(SelectableLabelWithHelpIcon l)
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.- Parameters:
l- the label.
-
setWarningLabel
public static void setWarningLabel(JLabel l, org.forgerock.i18n.LocalizableMessage text)
Updates a label by setting a warning icon and a text.- Parameters:
l- the label to be updated.text- the text to be set on the label.
-
setNotAvailable
public static void setNotAvailable(LabelWithHelpIcon l)
Sets the not available text to a label with no icon nor tooltip.- Parameters:
l- the label.
-
setTextValue
public static void setTextValue(LabelWithHelpIcon l, String text)
Sets the a text to a label with no icon nor tooltip.- Parameters:
l- the label.text- the text.
-
setNotAvailable
public static void setNotAvailable(SelectableLabelWithHelpIcon l)
Sets the not available text to a label with no icon nor tooltip.- Parameters:
l- the label.
-
setTextValue
public static void setTextValue(SelectableLabelWithHelpIcon l, String text)
Sets the a text to a label with no icon nor tooltip.- Parameters:
l- the label.text- the text.
-
getServerRootDirectory
public static File getServerRootDirectory()
Returns the server root directory (the path where the server is installed).Note: this method is called by SNMP code.
- Returns:
- the server root directory (the path where the server is installed).
-
getInstanceRootDirectory
public static File getInstanceRootDirectory(String installPath)
Returns the instance root directory (the path where the instance is installed).- Parameters:
installPath- The installRoot path.- Returns:
- the instance root directory (the path where the instance is installed).
-
getInstallPathFromClasspath
public static String getInstallPathFromClasspath()
Returns the path of the installation of the directory server. Note that this method assumes that this code is being run locally.- Returns:
- the path of the installation of the directory server.
-
isServerRunning
public static boolean isServerRunning(File serverRootDirectory)
Returns whether the server located in the provided path is running.- Parameters:
serverRootDirectory- the path where the server is installed.- Returns:
trueif the server located in the provided path is running,falseotherwise.
-
isValidAttributeName
public static boolean isValidAttributeName(String s)
Returns whether the provided string can be used as attribute name.- Parameters:
s- the string to be analyzed.- Returns:
trueif the provided string can be used as attribute name,falseotherwise.
-
getVLVNameInCommandLine
public static String getVLVNameInCommandLine(VLVIndexDescriptor index)
Returns the representation of the VLV index as it must be used in the command-line.- Parameters:
index- the VLV index.- Returns:
- the representation of the VLV index as it must be used in the command-line.
-
getVLVNameInCellRenderer
public static String getVLVNameInCellRenderer(VLVIndexDescriptor index)
Returns a string representing the VLV index in a cell.- Parameters:
index- the VLV index to be represented.- Returns:
- the string representing the VLV index in a cell.
-
isStandard
public static boolean isStandard(SchemaElement fileElement)
Returns whether the provided schema element is part of the standard.- Parameters:
fileElement- the schema element.- Returns:
trueif the provided schema element is part of the standard,falseotherwise.
-
isConfiguration
public static boolean isConfiguration(SchemaElement fileElement)
Returns whether the provided schema element is part of the configuration.- Parameters:
fileElement- the schema element.- Returns:
trueif the provided schema element is part of the configuration,falseotherwise.
-
getSyntaxText
public static String getSyntaxText(Syntax syntax)
Returns the string representation of an attribute syntax.- Parameters:
syntax- the attribute syntax.- Returns:
- the string representation of an attribute syntax.
-
hasImageSyntax
public static boolean hasImageSyntax(String attrName, Schema schema)
Returns whether the provided attribute has image syntax.- Parameters:
attrName- the name of the attribute.schema- the schema.- Returns:
trueif the provided attribute has image syntax,falseotherwise.
-
hasBinarySyntax
public static boolean hasBinarySyntax(String attrName, Schema schema)
Returns whether the provided attribute has binary syntax.- Parameters:
attrName- the name of the attribute.schema- the schema.- Returns:
trueif the provided attribute has binary syntax,falseotherwise.
-
hasPasswordSyntax
public static boolean hasPasswordSyntax(String attrName, Schema schema)
Returns whether the provided attribute has password syntax.- Parameters:
attrName- the name of the attribute.schema- the schema.- Returns:
trueif the provided attribute has password syntax,falseotherwise.
-
getMatchingRuleText
public static String getMatchingRuleText(MatchingRule matchingRule)
Returns the string representation of a matching rule.- Parameters:
matchingRule- the matching rule.- Returns:
- the string representation of a matching rule.
-
getAdminConnection
public static ConnectionWrapper getAdminConnection(ControlPanelInfo controlInfo, DN bindDN, String pwd) throws IOException, ConfigReadException
Returns the connection 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.- Parameters:
controlInfo- the object which provides the connection parameters.bindDN- the base DN to be used to bind.pwd- the password to be used to bind.- Returns:
- the connection to the server.
- Throws:
IOException- if there was a problem connecting to the server or the provided credentials do not have enough rights.ConfigReadException- if there is an error reading the configuration.
-
getUserDataConnection
public static ConnectionWrapper getUserDataConnection(ControlPanelInfo controlInfo, DN bindDN, String pwd) throws IOException, ConfigReadException
Returns the connection 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.- Parameters:
controlInfo- the object which provides the connection parameters.bindDN- the base DN to be used to bind.pwd- the password to be used to bind.- Returns:
- the connection to the server.
- Throws:
IOException- if there was a problem connecting to the server or the provided credentials do not have enough rights.ConfigReadException- if there is an error reading the configuration.
-
ping
public static void ping(ConnectionWrapper connWrapper)
Ping the specified connection. This method sends a search request on the root entry of the DIT and forward the corresponding exception (if any).- Parameters:
connWrapper- the connection to be "pinged".
-
deleteConfigSubtree
public static void deleteConfigSubtree(ConfigurationHandler confHandler, DN dn) throws OpenDsException, ConfigException
Deletes a configuration subtree using the provided configuration handler.- Parameters:
confHandler- the configuration handler to be used to delete the subtree.dn- the DN of the subtree to be deleted.- Throws:
OpenDsException- if an error occurs.ConfigException- if an error occurs.
-
setRequiredIcon
public static void setRequiredIcon(JLabel label)
Sets the required icon to the provided label.- Parameters:
label- the label to be updated.
-
updateViewPositions
public static void updateViewPositions(ViewPositions pos)
Updates the scrolls with the provided points. This method uses SwingUtilities.invokeLater so it can be also called outside the event thread.- Parameters:
pos- the scroll and points.
-
getViewPositions
public static ViewPositions getViewPositions(Component comp)
Gets the view positions object for the provided component. This includes all the scroll panes inside the provided component.- Parameters:
comp- the component.- Returns:
- the view positions for the provided component.
-
getContainingScroll
public static JScrollPane getContainingScroll(Component comp)
Returns the scrollpane where the provided component is contained.nullif the component is not contained in any scrollpane.- Parameters:
comp- the component.- Returns:
- the scrollpane where the provided component is contained.
-
getFirstValueAsString
public static String getFirstValueAsString(Entry sr, String attrName)
Returns the first value as a String for a given attribute in the provided entry.- Parameters:
sr- the entry. It may benull.attrName- the attribute name.- Returns:
- the first value as a String for a given attribute in the provided entry.
-
getMonitoringValue
public static String getMonitoringValue(MonitoringAttributes attr, SearchResultEntry monitoringEntry)
Returns the monitoring value in a String form to be displayed to the user.- Parameters:
attr- the attribute to analyze.monitoringEntry- the monitoring entry.- Returns:
- the monitoring value in a String form to be displayed to the user.
-
addClickTooltipListener
public static void addClickTooltipListener(JComponent comp)
Adds a click tool tip listener to the provided component.- Parameters:
comp- the component.
-
updateComboBoxModel
public static void updateComboBoxModel(Collection<?> newElements, DefaultComboBoxModel model)
Updates a combo box model with a number of items. The method assumes that is being called from the event thread.- Parameters:
newElements- the new items for the combo box model.model- the combo box model to be updated.
-
updateComboBoxModel
public static void updateComboBoxModel(Collection<?> newElements, DefaultComboBoxModel model, Comparator<Object> comparator)
Updates a combo box model with a number of items. The method assumes that is being called from the event thread.- Parameters:
newElements- the new items for the combo box model.model- the combo box model to be updated.comparator- the object that will be used to compare the objects in the model. Ifnull, the equals method will be used.
-
computeMonitoringPossibleResults
public static void computeMonitoringPossibleResults(SearchResultEntry monitor1, SearchResultEntry monitor2, List<Integer> possibleResults, Collection<String> attrNames)
Computes the possible comparison results for monitoring information.- Parameters:
monitor1- the first monitor to comparemonitor2- the second monitor to comparepossibleResults- where possible results are outputattrNames- the names for which to compute possible comparison results
-
throwFirstFrom
public static <E extends Exception> void throwFirstFrom(List<? extends E> exceptions) throws E extends Exception
Throw the first exception of the list (if any).- Type Parameters:
E- The exception type- Parameters:
exceptions- A list of exceptions.- Throws:
E- The first element of the provided list (if the list is not empty).E extends Exception
-
initializeConfigurationFramework
public static void initializeConfigurationFramework()
Initialize the configuration framework.
-
isAttributeType
public static boolean isAttributeType(SchemaElement element)
Test whether provided schema element is an attribute type.- Parameters:
element- Element to check.- Returns:
trueiff element is an attribute type.
-
getAttributeConfigName
public static String getAttributeConfigName(SchemaElement element)
Returns the name of configuration attribute corresponding to the provided element.- Parameters:
element- Either an attribute type or an object class. Using any other schema element will return invalid result.- Returns:
- Either "attributeTypes" or "objectClasses"
-
getElementNameOrOID
public static String getElementNameOrOID(SchemaElement element)
Returns the name or OID of provided element.- Parameters:
element- Either an attribute type or an object class. Using any other schema element will yield an exception.- Returns:
- Either "attributeTypes" or "objectClasses"
-
getElementOID
public static String getElementOID(SchemaElement element)
Returns the OID of provided element.- Parameters:
element- Either an attribute type or an object class. Using any other schema element will yield an exception.- Returns:
- Either "attributeTypes" or "objectClasses"
-
getNewAttributeTypeWithNewSuperiorType
public static AttributeType getNewAttributeTypeWithNewSuperiorType(AttributeType attributeType, AttributeType newSuperiorType)
Return a new attribute type with the provided new superior type.- Parameters:
attributeType- Initial attribute type.newSuperiorType- new superior type to use.- Returns:
- the new attribute type
-
updateSchemaElementExtraPropertySingleValue
public static SchemaElement updateSchemaElementExtraPropertySingleValue(ServerContext serverContext, SchemaElement element, String property, String value)
Updates an extra property of provided schema element with a single value.- Parameters:
serverContext- the server contextelement- Either an attribute type or an object class. Using any other schema element will yield an exception.property- the property to setvalue- the value to set- Returns:
- the updated schema element
-
updateSchemaElementExtraPropertyMultiplesValues
public static SchemaElement updateSchemaElementExtraPropertyMultiplesValues(ServerContext serverContext, SchemaElement element, String property, List<String> values)
Updates an extra property of provided schema element with several values.- Parameters:
serverContext- the server contextelement- Either an attribute type or an object class. Using any other schema element will yield an exception.property- the property to setvalues- the list of values to set- Returns:
- the updated schema element
-
-