Example usage for org.apache.commons.lang3 StringUtils isAsciiPrintable

List of usage examples for org.apache.commons.lang3 StringUtils isAsciiPrintable

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isAsciiPrintable.

Prototype

public static boolean isAsciiPrintable(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only ASCII printable characters.

null will return false .

Usage

From source file:org.openecomp.sdnc.sli.resource.sql.SqlResource.java

private String decryptColumn(String tableName, String colName, byte[] colValue, DbLibService dblibSvc) {
    String strValue = new String(colValue);

    if (StringUtils.isAsciiPrintable(strValue)) {

        // If printable, not encrypted
        return (strValue);
    } else {/*from w w w .j  a v  a 2  s  .  c o  m*/
        PreparedStatement stmt = null;
        Connection conn = null;
        ResultSet results = null;
        try {
            // CachedRowSet results =
            // dblibSvc.getData("SELECT
            // CAST(AES_DECRYPT('"+strValue+"','"+CRYPT_KEY+"') AS CHAR(50))
            // FROM DUAL",
            // null, null);
            conn = ((DBResourceManager) dblibSvc).getConnection();

            stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL");

            stmt.setBytes(1, colValue);
            stmt.setString(2, getCryptKey());

            results = stmt.executeQuery();

            if ((results != null) && results.next()) {
                strValue = results.getString(1);
                LOG.debug("Decrypted value is " + strValue);
            } else {
                LOG.warn("Cannot decrypt " + tableName + "." + colName);
            }
        } catch (Exception e) {
            LOG.error("Caught exception trying to decrypt " + tableName + "." + colName, e);
        } finally {
            try {
                if (results != null) {
                    results.close();
                    results = null;
                }
            } catch (Exception exc) {

            }

            try {
                if (stmt != null) {
                    stmt.close();
                    stmt = null;
                }
            } catch (Exception exc) {

            }

            try {
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            } catch (Exception exc) {

            }

        }
    }
    return (strValue);
}

From source file:org.seasar.robot.client.fs.FileSystemClient.java

protected String preprocessUri(final String uri) {
    if (StringUtil.isEmpty(uri)) {
        throw new RobotSystemException("The uri is empty.");
    }//from  w ww . j a  v a2  s  .  com

    String filePath = uri;
    if (!filePath.startsWith("file:")) {
        filePath = "file://" + filePath;
    }

    final StringBuilder buf = new StringBuilder(filePath.length() + 100);
    try {
        for (final char c : filePath.toCharArray()) {
            if (c == ' ') {
                buf.append("%20");
            } else {
                final String str = String.valueOf(c);
                if (StringUtils.isAsciiPrintable(str)) {
                    buf.append(c);
                } else {
                    buf.append(URLEncoder.encode(str, charset));
                }
            }
        }
    } catch (final UnsupportedEncodingException e) {
        return filePath;
    }
    return buf.toString();
}

From source file:org.springframework.cloud.sleuth.instrument.web.TraceRestTemplateInterceptorTests.java

@Test
public void createdSpanNameHasOnlyPrintableAsciiCharactersForNonEncodedURIWithNonAsciiChars() {
    setInterceptors(HttpTracing.newBuilder(this.tracing)
            .clientParser(new SleuthHttpClientParser(this.traceKeys)).build());
    Span span = this.tracer.nextSpan().name("new trace");

    try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
        this.template.getForEntity("/cas~fs~", Map.class).getBody();
    } catch (Exception e) {

    } finally {//  w  w w  .  j av a 2  s .  c om
        span.finish();
    }

    List<zipkin2.Span> spans = reporter.getSpans();
    then(spans).hasSize(2);
    String spanName = spans.get(0).name();
    then(spanName).isEqualTo("http:/cas~fs~%c3%a5%cb%86%e2%80%99");
    then(StringUtils.isAsciiPrintable(spanName));
}

From source file:org.springframework.cloud.sleuth.instrument.web.TraceRestTemplateInterceptorTests.java

@Test
public void willShortenTheNameOfTheSpan() {
    setInterceptors(HttpTracing.newBuilder(this.tracing)
            .clientParser(new SleuthHttpClientParser(this.traceKeys)).build());
    Span span = this.tracer.nextSpan().name("new trace");

    try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
        this.template.getForEntity("/" + bigName(), Map.class).getBody();
    } catch (Exception e) {

    } finally {/*from ww  w.  j  a  v  a2  s.  c  o  m*/
        span.finish();
    }

    List<zipkin2.Span> spans = reporter.getSpans();
    then(spans).isNotEmpty();
    String spanName = spans.get(0).name();
    then(spanName).hasSize(50);
    then(StringUtils.isAsciiPrintable(spanName));
}

From source file:org.wise.portal.presentation.validators.UserAccountFormValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 *///from  ww w . ja v a 2s .  co  m
public void validate(Object userAccountFormIn, Errors errors) {
    UserAccountForm userAccountForm = (UserAccountForm) userAccountFormIn;
    MutableUserDetails userDetails = userAccountForm.getUserDetails();

    if (userAccountForm.isNewAccount()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.password",
                "error.password-not-specified");

        if (errors.getFieldErrorCount("userDetails.password") > 0) {
            return;
        }

        if (userDetails.getPassword().length() > MAX_PASSWORD_LENGTH) {
            errors.rejectValue("userDetails.password", "error.password-too-long");
            return;
        }

        if (!StringUtils.isAlphanumeric(userDetails.getPassword())) {
            errors.rejectValue("userDetails.password",
                    "presentation.validators.ChangePasswordParametersValidator.errorPasswordContainsIllegalCharacters");
            return;
        }

        if (userDetails.getSignupdate() == null) {
            errors.rejectValue("userDetails.signupdate", "error.signupdate-not-specified");
            return;
        }
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.username",
                "error.username-not-specified");

        if (!StringUtils.isAlphanumeric(userDetails.getUsername())) {
            errors.rejectValue("userDetails.username", "error.username-illegal-characters");
        }
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.firstname", "error.firstname-not-specified");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.lastname", "error.lastname-not-specified");

    if (!StringUtils.isAlphanumeric(userDetails.getFirstname())
            || !StringUtils.isAsciiPrintable(userDetails.getFirstname())) {
        errors.rejectValue("userDetails.firstname", "error.firstname-illegal-characters");
        return;
    }

    if (!StringUtils.isAlphanumeric(userDetails.getLastname())
            || !StringUtils.isAsciiPrintable(userDetails.getLastname())) {
        errors.rejectValue("userDetails.lastname", "error.lastname-illegal-characters");
        return;
    }

    if (errors.hasErrors())
        userDetails.setPassword("");
}

From source file:org.xwiki.rendering.internal.renderer.event.EventsChainingRenderer.java

public String getEscaped(String str) {
    String printableStr;/*from ww  w . java2 s  .  c  om*/

    if (str == null) {
        printableStr = null;
    } else if (StringUtils.isAsciiPrintable(str)) {
        printableStr = str;
    } else {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c > 126) {
                buffer.append("(((").append((int) c).append(")))");
            } else {
                buffer.append(c);
            }
        }
        printableStr = buffer.toString();
    }

    return printableStr;
}

From source file:pcgen.gui2.ScanForUnusedIl8nKeys.java

/**
 * @param inputPropsFile/*w w w. j a v  a2 s. com*/
 * @param cleanPropsFile
 * @param unusedKeys
 * @throws IOException 
 */
private void outputCleanedProperties(File inputPropsFile, File cleanPropsFile, Set<String> unusedKeys)
        throws IOException {
    Reader reader = new BufferedReader(new FileReader(inputPropsFile));
    List<String> lines = IOUtils.readLines(reader);
    reader.close();
    Writer writer = new BufferedWriter(new PrintWriter(cleanPropsFile, "ISO-8859-1"));
    writer.write("# " + PROPERTIES_FILE + " with all unused keys removed as at "
            + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date()) + "\n");
    boolean lastLineBlank = false;
    for (String line : lines) {
        boolean found = false;
        if (lastLineBlank && line.trim().isEmpty()) {
            continue;
        } else {
            for (String key : unusedKeys) {
                if (line.startsWith(key + "=")) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            lastLineBlank = line.trim().isEmpty();
            if (!StringUtils.isAsciiPrintable(line)) {
                System.out.println("Found a non adcii line " + line);
            }

            writer.write(line + "\n");
        }
    }
    writer.close();
}

From source file:vista.controlador.Validador.java

/**
 * Valida que el campo sea una contrasea, esto es que no est vaco y que
 * contenga los caracteres permitidos//from  ww w .j a  va  2s .co m
 *
 * @param campo la cadena de texto a validar
 * @return true si el campo es contrasea, false si no es as.
 */
public static boolean esPassword(String campo) {
    boolean ok = true;

    if (estaVacio(campo) || !StringUtils.isAsciiPrintable(campo) || campo.contains("'") || campo.contains("\"")
            || campo.contains("<") || campo.contains(">") || campo.contains("\\") || campo.contains("&")
            || campo.contains("%") || campo.contains("_") || campo.length() < 4) {
        ok = false;
    }

    return ok;
}