Example usage for org.apache.commons.lang ArrayUtils EMPTY_STRING_ARRAY

List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_STRING_ARRAY

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils EMPTY_STRING_ARRAY.

Prototype

String[] EMPTY_STRING_ARRAY

To view the source code for org.apache.commons.lang ArrayUtils EMPTY_STRING_ARRAY.

Click Source Link

Document

An empty immutable String array.

Usage

From source file:org.apache.archiva.common.utils.VersionComparator.java

public static String[] toParts(String version) {
    if (StringUtils.isBlank(version)) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }//  w ww.  ja v  a  2  s.  c  o  m

    int modeOther = 0;
    int modeDigit = 1;
    int modeText = 2;

    List<String> parts = new ArrayList<>();
    int len = version.length();
    int i = 0;
    int start = 0;
    int mode = modeOther;

    while (i < len) {
        char c = version.charAt(i);

        if (Character.isDigit(c)) {
            if (mode != modeDigit) {
                if (mode != modeOther) {
                    parts.add(version.substring(start, i));
                }
                mode = modeDigit;
                start = i;
            }
        } else if (Character.isLetter(c)) {
            if (mode != modeText) {
                if (mode != modeOther) {
                    parts.add(version.substring(start, i));
                }
                mode = modeText;
                start = i;
            }
        } else {
            // Other.
            if (mode != modeOther) {
                parts.add(version.substring(start, i));
                mode = modeOther;
            }
        }

        i++;
    }

    // Add remainder
    if (mode != modeOther) {
        parts.add(version.substring(start, i));
    }

    return parts.toArray(new String[parts.size()]);
}

From source file:org.apache.directory.server.core.api.interceptor.context.FilteringOperationContext.java

public void setReturningAttributes(String... attributeIds) {
    if ((attributeIds != null) && (attributeIds.length != 0) && (attributeIds[0] != null)) {
        // We have something in the list
        // first, ignore all the unkown AT and convert the strings to 
        // AttributeTypeOptions
        returningAttributes = new HashSet<>();
        Set<String> attributesString = new HashSet<>();

        Set<AttributeTypeOptions> collectedAttributes = collectAttributeTypes(attributeIds);

        // If we have valid, '*' or '+' attributes, we can get rid of the NoAttributes flag
        if (!collectedAttributes.isEmpty() || allUserAttributes || allOperationalAttributes) {
            noAttributes = false;/*from w ww  .  j av  a2  s. com*/
        }

        // Now, loop on the list of attributes, and remove all the USER attributes if
        // we have the '*' attribute, and remove all the OPERATIONAL attributes if we
        // have the '+' attribute
        if (!collectedAttributes.isEmpty()) {
            for (AttributeTypeOptions attributeTypeOption : collectedAttributes) {
                if (attributeTypeOption.getAttributeType().isUser() && !allUserAttributes) {
                    // We can add the AttributeType in the list of returningAttributeTypes
                    returningAttributes.add(attributeTypeOption);
                    attributesString.add(attributeTypeOption.getAttributeType().getOid());
                }

                if (attributeTypeOption.getAttributeType().isOperational() && !allOperationalAttributes) {
                    // We can add the AttributeType in the list of returningAttributeTypes
                    returningAttributes.add(attributeTypeOption);
                    attributesString.add(attributeTypeOption.getAttributeType().getOid());
                }
            }
        }

        if (!attributesString.isEmpty()) {
            // We have some valid attributes, lt's convert it to String
            returningAttributesString = attributesString.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
        } else {
            // No valid attributes remaining, that means they were all invalid
            returningAttributesString = ArrayUtils.EMPTY_STRING_ARRAY;
        }
    } else {
        // Nothing in the list : default to '*'
        allUserAttributes = true;
        returningAttributesString = ArrayUtils.EMPTY_STRING_ARRAY;
    }
}

From source file:org.apache.directory.studio.ldapbrowser.common.dialogs.RenameEntryDialog.java

/**     
 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 *//* w  w w.j  a  v  a 2  s  .c  o  m*/
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH) * 3 / 2;
    composite.setLayoutData(gd);

    BaseWidgetUtils.createLabel(composite, Messages.getString("RenameEntryDialog.RenameEntryDescription"), 1); //$NON-NLS-1$

    dnBuilderWidget = new DnBuilderWidget(true, false);
    dnBuilderWidget.addWidgetModifyListener(this);
    dnBuilderWidget.createContents(composite);
    Collection<AttributeType> allAtds = SchemaUtils.getAllAttributeTypeDescriptions(entry);
    String[] allAttributeNames = SchemaUtils.getNames(allAtds).toArray(ArrayUtils.EMPTY_STRING_ARRAY);
    dnBuilderWidget.setInput(entry.getBrowserConnection(), allAttributeNames, entry.getRdn(), null);

    applyDialogFont(composite);

    initialized = true;

    return composite;
}

From source file:org.apache.directory.studio.ldapbrowser.common.wizards.NewEntryDnWizardPage.java

/**
 * Initializes the Dn builder widget with the Dn of
 * the prototype entry. Called when this page becomes visible.
 *///from w w w. j  a  v a2s .  c om
private void loadState() {
    DummyEntry newEntry = wizard.getPrototypeEntry();

    if (wizard.isNewContextEntry()) {
        IAttribute attribute = wizard.getSelectedConnection().getRootDSE()
                .getAttribute(SchemaConstants.NAMING_CONTEXTS_AT);
        if (attribute != null) {
            String[] values = attribute.getStringValues();

            // content proposals
            contextEntryDnComboCPA.setContentProposalProvider(new ListContentProposalProvider(values));

            // fill namingContext values into combo 
            contextEntryDnCombo.setItems(values);

            // preset combo text
            if (Arrays.asList(values).contains(newEntry.getDn().getName())) {
                contextEntryDnCombo.setText(newEntry.getDn().getName());
            }
        }
    } else {
        Collection<AttributeType> atds = SchemaUtils.getAllAttributeTypeDescriptions(newEntry);
        String[] attributeNames = SchemaUtils.getNames(atds).toArray(ArrayUtils.EMPTY_STRING_ARRAY);

        Dn parentDn = null;

        boolean hasSelectedEntry = wizard.getSelectedEntry() != null;
        boolean newEntryParentDnNotNullOrEmpty = !Dn.isNullOrEmpty(newEntry.getDn().getParent());

        if (hasSelectedEntry) {
            boolean newEntryDnEqualsSelectedEntryDn = newEntry.getDn()
                    .equals(wizard.getSelectedEntry().getDn());

            if (newEntryDnEqualsSelectedEntryDn && newEntryParentDnNotNullOrEmpty) {
                parentDn = newEntry.getDn().getParent();
            } else {
                parentDn = wizard.getSelectedEntry().getDn();
            }
        } else if (newEntryParentDnNotNullOrEmpty) {
            parentDn = newEntry.getDn().getParent();
        }

        Rdn rdn = newEntry.getRdn();

        dnBuilderWidget.setInput(wizard.getSelectedConnection(), attributeNames, rdn, parentDn);
    }
}

From source file:org.apache.directory.studio.ldapbrowser.common.wizards.NewEntryDnWizardPage.java

/**
 * {@inheritDoc}/*from w  w  w .  java 2 s .c  o m*/
 */
public void createControl(Composite parent) {
    if (wizard.isNewContextEntry()) {
        // the combo
        Composite composite = BaseWidgetUtils.createColumnContainer(parent, 1, 1);
        contextEntryDnCombo = BaseWidgetUtils.createCombo(composite, ArrayUtils.EMPTY_STRING_ARRAY, 0, 1);
        contextEntryDnCombo.addModifyListener(event -> validate());

        // attach content proposal behavior
        contextEntryDnComboCPA = new ContentProposalAdapter(contextEntryDnCombo, new ComboContentAdapter(),
                null, null, null);
        contextEntryDnComboCPA.setFilterStyle(ContentProposalAdapter.FILTER_NONE);
        contextEntryDnComboCPA.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

        setControl(composite);
    } else {
        dnBuilderWidget = new DnBuilderWidget(true, true);
        dnBuilderWidget.addWidgetModifyListener(this);
        Composite composite = dnBuilderWidget.createContents(parent);
        setControl(composite);
    }
}

From source file:org.apache.geode.management.internal.cli.commands.StartMemberUtils.java

static String toClasspath(final boolean includeSystemClasspath, String[] jarFilePathnames,
        String... userClasspaths) {
    // gemfire jar must absolutely be the first JAR file on the CLASSPATH!!!
    StringBuilder classpath = new StringBuilder(getGemFireJarPath());

    userClasspaths = (userClasspaths != null ? userClasspaths : ArrayUtils.EMPTY_STRING_ARRAY);

    // Then, include user-specified classes on CLASSPATH to enable the user to override GemFire JAR
    // dependencies
    // with application-specific versions; this logic/block corresponds to classes/jar-files
    // specified with the
    // --classpath option to the 'start locator' and 'start server commands'; also this will
    // override any
    // System CLASSPATH environment variable setting, which is consistent with the Java platform
    // behavior...
    for (String userClasspath : userClasspaths) {
        if (StringUtils.isNotBlank(userClasspath)) {
            classpath.append((classpath.length() == 0) ? StringUtils.EMPTY : File.pathSeparator);
            classpath.append(userClasspath);
        }/*from w  ww  . j  av  a 2  s.  c  om*/
    }

    // Now, include any System-specified CLASSPATH environment variable setting...
    if (includeSystemClasspath) {
        classpath.append(File.pathSeparator);
        classpath.append(getSystemClasspath());
    }

    jarFilePathnames = (jarFilePathnames != null ? jarFilePathnames : ArrayUtils.EMPTY_STRING_ARRAY);

    // And finally, include all GemFire dependencies on the CLASSPATH...
    for (String jarFilePathname : jarFilePathnames) {
        if (StringUtils.isNotBlank(jarFilePathname)) {
            classpath.append((classpath.length() == 0) ? StringUtils.EMPTY : File.pathSeparator);
            classpath.append(jarFilePathname);
        }
    }
    return classpath.toString();
}

From source file:org.apache.geode.management.internal.web.controllers.ShellCommandsController.java

@RequestMapping(method = RequestMethod.POST, value = "/mbean/operation")
public ResponseEntity<?> invoke(@RequestParam("resourceName") final String resourceName,
        @RequestParam("operationName") final String operationName,
        @RequestParam(value = "signature", required = false) String[] signature,
        @RequestParam(value = "parameters", required = false) Object[] parameters)
        throws MalformedObjectNameException, MBeanException, InstanceNotFoundException, ReflectionException,
        IOException {/* w w  w.ja  v a  2 s . c  o  m*/
    // Exceptions are caught by the @ExceptionHandler AbstractCommandsController.handleAppException
    signature = (signature != null ? signature : ArrayUtils.EMPTY_STRING_ARRAY);
    parameters = (parameters != null ? parameters : ObjectUtils.EMPTY_OBJECT_ARRAY);
    MBeanServer mBeanServer = getMBeanServer();
    ObjectName objectName = ObjectName.getInstance(decode(resourceName));
    final Object result = mBeanServer.invoke(objectName, decode(operationName), parameters, signature);
    byte[] serializedResult = IOUtils.serializeObject(result);
    return new ResponseEntity<>(serializedResult, HttpStatus.OK);
}

From source file:org.apache.hadoop.hbase.rest.HBaseRESTTestingUtility.java

public void startServletContainer(Configuration conf) throws Exception {
    if (server != null) {
        LOG.error("ServletContainer already running");
        return;//from  ww  w .j  a v  a  2s  .  com
    }

    // Inject the conf for the test by being first to make singleton
    RESTServlet.getInstance(conf, User.getCurrent().getUGI());

    // set up the Jersey servlet container for Jetty
    ServletHolder sh = new ServletHolder(ServletContainer.class);
    sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
            ResourceConfig.class.getCanonicalName());
    sh.setInitParameter("com.sun.jersey.config.property.packages", "jetty");

    LOG.info("configured " + ServletContainer.class.getName());

    // set up Jetty and run the embedded server
    server = new Server(0);
    server.setSendServerVersion(false);
    server.setSendDateHeader(false);
    // set up context
    Context context = new Context(server, "/", Context.SESSIONS);
    context.addServlet(sh, "/*");
    // Load filters specified from configuration.
    String[] filterClasses = conf.getStrings(Constants.FILTER_CLASSES, ArrayUtils.EMPTY_STRING_ARRAY);
    for (String filter : filterClasses) {
        filter = filter.trim();
        context.addFilter(Class.forName(filter), "/*", 0);
    }
    HttpServerUtil.constrainHttpMethods(context);
    LOG.info("Loaded filter classes :" + filterClasses);
    // start the server
    server.start();
    // get the port
    testServletPort = server.getConnectors()[0].getLocalPort();

    LOG.info("started " + server.getClass().getName() + " on port " + testServletPort);
}

From source file:org.apache.hadoop.hbase.rest.RESTServer.java

/**
 * The main method for the HBase rest server.
 * @param args command-line arguments/*from  ww w. j  av  a 2 s .  c  om*/
 * @throws Exception exception
 */
public static void main(String[] args) throws Exception {
    Log LOG = LogFactory.getLog("RESTServer");

    VersionInfo.logVersion();
    FilterHolder authFilter = null;
    Configuration conf = HBaseConfiguration.create();
    Class<? extends ServletContainer> containerClass = ServletContainer.class;
    UserProvider userProvider = UserProvider.instantiate(conf);
    // login the server principal (if using secure Hadoop)
    if (userProvider.isHadoopSecurityEnabled() && userProvider.isHBaseSecurityEnabled()) {
        String machineName = Strings.domainNamePointerToHostName(DNS.getDefaultHost(
                conf.get(REST_DNS_INTERFACE, "default"), conf.get(REST_DNS_NAMESERVER, "default")));
        String keytabFilename = conf.get(REST_KEYTAB_FILE);
        Preconditions.checkArgument(keytabFilename != null && !keytabFilename.isEmpty(),
                REST_KEYTAB_FILE + " should be set if security is enabled");
        String principalConfig = conf.get(REST_KERBEROS_PRINCIPAL);
        Preconditions.checkArgument(principalConfig != null && !principalConfig.isEmpty(),
                REST_KERBEROS_PRINCIPAL + " should be set if security is enabled");
        userProvider.login(REST_KEYTAB_FILE, REST_KERBEROS_PRINCIPAL, machineName);
        if (conf.get(REST_AUTHENTICATION_TYPE) != null) {
            containerClass = RESTServletContainer.class;
            authFilter = new FilterHolder();
            authFilter.setClassName(AuthFilter.class.getName());
            authFilter.setName("AuthenticationFilter");
        }
    }

    UserGroupInformation realUser = userProvider.getCurrent().getUGI();
    RESTServlet servlet = RESTServlet.getInstance(conf, realUser);

    Options options = new Options();
    options.addOption("p", "port", true, "Port to bind to [default: 8080]");
    options.addOption("ro", "readonly", false,
            "Respond only to GET HTTP " + "method requests [default: false]");
    options.addOption(null, "infoport", true, "Port for web UI");

    CommandLine commandLine = null;
    try {
        commandLine = new PosixParser().parse(options, args);
    } catch (ParseException e) {
        LOG.error("Could not parse: ", e);
        printUsageAndExit(options, -1);
    }

    // check for user-defined port setting, if so override the conf
    if (commandLine != null && commandLine.hasOption("port")) {
        String val = commandLine.getOptionValue("port");
        servlet.getConfiguration().setInt("hbase.rest.port", Integer.valueOf(val));
        LOG.debug("port set to " + val);
    }

    // check if server should only process GET requests, if so override the conf
    if (commandLine != null && commandLine.hasOption("readonly")) {
        servlet.getConfiguration().setBoolean("hbase.rest.readonly", true);
        LOG.debug("readonly set to true");
    }

    // check for user-defined info server port setting, if so override the conf
    if (commandLine != null && commandLine.hasOption("infoport")) {
        String val = commandLine.getOptionValue("infoport");
        servlet.getConfiguration().setInt("hbase.rest.info.port", Integer.valueOf(val));
        LOG.debug("Web UI port set to " + val);
    }

    @SuppressWarnings("unchecked")
    List<String> remainingArgs = commandLine != null ? commandLine.getArgList() : new ArrayList<String>();
    if (remainingArgs.size() != 1) {
        printUsageAndExit(options, 1);
    }

    String command = remainingArgs.get(0);
    if ("start".equals(command)) {
        // continue and start container
    } else if ("stop".equals(command)) {
        System.exit(1);
    } else {
        printUsageAndExit(options, 1);
    }

    // set up the Jersey servlet container for Jetty
    ServletHolder sh = new ServletHolder(containerClass);
    sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
            ResourceConfig.class.getCanonicalName());
    sh.setInitParameter("com.sun.jersey.config.property.packages", "jetty");
    // The servlet holder below is instantiated to only handle the case
    // of the /status/cluster returning arrays of nodes (live/dead). Without
    // this servlet holder, the problem is that the node arrays in the response
    // are collapsed to single nodes. We want to be able to treat the
    // node lists as POJO in the response to /status/cluster servlet call,
    // but not change the behavior for any of the other servlets
    // Hence we don't use the servlet holder for all servlets / paths
    ServletHolder shPojoMap = new ServletHolder(containerClass);
    @SuppressWarnings("unchecked")
    Map<String, String> shInitMap = sh.getInitParameters();
    for (Entry<String, String> e : shInitMap.entrySet()) {
        shPojoMap.setInitParameter(e.getKey(), e.getValue());
    }
    shPojoMap.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true");

    // set up Jetty and run the embedded server

    Server server = new Server();

    Connector connector = new SelectChannelConnector();
    if (conf.getBoolean(REST_SSL_ENABLED, false)) {
        SslSelectChannelConnector sslConnector = new SslSelectChannelConnector();
        String keystore = conf.get(REST_SSL_KEYSTORE_STORE);
        String password = conf.get(REST_SSL_KEYSTORE_PASSWORD);
        String keyPassword = conf.get(REST_SSL_KEYSTORE_KEYPASSWORD, password);
        sslConnector.setKeystore(keystore);
        sslConnector.setPassword(password);
        sslConnector.setKeyPassword(keyPassword);
        connector = sslConnector;
    }
    connector.setPort(servlet.getConfiguration().getInt("hbase.rest.port", 8080));
    connector.setHost(servlet.getConfiguration().get("hbase.rest.host", "0.0.0.0"));

    server.addConnector(connector);

    // Set the default max thread number to 100 to limit
    // the number of concurrent requests so that REST server doesn't OOM easily.
    // Jetty set the default max thread number to 250, if we don't set it.
    //
    // Our default min thread number 2 is the same as that used by Jetty.
    int maxThreads = servlet.getConfiguration().getInt("hbase.rest.threads.max", 100);
    int minThreads = servlet.getConfiguration().getInt("hbase.rest.threads.min", 2);
    QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads);
    threadPool.setMinThreads(minThreads);
    server.setThreadPool(threadPool);

    server.setSendServerVersion(false);
    server.setSendDateHeader(false);
    server.setStopAtShutdown(true);
    // set up context
    Context context = new Context(server, "/", Context.SESSIONS);
    context.addServlet(shPojoMap, "/status/cluster");
    context.addServlet(sh, "/*");
    if (authFilter != null) {
        context.addFilter(authFilter, "/*", 1);
    }

    // Load filters from configuration.
    String[] filterClasses = servlet.getConfiguration().getStrings(FILTER_CLASSES,
            ArrayUtils.EMPTY_STRING_ARRAY);
    for (String filter : filterClasses) {
        filter = filter.trim();
        context.addFilter(Class.forName(filter), "/*", 0);
    }
    HttpServerUtil.constrainHttpMethods(context);

    // Put up info server.
    int port = conf.getInt("hbase.rest.info.port", 8085);
    if (port >= 0) {
        conf.setLong("startcode", System.currentTimeMillis());
        String a = conf.get("hbase.rest.info.bindAddress", "0.0.0.0");
        InfoServer infoServer = new InfoServer("rest", a, port, false, conf);
        infoServer.setAttribute("hbase.conf", conf);
        infoServer.start();
    }

    // start server
    server.start();
    server.join();
}

From source file:org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset.java

@Override // FsDatasetSpi
public VolumeFailureSummary getVolumeFailureSummary() {
    return new VolumeFailureSummary(ArrayUtils.EMPTY_STRING_ARRAY, 0, 0);
}