| | |
| | | import org.opends.server.types.ObjectClass; |
| | | import org.opends.server.types.RDN; |
| | | |
| | | import static org.opends.server.loggers.Debug.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugCought; |
| | | import static org.opends.server.loggers.debug.DebugLogger.debugEnabled; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | import static org.opends.server.messages.UtilityMessages.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | |
| | | */ |
| | | public final class StaticUtils |
| | | { |
| | | /** |
| | | * The fully-qualified name of this class for debugging purposes. |
| | | */ |
| | | private static final String CLASS_NAME = "org.opends.server.util.StaticUtils"; |
| | | |
| | | |
| | | |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "getBytes", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | try |
| | | { |
| | |
| | | } |
| | | catch (Exception e2) |
| | | { |
| | | assert debugException(CLASS_NAME, "getBytes", e2); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e2); |
| | | } |
| | | |
| | | return s.getBytes(); |
| | | } |
| | |
| | | */ |
| | | public static boolean needsBase64Encoding(byte[] valueBytes) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "needsBase64Encoding", |
| | | String.valueOf(valueBytes)); |
| | | |
| | | int length; |
| | | if ((valueBytes == null) || ((length = valueBytes.length) == 0)) |
| | |
| | | */ |
| | | public static boolean needsBase64Encoding(String valueString) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "needsBase64Encoding", |
| | | String.valueOf(valueString)); |
| | | |
| | | int length; |
| | | if ((valueString == null) || ((length = valueString.length()) == 0)) |
| | |
| | | */ |
| | | public static boolean mayUseExec() |
| | | { |
| | | assert debugEnter(CLASS_NAME, "mayUseExec"); |
| | | |
| | | String s = System.getProperty(PROPERTY_DISABLE_EXEC); |
| | | if (s == null) |
| | |
| | | Map<String,String> environment, List<String> output) |
| | | throws IOException, SecurityException |
| | | { |
| | | assert debugEnter(CLASS_NAME, "exec", String.valueOf(command), |
| | | String.valueOf(args)); |
| | | |
| | | |
| | | // See whether we'll allow the use of exec on this system. If not, then |
| | |
| | | } |
| | | catch (InterruptedException ie) |
| | | { |
| | | assert debugException(CLASS_NAME, "exec", ie); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, ie); |
| | | } |
| | | |
| | | // If this happens, then we have no choice but to forcefully terminate |
| | | // the process. |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "exec", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | |
| | | return process.exitValue(); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "exec", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (InterruptedException ie) |
| | | { |
| | | assert debugException(CLASS_NAME, "exec", ie); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, ie); |
| | | } |
| | | |
| | | // If this happens, then we have no choice but to forcefully terminate |
| | | // the process. |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "exec", e); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | |
| | | return process.exitValue(); |
| | |
| | | int endPos, |
| | | StringBuilder invalidReason) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "isValidSchemaElement", |
| | | String.valueOf(element), String.valueOf(startPos), |
| | | String.valueOf(endPos), "java.lang.StringBuilder"); |
| | | |
| | | |
| | | if ((element == null) || (startPos >= endPos)) |
| | |
| | | */ |
| | | public static String toLowerCase(String s) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toLowerCase", String.valueOf(s)); |
| | | |
| | | if (s == null) |
| | | { |
| | |
| | | */ |
| | | public static void toLowerCase(String s, StringBuilder buffer) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toLowerCase", String.valueOf(s), |
| | | "java.lang.StringBuilder"); |
| | | |
| | | if (s == null) |
| | | { |
| | |
| | | */ |
| | | public static void toLowerCase(byte[] b, StringBuilder buffer, boolean trim) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toLowerCase", String.valueOf(b), |
| | | "java.lang.StringBuilder", String.valueOf(trim)); |
| | | |
| | | if (b == null) |
| | | { |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "toLowerCase", e); |
| | | buffer.append(new String(b, i, (length-i)).toLowerCase()); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | buffer.append(new String(b, i, (length - i)).toLowerCase()); |
| | | } |
| | | break; |
| | | } |
| | |
| | | */ |
| | | public static String toUpperCase(String s) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toUpperCase", String.valueOf(s)); |
| | | |
| | | if (s == null) |
| | | { |
| | |
| | | */ |
| | | public static void toUpperCase(String s, StringBuilder buffer) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toUpperCase", String.valueOf(s), |
| | | "java.lang.StringBuilder"); |
| | | |
| | | if (s == null) |
| | | { |
| | |
| | | */ |
| | | public static void toUpperCase(byte[] b, StringBuilder buffer, boolean trim) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toUpperCase", String.valueOf(b), |
| | | "java.lang.StringBuilder", String.valueOf(trim)); |
| | | |
| | | if (b == null) |
| | | { |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | assert debugException(CLASS_NAME, "toUpperCase", e); |
| | | buffer.append(new String(b, i, (length-i)).toUpperCase()); |
| | | if (debugEnabled()) |
| | | { |
| | | debugCought(DebugLogLevel.ERROR, e); |
| | | } |
| | | buffer.append(new String(b, i, (length - i)).toUpperCase()); |
| | | } |
| | | break; |
| | | } |
| | |
| | | public static StringBuilder toRFC3641StringValue(StringBuilder builder, |
| | | String string) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "toRFC3641StringValue"); |
| | | |
| | | // Initial double-quote. |
| | | builder.append('"'); |
| | |
| | | */ |
| | | public static String[] listToArray(List<String> stringList) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "listToArray", "java.util.List<String>"); |
| | | |
| | | if (stringList == null) |
| | | { |
| | |
| | | */ |
| | | public static ArrayList<String> arrayToList(String[] stringArray) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "arrayToList", String.valueOf(stringArray)); |
| | | |
| | | if (stringArray == null) |
| | | { |
| | |
| | | */ |
| | | public static boolean recursiveDelete(File file) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "recursiveDelete", String.valueOf(file)); |
| | | |
| | | boolean successful = true; |
| | | if (file.isDirectory()) |
| | |
| | | */ |
| | | public static boolean isRelativePath(String path) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "isRelativePath", String.valueOf(path)); |
| | | |
| | | File f = new File(path); |
| | | return (! f.isAbsolute()); |
| | |
| | | */ |
| | | public static File getFileForPath(String path) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "getFileForPath", String.valueOf(path)); |
| | | |
| | | File f = new File (path); |
| | | |
| | |
| | | */ |
| | | public static Entry createEntry(DN dn) |
| | | { |
| | | assert debugEnter(CLASS_NAME, "createEntry", String.valueOf(dn)); |
| | | |
| | | |
| | | // If the provided DN was null or empty, then return null because we don't |