Example usage for com.liferay.portal.kernel.util StringUtil unquote

List of usage examples for com.liferay.portal.kernel.util StringUtil unquote

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringUtil unquote.

Prototype

public static String unquote(String s) 

Source Link

Document

Removes leading and trailing double and single quotation marks from the string.

Usage

From source file:com.liferay.alloy.util.DefaultValueUtil.java

License:Open Source License

public static String getDefaultValue(String className, String value) {
    String defaultValue = StringPool.BLANK;

    if (className.equals(ArrayList.class.getName()) || className.equals(HashMap.class.getName())
            || className.equals(Object.class.getName()) || className.equals(String.class.getName())) {

        if (!isValidStringValue(value)) {
            return defaultValue;
        }/* w ww.ja  va2  s  . co  m*/

        if (_EMPTY_STRINGS.contains(value)) {
            value = StringPool.BLANK;
        } else if (className.equals(ArrayList.class.getName())
                && !StringUtil.startsWith(value.trim(), StringPool.OPEN_BRACKET)) {

            value = "[]";
        } else if (className.equals(HashMap.class.getName())
                && !StringUtil.startsWith(value.trim(), StringPool.OPEN_CURLY_BRACE)) {

            value = "{}";
        }

        defaultValue = StringUtil.unquote(value);
    } else if (className.equals(boolean.class.getName()) || className.equals(Boolean.class.getName())) {

        defaultValue = String.valueOf(GetterUtil.getBoolean(value));
    } else if (className.equals(int.class.getName()) || className.equals(Integer.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Integer.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getInteger(value));
    } else if (className.equals(double.class.getName()) || className.equals(Double.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Double.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getDouble(value));
    } else if (className.equals(float.class.getName()) || className.equals(Float.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Float.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getFloat(value));
    } else if (className.equals(long.class.getName()) || className.equals(Long.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Long.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getLong(value));
    } else if (className.equals(short.class.getName()) || className.equals(Short.class.getName())) {

        if (_INFINITY.contains(value)) {
            value = String.valueOf(Short.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getShort(value));
    } else if (className.equals(Number.class.getName())) {
        if (_INFINITY.contains(value)) {
            value = String.valueOf(Integer.MAX_VALUE);
        }

        defaultValue = String.valueOf(GetterUtil.getNumber(value));
    }

    return defaultValue;
}

From source file:com.liferay.dynamic.data.mapping.expression.internal.DDMExpressionEvaluatorVisitor.java

License:Open Source License

@Override
public Object visitStringLiteral(@NotNull StringLiteralContext context) {
    return StringUtil.unquote(context.getText());
}

From source file:com.liferay.dynamic.data.mapping.expression.internal.DDMExpressionModelVisitor.java

License:Open Source License

@Override
public Expression visitStringLiteral(@NotNull StringLiteralContext context) {

    return new StringLiteral(StringUtil.unquote(context.getText()));
}

From source file:com.liferay.dynamic.data.mapping.form.values.query.internal.DDMFormValuesQueryListener.java

License:Open Source License

@Override
public void exitLocaleExpression(LocaleExpressionContext localeExpressionContext) {

    ParseTree stringLiteral = localeExpressionContext.STRING_LITERAL();

    String languageId = StringUtil.unquote(stringLiteral.getText());

    DDMFormFieldValueValueMatcher lastDDMFormFieldValueValueMatcher = (DDMFormFieldValueValueMatcher) ddmFormFieldValueMatchers
            .peek();//from  www .  jav  a  2  s.  c om

    lastDDMFormFieldValueValueMatcher.setLocale(LocaleUtil.fromLanguageId(languageId));
}

From source file:com.liferay.dynamic.data.mapping.form.values.query.internal.DDMFormValuesQueryListener.java

License:Open Source License

@Override
public void exitPredicateEqualityExpression(
        PredicateEqualityExpressionContext predicateEqualityExpressionContext) {

    DDMFormFieldValueMatcher lastDDMFormFieldValueMatcher = ddmFormFieldValueMatchers.pop();

    ParseTree stringLiteral = predicateEqualityExpressionContext.STRING_LITERAL();

    String text = StringUtil.unquote(stringLiteral.getText());

    if (lastDDMFormFieldValueMatcher instanceof DDMFormFieldValueTypeMatcher) {

        DDMFormFieldValueTypeMatcher ddmFormFieldValueTypeMatcher = (DDMFormFieldValueTypeMatcher) lastDDMFormFieldValueMatcher;

        ddmFormFieldValueTypeMatcher.setType(text);
    } else {//from   ww w  .  j a  v a 2s.  c  om
        DDMFormFieldValueValueMatcher ddmFormFieldValueValueMatcher = (DDMFormFieldValueValueMatcher) lastDDMFormFieldValueMatcher;

        ddmFormFieldValueValueMatcher.setValue(text);
    }

    DDMFormFieldValueMatchesAllMatcher andDDMFormFieldValueMatchesAllMatcher = (DDMFormFieldValueMatchesAllMatcher) ddmFormFieldValueMatchers
            .peek();

    andDDMFormFieldValueMatchesAllMatcher.addDDMFormFieldValueMatcher(lastDDMFormFieldValueMatcher);
}

From source file:com.liferay.journal.content.search.web.internal.display.context.JournalContentSearchDisplayContext.java

License:Open Source License

public String getKeywords() {
    if (_keywords != null) {
        return _keywords;
    }//from  ww w  .ja v  a2s .  c o  m

    String defaultKeywords = LanguageUtil.get(_request, "search") + StringPool.TRIPLE_PERIOD;

    _keywords = StringUtil.unquote(ParamUtil.getString(_request, "keywords", defaultKeywords));

    return _keywords;
}

From source file:com.liferay.sync.util.SyncUtil.java

License:Open Source License

public static String buildExceptionMessage(Throwable throwable) {

    // SYNC-1253//from  w w w . ja v  a  2s  .c o m

    StringBundler sb = new StringBundler(13);

    if (throwable instanceof InvocationTargetException) {
        throwable = throwable.getCause();
    }

    String throwableMessage = throwable.getMessage();

    if (Validator.isNull(throwableMessage)) {
        throwableMessage = throwable.toString();
    }

    sb.append(StringPool.QUOTE);
    sb.append(throwableMessage);
    sb.append(StringPool.QUOTE);
    sb.append(StringPool.COMMA_AND_SPACE);
    sb.append("\"error\": ");

    JSONObject errorJSONObject = JSONFactoryUtil.createJSONObject();

    errorJSONObject.put("message", throwableMessage);
    errorJSONObject.put("type", ClassUtil.getClassName(throwable));

    sb.append(errorJSONObject.toString());

    sb.append(StringPool.COMMA_AND_SPACE);
    sb.append("\"throwable\": \"");
    sb.append(throwable.toString());
    sb.append(StringPool.QUOTE);

    if (throwable.getCause() == null) {
        return StringUtil.unquote(sb.toString());
    }

    sb.append(StringPool.COMMA_AND_SPACE);
    sb.append("\"rootCause\": ");

    Throwable rootCauseThrowable = throwable;

    while (rootCauseThrowable.getCause() != null) {
        rootCauseThrowable = rootCauseThrowable.getCause();
    }

    JSONObject rootCauseJSONObject = JSONFactoryUtil.createJSONObject();

    throwableMessage = rootCauseThrowable.getMessage();

    if (Validator.isNull(throwableMessage)) {
        throwableMessage = rootCauseThrowable.toString();
    }

    rootCauseJSONObject.put("message", throwableMessage);

    rootCauseJSONObject.put("type", ClassUtil.getClassName(rootCauseThrowable));

    sb.append(rootCauseJSONObject);

    return StringUtil.unquote(sb.toString());
}

From source file:jorgediazest.util.reflection.ReflectionUtil.java

License:Open Source License

public static Object castStringToJdbcTypeObject(int type, String value) {
    value = StringUtil.unquote(value);

    Object result = null;/*from w  ww .ja  va2 s .c o  m*/

    switch (type) {
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.CLOB:
        result = value;
        break;

    case Types.NUMERIC:
    case Types.DECIMAL:
        result = new java.math.BigDecimal(value);
        break;

    case Types.BIT:
    case Types.BOOLEAN:
        result = Boolean.parseBoolean(value);
        break;

    case Types.TINYINT:
        result = Byte.parseByte(value);
        break;

    case Types.SMALLINT:
        result = Short.parseShort(value);
        break;

    case Types.INTEGER:
        result = Integer.parseInt(value);
        break;

    case Types.BIGINT:
        result = Long.parseLong(value);
        break;

    case Types.REAL:
    case Types.FLOAT:
        result = Float.parseFloat(value);
        break;

    case Types.DOUBLE:
        result = Double.parseDouble(value);
        break;

    case Types.BINARY:
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
        result = value.getBytes();
        break;

    case Types.DATE:
        result = java.sql.Date.valueOf(value);
        break;

    case Types.TIME:
        result = java.sql.Time.valueOf(value);
        break;

    case Types.TIMESTAMP:
        result = java.sql.Timestamp.valueOf(value);
        break;

    default:
        throw new RuntimeException("Unsupported conversion for " + ReflectionUtil.getJdbcTypeNames().get(type));
    }

    return result;
}