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.onehippo.cms7.essentials.components.cms.modules.BlogListenerModule.java

private String[] readStrings(final Node node, final String propertyName) {
    try {//  w w  w. j ava 2s  .  c o m
        if (node.hasProperty(propertyName)) {
            final Property property = node.getProperty(propertyName);
            final List<String> retVal = new ArrayList<>();
            if (property.isMultiple()) {
                final Value[] values = property.getValues();
                for (Value value : values) {
                    final String myUrl = value.getString();
                    retVal.add(myUrl);
                }
            }
            return retVal.toArray(new String[retVal.size()]);
        }

    } catch (RepositoryException e) {
        log.error("Error reading property", e);
    }
    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.onehippo.cms7.essentials.components.utils.SiteUtils.java

/**
 * For given string, comma separate it and convert to array
 *
 * @param inputString comma separated document types
 * @return empty array if null or empty/* w w w  . j  a va2s .  c  o  m*/
 */
@Nonnull
public static String[] parseCommaSeparatedValue(final String inputString) {
    if (Strings.isNullOrEmpty(inputString)) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }
    final Iterable<String> iterable = Splitter.on(",").trimResults().omitEmptyStrings().split(inputString);
    return Iterables.toArray(iterable, String.class);
}

From source file:org.onehippo.cms7.essentials.dashboard.instruction.CndInstruction.java

@Override
public InstructionStatus process(final PluginContext context, final InstructionStatus previousStatus) {
    if (Strings.isNullOrEmpty(namespacePrefix)) {
        namespace = context.getProjectNamespacePrefix();
    } else {//  w ww.j a  va  2  s . c  o  m
        namespace = namespacePrefix;
    }
    final Map<String, Object> data = context.getPlaceholderData();
    processAllPlaceholders(data);
    //

    final String prefix = context.getProjectNamespacePrefix();
    final Session session = context.createSession();
    try {
        // TODO extend so we can define supertypes
        String[] superTypes;
        if (!Strings.isNullOrEmpty(superType)) {
            final Iterable<String> split = Splitter.on(",").omitEmptyStrings().trimResults().split(superType);
            superTypes = Iterables.toArray(split, String.class);
        } else {
            superTypes = ArrayUtils.EMPTY_STRING_ARRAY;
        }
        CndUtils.registerDocumentType(context, prefix, documentType, true, false, superTypes);
        session.save();
        // TODO add message
        eventBus.post(new InstructionEvent(this));
        return InstructionStatus.SUCCESS;
    } catch (NodeTypeExistsException e) {
        // just add already exiting ones:
        GlobalUtils.refreshSession(session, false);

    } catch (RepositoryException e) {
        log.error(String.format("Error registering document type: %s", namespace), e);
        GlobalUtils.refreshSession(session, false);
    } finally {
        GlobalUtils.cleanupSession(session);
    }

    message = messageRegisterError;
    eventBus.post(new InstructionEvent(this));
    return InstructionStatus.FAILED;
}

From source file:org.onehippo.cms7.essentials.dashboard.utils.PayloadUtils.java

public static String[] extractValueArray(final String value) {
    if (Strings.isNullOrEmpty(value)) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }/*from ww w.j a v  a  2 s  . co m*/
    final List<String> strings = extractValueList(value);
    return strings.toArray(new String[strings.size()]);
}

From source file:org.onehippo.forge.content.exim.core.util.HippoNodeUtils.java

/**
 * Detects if the document handle is representing a live document at the moment.
 * @param handle document handle node/*from   w  w w.  ja  v  a 2 s.  c  om*/
 * @return true if the document handle is representing a live document at the moment
 * @throws RepositoryException if any repository/workflow exception occurs
 */
public static boolean isDocumentHandleLive(final Node handle) throws RepositoryException {
    Node liveVariant = getDocumentVariantByHippoStdState(handle, HippoStdNodeType.PUBLISHED);

    if (liveVariant != null) {
        String[] availabilities = JcrUtils.getMultipleStringProperty(liveVariant,
                HippoNodeType.HIPPO_AVAILABILITY, ArrayUtils.EMPTY_STRING_ARRAY);
        for (String availability : availabilities) {
            if (StringUtils.equals("live", availability)) {
                return true;
            }
        }
    }

    return false;
}

From source file:org.onehippo.forge.folderctxmenus.common.FolderCopyTask.java

/**
 * Takes offline all the hippo documents under the {@code destFolderNode}.
 *///w  w  w  .j a v  a  2s.  c  o  m
protected void takeOfflineHippoDocs() {
    String destFolderNodePath = null;

    try {
        destFolderNodePath = getDestFolderNode().getPath();

        JcrTraverseUtils.traverseNodes(getDestFolderNode(), new NodeTraverser() {
            @Override
            public boolean isAcceptable(Node node) throws RepositoryException {
                if (!node.isNodeType("hippostdpubwf:document")) {
                    return false;
                }

                return isLiveVariantNode(node) && StringUtils.equals("published",
                        JcrUtils.getStringProperty(node, "hippostd:state", null));
            }

            @Override
            public boolean isTraversable(Node node) throws RepositoryException {
                return !node.isNodeType("hippostdpubwf:document");
            }

            private boolean isLiveVariantNode(final Node variantNode) throws RepositoryException {
                if (variantNode.hasProperty("hippo:availability")) {
                    for (Value value : variantNode.getProperty("hippo:availability").getValues()) {
                        if (StringUtils.equals("live", value.getString())) {
                            return true;
                        }
                    }
                }

                return false;
            }

            @Override
            public void accept(Node liveVariant) throws RepositoryException {
                liveVariant.setProperty("hippo:availability", ArrayUtils.EMPTY_STRING_ARRAY);
                liveVariant.setProperty("hippostd:stateSummary", "new");
            }
        });
    } catch (RepositoryException e) {
        getLogger().error("Failed to take offline link hippostd:publishableSummary nodes under {}.",
                destFolderNodePath, e);
    }
}

From source file:org.opencloudengine.flamingo.mapreduce.util.StringUtils.java

/**
 * Performs the logic for the <code>split</code> and
 * <code>splitPreserveAllTokens</code> methods that return a maximum array
 * length.//from ww w.ja  v  a  2s.c  o m
 *
 * @param str               the String to parse, may be <code>null</code>
 * @param separatorChars    the separate character
 * @param max               the maximum number of elements to include in the
 *                          array. A zero or negative value implies no limit.
 * @param preserveAllTokens if <code>true</code>, adjacent separators are
 *                          treated as empty token separators; if <code>false</code>, adjacent
 *                          separators are treated as one separator.
 * @return an array of parsed Strings, <code>null</code> if null String input
 */
private static String[] splitWorker(String str, String separatorChars, int max, boolean preserveAllTokens) {
    // Performance tuned for 2.0 (JDK1.4)
    // Direct code is quicker than StringTokenizer.
    // Also, StringTokenizer uses isSpace() not isWhitespace()

    if (str == null) {
        return null;
    }
    int len = str.length();
    if (len == 0) {
        return ArrayUtils.EMPTY_STRING_ARRAY;
    }
    List list = new ArrayList();
    int sizePlus1 = 1;
    int i = 0, start = 0;
    boolean match = false;
    boolean lastMatch = false;
    if (separatorChars == null) {
        // Null separator means use whitespace
        while (i < len) {
            if (Character.isWhitespace(str.charAt(i))) {
                if (match || preserveAllTokens) {
                    lastMatch = true;
                    if (sizePlus1++ == max) {
                        i = len;
                        lastMatch = false;
                    }
                    list.add(str.substring(start, i));
                    match = false;
                }
                start = ++i;
                continue;
            }
            lastMatch = false;
            match = true;
            i++;
        }
    } else if (separatorChars.length() == 1) {
        // Optimise 1 character case
        char sep = separatorChars.charAt(0);
        while (i < len) {
            if (str.charAt(i) == sep) {
                if (match || preserveAllTokens) {
                    lastMatch = true;
                    if (sizePlus1++ == max) {
                        i = len;
                        lastMatch = false;
                    }
                    list.add(str.substring(start, i));
                    match = false;
                }
                start = ++i;
                continue;
            }
            lastMatch = false;
            match = true;
            i++;
        }
    } else {
        // standard case
        while (i < len) {
            if (separatorChars.indexOf(str.charAt(i)) >= 0) {
                if (match || preserveAllTokens) {
                    lastMatch = true;
                    if (sizePlus1++ == max) {
                        i = len;
                        lastMatch = false;
                    }
                    if ("".equals(str.substring(start, i)) == false)
                        list.add(str.substring(start, i));
                    match = false;
                }
                start = ++i;
                continue;
            }
            lastMatch = false;
            match = true;
            i++;
        }
    }
    if (match || (preserveAllTokens && lastMatch)) {
        list.add(str.substring(start, i));
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:org.openhab.tools.analysis.checkstyle.test.KarafFeatureCheckTest.java

@Test
public void testIncludedBundle() throws Exception {
    verify("includedBundle", ArrayUtils.EMPTY_STRING_ARRAY);
}

From source file:org.openhab.tools.analysis.checkstyle.test.KarafFeatureCheckTest.java

@Test
public void testIncludedBundleWithParentGroupIdOnly() throws Exception {
    verify("includedBundleWithParentGroupIdOnly", ArrayUtils.EMPTY_STRING_ARRAY);
}

From source file:org.openhab.tools.analysis.checkstyle.test.KarafFeatureCheckTest.java

@Test
public void testInvalidBundle() throws Exception {
    verify("invalidBundle", ArrayUtils.EMPTY_STRING_ARRAY);

    org.mockito.Mockito.verify(handler, times(1)).publish(captor.capture());

    assertThat(captor.getValue().getLevel(), is(Level.WARNING));
    assertThat(captor.getValue().getMessage(), startsWith(
            "KarafFeatureCheck will be skipped. Could not find Maven group ID (parent group ID) or artifact ID in"));
}