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();
}
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();
}
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();
}
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();
}
Aggregations