use of org.apache.wicket.util.string.StringValue in project hale by halestudio.
the class EditTemplatePage method addControls.
@Override
protected void addControls() {
StringValue idParam = getPageParameters().get(0);
if (!idParam.isNull() && !idParam.isEmpty()) {
String templateId = idParam.toString();
OrientGraph graph = DatabaseHelper.getGraph();
try {
Template template = null;
try {
template = Template.getByTemplateId(graph, templateId);
} catch (NonUniqueResultException e) {
log.error("Duplicate template representation: " + templateId, e);
}
if (template != null) {
// get associated user
Vertex v = template.getV();
Iterator<Vertex> owners = v.getVertices(Direction.OUT, "owner").iterator();
if (// user is admin
UserUtil.isAdmin() || // or user is owner
(owners.hasNext() && UserUtil.getLogin().equals(new User(owners.next(), graph).getLogin()))) {
add(new TemplateForm("edit-form", false, templateId));
} else {
throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_FORBIDDEN);
}
} else {
throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Template not found.");
}
} finally {
graph.shutdown();
}
} else
throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST, "Template identifier must be specified.");
}
use of org.apache.wicket.util.string.StringValue in project hale by halestudio.
the class BasePage method configureTheme.
/**
* sets the theme for the current user.
*
* @param pageParameters current page parameters
*/
private void configureTheme(PageParameters pageParameters) {
StringValue theme = pageParameters.get("theme");
if (!theme.isEmpty()) {
IBootstrapSettings settings = Bootstrap.getSettings(getApplication());
settings.getActiveThemeProvider().setActiveTheme(theme.toString(""));
}
}
use of org.apache.wicket.util.string.StringValue in project the-app by devops-dojo.
the class CartRequestCycleListener method onBeginRequest.
@Override
public void onBeginRequest(RequestCycle cycle) {
StringValue cartParameterValue = cycle.getRequest().getRequestParameters().getParameterValue(CART_PARAMETER);
if (!cartParameterValue.isEmpty()) {
try {
selectedRedisMicroserviceCart();
cart.setCartId(cartParameterValue.toString());
LOGGER.info(String.format("Session '%s' set cart '%s'", ShopSession.get().getId(), cartParameterValue.toString()));
} catch (Exception e) {
LOGGER.error("Cart processing failed:", e);
}
}
}
use of org.apache.wicket.util.string.StringValue in project wicket by apache.
the class MockHttpServletRequest method buildRequest.
/**
* Build the request based on the uploaded files and the parameters.
*
* @return The request as a string.
*/
private byte[] buildRequest() {
if (uploadedFiles == null && useMultiPartContentType == false) {
if (post.getParameterNames().size() == 0) {
return "".getBytes();
}
Url url = new Url();
for (final String parameterName : post.getParameterNames()) {
List<StringValue> values = post.getParameterValues(parameterName);
for (StringValue value : values) {
url.addQueryParameter(parameterName, value.toString());
}
}
String body = url.toString().substring(1);
return body.getBytes();
}
try {
// Build up the input stream based on the files and parameters
ByteArrayOutputStream out = new ByteArrayOutputStream();
// Add parameters
for (final String parameterName : post.getParameterNames()) {
List<StringValue> values = post.getParameterValues(parameterName);
for (StringValue value : values) {
newAttachment(out);
out.write("; name=\"".getBytes());
out.write(parameterName.getBytes());
out.write("\"".getBytes());
out.write(crlf.getBytes());
out.write(crlf.getBytes());
out.write(value.toString().getBytes());
out.write(crlf.getBytes());
}
}
// Add files
if (uploadedFiles != null) {
for (Map.Entry<String, List<UploadedFile>> entry : uploadedFiles.entrySet()) {
String fieldName = entry.getKey();
List<UploadedFile> files = entry.getValue();
for (UploadedFile uf : files) {
newAttachment(out);
out.write("; name=\"".getBytes());
out.write(fieldName.getBytes());
out.write("\"; filename=\"".getBytes());
if (uf.getFile() != null) {
out.write(uf.getFile().getName().getBytes());
}
out.write("\"".getBytes());
out.write(crlf.getBytes());
out.write("Content-Type: ".getBytes());
out.write(uf.getContentType().getBytes());
out.write(crlf.getBytes());
out.write(crlf.getBytes());
if (uf.getFile() != null) {
// Load the file and put it into the the inputstream
FileInputStream fis = new FileInputStream(uf.getFile());
try {
IOUtils.copy(fis, out);
} finally {
fis.close();
}
}
out.write(crlf.getBytes());
}
}
}
out.write(boundary.getBytes());
out.write("--".getBytes());
out.write(crlf.getBytes());
return out.toByteArray();
} catch (IOException e) {
// NOTE: IllegalStateException(Throwable) only exists since Java 1.5
throw new WicketRuntimeException(e);
}
}
use of org.apache.wicket.util.string.StringValue in project wicket by apache.
the class ServletWebRequest method generatePostParameters.
protected Map<String, List<StringValue>> generatePostParameters() {
Map<String, List<StringValue>> postParameters = new HashMap<>();
IRequestParameters queryParams = getQueryParameters();
@SuppressWarnings("unchecked") Map<String, String[]> params = getContainerRequest().getParameterMap();
for (Map.Entry<String, String[]> param : params.entrySet()) {
final String name = param.getKey();
final String[] values = param.getValue();
if (name != null && values != null) {
// build a mutable list of query params that have the same name as the post param
List<StringValue> queryValues = queryParams.getParameterValues(name);
if (queryValues == null) {
queryValues = Collections.emptyList();
} else {
queryValues = new ArrayList<>(queryValues);
}
// the list that will contain accepted post param values
List<StringValue> postValues = new ArrayList<>();
for (String value : values) {
StringValue val = StringValue.valueOf(value);
if (queryValues.contains(val)) {
// if a query param with this value exists remove it and continue
queryValues.remove(val);
} else {
// there is no query param with this value, assume post
postValues.add(val);
}
}
if (!postValues.isEmpty()) {
postParameters.put(name, postValues);
}
}
}
return postParameters;
}
Aggregations