Example usage for org.apache.wicket.util.string Strings toEscapedUnicode

List of usage examples for org.apache.wicket.util.string Strings toEscapedUnicode

Introduction

In this page you can find the example usage for org.apache.wicket.util.string Strings toEscapedUnicode.

Prototype

public static String toEscapedUnicode(final String unicodeString) 

Source Link

Document

Converts unicodes to encoded \uxxxx.

Usage

From source file:org.wicketstuff.datetime.extensions.yui.calendar.DatePicker.java

License:Apache License

/**
 * /*w  w  w  .j  a  va2  s. c  o  m*/
 * @param map
 *            the key-value pairs to be serialized
 * @param json
 *            the buffer holding the constructed json
 */
private void appendMapping(final Map<String, Object> map, final StringBuilder json) {
    json.append('{');
    for (Iterator<Entry<String, Object>> i = map.entrySet().iterator(); i.hasNext();) {
        Entry<String, Object> entry = i.next();
        json.append(entry.getKey());
        Object value = entry.getValue();
        if (value instanceof CharSequence) {
            json.append(":\"");
            json.append(Strings.toEscapedUnicode(value.toString()));
            json.append('"');
        } else if (value instanceof CharSequence[]) {
            json.append(":[");
            CharSequence[] valueArray = (CharSequence[]) value;
            for (int j = 0; j < valueArray.length; j++) {
                CharSequence tmpValue = valueArray[j];
                if (j > 0) {
                    json.append(',');
                }
                if (tmpValue != null) {
                    json.append('"');
                    json.append(Strings.toEscapedUnicode(tmpValue.toString()));
                    json.append('"');
                }
            }
            json.append(']');
        } else if (value instanceof Map) {
            json.append(':');
            @SuppressWarnings("unchecked")
            Map<String, Object> nmap = (Map<String, Object>) value;
            appendMapping(nmap, json);
        } else {
            json.append(':');
            json.append(Strings.toEscapedUnicode(String.valueOf(value)));
        }
        if (i.hasNext()) {
            json.append(',');
        }
    }
    json.append('}');
}

From source file:org.wicketstuff.minis.behavior.spinner.Spinner.java

License:Apache License

/**
 * Transforms a {@link Properties} instance into an associative javascript array. <br/>
 * TODO: this is copied from wicket-datetime/DatePicker and should be moved to
 * {@link JavaScriptUtils}//from  w w  w.  j  av a2  s.  c o m
 * 
 * @param p
 *            the {@link Properties} to process.
 * @return the {@link String} representing the given {@link Properties} instance as an
 *         associative javascript array.
 */
private String propertiesToJavascriptArray(final Properties p) {
    final StringBuilder sb = new StringBuilder();
    for (final Iterator<Map.Entry<Object, Object>> it = p.entrySet().iterator(); it.hasNext();) {
        final Entry<Object, Object> entry = it.next();
        sb.append(entry.getKey());
        final Object value = entry.getValue();
        if (value instanceof CharSequence) {
            sb.append(":\"");
            sb.append(Strings.toEscapedUnicode(value.toString()));
            sb.append("\"");
        } else if (value instanceof CharSequence[]) {
            sb.append(":[");
            final CharSequence[] valueArray = (CharSequence[]) value;
            for (int j = 0; j < valueArray.length; j++) {
                final CharSequence tmpValue = valueArray[j];
                if (j > 0)
                    sb.append(',');
                if (tmpValue != null) {
                    sb.append("\"");
                    sb.append(Strings.toEscapedUnicode(tmpValue.toString()));
                    sb.append("\"");
                }
            }
            sb.append(']');
        } else {
            sb.append(':');
            sb.append(String.valueOf(value)); // no Strings.toEscapedUnicode for properties like afterUpdate, ... that need to evaluate as JS functions, not strings
        }
        if (it.hasNext())
            sb.append(',');
    }
    return sb.toString();
}

From source file:org.wicketstuff.minis.spinner.Spinner.java

License:Apache License

/**
 * Transforms a {@link Properties} instance into an associative javascript array. <br/>
 * TODO: this is copied from wicket-datetime/DatePicker and should be moved to
 * {@link JavaScriptUtils}/*from ww w . ja  va  2  s.  c om*/
 * 
 * @param p
 *            the {@link Properties} to process.
 * @return the {@link String} representing the given {@link Properties} instance as an
 *         associative javascript array.
 */
private String propertiesToJavascriptArray(final Properties p) {
    final StringBuilder sb = new StringBuilder();
    for (final Iterator<Map.Entry<Object, Object>> it = p.entrySet().iterator(); it.hasNext();) {
        final Entry<Object, Object> entry = it.next();
        sb.append(entry.getKey());
        final Object value = entry.getValue();
        if (value instanceof CharSequence) {
            sb.append(":\"");
            sb.append(Strings.toEscapedUnicode(value.toString()));
            sb.append("\"");
        } else if (value instanceof CharSequence[]) {
            sb.append(":[");
            final CharSequence[] valueArray = (CharSequence[]) value;
            for (int j = 0; j < valueArray.length; j++) {
                final CharSequence tmpValue = valueArray[j];
                if (j > 0)
                    sb.append(',');
                if (tmpValue != null) {
                    sb.append("\"");
                    sb.append(Strings.toEscapedUnicode(tmpValue.toString()));
                    sb.append("\"");
                }
            }
            sb.append(']');
        } else {
            sb.append(':');
            sb.append(Strings.toEscapedUnicode(String.valueOf(value)));
        }
        if (it.hasNext())
            sb.append(',');
    }
    return sb.toString();
}