Search in sources :

Example 1 with PrependingStringBuffer

use of org.apache.wicket.util.string.PrependingStringBuffer in project wicket by apache.

the class LongEncoder method encode.

/**
 * Encodes value into the specified alphabet
 *
 * @param value
 * @param alphabet
 * @return encoded value
 */
public static String encode(long value, final String alphabet) {
    final int len = alphabet.length() - 1;
    PrependingStringBuffer buff = new PrependingStringBuffer();
    final boolean negative = value < 0;
    if (negative) {
        value = -value;
    }
    do {
        int mod = (int) (value % len);
        buff.prepend(alphabet.charAt(mod));
        value = value / len;
    } while (value > 0);
    if (negative) {
        buff.prepend(alphabet.charAt(len));
    }
    return buff.toString();
}
Also used : PrependingStringBuffer(org.apache.wicket.util.string.PrependingStringBuffer)

Example 2 with PrependingStringBuffer

use of org.apache.wicket.util.string.PrependingStringBuffer in project wicket by apache.

the class ServletWebRequest method getPrefixToContextPath.

@Override
public String getPrefixToContextPath() {
    PrependingStringBuffer buffer = new PrependingStringBuffer();
    Url filterPrefixUrl = Url.parse(filterPrefix, getCharset());
    for (int i = 0; i < filterPrefixUrl.getSegments().size() - 1; ++i) {
        buffer.prepend("../");
    }
    return buffer.toString();
}
Also used : PrependingStringBuffer(org.apache.wicket.util.string.PrependingStringBuffer) Url(org.apache.wicket.request.Url)

Example 3 with PrependingStringBuffer

use of org.apache.wicket.util.string.PrependingStringBuffer in project wicket by apache.

the class UrlRenderer method renderContextRelativeUrl.

/**
 * Renders the URL within context relative to current base URL.
 *
 * @param url
 * @return relative URL
 */
public String renderContextRelativeUrl(String url) {
    Args.notNull(url, "url");
    if (url.startsWith("/")) {
        url = url.substring(1);
    }
    PrependingStringBuffer buffer = new PrependingStringBuffer(url);
    for (int i = 0; i < getBaseUrl().getSegments().size() - 1; ++i) {
        buffer.prepend("../");
    }
    buffer.prepend(request.getPrefixToContextPath());
    return buffer.toString();
}
Also used : PrependingStringBuffer(org.apache.wicket.util.string.PrependingStringBuffer)

Example 4 with PrependingStringBuffer

use of org.apache.wicket.util.string.PrependingStringBuffer in project wicket by apache.

the class Form method getRootFormRelativeId.

/**
 * Utility method to assemble an id to distinct form components from different nesting levels.
 * Useful to generate input names attributes.
 *
 * @param component
 * @return form relative identification string
 */
public static String getRootFormRelativeId(Component component) {
    String id = component.getId();
    final PrependingStringBuffer inputName = new PrependingStringBuffer(id.length());
    Component c = component;
    while (true) {
        inputName.prepend(id);
        c = c.getParent();
        if (c == null || (c instanceof Form<?> && ((Form<?>) c).isRootForm()) || c instanceof Page) {
            break;
        }
        inputName.prepend(Component.PATH_SEPARATOR);
        id = c.getId();
    }
    /*
		 * Certain input names causes problems with JavaScript. If the input name would cause a
		 * problem, we create a replacement unique name by prefixing the name with a path that would
		 * otherwise never be used (blank id in path).
		 * 
		 * Input names must start with [A-Za-z] according to HTML 4.01 spec. HTML 5 allows almost
		 * anything.
		 */
    if (JavaScriptReservedNames.isNameReserved(inputName.toString())) {
        inputName.prepend(Component.PATH_SEPARATOR);
        inputName.prepend(Component.PATH_SEPARATOR);
        inputName.prepend("p");
    }
    return inputName.toString();
}
Also used : Page(org.apache.wicket.Page) Component(org.apache.wicket.Component) IGenericComponent(org.apache.wicket.IGenericComponent) PrependingStringBuffer(org.apache.wicket.util.string.PrependingStringBuffer)

Aggregations

PrependingStringBuffer (org.apache.wicket.util.string.PrependingStringBuffer)4 Component (org.apache.wicket.Component)1 IGenericComponent (org.apache.wicket.IGenericComponent)1 Page (org.apache.wicket.Page)1 Url (org.apache.wicket.request.Url)1