Example usage for org.apache.wicket.request.resource SharedResourceReference SharedResourceReference

List of usage examples for org.apache.wicket.request.resource SharedResourceReference SharedResourceReference

Introduction

In this page you can find the example usage for org.apache.wicket.request.resource SharedResourceReference SharedResourceReference.

Prototype

public SharedResourceReference(String name) 

Source Link

Document

Construct.

Usage

From source file:ch.tkuhn.nanobrowser.NanobrowserApplication.java

License:Open Source License

protected void internalInit() {
    super.internalInit();
    mountPage("/nanopub", NanopubPage.class);
    mountPage("/sentence", SentencePage.class);
    mountPage("/agent", AgentPage.class);
    mountPage("/paper", PaperPage.class);
    mountPage("/thing", ThingPage.class);
    mountPage("/search", SearchPage.class);
    mountPage("/publish", PublishPage.class);
    getSharedResources().add("/trig", new RawNanopubPage(RDFFormat.TRIG));
    mountResource("/trig", new SharedResourceReference("/trig"));
    getSharedResources().add("/xml", new RawNanopubPage(RDFFormat.TRIX));
    mountResource("/xml", new SharedResourceReference("/xml"));
    getSharedResources().add("/nq", new RawNanopubPage(RDFFormat.NQUADS));
    mountResource("/nq", new SharedResourceReference("/nq"));
}

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.WicketApplication.java

License:Apache License

@Override
protected void init() {
    super.init();
    getComponentInstantiationListeners().add(new SpringComponentInjector(this));

    if (!isInitialized) {
        // Enable dynamic switching between JQuery 1 and JQuery 2 based on the browser
        // identification. 
        getJavaScriptLibrarySettings().setJQueryReference(new DynamicJQueryResourceReference());

        mountPage("/login.html", getSignInPageClass());
        mountPage("/welcome.html", getHomePage());

        // Mount the other pages via @MountPath annotation on the page classes
        new AnnotatedMountScanner().scanPackage("de.tudarmstadt.ukp.clarin.webanno").mount(this);

        // FIXME Handling brat font/css resources should be moved to brat module
        mountResource("/style-vis.css",
                new CssResourceReference(WebAnnoResources.class, "client/css/style-vis.css"));
        mountResource("/style-ui.css",
                new CssResourceReference(WebAnnoResources.class, "client/css/style-ui.css"));
        mountResource("/static/fonts/PT_Sans-Caption-Web-Regular.ttf",
                new PackageResourceReference(WebAnnoResources.class, "fonts/PT_Sans-Caption-Web-Regular.ttf"));
        // For an unknown reason, this file doesn't load from the package... so still keeping
        // it in static under the webapp
        //            mountResource("/static/fonts/Liberation_Sans-Regular.ttf",
        //                    new PackageResourceReference(WebAnnoResources.class, "fonts/Liberation_Sans-Regular.ttf"));

        Properties settings = SettingsUtil.getSettings();
        String logoValue = settings.getProperty("style.logo");
        if (StringUtils.isNotBlank(logoValue) && new File(logoValue).canRead()) {
            getSharedResources().add("logo", new FileSystemResource(new File(logoValue)));
            mountResource("/images/logo.png", new SharedResourceReference("logo"));
        } else {/*from   w  ww.j  a va 2 s.  c o  m*/
            mountResource("/images/logo.png", new ContextRelativeResourceReference("images/logo.png", false));
        }

        // Display stack trace instead of internal error
        if ("true".equalsIgnoreCase(settings.getProperty("debug.showExceptionPage"))) {
            getExceptionSettings().setUnexpectedExceptionDisplay(IExceptionSettings.SHOW_EXCEPTION_PAGE);
        }

        isInitialized = true;
    }
}

From source file:nl.mpi.lamus.web.pages.LamusPage.java

License:Open Source License

/**
 * edit title of the page, logo and userName
 *//*from   ww  w. j a  v a  2 s  .co  m*/
@SuppressWarnings("LeakingThisInConstructor")
public LamusPage() {
    super();

    String appName = getLocalizer().getString("header_app_name", this);

    feedbackPanel = new FeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.setOutputMarkupPlaceholderTag(true);
    feedbackPanel.setEscapeModelStrings(false);

    add(feedbackPanel);

    add(new Image("header_tla_logo", new SharedResourceReference("tlaLogoImage")));
    add(new Label("header_appname", appName));
    add(new Image("header_clarin_logo", new SharedResourceReference("clarinInvertedImage")));

    Link homePageLink = new Link("home_page_link") {
        @Override
        public void onClick() {
            final IndexPage resultPage = new IndexPage();
            setResponsePage(resultPage);
        }
    };
    homePageLink.add(new Image("home_image", new SharedResourceReference("homeImage")));
    add(homePageLink);

    final ModalWindow modalAbout = createAboutModalWindow();
    add(modalAbout);
    add(new AjaxLink<Void>("showModalAbout") {
        @Override
        public void onClick(AjaxRequestTarget art) {
            modalAbout.show(art);
        }
    });

    add(new ExternalLink("manual_link", Model.of(manualUrl)));

    add(new ExternalLink("register_link", Model.of(registerUrl)));

    add(new Label("header_username", new HeaderUsernameModel()));

    if ("anonymous".equals(LamusSession.get().getUserId())) {
        add(new ExternalLink("loginOrLogoutLink", "login",
                getLocalizer().getString("header_login_label", this)));
    } else {
        add(new ExternalLink("loginOrLogoutLink", "logout",
                getLocalizer().getString("header_logout_label", this)));
    }
}

From source file:org.apache.isis.viewer.wicket.ui.components.widgets.zclip.ZeroClipboardLink.java

License:Apache License

public ZeroClipboardLink(String id, String linkJQuerySelector) {
    super(id);//from   w  w  w  . j a v  a 2 s  . c om
    this.linkJQuerySelector = linkJQuerySelector;
    this.zeroClipboardSwfUrl = getRequestCycle().getUrlRenderer()
            .renderFullUrl(Url.parse(urlFor(new SharedResourceReference(SHARED_RESOURCE_NAME), null)));
    this.baseUrl = getRequestCycle().getUrlRenderer().renderFullUrl(Url.parse("."));
}

From source file:org.devgateway.toolkit.forms.wicket.page.reports.AbstractReportPage.java

License:Open Source License

/**
 * Generates the report in the specified <code>outputType</code> and writes
 * it into the specified <code>outputStream</code>.
 *
 * It is the responsibility of the caller to close the
 * <code>outputStream</code> after this method is executed.
 *
 * @param outputType/*from   w  w  w  .  j av  a 2  s. c om*/
 *            the output type of the report (HTML, PDF, HTML)
 * @param outputStream
 *            the stream into which the report will be written
 * @throws IllegalArgumentException
 *             indicates the required parameters were not provided
 * @throws ReportProcessingException
 *             indicates an error generating the report
 */

public void generateReport(final OutputType outputType, final OutputStream outputStream)
        throws IllegalArgumentException, ReportProcessingException {
    if (outputStream == null) {
        throw new IllegalArgumentException("The output stream was not specified");
    }

    // Get the report and data factory
    final MasterReport report = getReportDefinition();

    // Add any parameters to the report
    final Map<String, Object> reportParameters = getReportParameters();
    if (reportParameters == null) {
        return;
    }

    for (String key : reportParameters.keySet()) {
        report.getParameterValues().put(key, reportParameters.get(key));
    }

    // Prepare to generate the report
    AbstractReportProcessor reportProcessor = null;
    try {
        // Greate the report processor for the specified output type
        switch (outputType) {
        case PDF:
            final PdfOutputProcessor targetPdf = new PdfOutputProcessor(report.getConfiguration(), outputStream,
                    report.getResourceManager());
            reportProcessor = new PageableReportProcessor(report, targetPdf);
            reportProcessor.processReport();
            break;

        case EXCEL:
            final FlowExcelOutputProcessor targetExcel = new FlowExcelOutputProcessor(report.getConfiguration(),
                    outputStream, report.getResourceManager());
            reportProcessor = new FlowReportProcessor(report, targetExcel);
            reportProcessor.processReport();
            break;

        case RTF:
            final FlowRTFOutputProcessor targetRtf = new FlowRTFOutputProcessor(report.getConfiguration(),
                    outputStream, report.getResourceManager());
            reportProcessor = new FlowReportProcessor(report, targetRtf);
            reportProcessor.processReport();
            break;

        case HTML:
            ContentLocation targetRoot = null;
            File tempDir = null;
            try {

                //we manually make the folder to drop all exported html files into
                tempDir = ReportUtil.createTemporaryDirectory("tmpreport");
                targetRoot = new FileRepository(tempDir).getRoot();
            } catch (ContentIOException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            //we create a folder content resource for the entire tmpdir.
            // This dir will only hold the fields for this export
            FolderContentResource fcr = new FolderContentResource(tempDir);

            //we always have an authenticated web app
            AuthenticatedWebApplication authApp = (AuthenticatedWebApplication) getApplication();

            //we add the folder resource as a shared resource
            authApp.getSharedResources().add(tempDir.getName(), fcr);
            SharedResourceReference folderResourceReference = new SharedResourceReference(tempDir.getName());
            authApp.mountResource(tempDir.getName(), folderResourceReference);

            final HtmlOutputProcessor outputProcessor = new StreamHtmlOutputProcessor(
                    report.getConfiguration());
            final HtmlPrinter printer = new AllItemsHtmlPrinter(report.getResourceManager());
            printer.setContentWriter(targetRoot, new DefaultNameGenerator(targetRoot, "index", "html"));

            printer.setDataWriter(targetRoot, new DefaultNameGenerator(targetRoot, "content")); //$NON-NLS-1$

            //we use a special URL Rewriter that knows how to speak Wicket :-)
            printer.setUrlRewriter(new WicketResourceURLRewriter(folderResourceReference));
            outputProcessor.setPrinter(printer);
            reportProcessor = new StreamReportProcessor(report, outputProcessor);
            reportProcessor.processReport();

            // we plug the html file stream into the output stream
            FileInputStream indexFileStream = new FileInputStream(
                    tempDir.getAbsolutePath() + File.separator + "index.html");
            IOUtils.copy(indexFileStream, outputStream);
            indexFileStream.close();

            break;

        default:
            throw new RuntimeException("Unknown output type provided!");
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reportProcessor != null) {
            reportProcessor.close();
        }
    }
}

From source file:org.opensingular.form.wicket.mapper.attachment.DownloadSupportedBehavior.java

License:Apache License

/**
 * Registra um recurso compartilhado do wicket para permitir o download
 * sem bloquear a fila de ajax do wicket.
 * O recurso compartilhado  removido to logo o download  executado
 * Esse procedimento visa garantir que somente quem tem acesso  pgina pode fazer
 * download dos arquivos./*from w w  w  .  ja v a  2s .c  o m*/
 *
 * @param filename
 * @return
 */
private String getDownloadURL(String id, String filename) {
    String url = DOWNLOAD_PATH + "/" + id + "/" + new Date().getTime();
    SharedResourceReference ref = new SharedResourceReference(String.valueOf(id));
    AbstractResource resource = new AbstractResource() {
        @Override
        protected ResourceResponse newResourceResponse(Attributes attributes) {
            IAttachmentRef fileRef = findAttachmentRef(id);
            if (fileRef == null) {
                return new ResourceResponse().setStatusCode(HttpServletResponse.SC_NOT_FOUND);
            }
            ResourceResponse resourceResponse = new ResourceResponse();
            if (fileRef.getSize() > 0) {
                resourceResponse.setContentLength(fileRef.getSize());
            }
            resourceResponse.setFileName(filename);
            try {
                resourceResponse.setContentDisposition(contentDisposition);
                resourceResponse.setContentType(fileRef.getContentType());
                resourceResponse.setWriteCallback(new WriteCallback() {
                    @Override
                    public void writeData(Attributes attributes) throws IOException {
                        try (InputStream inputStream = fileRef.getContentAsInputStream()) {
                            IOUtils.copy(inputStream, attributes.getResponse().getOutputStream());
                            /*Desregistrando recurso compartilhado*/
                            WebApplication.get().unmount(url);
                            WebApplication.get().getSharedResources().remove(ref.getKey());
                        } catch (Exception e) {
                            getLogger().error("Erro ao recuperar arquivo.", e);
                            ((WebResponse) attributes.getResponse())
                                    .setStatus(HttpServletResponse.SC_NOT_FOUND);
                            resourceResponse.setStatusCode(HttpServletResponse.SC_NOT_FOUND);
                        }
                    }
                });
            } catch (Exception e) {
                getLogger().error("Erro ao recuperar arquivo.", e);
                resourceResponse.setStatusCode(HttpServletResponse.SC_NOT_FOUND);
            }
            return resourceResponse;
        }
    };
    /*registrando recurso compartilhado*/
    WebApplication.get().getSharedResources().add(String.valueOf(id), resource);
    WebApplication.get().mountResource(url, ref);
    String path = WebApplication.get().getServletContext().getContextPath() + "/"
            + WebApplication.get().getWicketFilter().getFilterPath() + url;
    path = path.replaceAll("\\*", "").replaceAll("//", "/");
    return path;
}

From source file:org.opensingular.form.wicket.panel.SUploadProgressBar.java

License:Apache License

/**
 * {@inheritDoc}/*from  w  ww  .j  a v a  2 s  .c o  m*/
 */
@Override
public void renderHead(final IHeaderResponse response) {
    super.renderHead(response);

    CoreLibrariesContributor.contributeAjax(getApplication(), response);
    response.render(JavaScriptHeaderItem.forReference(JS));
    ResourceReference css = getCss();
    if (css != null) {
        response.render(CssHeaderItem.forReference(css));
    }

    ResourceReference ref = new SharedResourceReference(RESOURCE_NAME);

    final String uploadFieldId = (uploadField == null) ? "" : uploadField.getMarkupId();

    final String status = new StringResourceModel(RESOURCE_STARTING, this, (IModel<?>) null).getString();

    CharSequence url = urlFor(ref, UploadStatusResource.newParameter(getPage().getId()));

    StringBuilder builder = new StringBuilder(128);
    Formatter formatter = new Formatter(builder);

    formatter.format("new Wicket.WUPB('%s', '%s', '%s', '%s', '%s', '%s');", getCallbackForm().getMarkupId(),
            statusDiv.getMarkupId(), barDiv.getMarkupId(), url, uploadFieldId, status);

    formatter.close();
    response.render(OnDomReadyHeaderItem.forScript(builder.toString()));
}

From source file:org.wicketTutorial.resmounting.HomePage.java

License:Apache License

public HomePage(final PageParameters parameters) {
    super(parameters);

    add(new ResourceLink("rssLink", new RSSProducerResource()));
    add(new ResourceLink("globalRssLink", new SharedResourceReference("globalRSSProducer")));
}

From source file:org.xaloon.wicket.component.security.AuthenticatedWebApplication.java

License:Apache License

protected void mountImages() {
    String resourceKey = ImageLink.IMAGE_RESOURCE;
    getSharedResources().add(resourceKey, new FileResource());
    mountResource(resourceKey, new SharedResourceReference(resourceKey));
}

From source file:org.xaloon.wicket.util.UrlUtils.java

License:Apache License

/**
 * @param sharedResource/*from w w w . j  a va  2  s.  com*/
 * @param absoluteImagePath
 * @return absolute image path
 */
public static String toAbsoluteImagePath(String sharedResource, String absoluteImagePath) {
    String url;
    if (absoluteImagePath.startsWith(HtmlElementEnum.PROTOCOL_HTTP.value())) {
        url = absoluteImagePath;
    } else {
        ResourceReference imageResource = new SharedResourceReference(sharedResource);
        PageParameters params = new PageParameters();
        params.set(0, absoluteImagePath);
        HttpServletRequest req = (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest();
        url = RequestCycle.get().getUrlRenderer()
                .renderUrl(RequestCycle.get().mapUrlFor(imageResource, params));
    }
    return url;
}