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

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

Introduction

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

Prototype

public static boolean isNotEmpty(boolean[] array) 

Source Link

Document

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

Usage

From source file:it.openprj.jValidator.spring.ExtraCheckCustomCodeValidator.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String code = request.getParameter("value");
    String name = request.getParameter("name");
    String addReq = request.getParameter("addReq");

    //TODO: take the result message from "locale"
    String result = null;//www .j av a  2  s  .  c  om
    ObjectMapper mapper = new ObjectMapper();
    ServletOutputStream out = null;
    response.setContentType("application/json");
    out = response.getOutputStream();
    if (StringUtils.isEmpty(code) || StringUtils.isEmpty(name)) {
        result = I18n.getMessage("error.extracheck.invaliddata");
    } else {
        name = name.trim();
        if (addReq.equalsIgnoreCase("true")) {
            ReadList list = checksTypeDao.findCustomCodeByName(name);
            if (list != null && CollectionUtils.isNotEmpty(list.getResults())) {
                result = I18n.getMessage("error.extracheck.name.alreadyexist");
                out.write(mapper.writeValueAsBytes(result));
                out.flush();
                out.close();
                return null;
            }
        }
        try {
            File sourceDir = new File(System.getProperty("java.io.tmpdir"), "jValidator/src");
            sourceDir.mkdirs();
            String classNamePack = name.replace('.', File.separatorChar);
            String srcFilePath = sourceDir + "" + File.separatorChar + classNamePack + ".java";
            File sourceFile = new File(srcFilePath);
            if (sourceFile.exists()) {
                sourceFile.delete();
            }
            FileUtils.writeStringToFile(new File(srcFilePath), code);
            DynamicClassLoader dynacode = DynamicClassLoader.getInstance();
            dynacode.addSourceDir(sourceDir);
            CustomCodeValidator customCodeValidator = (CustomCodeValidator) dynacode
                    .newProxyInstance(CustomCodeValidator.class, name);
            boolean isValid = false;
            if (customCodeValidator != null) {
                Class clazz = dynacode.getLoadedClass(name);
                if (clazz != null) {
                    Class[] interfaces = clazz.getInterfaces();
                    if (ArrayUtils.isNotEmpty(interfaces)) {
                        for (Class clz : interfaces) {
                            if ((clz.getName().equalsIgnoreCase(
                                    "it.openprj.jValidator.utils.validation.SingleValidation"))) {
                                isValid = true;
                            }
                        }
                    }
                }
            }
            if (isValid) {
                result = "Success";
            } else {
                result = I18n.getMessage("error.extracheck.wrongimpl");
            }
        } catch (Exception e) {
            result = "Failed. Reason:" + e.getMessage();
        }
    }
    out.write(mapper.writeValueAsBytes(result));
    out.flush();
    out.close();
    return null;
}

From source file:com.hp.autonomy.searchcomponents.hod.search.fields.HodSearchResultDeserializer.java

private String parseAsStringFromArray(@SuppressWarnings("TypeMayBeWeakened") final JsonNode node,
        final String fieldName) throws JsonProcessingException {
    final String[] values = parseAsStringArray(node, fieldName);
    return ArrayUtils.isNotEmpty(values) ? values[0] : null;
}

From source file:de.pawlidi.openaletheia.utils.CipherUtilsTest.java

@Test
public void testEncryptDecrypt() throws UnsupportedEncodingException {
    KeyPair keyPair = CipherUtils.generateKeyPair();
    String publicKeyString = CipherUtils.getPublicKey(keyPair);
    String privateKeyString = CipherUtils.getPrivateKey(keyPair);
    RSAPublicKey publicKey = CipherUtils.buildPublicKey(publicKeyString);
    RSAPrivateKey privateKey = CipherUtils.buildPrivateKey(privateKeyString);

    byte[] encrypt = CipherUtils.encrypt(Converter.getBytesUtf8(secret), privateKey);
    Assert.assertTrue(ArrayUtils.isNotEmpty(encrypt));

    byte[] decrypt = CipherUtils.decrypt(encrypt, publicKey);
    Assert.assertTrue(ArrayUtils.isNotEmpty(decrypt));

    Assert.assertEquals(secret, new String(decrypt, Converter.UTF_8));
}

From source file:com.photon.phresco.service.admin.actions.admin.Users.java

public String delete() throws PhrescoException {
    if (isDebugEnabled) {
        LOGGER.debug("Users.delete : Entry");
    }//from  w  w  w .java  2s.c  o  m

    String[] userIds = getHttpRequest().getParameterValues("userId");
    if (ArrayUtils.isNotEmpty(userIds)) {
        for (String userid : userIds) {
            getServiceManager().deleteUser(userid);
        }
        addActionMessage(getText(USER_DELETED));
    }

    return ADMIN_USER_LIST;
}

From source file:com.fortify.bugtracker.tgt.tfs.connection.TFSRestConnection.java

public JSONMap getWorkItemFields(String collection, TargetIssueLocator targetIssueLocator, String... fields) {
    LOG.trace(String.format("[TFS] Retrieving issue data for %s", targetIssueLocator.getDeepLink()));
    String issueId = getIssueId(targetIssueLocator);
    if (issueId == null) {
        LOG.warn(String.format("[TFS] Cannot get work item id from URL %s", targetIssueLocator.getDeepLink()));
        return null;
    } else {/*from  ww w  . j  a  v a2  s  .co m*/
        WebTarget target = getBaseResource().path(collection).path("/_apis/wit/workitems").path(issueId);
        if (ArrayUtils.isNotEmpty(fields)) {
            target = target.queryParam("fields", StringUtils.join(fields, ","));
        }
        return executeRequest(HttpMethod.GET, target, JSONMap.class).getOrCreateJSONMap("fields");
    }
}

From source file:de.pawlidi.openaletheia.utils.CipherUtils.java

/**
 * //ww w.j  ava2  s.  c om
 * @param data
 * @param key
 * @return
 */
public static byte[] decrypt(byte[] data, Key key) {
    if (key != null && ArrayUtils.isNotEmpty(data)) {
        try {
            Cipher rsaCipher = Cipher.getInstance(CIPHER_EXTENDED_ALGORITHM);
            rsaCipher.init(Cipher.DECRYPT_MODE, key);
            return rsaCipher.doFinal(data);
        } catch (Exception e1) {
            try {
                Cipher rsaCipher = Cipher.getInstance(CIPHER_ALGORITHM);
                rsaCipher.init(2, key);
                return rsaCipher.doFinal(data);
            } catch (Exception e2) {
                throw new RuntimeException("Cannot decrypt, " + CIPHER_ALGORITHM + " error", e2);
            }
        }
    }
    return null;
}

From source file:ddf.catalog.metacard.duplication.DuplicationValidator.java

private Set<ValidationViolation> reportDuplicates(final Metacard metacard) {

    Set<ValidationViolation> violations = new HashSet<>();

    if (ArrayUtils.isNotEmpty(warnOnDuplicateAttributes)) {
        ValidationViolation warnValidation = reportDuplicates(metacard, warnOnDuplicateAttributes,
                ValidationViolation.Severity.WARNING);
        if (warnValidation != null) {
            violations.add(warnValidation);
        }//from w  ww .  j  av a 2 s.c o  m
    }
    if (ArrayUtils.isNotEmpty(errorOnDuplicateAttributes)) {
        ValidationViolation errorViolation = reportDuplicates(metacard, errorOnDuplicateAttributes,
                ValidationViolation.Severity.ERROR);
        if (errorViolation != null) {
            violations.add(errorViolation);
        }
    }

    return violations;

}

From source file:de.hybris.platform.acceleratorfacades.urlencoder.impl.DefaultUrlEncoderFacade.java

@Override
public String calculateAndUpdateUrlEncodingData(final String uri, final String contextPath) {
    final List<UrlEncoderData> urlEncodingAttributes = getCurrentUrlEncodingData();
    final String[] splitUrl = StringUtils.split(uri, "/");
    int splitUrlCounter = (ArrayUtils.isNotEmpty(splitUrl)
            && (StringUtils.remove(contextPath, "/").equals(splitUrl[0]))) ? 1 : 0;

    final StringBuilder patternSb = new StringBuilder();
    for (final UrlEncoderData urlEncoderData : urlEncodingAttributes) {
        String tempValue = urlEncoderData.getCurrentValue();
        if ((splitUrlCounter) < splitUrl.length) {
            tempValue = splitUrl[splitUrlCounter];
            if (!isValid(urlEncoderData.getAttributeName(), tempValue)) {
                tempValue = urlEncoderData.getDefaultValue();
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Encoding attributes are absent. Injecting default value :  [" + tempValue + "]");
                }//from   w  w  w  .j a  v  a2  s. c  om
            }
            urlEncoderData.setCurrentValue(tempValue);
            splitUrlCounter++;
        }

        if (patternSb.length() != 0) {
            patternSb.append('/');
        }
        patternSb.append(tempValue);

    }
    return patternSb.toString();
}

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

@Override
@SuppressWarnings("squid:S3776")
public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
        final FilterChain filterChain) throws IOException, ServletException {

    if (!(servletRequest instanceof HttpServletRequest) || !(servletResponse instanceof HttpServletResponse)) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;//from ww  w  .  j  a  va2s .  com
    }

    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpServletResponse response = (HttpServletResponse) servletResponse;

    if (!this.accepts(request)) {
        filterChain.doFilter(request, response);
        return;
    }

    final BufferingResponse capturedResponse = new BufferingResponse(response);

    filterChain.doFilter(request, capturedResponse);

    boolean doInclude = true;
    if (ArrayUtils.isNotEmpty(excludedWCMModes)) {
        // Test for configured WCM modes, where the indicators are not displayed
        WCMMode wcmmode = extractFromRequest(request);

        if (wcmmode != null) {
            for (String m : excludedWCMModes) {
                if (StringUtils.equalsIgnoreCase(wcmmode.name(), m)) {
                    doInclude = false;
                    break;
                }
            }
        } else {
            // No wcmmode could be extracted from the request
        }
    }

    // Get contents
    final String contents = capturedResponse.getContents();

    if (doInclude && contents != null && StringUtils.contains(response.getContentType(), "html")) {

        final int bodyIndex = contents.indexOf("</body>");

        if (bodyIndex != -1) {
            final PrintWriter printWriter = response.getWriter();

            printWriter.write(contents.substring(0, bodyIndex));

            if (StringUtils.isNotBlank(css)) {
                printWriter.write("<style>" + css + " </style>");
                printWriter.write("<div id=\"" + DIV_ID + "\">" + innerHTML + "</div>");
            }

            if (StringUtils.isNotBlank(titlePrefix)) {
                printWriter.printf(TITLE_UPDATE_SCRIPT, titlePrefix);
            }

            printWriter.write(contents.substring(bodyIndex));
            return;
        }
    }

    if (contents != null) {
        response.getWriter().write(contents);
    }
}

From source file:eu.europa.esig.dss.applet.wizard.signature.SignatureWizardController.java

/**
 * @throws IOException/* w ww  . j  av a 2s.c  o  m*/
 * @throws NoSuchAlgorithmException
 * @throws DSSException
 */
public void signDocument() throws IOException, NoSuchAlgorithmException, DSSException {

    final SignatureModel model = getModel();

    final File fileToSign = model.getSelectedFile();
    final SignatureTokenConnection tokenConnection = model.getTokenConnection();
    final DSSPrivateKeyEntry privateKey = model.getSelectedPrivateKey();

    final RemoteSignatureParameters parameters = new RemoteSignatureParameters();

    RemoteCertificate signingCertificate = new RemoteCertificate(privateKey.getCertificate().getEncoded());
    parameters.setSigningCertificate(signingCertificate);

    List<RemoteCertificate> chainCertificateList = new ArrayList<RemoteCertificate>();
    chainCertificateList.add(signingCertificate);

    CertificateToken[] certificateChain = privateKey.getCertificateChain();
    if (ArrayUtils.isNotEmpty(certificateChain)) {
        for (CertificateToken certificateToken : certificateChain) {
            chainCertificateList.add(new RemoteCertificate(certificateToken.getEncoded()));
        }
    }
    parameters.setCertificateChain(chainCertificateList);

    parameters.setEncryptionAlgorithm(privateKey.getEncryptionAlgorithm());

    parameters.bLevel().setSigningDate(new Date());

    DigestAlgorithm digestAlgorithm = model.getSignatureDigestAlgorithm();
    if (digestAlgorithm == null) {
        parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
    } else {
        parameters.setDigestAlgorithm(digestAlgorithm);
    }

    prepareCommonSignature(model, parameters);

    final DSSDocument signedDocument = SigningUtils.signDocument(serviceURL, fileToSign, parameters, privateKey,
            tokenConnection);
    final FileOutputStream fileOutputStream = new FileOutputStream(model.getTargetFile());
    final InputStream inputStream = signedDocument.openStream();
    IOUtils.copy(inputStream, fileOutputStream);
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(fileOutputStream);
}