Search in sources :

Example 21 with ResourceReference

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;
}
Also used : ResourceReferenceRequestHandler(org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) MetaInfStaticResourceReference(org.apache.wicket.request.resource.MetaInfStaticResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) ResourceUrl(org.apache.wicket.request.resource.caching.ResourceUrl) Url(org.apache.wicket.request.Url) ResourceUrl(org.apache.wicket.request.resource.caching.ResourceUrl)

Example 22 with ResourceReference

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());
}
Also used : PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) Test(org.junit.Test)

Example 23 with ResourceReference

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);
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ResourceReference(org.apache.wicket.request.resource.ResourceReference) AjaxDownloadBehavior(org.apache.wicket.extensions.ajax.AjaxDownloadBehavior)

Example 24 with ResourceReference

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()));
}
Also used : Label(org.apache.wicket.markup.html.basic.Label) ResourceReference(org.apache.wicket.request.resource.ResourceReference) Image(org.apache.wicket.markup.html.image.Image) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer)

Example 25 with ResourceReference

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");
    }
}
Also used : SingleThemeProvider(de.agilecoders.wicket.core.settings.SingleThemeProvider) Properties(java.util.Properties) MetaDataRoleAuthorizationStrategy(org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy) IBootstrapSettings(de.agilecoders.wicket.core.settings.IBootstrapSettings) BootstrapSettings(de.agilecoders.wicket.core.settings.BootstrapSettings) CsrfPreventionRequestCycleListener(org.apache.wicket.protocol.http.CsrfPreventionRequestCycleListener) IBootstrapSettings(de.agilecoders.wicket.core.settings.IBootstrapSettings) FilesystemResource(org.apache.syncope.client.console.resources.FilesystemResource) ClassPathScanImplementationLookup(org.apache.syncope.client.console.init.ClassPathScanImplementationLookup) WorkflowDefGETResource(org.apache.syncope.client.console.resources.WorkflowDefGETResource) AdminLTE(org.apache.syncope.client.console.themes.AdminLTE) DynamicJQueryResourceReference(org.apache.wicket.resource.DynamicJQueryResourceReference) ResourceReference(org.apache.wicket.request.resource.ResourceReference) WorkflowDefPUTResource(org.apache.syncope.client.console.resources.WorkflowDefPUTResource) DynamicJQueryResourceReference(org.apache.wicket.resource.DynamicJQueryResourceReference) IResource(org.apache.wicket.request.resource.IResource)

Aggregations

ResourceReference (org.apache.wicket.request.resource.ResourceReference)46 IResource (org.apache.wicket.request.resource.IResource)10 PackageResourceReference (org.apache.wicket.request.resource.PackageResourceReference)8 SharedResourceReference (org.apache.wicket.request.resource.SharedResourceReference)7 Test (org.junit.Test)7 ResourceReferenceRequestHandler (org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler)6 HeaderItem (org.apache.wicket.markup.head.HeaderItem)5 Url (org.apache.wicket.request.Url)5 JavaScriptResourceReference (org.apache.wicket.request.resource.JavaScriptResourceReference)5 JavaScriptLibrarySettings (org.apache.wicket.settings.JavaScriptLibrarySettings)5 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)4 Page (org.apache.wicket.Page)3 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 JavaScriptHeaderItem (org.apache.wicket.markup.head.JavaScriptHeaderItem)3 Image (org.apache.wicket.markup.html.image.Image)3 Properties (java.util.Properties)2 Application (org.apache.wicket.Application)2 StringResourceModel (org.apache.wicket.model.StringResourceModel)2 ByteArrayResource (org.apache.wicket.request.resource.ByteArrayResource)2 CssResourceReference (org.apache.wicket.request.resource.CssResourceReference)2