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

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

Introduction

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

Prototype

public static boolean isEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is empty or null.

Usage

From source file:fr.paris.lutece.plugins.stock.modules.billetterie.web.BilletterieSolrSearch.java

/**
 * Get billetterie specific parameters and call Solr Module.
 *
 * @param request the request/* ww w  .java 2  s .  com*/
 * @param response the response
 * @throws ServletException the servlet exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    StringBuilder sbReq = new StringBuilder("");
    sbReq.append(AppPathService.getBaseUrl(request)).append("jsp/site/Portal.jsp?page=search-solr");

    String sTypeSearch = request.getParameter(MARK_TYPE_SEARCH);
    String sTypeSort = request.getParameter(MARK_SORT);

    StringBuilder sbFilter = new StringBuilder("");
    StringBuilder sbSort = null;
    String sQuery = request.getParameter(MARK_QUERY);

    if (StringUtils.isNotEmpty(sTypeSort) && MARK_SORT_ALPHABETIQUE.equals(sTypeSort)) {
        // sort by title
        sbSort = new StringBuilder("&sort_name=title_string&sort_order=asc");
    } else {
        // Sort by date
        sTypeSort = MARK_SORT_DATE;
        sbSort = new StringBuilder("&sort_name=end_date&sort_order=desc");
    }

    if (StringUtils.isEmpty(sTypeSearch) || SEARCH_SIMPLE.equals(sTypeSearch)) {
        // simple search with facets 
        sTypeSearch = SEARCH_SIMPLE;

        String sQuoi = request.getParameter(MARK_QUOI);
        String sOu = request.getParameter(MARK_OU);
        String sQuand = request.getParameter(MARK_QUAND);

        if (StringUtils.isNotEmpty(sQuery)) {
            sbReq.append("&query=" + sQuery);
        }

        if (StringUtils.isNotEmpty(sQuoi)) {
            sbFilter.append(sQuoi);
        }

        if (StringUtils.isNotEmpty(sOu)) {
            sbFilter.append(sOu);
        }

        if (StringUtils.isNotEmpty(sQuand)) {
            sbFilter.append(sQuand);
        }
    } else if (SEARCH_AVANCEE.equals(sTypeSearch)) {
        SimpleDateFormat sdfXml = new SimpleDateFormat(DateUtils.XML_DATE_FORMAT);
        String sTarifReduit = request.getParameter(MARK_TARIF_REDUIT);
        String sInvitation = request.getParameter(MARK_INVITATION);
        String sInvitationEnfant = request.getParameter(MARK_INVITATION_ENFANT);
        String sFullShow = request.getParameter(MARK_FULL_SHOW);
        String[] categories = request.getParameterValues(MARK_CATEGORY);

        String sShowDateStart = request.getParameter("show_date_start");
        String sShowDateEnd = request.getParameter("show_date_end");

        if (CHECKBOX_ON.equals(sTarifReduit)) {
            sbFilter.append("&fq=tarif_reduit_string:true");
        }

        if (CHECKBOX_ON.equals(sInvitation)) {
            sbFilter.append("&fq=invitation_string:true");
        }

        if (CHECKBOX_ON.equals(sInvitationEnfant)) {
            sbFilter.append("&fq=invitation_enfant_string:true");
        }

        if (CHECKBOX_ON.equals(sFullShow)) {
            sbFilter.append("&fq=full_string:false");
        }

        if (StringUtils.isNotEmpty(sQuery) && ArrayUtils.isEmpty(categories)) {
            sbReq.append("&query=" + sQuery);
        } else if (StringUtils.isNotEmpty(sQuery) && !ArrayUtils.isEmpty(categories)) {
            sbReq.append("&query=(" + sQuery);

            sbFilter.append(" AND categorie:(");

            int i = 1;

            for (String categorie : categories) {
                if (i < categories.length) {
                    sbFilter.append(categorie.replace(" ", "*")).append(" OR ");
                } else {
                    sbFilter.append(categorie.replace(" ", "*"));
                }

                i++;
            }

            sbFilter.append("))");
        } else if (!ArrayUtils.isEmpty(categories)) {
            sbFilter.append("&query=categorie:(");

            int i = 1;

            for (String categorie : categories) {
                if (i < categories.length) {
                    sbFilter.append(categorie.replace(" ", "*")).append(" OR ");
                } else {
                    sbFilter.append(categorie.replace(" ", "*"));
                }

                i++;
            }

            sbFilter.append(")");
        }

        if (StringUtils.isNotEmpty(sShowDateStart)) {
            Timestamp showDateStart = DateUtils.getDate(sShowDateStart, true);
            String sXmlShowDateStart = sdfXml.format(showDateStart);
            sbFilter.append("&fq=end_date:[").append(sXmlShowDateStart).append(" TO *]");
        }

        if (StringUtils.isNotEmpty(sShowDateEnd)) {
            Timestamp showDateEnd = DateUtils.getDate(sShowDateEnd, true);
            String sXmlShowDateEnd = sdfXml.format(showDateEnd);

            sbFilter.append("&fq=start_date:[* TO ").append(sXmlShowDateEnd).append("]");
        }
    }

    StringBuilder sbType = new StringBuilder("&type_search=" + sTypeSearch);

    if (sbFilter.toString().isEmpty() && StringUtils.isEmpty(sQuery)) {
        // Create default filter
        sbReq.append("&query=*:*");
    } else {
        sbReq.append(sbFilter.toString());
    }

    sbReq.append(sbSort.toString());
    sbReq.append(sbType.toString());

    LOGGER.debug("Requte SOLR de date, redirection vers " + sbReq.toString());

    response.sendRedirect(UriUtils.encodeUri(sbReq.toString(), "UTF-8"));
}

From source file:com.activecq.samples.workflow.impl.LocalizedTagTitleExtractorProcessWorkflow.java

/**
 * Work flow execute method *//from w  w  w  . j av  a2  s  . c om
 */

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args)
        throws WorkflowException {
    boolean useUpstream = true;
    boolean useDownstream = true;

    final WorkflowData workflowData = workItem.getWorkflowData();
    final String type = workflowData.getPayloadType();

    // Check if the payload is a path in the JCR
    if (!StringUtils.equals(type, "JCR_PATH")) {
        return;
    }

    Session session = workflowSession.getSession();
    // Get the path to the JCR resource from the payload
    String path = workflowData.getPayload().toString();

    // Get a ResourceResolver using the same permission set as the Workflow's executing Session
    ResourceResolver resolver = null;
    Map<String, Object> authInfo = new HashMap<String, Object>();
    authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session);

    // Initialize some variables
    List<String> newTagTitles = new ArrayList<String>();
    List<String> newUpstreamTagTitles = new ArrayList<String>();
    List<String> newDownstreamTagTitles = new ArrayList<String>();
    Locale locale = null;

    try {
        // Get the Workflow Sessions' resource resolver using the authInfo created above
        resolver = resourceResolverFactory.getResourceResolver(authInfo);

        // Get the Resource representing the WF payload
        final Resource resource = resolver.getResource(path);

        // Get the TagManager (using the same permission level as the Workflow's Session)
        final TagManager tagManager = resolver.adaptTo(TagManager.class);

        // Use custom implementation to find the resource to look for cq:tags and write the
        // custom property "tag-titles" to
        final Resource contentResource = getContentResource(resource);

        if (contentResource == null) {
            log.error("Could not find a valid content resource node for payload: {}", resource.getPath());
            return;
        }

        // Gain access to the content resournce's properties
        final ValueMap properties = contentResource.adaptTo(ValueMap.class);

        // Get the full tag paths (namespace:path/to/tag) from the content resource
        // This only works on the cq:tags property
        final Tag[] tags = tagManager.getTags(contentResource);

        // Get any previously applied Localized Tag Titles.
        // This is used to determine if changes if any updates are needed to this node.
        final String[] previousTagTitles = properties.get(PROPERTY_TAG_TITLES, new String[] {});

        if (!ArrayUtils.isEmpty(tags)) {
            // Derive the locale
            if (DamUtil.isAsset(resource)) {
                // Dam assets use path segments to derive the locale (/content/dam/us/en/...)
                locale = getLocaleFromPath(resource);
            } else {
                // Page's use the jcr:language property accessed via the CQ Page API
                Page page = resource.adaptTo(Page.class);
                if (page != null) {
                    locale = page.getLanguage(true);
                }
            }

            // Derive the Localized Tag Titles for all tags in the tag hierarchy from the Tags stored in the cq:tags property
            // This does not remove duplicate titles (different tag trees could repeat titles)
            if (useUpstream) {
                newUpstreamTagTitles = tagsToUpstreamLocalizedTagTitles(tags, locale, tagManager);
                newTagTitles.addAll(newUpstreamTagTitles);
            }

            if (useDownstream) {
                newDownstreamTagTitles = tagsToDownstreamLocalizedTagTitles(tags, locale, tagManager,
                        new ArrayList<String>(), 0);
                newTagTitles.addAll(newDownstreamTagTitles);
            }

            if (!useUpstream && !useDownstream) {
                newTagTitles.addAll(tagsToLocalizedTagTitles(tags, locale));
            }

        }

        try {
            // Get the node in the JCR the payload points to
            final Node node = session.getNode(contentResource.getPath());

            // If the currently applied Tag Titles are the same as the derived Tag titles then skip!
            if (!isSame(newTagTitles.toArray(new String[] {}), previousTagTitles)) {
                // If changes have been made to the Tag Names, then apply to the tag-titles property
                // on the content resource.
                node.setProperty(PROPERTY_TAG_TITLES,
                        newUpstreamTagTitles.toArray(new String[newUpstreamTagTitles.size()]));
            } else {
                log.debug("No change in Tag Titles. Do not update this content resource.");
            }

        } catch (PathNotFoundException ex) {
            log.error(ex.getMessage());
        } catch (RepositoryException ex) {
            log.error(ex.getMessage());
        }
    } catch (LoginException ex) {
        log.error(ex.getMessage());
    } finally {
        // Clean up after yourself please!!!
        if (resolver != null) {
            resolver.close();
            resolver = null;
        }
    }
}

From source file:com.lyh.licenseworkflow.dao.EnhancedHibernateDaoSupport.java

/**
 * ??/*w ww  .j  a v a  2s .  c  o  m*/
 *
 * @param propertyNames
 * @param values
 * @return true??false
 */
@SuppressWarnings("unchecked")
public boolean isEntityExisted(final String[] propertyNames, final Object[] values) {
    if (ArrayUtils.isEmpty(propertyNames) || ArrayUtils.isEmpty(values)
            || propertyNames.length != values.length)
        throw new IllegalArgumentException("Invalid arguments to execute sql query.");
    StringBuilder queryString = new StringBuilder("select id from " + getEntityName() + " where ");
    for (int i = 0, n = propertyNames.length; i < n; i++) {
        if (i != n - 1)
            queryString.append(propertyNames[i] + " = ? and ");
        else
            queryString.append(propertyNames[i] + " = ?");
    }
    List result = getHibernateTemplate().find(queryString.toString(), values);
    return CollectionUtils.isNotEmpty(result);
}

From source file:de.codesourcery.eve.skills.datamodel.MarketOrder.java

public boolean hasState(OrderState... states) {
    if (ArrayUtils.isEmpty(states)) {
        throw new IllegalArgumentException("states array cannot be NULL/empty");
    }//from  ww  w . ja  v  a  2  s.co  m

    for (OrderState s : states) {
        if (getState() == s) {
            return true;
        }
    }
    return false;
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getViolationFeeAmount() {
    BigDecimal total = new BigDecimal(0.0);
    if (!ArrayUtils.isEmpty(violations)) {
        for (int i = 0; i < violations.length; i++) {
            total = total.add(BigDecimalUtil.nullSafe(violations[i].getOnlineFee()));
        }/*from ww  w .ja  v  a  2s  .com*/
    }
    return total;
}

From source file:com.fiveamsolutions.nci.commons.search.OneCriterionSpecifiedCallback.java

private void checkFields(Method m, Object result)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    String[] fields = m.getAnnotation(Searchable.class).fields();
    boolean nested = m.getAnnotation(Searchable.class).nested();
    if (result instanceof Collection<?>) {
        checkCollectionResultForCriteria((Collection<?>) result, fields, nested);
    } else if (!ArrayUtils.isEmpty(fields)) {
        checkSubFieldsForCriteria(result, fields);
    } else if (nested) {
        if (!nestedHistory.containsKey(result)) {
            nestedHistory.put(result, result);
            SearchableUtils.iterateAnnotatedMethods(result, this);
        }//from  ww  w.ja  va2s  .co m
    } else {
        // not a collection, and no subfields selected, so because it is non-null, a criterion was found
        if (isStringAndBlank(result)) {
            return;
        }
        hasOneCriterion = true;
    }
}

From source file:com.photon.phresco.framework.impl.ProjectManagerImpl.java

public List<ProjectInfo> discover(String customerId) throws PhrescoException {
    try {/*from  w  w  w  . jav  a2 s.c o m*/
        if (isDebugEnabled) {
            S_LOGGER.debug("Entering Method ProjectManagerImpl.discover(String CustomerId)");
        }
        File projectsHome = new File(Utility.getProjectHome());
        if (isDebugEnabled) {
            S_LOGGER.debug("discover( )  projectHome = " + projectsHome);
        }
        if (!projectsHome.exists()) {
            return null;
        }
        Map<String, ProjectInfo> projectInfosMap = new HashMap<String, ProjectInfo>();
        List<ProjectInfo> projectInfos = new ArrayList<ProjectInfo>();
        File[] appDirs = projectsHome.listFiles();
        for (File appDir : appDirs) {
            if (appDir.isDirectory()) {
                File[] split_phresco = null;
                File[] split_src = null;
                File[] dotPhrescoFolders = null;
                dotPhrescoFolders = appDir.listFiles(new PhrescoFileNameFilter(FOLDER_DOT_PHRESCO));
                if (ArrayUtils.isEmpty(dotPhrescoFolders)) {
                    File dotAppDir = new File(appDir + File.separator + appDir.getName() + SUFFIX_PHRESCO);
                    split_phresco = dotAppDir.listFiles(new PhrescoFileNameFilter(FOLDER_DOT_PHRESCO));
                    if (ArrayUtils.isEmpty(split_phresco)) {
                        File srcAppDir = new File(appDir + File.separator + appDir.getName());
                        split_src = srcAppDir.listFiles(new PhrescoFileNameFilter(FOLDER_DOT_PHRESCO));
                        if (ArrayUtils.isEmpty(split_src)) {
                            continue;
                        }
                    }
                }

                if (!ArrayUtils.isEmpty(dotPhrescoFolders)) {
                    File[] dotProjectFiles = dotPhrescoFolders[0]
                            .listFiles(new PhrescoFileNameFilter(PROJECT_INFO_FILE));
                    if (!ArrayUtils.isEmpty(dotProjectFiles)) {
                        projectInfosMap = fillProjects(dotProjectFiles[0], customerId, projectInfosMap);
                    }
                }
                if (!ArrayUtils.isEmpty(split_phresco)) {
                    File[] splitDotProjectFiles = split_phresco[0]
                            .listFiles(new PhrescoFileNameFilter(PROJECT_INFO_FILE));
                    if (!ArrayUtils.isEmpty(splitDotProjectFiles)) {
                        projectInfosMap = fillProjects(splitDotProjectFiles[0], customerId, projectInfosMap);
                    }
                }
                if (!ArrayUtils.isEmpty(split_src)) {
                    File[] splitSrcDotProjectFiles = split_src[0]
                            .listFiles(new PhrescoFileNameFilter(PROJECT_INFO_FILE));
                    if (!ArrayUtils.isEmpty(splitSrcDotProjectFiles)) {
                        projectInfosMap = fillProjects(splitSrcDotProjectFiles[0], customerId, projectInfosMap);
                    }
                }
            }
        }

        Iterator<Entry<String, ProjectInfo>> iterator = projectInfosMap.entrySet().iterator();
        while (iterator.hasNext()) {
            projectInfos.add(iterator.next().getValue());
        }
        return projectInfos;
    } catch (Exception e) {
        throw new PhrescoException(e);
    }
}

From source file:eu.europa.esig.dss.tsl.service.TSLRepository.java

boolean isLastVersion(TSLLoaderResult resultLoader) {
    TSLValidationModel validationModel = getByCountry(resultLoader.getCountryCode());
    if (validationModel == null) {
        return false;
    } else {/*from  w  ww  .  java2s.  c  om*/
        // TODO Best place ? Download didn't work, we use previous version
        if (ArrayUtils.isEmpty(resultLoader.getContent())) {
            return true;
        }
        validationModel.setUrl(resultLoader.getUrl());
        validationModel.setLoadedDate(new Date());
        String lastSha256 = getSHA256(resultLoader.getContent());
        return StringUtils.equals(lastSha256, validationModel.getSha256FileContent());
    }
}

From source file:hudson.plugins.plot.XMLSeries.java

/**
 * Load the series from a properties file.
 */// ww w .  j  a  va  2 s. co  m
@Override
public List<PlotPoint> loadSeries(FilePath workspaceRootDir, int buildNumber, PrintStream logger) {
    InputStream in = null;
    InputSource inputSource = null;

    try {
        List<PlotPoint> ret = new ArrayList<PlotPoint>();
        FilePath[] seriesFiles = null;

        try {
            seriesFiles = workspaceRootDir.list(getFile());
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Exception trying to retrieve series files", e);
            return null;
        }

        if (ArrayUtils.isEmpty(seriesFiles)) {
            LOGGER.info("No plot data file found: " + getFile());
            return null;
        }

        try {
            if (LOGGER.isLoggable(defaultLogLevel))
                LOGGER.log(defaultLogLevel, "Loading plot series data from: " + getFile());

            in = seriesFiles[0].read();
            // load existing plot file
            inputSource = new InputSource(in);
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Exception reading plot series data from " + seriesFiles[0], e);
            return null;
        }

        if (LOGGER.isLoggable(defaultLogLevel))
            LOGGER.log(defaultLogLevel, "NodeType " + nodeTypeString + " : " + nodeType);

        if (LOGGER.isLoggable(defaultLogLevel))
            LOGGER.log(defaultLogLevel, "Loaded XML Plot file: " + getFile());

        XPath xpath = XPathFactory.newInstance().newXPath();
        Object xmlObject = xpath.evaluate(xpathString, inputSource, nodeType);

        /*
         * If we have a nodeset, we need multiples, otherwise we just need
         * one value, and can do a toString() to set it.
         */
        if (nodeType.equals(XPathConstants.NODESET)) {
            NodeList nl = (NodeList) xmlObject;
            if (LOGGER.isLoggable(defaultLogLevel))
                LOGGER.log(defaultLogLevel, "Number of nodes: " + nl.getLength());

            for (int i = 0; i < nl.getLength(); i++) {
                Node node = nl.item(i);
                if (!new Scanner(node.getTextContent().trim()).hasNextDouble()) {
                    return coalesceTextnodesAsLabelsStrategy(nl, buildNumber);
                }
            }
            return mapNodeNameAsLabelTextContentAsValueStrategy(nl, buildNumber);
        } else if (nodeType.equals(XPathConstants.NODE)) {
            addNodeToList(ret, (Node) xmlObject, buildNumber);
        } else {
            // otherwise we have a single type and can do a toString on it.
            if (xmlObject instanceof NodeList) {
                NodeList nl = (NodeList) xmlObject;

                if (LOGGER.isLoggable(defaultLogLevel))
                    LOGGER.log(defaultLogLevel, "Number of nodes: " + nl.getLength());

                for (int i = 0; i < nl.getLength(); i++) {
                    Node n = nl.item(i);

                    if (n != null && n.getLocalName() != null && n.getTextContent() != null) {
                        addValueToList(ret, label, xmlObject, buildNumber);
                    }
                }

            } else {
                addValueToList(ret, label, xmlObject, buildNumber);
            }
        }
        return ret;

    } catch (XPathExpressionException e) {
        LOGGER.log(Level.SEVERE, "XPathExpressionException for XPath '" + getXpath() + "'", e);
    } finally {
        IOUtils.closeQuietly(in);
    }

    return null;
}

From source file:com.adobe.acs.commons.wcm.views.impl.WCMViewsFilter.java

/**
 * Determines if the filter should process this request.
 *
 * @param request the request/*from   w ww . j ava2 s .  c o m*/
 * @return true is the filter should attempt to process
 */
@SuppressWarnings("squid:S3776")
private boolean accepts(final SlingHttpServletRequest request) {
    final PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class);
    final Resource resource = request.getResource();

    // Only process requests that match the include path prefixes if any are provided
    if (ArrayUtils.isEmpty(this.includePathPrefixes)
            || (!StringUtils.startsWithAny(request.getResource().getPath(), this.includePathPrefixes))) {
        return false;
    }

    // If the WCM Views on Request is set to disabled; do not process
    if (this.getRequestViews(request).contains(WCM_VIEW_DISABLED)) {
        return false;
    }

    // Only process resources that are part of a Page
    if (pageManager.getContainingPage(request.getResource()) == null) {
        return false;
    }

    final Node node = request.getResource().adaptTo(Node.class);

    if (node != null) {
        try {
            // Do not process cq:Page or cq:PageContent nodes as this will break all sorts of things,
            // and they dont have dropzone of their own
            if (node.isNodeType(NameConstants.NT_PAGE) || node.isNodeType("cq:PageContent") // Do not process Page node inclusions
                    || JcrConstants.JCR_CONTENT.equals(node.getName())) { // Do not process Page jcr:content nodes (that may not have the cq:PageContent jcr:primaryType)
                return false;
            }
        } catch (RepositoryException e) {
            log.error("Repository exception prevented WCM Views Filter "
                    + "from determining if the resource is acceptable", e);
            return false;
        }
    }

    if (CollectionUtils.isNotEmpty(this.resourceTypesIncludes)) {
        for (final Pattern pattern : this.resourceTypesIncludes) {
            final Matcher matcher = pattern.matcher(resource.getResourceType());

            if (matcher.matches()) {
                return true;
            }
        }

        return false;
    }

    return true;
}