use of org.apache.wicket.request.resource.ResourceReference in project wicket by apache.
the class BasicResourceReferenceMapper method mapRequest.
@Override
public IRequestHandler mapRequest(Request request) {
Url url = request.getUrl();
if (canBeHandled(url)) {
final int segmentsSize = url.getSegments().size();
// extract the PageParameters from URL if there are any
PageParameters pageParameters = extractPageParameters(request, segmentsSize, pageParametersEncoder);
if (pageParameters != null) {
pageParameters.setLocale(resolveLocale());
}
String className = url.getSegments().get(2);
StringBuilder name = new StringBuilder(segmentsSize * 2);
for (int i = 3; i < segmentsSize; ++i) {
String segment = url.getSegments().get(i);
// ignore invalid segments
if (segment.indexOf('/') > -1) {
return null;
}
// remove caching information
if (i + 1 == segmentsSize && Strings.isEmpty(segment) == false) {
// The filename + parameters eventually contain caching
// related information which needs to be removed
ResourceUrl resourceUrl = new ResourceUrl(segment, pageParameters);
getCachingStrategy().undecorateUrl(resourceUrl);
segment = resourceUrl.getFileName();
Checks.notEmpty(segment, "Caching strategy returned empty name for '%s'", resourceUrl);
}
if (name.length() > 0) {
name.append('/');
}
name.append(segment);
}
ResourceReference.UrlAttributes attributes = ResourceUtil.decodeResourceReferenceAttributes(url);
Class<?> scope = resolveClass(className);
if (scope != null && scope.getPackage() != null) {
ResourceReference res = getContext().getResourceReferenceRegistry().getResourceReference(scope, name.toString(), attributes.getLocale(), attributes.getStyle(), attributes.getVariation(), true, true);
if (res != null) {
return new ResourceReferenceRequestHandler(res, pageParameters);
}
}
}
return null;
}
use of org.apache.wicket.request.resource.ResourceReference in project wicket by apache.
the class PackageResourceTest method lenientPackageResourceMatching.
/**
* Test lenient matching
*
* @throws Exception
*/
@Test
public void lenientPackageResourceMatching() throws Exception {
ResourceReference invalidResource = new PackageResourceReference(PackageResourceTest.class, "i_do_not_exist.txt", Locale.ENGLISH, null, null);
assertNotNull("resource i_do_not_exist.txt SHOULD be available as a packaged resource even if it doesn't exist", invalidResource.getResource());
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1.txt", null, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1.txt", Locale.CHINA, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1.txt", Locale.CHINA, "foo", null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1.txt", null, "foo", null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en.txt", null, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt", null, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt", null, "foo", null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt", Locale.US, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt", Locale.CANADA, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_en_US.txt", Locale.CHINA, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_foo_bar_en.txt", null, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_foo_bar_en_US.txt", null, null, null));
assertTrue(PackageResource.exists(PackageResourceTest.class, "packaged1_foo_bar_en_US_MAC.txt", null, null, null));
tester.getRequest().setUrl(tester.getRequestCycle().mapUrlFor(invalidResource, null));
// since the resource does not exist wicket should let the handling fall through to the next
// filter/servlet which will cause a 404 later
assertFalse(tester.processRequest());
}
use of org.apache.wicket.request.resource.ResourceReference in project wicket by apache.
the class AjaxDownloadPage method initDownloadReference.
private void initDownloadReference() {
ResourceReference reference = new ResourceReference("referenceToResource") {
@Override
public IResource getResource() {
return new StaticResource();
}
};
final AjaxDownloadBehavior download = new AjaxDownloadBehavior(reference) {
@Override
protected void onBeforeDownload(AjaxRequestTarget target) {
downloadingContainer.setVisible(true);
target.add(downloadingContainer);
}
@Override
protected void onDownloadSuccess(AjaxRequestTarget target) {
downloadingContainer.setVisible(false);
target.add(downloadingContainer);
}
@Override
protected void onDownloadFailed(AjaxRequestTarget target) {
downloadingContainer.setVisible(false);
target.add(downloadingContainer);
target.appendJavaScript("alert('Download failed');");
}
};
add(download);
add(new AjaxLink<Void>("downloadReference") {
@Override
public void onClick(AjaxRequestTarget target) {
download.initiate(target);
}
});
}
use of org.apache.wicket.request.resource.ResourceReference in project wicket by apache.
the class StandardDebugPanel method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
BookmarkablePageLink<Void> link = createLink("link");
add(link);
ResourceReference img = getImageResourceReference();
if (img == null) {
link.add(new WebMarkupContainer("img").setVisibilityAllowed(false));
} else {
link.add(new Image("img", img));
}
link.add(new Label("data", getDataModel()));
}
use of org.apache.wicket.request.resource.ResourceReference in project syncope by apache.
the class SyncopeConsoleApplication method init.
@Override
protected void init() {
super.init();
// read console.properties
Properties props = PropertyUtils.read(getClass(), CONSOLE_PROPERTIES, "console.directory").getLeft();
site = props.getProperty("site");
Args.notNull(site, "<site>");
anonymousUser = props.getProperty("anonymousUser");
Args.notNull(anonymousUser, "<anonymousUser>");
anonymousKey = props.getProperty("anonymousKey");
Args.notNull(anonymousKey, "<anonymousKey>");
scheme = props.getProperty("scheme");
Args.notNull(scheme, "<scheme>");
host = props.getProperty("host");
Args.notNull(host, "<host>");
port = props.getProperty("port");
Args.notNull(port, "<port>");
rootPath = props.getProperty("rootPath");
Args.notNull(rootPath, "<rootPath>");
useGZIPCompression = props.getProperty("useGZIPCompression");
Args.notNull(useGZIPCompression, "<useGZIPCompression>");
maxUploadFileSizeMB = props.getProperty("maxUploadFileSizeMB") == null ? null : Integer.valueOf(props.getProperty("maxUploadFileSizeMB"));
maxWaitTime = Integer.valueOf(props.getProperty("maxWaitTimeOnApplyChanges", "30"));
String csrf = props.getProperty("csrf");
// process page properties
pageClasses = new HashMap<>();
populatePageClasses(props);
pageClasses = Collections.unmodifiableMap(pageClasses);
// Application settings
IBootstrapSettings settings = new BootstrapSettings();
// set theme provider
settings.setThemeProvider(new SingleThemeProvider(new AdminLTE()));
// install application settings
Bootstrap.install(this, settings);
getResourceSettings().setUseMinifiedResources(true);
getResourceSettings().setThrowExceptionOnMissingResource(true);
getJavaScriptLibrarySettings().setJQueryReference(new DynamicJQueryResourceReference());
getSecuritySettings().setAuthorizationStrategy(new MetaDataRoleAuthorizationStrategy(this));
ClassPathScanImplementationLookup lookup = (ClassPathScanImplementationLookup) getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP);
lookup.getPageClasses().forEach(cls -> MetaDataRoleAuthorizationStrategy.authorize(cls, SyncopeConsoleSession.AUTHENTICATED));
getMarkupSettings().setStripWicketTags(true);
getMarkupSettings().setCompressWhitespace(true);
if (BooleanUtils.toBoolean(csrf)) {
getRequestCycleListeners().add(new CsrfPreventionRequestCycleListener());
}
getRequestCycleListeners().add(new SyncopeConsoleRequestCycleListener());
mountPage("/login", getSignInPageClass());
flowableModelerDirectory = props.getProperty("flowableModelerDirectory");
Args.notNull(flowableModelerDirectory, "<flowableModelerDirectory>");
try {
reconciliationReportKey = props.getProperty("reconciliationReportKey");
} catch (NumberFormatException e) {
LOG.error("While parsing reconciliationReportKey", e);
}
Args.notNull(reconciliationReportKey, "<reconciliationReportKey>");
mountResource("/" + FLOWABLE_MODELER_CONTEXT, new ResourceReference(FLOWABLE_MODELER_CONTEXT) {
private static final long serialVersionUID = -128426276529456602L;
@Override
public IResource getResource() {
return new FilesystemResource(FLOWABLE_MODELER_CONTEXT, flowableModelerDirectory);
}
});
mountResource("/workflowDefGET", new ResourceReference("workflowDefGET") {
private static final long serialVersionUID = -128426276529456602L;
@Override
public IResource getResource() {
return new WorkflowDefGETResource();
}
});
mountResource("/workflowDefPUT", new ResourceReference("workflowDefPUT") {
private static final long serialVersionUID = -128426276529456602L;
@Override
public IResource getResource() {
return new WorkflowDefPUTResource();
}
});
// enable component path
if (getDebugSettings().isAjaxDebugModeEnabled()) {
getDebugSettings().setComponentPathAttributeName("syncope-path");
}
}
Aggregations