Example usage for org.apache.commons.lang3 StringEscapeUtils escapeJava

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeJava

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeJava.

Prototype

public static final String escapeJava(final String input) 

Source Link

Document

Escapes the characters in a String using Java String rules.

Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

So a tab becomes the characters '\\' and 't' .

The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote and forward-slash (/) are escaped.

Example:

 input string: He didn't say, "Stop!" 

Usage

From source file:org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl.java

/**
 * Converts the pattern constraints from <code>typedef</code> to the list of
 * the strings which represents these constraints.
 *
 * @param typedef//from  w  ww . j  a  v  a 2 s  .  c o m
 *            extended type in which are the pattern constraints sought
 * @return list of strings which represents the constraint patterns
 * @throws IllegalArgumentException
 *             if <code>typedef</code> equals null
 *
 */
private static List<String> resolveRegExpressionsFromTypedef(final TypeDefinition<?> typedef) {
    Preconditions.checkArgument(typedef != null, "typedef can't be null");

    final List<PatternConstraint> patternConstraints;
    if (typedef instanceof StringTypeDefinition) {
        // FIXME: run diff against base
        patternConstraints = ((StringTypeDefinition) typedef).getPatternConstraints();
    } else {
        patternConstraints = ImmutableList.of();
    }

    final List<String> regExps = new ArrayList<>(patternConstraints.size());
    for (PatternConstraint patternConstraint : patternConstraints) {
        final String regEx = patternConstraint.getRegularExpression();
        final String modifiedRegEx = StringEscapeUtils.escapeJava(regEx);
        regExps.add(modifiedRegEx);
    }

    return regExps;
}

From source file:org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl.java

/**
 * Converts the pattern constraints from <code>typedef</code> to the list of
 * the strings which represents these constraints.
 *
 * @param typedef//from ww  w. j a  v a  2s  .  co m
 *            extended type in which are the pattern constraints sought
 * @return list of strings which represents the constraint patterns
 * @throws IllegalArgumentException
 *             if <code>typedef</code> equals null
 *
 */
private static List<String> resolveRegExpressionsFromTypedef(final TypeDefinition<?> typedef) {
    Preconditions.checkArgument(typedef != null, "typedef can't be null");

    final List<PatternConstraint> patternConstraints;
    if (typedef instanceof ExtendedType) {
        final TypeDefinition<?> strTypeDef = baseTypeDefForExtendedType(typedef);
        if (strTypeDef instanceof StringTypeDefinition) {
            patternConstraints = ((ExtendedType) typedef).getPatternConstraints();
        } else {
            patternConstraints = ImmutableList.of();
        }
    } else if (typedef instanceof StringTypeDefinition) {
        // FIXME: run diff against base
        patternConstraints = ((StringTypeDefinition) typedef).getPatternConstraints();
    } else {
        patternConstraints = ImmutableList.of();
    }

    final List<String> regExps = new ArrayList<>(patternConstraints.size());
    for (PatternConstraint patternConstraint : patternConstraints) {
        final String regEx = patternConstraint.getRegularExpression();
        final String modifiedRegEx = StringEscapeUtils.escapeJava(regEx);
        regExps.add(modifiedRegEx);
    }

    return regExps;
}

From source file:org.openecomp.sdc.be.components.impl.ImportUtils.java

private static void addHeatParamDefinition(List<HeatParameterDefinition> moduleProperties,
        Entry<String, Object> propertyNameValue, boolean isJson) {
    HeatParameterDefinition property = new HeatParameterDefinition();
    Object value = propertyNameValue.getValue();
    if (value != null) {
        property.setDefaultValue(isJson ? new Gson().toJson(value).toString()
                : StringEscapeUtils.escapeJava(String.valueOf(value)));
    }//  w ww.  j  a v  a 2s .  com
    property.setName(String.valueOf(propertyNameValue.getKey()));
    moduleProperties.add(property);
}

From source file:org.openecomp.sdc.be.components.impl.ImportUtils.java

private static Either<HeatParameterDefinition, ResultStatusEnum> createModuleHeatParameter(
        Map<String, Object> propertyValue) {
    HeatParameterDefinition propertyDef = new HeatParameterDefinition();
    String type;//w  ww.  j a v  a 2 s.  co  m
    Either<String, ResultStatusEnum> propertyFieldType = findFirstToscaStringElement(propertyValue,
            ToscaTagNamesEnum.TYPE);
    if (propertyFieldType.isLeft()) {
        type = propertyFieldType.left().value();
        propertyDef.setType(type);
    } else {
        return Either.right(ResultStatusEnum.INVALID_PROPERTY_TYPE);
    }
    Either<String, ResultStatusEnum> propertyFieldDescription = findFirstToscaStringElement(propertyValue,
            ToscaTagNamesEnum.DESCRIPTION);
    if (propertyFieldDescription.isLeft()) {
        propertyDef.setDescription(propertyFieldDescription.left().value());
    }

    Either<Object, ResultStatusEnum> propertyFieldDefaultVal = findToscaElement(propertyValue,
            ToscaTagNamesEnum.DEFAULT_VALUE, ToscaElementTypeEnum.ALL);
    if (propertyFieldDefaultVal.isLeft()) {
        if (propertyFieldDefaultVal.left().value() == null) {
            return Either.right(ResultStatusEnum.INVALID_PROPERTY_VALUE);
        }
        Object value = propertyFieldDefaultVal.left().value();
        String defaultValue = type.equals(HeatParameterType.JSON.getType())
                ? new Gson().toJson(value).toString()
                : StringEscapeUtils.escapeJava(String.valueOf(value));
        propertyDef.setDefaultValue(defaultValue);
        propertyDef.setCurrentValue(defaultValue);
    }

    return Either.left(propertyDef);
}

From source file:org.plos.crepo.model.identity.RepoId.java

@Override
public String toString() {
    return String.format("%s(\"%s\", \"%s\")", getClass().getSimpleName(),
            StringEscapeUtils.escapeJava(bucketName), StringEscapeUtils.escapeJava(key));
}

From source file:org.plos.crepo.model.identity.RepoVersion.java

@Override
public String toString() {
    return String.format("%s(\"%s\", \"%s\", \"%s\")", getClass().getSimpleName(),
            StringEscapeUtils.escapeJava(id.getBucketName()), StringEscapeUtils.escapeJava(id.getKey()), uuid);
}

From source file:org.plos.crepo.model.identity.RepoVersionNumber.java

@Override
public String toString() {
    return String.format("%s(\"%s\", \"%s\", \"%s\")", getClass().getSimpleName(),
            StringEscapeUtils.escapeJava(id.getBucketName()), StringEscapeUtils.escapeJava(id.getKey()),
            number);/*from   ww  w  . j a v a  2 s  .  com*/
}

From source file:org.plos.crepo.model.identity.RepoVersionTag.java

@Override
public String toString() {
    return String.format("%s(\"%s\", \"%s\", \"%s\")", getClass().getSimpleName(),
            StringEscapeUtils.escapeJava(id.getBucketName()), StringEscapeUtils.escapeJava(id.getKey()),
            StringEscapeUtils.escapeJava(tag));
}

From source file:org.power.commons.lang.util.SystemUtils.java

/**
 * <code>StringBuilder</code>
 *
 * @param buffer  <code>StringBuilder</code>
 * @param caption /*from   w w w .  j  a va  2 s  .  c om*/
 * @param value   
 */
private static void append(StringBuilder buffer, String caption, String value) {
    buffer.append(caption).append(
            org.apache.commons.lang3.StringUtils.defaultString(StringEscapeUtils.escapeJava(value), "[n/a]"))
            .append("\n");
}

From source file:org.projectspinoza.isak.resources.GetLocationInfo.java

public static void get(String[] args) throws IOException {

    userApiKey = StringEscapeUtils.escapeJava(args[0]);
    locationId = StringEscapeUtils.escapeJava(args[1]);
    fileOutputFormat = StringEscapeUtils.escapeJava(args[2]);
    fileOutputPath = StringEscapeUtils.escapeJava(args[3]);

    Instagram instagram = new Instagram(userApiKey);

    try {/*from ww  w  . j a va  2  s .c o  m*/

        LocationInfo locationInfo = instagram.getLocationInfo(locationId);
        if (!"".equals(locationInfo.getLocationData().getId())) {
            Location location = locationInfo.getLocationData();

            if ("console".equals(fileOutputFormat.toLowerCase())
                    || "cj".equals(fileOutputFormat.toLowerCase())) {
                log.info("id: " + location.getId());
                log.info("name: " + location.getName());
                log.info("latitude: " + location.getLatitude());
                log.info("longitude: " + location.getLongitude());
            }

            if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) {

                try (
                        // put entities JSON in a file
                        PrintWriter writer = new PrintWriter(
                                fileOutputPath + "/" + locationId + "_location_info", "UTF-8")) {
                    String json = new Gson().toJson(location);
                    writer.println(json);
                    writer.close();
                }
            }

            Helpers.showRateLimitStatus(locationInfo.getAPILimitStatus(),
                    locationInfo.getRemainingLimitStatus());
            log.info("!!! DONE !!!");
        } else {
            log.info("No information found agianst provided location id");
        }
    } catch (InstagramException ex) {
        throw new InstagramException(ex.getMessage());
    } catch (JsonSyntaxException ex) {
        throw new IOException("Provide location id is not working");
    }
}