List of usage examples for org.apache.wicket.util.string StringValue valueOf
public static StringValue valueOf(final AppendingStringBuffer buffer)
From source file:codetroopers.wicket.web.routes.mapper.ParamCheckingPatternMapper.java
License:Apache License
/** * First delegate to the superclass to parse the request as normal, then additionally * verify that all regular expressions specified in the placeholders match. *//*w ww . jav a2 s . c o m*/ @Override protected UrlInfo parseRequest(Request request) { // Parse the request normally. If the standard impl can't parse it, we won't either. UrlInfo info = super.parseRequest(request); if (null == info || null == info.getPageParameters()) { return info; } // If exact matching, reject URLs that have more than expected number of segments if (exact) { int requestNumSegments = request.getUrl().getSegments().size(); if (requestNumSegments > this.numSegments) { return null; } } // Loop through each placeholder and verify that the regex of the placeholder matches // the value that was provided in the request url. If any of the values don't match, // immediately return null signifying that the url is not matched by this mapper. PageParameters params = info.getPageParameters(); for (PatternPlaceholder pp : getPatternPlaceholders()) { List<StringValue> values = params.getValues(pp.getName()); if (null == values || values.size() == 0) { values = Arrays.asList(StringValue.valueOf("")); } for (StringValue val : values) { if (!pp.matches(val.toString())) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( String.format("Parameter \"%s\" did not match pattern placeholder %s", val, pp)); } if (ignoreIncorrectParameters) { params.remove(pp.getName(), val.toString()); } else { return null; } } } } return info; }
From source file:com.pushinginertia.wicket.core.util.PageParametersUtilsTest.java
License:Open Source License
@Test public void copySubset() { final PageParameters pp = new PageParameters(); final PageParameters pp0 = PageParametersUtils.copySubset(pp, "a", "b", "c"); Assert.assertEquals(0, pp0.getNamedKeys().size()); pp.add("a", "1"); final PageParameters pp1 = PageParametersUtils.copySubset(pp, "a", "b", "c"); Assert.assertEquals(1, pp1.getNamedKeys().size()); Assert.assertEquals(1, pp1.getValues("a").size()); Assert.assertEquals("1", pp1.get("a").toString()); pp.add("a", "2"); final PageParameters pp2 = PageParametersUtils.copySubset(pp, "a", "b", "c"); Assert.assertEquals(1, pp2.getNamedKeys().size()); Assert.assertEquals(2, pp2.getValues("a").size()); Assert.assertTrue(pp2.getValues("a").contains(StringValue.valueOf("1"))); Assert.assertTrue(pp2.getValues("a").contains(StringValue.valueOf("2"))); pp.add("b", "3"); final PageParameters pp3 = PageParametersUtils.copySubset(pp, "a", "b", "c"); Assert.assertEquals(2, pp3.getNamedKeys().size()); Assert.assertEquals(2, pp3.getValues("a").size()); Assert.assertTrue(pp3.getValues("a").contains(StringValue.valueOf("1"))); Assert.assertTrue(pp3.getValues("a").contains(StringValue.valueOf("2"))); Assert.assertEquals(1, pp3.getValues("b").size()); Assert.assertTrue(pp3.getValues("b").contains(StringValue.valueOf("3"))); }
From source file:cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession.java
License:Apache License
public StringValue getSearchString() { if (searchString == null || searchString.isNull()) { return StringValue.valueOf(""); }/*from w ww . ja v a 2 s . c o m*/ return searchString; }
From source file:de.alpharogroup.wicket.base.util.parameter.PageParametersExtensionsTest.java
License:Apache License
@Test public void testIsNotNullOrEmpty() { boolean actual = PageParametersExtensions.isNotNullOrEmpty(null); AssertJUnit.assertFalse("Should be false.", actual); StringValue sv = StringValue.valueOf(""); actual = PageParametersExtensions.isNotNullOrEmpty(sv); AssertJUnit.assertFalse("Should be false.", actual); final String s = null; sv = StringValue.valueOf(s);/*w w w .j av a 2s . c o m*/ actual = PageParametersExtensions.isNotNullOrEmpty(sv); AssertJUnit.assertFalse("Should be false.", actual); }
From source file:de.alpharogroup.wicket.base.util.parameter.PageParametersExtensionsTest.java
License:Apache License
@Test public void testIsNullOrEmpty() { boolean actual = PageParametersExtensions.isNullOrEmpty(null); AssertJUnit.assertTrue("Should be true.", actual); StringValue sv = StringValue.valueOf(""); actual = PageParametersExtensions.isNullOrEmpty(sv); AssertJUnit.assertTrue("Should be true.", actual); final String s = null; sv = StringValue.valueOf(s);/* w w w. j a v a2s . c o m*/ actual = PageParametersExtensions.isNullOrEmpty(sv); AssertJUnit.assertTrue("Should be true.", actual); }
From source file:eu.uqasar.web.pages.qmtree.QMBaseTreePage.java
License:Apache License
private Long getRequestedNodeId() { StringValue id = getPageParameters().get("id"); if (id.isEmpty()) { String key = getPageParameters().get("qmodel-key").toOptionalString(); if (key != null) { IQMTreeNode<String> node = qmtreeNodeService.getTreeNodeByKey(key); if (node != null) { id = StringValue.valueOf(node.getId()); } else { // TODO give translated message for the 404 reason throw new AbortWithHttpErrorCodeException(404); }//from w w w . ja v a 2 s . c o m } } return id.toOptionalLong(); }
From source file:eu.uqasar.web.pages.tree.BaseTreePage.java
License:Apache License
private Long getRequestedNodeId() { StringValue id = getPageParameters().get("id"); if (id.isEmpty()) { String key = getPageParameters().get("project-key").toOptionalString(); if (key != null) { ITreeNode<String> node = treeNodeService.getTreeNodeByKey(key); if (node != null) { id = StringValue.valueOf(node.getId()); } else { // TODO give translated message for the 404 reason throw new AbortWithHttpErrorCodeException(404); }// ww w.j a va 2 s . co m } } return id.toOptionalLong(); }
From source file:eu.uqasar.web.pages.tree.historic.project.HistoricProjectPage.java
License:Apache License
protected Long getRequestedNodeId() { StringValue id = getPageParameters().get("id"); if (id.isEmpty()) { String key = getPageParameters().get("project-key").toOptionalString(); if (key != null) { ITreeNode<String> node = treeNodeService.getTreeNodeByKey(key); if (node != null) { id = StringValue.valueOf(node.getId()); } else { // TODO give translated message for the 404 reason throw new AbortWithHttpErrorCodeException(404); }//from www. jav a 2 s . c o m } } return id.toOptionalLong(); }
From source file:fiftyfive.wicket.mapper.PatternMountedMapper.java
License:Apache License
/** * First delegate to the superclass to parse the request as normal, then additionally * verify that all regular expressions specified in the placeholders match. *///from ww w. ja v a2 s. c o m @Override protected UrlInfo parseRequest(Request request) { // Parse the request normally. If the standard impl can't parse it, we won't either. UrlInfo info = super.parseRequest(request); if (null == info || null == info.getPageParameters()) { return info; } // If exact matching, reject URLs that have more than expected number of segments if (exact) { int requestNumSegments = request.getUrl().getSegments().size(); if (requestNumSegments > this.numSegments) { return null; } } // Loop through each placeholder and verify that the regex of the placeholder matches // the value that was provided in the request url. If any of the values don't match, // immediately return null signifying that the url is not matched by this mapper. PageParameters params = info.getPageParameters(); for (PatternPlaceholder pp : getPatternPlaceholders()) { List<StringValue> values = params.getValues(pp.getName()); if (null == values || values.size() == 0) { values = Arrays.asList(StringValue.valueOf("")); } for (StringValue val : values) { if (!pp.matches(val.toString())) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( String.format("Parameter \"%s\" did not match pattern placeholder %s", val, pp)); } return null; } } } return info; }
From source file:fiftyfive.wicket.shiro.markup.LogoutPage.java
License:Apache License
/** * Called by {@link #onBeforeRender} after {@link #logout} to redirect to another page. * By default this is the application home page. However if a {@code "to"} page parameter * was provided, assume it is a URI and redirect to that URI instead. For security reasons, * full URLs (i.e. something starting with {@code http}) are ignored. * * @throws RedirectToUrlException to cause Wicket to perform a 302 redirect *///from w ww . j av a 2 s .co m protected void redirectAfterLogout() throws RedirectToUrlException { StringValue to = getPageParameters().get("to"); // If "to" param was not specified, or was erroneously set to // an absolute URL (i.e. containing a ":" like "http://blah"), then fall back // to the home page. if (null == to || to.isNull() || to.toString().indexOf(":") >= 0) { to = StringValue.valueOf(urlFor(getApplication().getHomePage(), null)); } throw new RedirectToUrlException(to.toString(), 302); }