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.exoplatform.social.core.storage.memory.InMemoryActivityStorageImpl.java

/**
 * Persist the comment in memory to storage
 * //from  w  ww . ja  va2  s. co m
 * @param activity
 * @param comment
 * @throws ActivityStorageException
 */
public void persistCommentInMemory(ExoSocialActivity activity, ExoSocialActivity comment)
        throws ActivityStorageException {

    try {
        //
        long currentMillis = System.currentTimeMillis();
        long commentMillis = (comment.getPostedTime() != null ? comment.getPostedTime() : currentMillis);
        ActivityEntity activityEntity = _findById(ActivityEntity.class, activity.getId());
        ActivityEntity commentEntity = activityEntity.createComment(String.valueOf(commentMillis));

        //
        long oldUpdated = getLastUpdatedTime(activityEntity);

        activityEntity.getComments().add(commentEntity);
        activityEntity.setMentioners(activity.getMentionedIds());
        activityEntity.setCommenters(activity.getCommentedIds());
        activityEntity.setLastUpdated(commentEntity.getPostedTime());

        //
        HidableEntity hidable = _getMixin(commentEntity, HidableEntity.class, true);
        hidable.setHidden(comment.isHidden());
        commentEntity.setTitle(comment.getTitle());
        commentEntity.setType(comment.getType());
        commentEntity.setTitleId(comment.getTitleId());
        commentEntity.setBody(comment.getBody());
        commentEntity.setIdentity(activityEntity.getIdentity());
        commentEntity.setPosterIdentity(_findById(IdentityEntity.class, comment.getUserId()));
        commentEntity.setComment(Boolean.TRUE);
        commentEntity.setPostedTime(commentMillis);
        commentEntity.setLastUpdated(commentMillis);
        commentEntity.setMentioners(processMentions(ArrayUtils.EMPTY_STRING_ARRAY, comment.getTitle(),
                new ArrayList<String>(), true));

        Map<String, String> params = comment.getTemplateParams();
        if (params != null) {
            commentEntity.putParams(params);
        }

        comment.setParentId(activity.getId());
        comment.setId(commentEntity.getId());

        List<String> commenters = StorageUtils.getIdentityIds(activityEntity.getCommenters());
        List<String> mentioners = StorageUtils.getIdentityIds(commentEntity.getMentioners());
        //
        //
        if (mustInjectStreams) {
            Identity identity = identityStorage.findIdentityById(comment.getUserId());
            StreamInvocationHelper.updateCommenter(identity, activityEntity, commenters.toArray(new String[0]),
                    oldUpdated);
            //make sure there is no duplicated identity in commenters and mentioners list 
            processIdentitiesList(mentioners, commenters.toArray(new String[0]));
            StreamInvocationHelper.addMentioners(activity, mentioners.toArray(new String[0]));
            //only update what's hot when add comment the current day after the last updated of activity
            if (StorageUtils.afterDayOrMore(oldUpdated, currentMillis)) {
                StreamInvocationHelper.update(activity, oldUpdated);
            }
        }
    } catch (NodeNotFoundException e) {
        throw new ActivityStorageException(ActivityStorageException.Type.FAILED_TO_SAVE_COMMENT, e.getMessage(),
                e);
    } catch (ChromatticException ex) {
        Throwable throwable = ex.getCause();
        if (throwable instanceof ItemExistsException || throwable instanceof InvalidItemStateException) {
            LOG.warn("Probably was inserted activity by another session", ex);
            LOG.debug(ex.getMessage(), ex);
        } else {
            throw new ActivityStorageException(ActivityStorageException.Type.FAILED_TO_SAVE_ACTIVITY,
                    ex.getMessage());
        }
    }

    LOG.debug(String.format("Comment %s by %s (%s) created: comment size is == %s ", comment.getTitle(),
            comment.getUserId(), comment.getId(), activity.getCommentedIds().length));
}

From source file:org.hippoecm.frontend.util.RequestUtils.java

/**
 * Returns the remote host addresses related to this request.
 * If there's any proxy server between the client and the server,
 * then the proxy addresses are contained in the returned array.
 * The lowest indexed element is the farthest downstream client and
 * each successive proxy addresses are the next elements.
 * @param request wicket request/*w  ww. j  av  a 2  s . c o  m*/
 * @return remote host addresses as non-null string array
 */
public static String[] getRemoteAddrs(final Request request) {
    if (request instanceof WebRequest) {
        WebRequest webRequest = (WebRequest) request;

        String headerName = getForwardedForHeaderName(webRequest);
        String headerValue = webRequest.getHeader(headerName);

        if (headerValue != null && headerValue.length() > 0) {
            String[] addrs = headerValue.split(",");
            for (int i = 0; i < addrs.length; i++) {
                addrs[i] = addrs[i].trim();
            }
            return addrs;
        } else if (webRequest.getContainerRequest() instanceof ServletRequest) {
            final ServletRequest servletRequest = (ServletRequest) webRequest.getContainerRequest();
            return new String[] { servletRequest.getRemoteAddr() };
        }
    }

    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.intellij.erlang.template.ErlangLiveTemplateProvider.java

@Override
public String[] getHiddenLiveTemplateFiles() {
    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.jahia.modules.external.ExternalQuery.java

@Override
public String[] getBindVariableNames() throws RepositoryException {
    return ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.jahia.modules.external.query.ExternalQueryResult.java

@Override
public String[] getColumnNames() throws RepositoryException {
    if (columns == null) {
        if (qom.getColumns().length == 0) {
            columns = ArrayUtils.EMPTY_STRING_ARRAY;
        } else {/*from  w  w w  . ja va  2s . c  o  m*/
            List<String> columnList = new LinkedList<String>();
            for (Column c : qom.getColumns()) {
                if (c.getColumnName() != null) {
                    columnList.add(c.getColumnName());
                }
            }
            columns = columnList.toArray(new String[] {});
        }
    }

    return columns;
}

From source file:org.jahia.modules.external.query.ExternalQueryResult.java

@Override
public String[] getSelectorNames() throws RepositoryException {
    if (selectors == null) {
        if (qom.getSource() instanceof Selector) {
            selectors = new String[] { ((Selector) qom.getSource()).getSelectorName() };
        } else {/*from w w w.ja  v  a 2 s  .  co  m*/
            selectors = ArrayUtils.EMPTY_STRING_ARRAY;
        }

    }
    return selectors;
}

From source file:org.jahia.services.history.ContentHistoryService.java

public void process(Exchange exchange) throws Exception {
    final String message = (String) exchange.getIn().getBody();
    final Matcher matcher = PATTERN.matcher(message);
    if (matcher.matches()) {
        long processedCount = this.processedCount.incrementAndGet();
        processedSinceLastReport.incrementAndGet();
        //            final String ipAddress = matcher.group(3);
        //            final String httpSessionId = matcher.group(4);
        //            final String nodeType = matcher.group(7);
        final String args = matcher.group(8);
        String propertyName = null;
        String[] argList = args != null && args.length() > 0 ? StringUtils.split(args, ' ')
                : ArrayUtils.EMPTY_STRING_ARRAY;
        String objectType = null;
        String action = null;/*from   w w w  .  ja  v  a  2 s  .c  o  m*/
        if (argList.length >= 2) {
            objectType = argList[0];
            action = argList[1];
        }

        if (VIEWED_ACTION_NAME.equals(action)) {
            ignoredCount.incrementAndGet();
            return;
        }

        final String path = matcher.group(6);
        if ("property".equals(objectType)) {
            int lastSlashPos = path.lastIndexOf("/");
            if (lastSlashPos > -1) {
                propertyName = path.substring(lastSlashPos + 1);
            }
        }

        if ((propertyName != null) && ignoreProperties.contains(propertyName)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Ignoring property " + propertyName + " as configured.");
            }
            ignoredCount.incrementAndGet();
            return;
        }

        final String nodeIdentifier = matcher.group(5);
        if ((nodeIdentifier != null) && !"null".equals(nodeIdentifier) && (ignoreNodeTypes.size() > 0)) {
            final JCRTemplate tpl = JCRTemplate.getInstance();
            String matchingNodeType = null;
            try {
                matchingNodeType = tpl.doExecuteWithSystemSession(new JCRCallback<String>() {
                    public String doInJCR(JCRSessionWrapper session) throws RepositoryException {
                        JCRNodeWrapper node = session.getNodeByIdentifier(nodeIdentifier);
                        if (node != null) {
                            for (String ignoreNodeType : ignoreNodeTypes) {
                                if (node.isNodeType(ignoreNodeType)) {
                                    return ignoreNodeType;
                                }
                            }
                        }
                        return null;
                    }
                });
                if (matchingNodeType != null) {
                    ignoredCount.incrementAndGet();
                    if (logger.isDebugEnabled()) {
                        logger.debug("Ignoring node type " + matchingNodeType + " as configured.");
                    }
                    return;
                }
            } catch (RepositoryException e) {
                // Node not found might be due to old logs so fail silently
                if (logger.isDebugEnabled()) {
                    logger.debug("Couldn't find node " + nodeIdentifier
                            + " will not insert log entry. This could be due to parsing an old log.");
                }
                ignoredCount.incrementAndGet();
                return;
            }

        }
        long timer = System.currentTimeMillis();
        Session session = sessionFactoryBean.openSession();
        String whatDidWeDo = "inserted";
        boolean shouldSkipInsertion = false;
        try {
            if (latestTimeProcessed.get() == 0L) {
                initTimestamps(session);
            }
            final Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS").parse(matcher.group(1));
            if (latestTimeProcessed.get() > date.getTime()) {
                if (logger.isDebugEnabled()) {
                    logger.debug(
                            "Skipping content history entry since it's date {} is older than last processed date",
                            date);
                }
                ignoredCount.incrementAndGet();
                whatDidWeDo = "skipped";
                shouldSkipInsertion = true;
            } else {
                // if the time is the same, we have to check for existing entries (or maybe it would be faster to
                // delete and re-create them ?)
                if (latestTimeProcessed.get() == date.getTime()) {

                    // we will now check if the UUID, property name and actions are equal to the last processed
                    // action, in order to avoid performing duplicate checks in the database if we can avoid them.
                    boolean mustCheckInDB = false;
                    if ((lastUUIDProcessed != null) && (lastUUIDProcessed.equals(nodeIdentifier))) {
                        if ((lastPropertyProcessed != null) && (lastPropertyProcessed.equals(propertyName))
                                || ((lastPropertyProcessed == null) && (propertyName == null))) {
                            if (lastActionProcessed.equals(action)) {
                                // everything is equal, we will have to check for duplicate in database.
                                mustCheckInDB = true;
                            }
                        }
                    }

                    if (mustCheckInDB) {
                        Criteria criteria = session.createCriteria(HistoryEntry.class);
                        criteria.add(Restrictions.eq("uuid", nodeIdentifier));
                        criteria.add(
                                Restrictions.eq("date", date != null ? Long.valueOf(date.getTime()) : null));
                        criteria.add(Restrictions.eq("propertyName", propertyName));
                        criteria.add(Restrictions.eq("action", action));

                        HistoryEntry historyEntry = (HistoryEntry) criteria.uniqueResult();
                        // Found update object
                        if (historyEntry != null) {
                            // history entry already exists, we will not update it.
                            if (logger.isDebugEnabled()) {
                                logger.debug("Content history entry " + historyEntry
                                        + " already exists, ignoring...");
                            }
                            ignoredCount.incrementAndGet();
                            whatDidWeDo = "skipped";
                            shouldSkipInsertion = true;
                        }
                    }
                }
            }
            // Not found new object
            if (!shouldSkipInsertion) {
                session.beginTransaction();
                HistoryEntry historyEntry = new HistoryEntry();
                historyEntry.setDate(date != null ? date.getTime() : null);
                historyEntry.setPath(path);
                historyEntry.setUuid(nodeIdentifier);
                final String userKey = matcher.group(2);
                historyEntry.setUserKey(userKey);
                historyEntry.setAction(action);
                historyEntry.setPropertyName(propertyName);
                String historyMessage = "";
                if (PUBLISHED_ACTION_NAME.equals(action)) {
                    if (argList.length >= 8) {
                        String sourceWorkspace = argList[3];
                        String destinationWorkspace = argList[5];
                        String historyComments = "";
                        int commentsPos = args.indexOf(WITH_COMMENTS_MESSAGE_PART);
                        if (commentsPos > -1) {
                            String comment = args.substring(commentsPos + WITH_COMMENTS_MESSAGE_PART.length());
                            if ((comment != null) && (!StringUtils.isEmpty(comment.trim()))) {
                                historyComments = ";;" + comment.trim();
                            }
                        }
                        historyMessage = sourceWorkspace + ";;" + destinationWorkspace + historyComments;
                    }
                }
                historyEntry.setMessage(historyMessage);
                try {
                    session.save(historyEntry);
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    session.getTransaction().rollback();
                    throw e;
                }
                insertedCount.incrementAndGet();
                latestTimeProcessed.set(date.getTime());
                lastUUIDProcessed = nodeIdentifier;
                lastPropertyProcessed = propertyName;
                lastActionProcessed = action;
            }
        } catch (HibernateException e) {
            whatDidWeDo = "insertion failed";
            logger.error(e.getMessage(), e);
        } finally {
            session.close();
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Entry " + whatDidWeDo + " in " + (System.currentTimeMillis() - timer) + " ms");
        }

        if (processedCount % 2000 == 0) {
            long nowTime = System.currentTimeMillis();
            double elapsedTimeInSeconds = ((double) (nowTime - timeSinceLastReport.get())) / 1000.0;
            double rate = ((double) processedSinceLastReport.get()) / elapsedTimeInSeconds;
            logger.info(
                    "Total count of processed content history messages: {}. Ignored: {}. Inserted: {}. Rate={} msgs/sec.",
                    new Object[] { processedCount, ignoredCount, insertedCount, rate });
            this.processedSinceLastReport.set(0);
            timeSinceLastReport.set(nowTime);
        }
    }
}

From source file:org.jahia.services.query.MultipleQueryResultAdapter.java

public String[] getColumnNames() throws RepositoryException {
    return !queryResults.isEmpty() ? queryResults.get(0).getColumnNames() : ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.jahia.services.query.MultipleQueryResultAdapter.java

public String[] getSelectorNames() throws RepositoryException {
    return !queryResults.isEmpty() ? queryResults.get(0).getSelectorNames() : ArrayUtils.EMPTY_STRING_ARRAY;
}

From source file:org.jahia.services.search.jcr.JahiaJCRSearchProvider.java

private String buildXpathQuery(SearchCriteria params, JCRSessionWrapper session) {
    String xpathQuery = null;//from ww w .  java  2s  .c  om

    StringBuilder query = new StringBuilder(256);
    String path = null;
    boolean includeChildren = false;
    if (!params.getFilePath().isEmpty()) {
        path = params.getFilePath().getValue().trim();
        includeChildren = params.getFilePath().isIncludeChildren();
    } else if (!params.getPagePath().isEmpty()) {
        path = params.getPagePath().getValue().trim();
        includeChildren = params.getPagePath().isIncludeChildren();
    }
    if (path != null) {
        String[] pathTokens = path != null ? Patterns.SLASH.split(StringEscapeUtils.unescapeHtml(path))
                : ArrayUtils.EMPTY_STRING_ARRAY;
        String lastFolder = null;
        StringBuilder jcrPath = new StringBuilder(64);
        jcrPath.append("/jcr:root/");
        for (String folder : pathTokens) {
            if (folder.length() == 0) {
                continue;
            }
            if (!includeChildren) {
                if (lastFolder != null) {
                    jcrPath.append(lastFolder).append("/");
                }
                lastFolder = folder;
            } else {
                jcrPath.append(folder).append("/");
            }
        }
        if (includeChildren) {
            jcrPath.append("/");
            lastFolder = "*";
        }
        query.append(ISO9075.encodePath(jcrPath.toString())).append("element(").append(lastFolder).append(",")
                .append(getNodeType(params)).append(")");
    } else if (!params.getSites().isEmpty()) {
        query.append("/jcr:root/sites/");
        if ("-all-".equals(params.getSites().getValue())) {
            query.append("*");
        } else {
            Set<String> sites = new LinkedHashSet<String>();
            for (String site : params.getSites().getValues()) {
                sites.add(site);
            }
            if (!params.getSitesForReferences().isEmpty()) {
                for (String site : params.getSitesForReferences().getValues()) {
                    sites.add(site);
                }
            }
            if (sites.size() == 1) {
                query.append(sites.iterator().next());
            } else {
                query.append("*[");
                int i = 0;
                for (String site : sites) {
                    if (i > 0) {
                        query.append(" or ");
                    }
                    query.append("fn:name() = '");
                    query.append(site);
                    query.append("'");
                    i++;
                }
                query.append("]");
            }
        }

        if (isSiteSearch(params)) {
            query.append("/*[@j:isHomePage='true' or fn:name() = 'files' or fn:name() = 'contents']");
        }

        query.append("//element(*,").append(getNodeType(params)).append(")");
    } else {
        query.append("//element(*,").append(getNodeType(params)).append(")");
    }

    query = appendConstraints(params, query, true);
    query = appendOrdering(params, query, true);

    xpathQuery = query.toString();

    if (logger.isDebugEnabled()) {
        logger.debug("XPath query built: " + xpathQuery);
    }

    return xpathQuery;
}