Example usage for org.apache.wicket.util.encoding UrlEncoder QUERY_INSTANCE

List of usage examples for org.apache.wicket.util.encoding UrlEncoder QUERY_INSTANCE

Introduction

In this page you can find the example usage for org.apache.wicket.util.encoding UrlEncoder QUERY_INSTANCE.

Prototype

UrlEncoder QUERY_INSTANCE

To view the source code for org.apache.wicket.util.encoding UrlEncoder QUERY_INSTANCE.

Click Source Link

Document

Encoder used to encode name or value components of a query string.<br/> <br/> For example: http://org.acme/notthis/northis/oreventhis?buthis=isokay&asis=thispart

Usage

From source file:de.inren.frontend.common.panel.DownloadActionLink.java

License:Apache License

public DownloadActionLink(String fileName, File file) {
    super(false, GlyphIconType.download);
    if (file == null) {
        throw new IllegalArgumentException("file cannot be null");
    }/* ww  w  .  ja  v  a2 s.c o  m*/
    if (Strings.isEmpty(fileName)) {
        throw new IllegalArgumentException("fileName cannot be an empty string");
    }
    this.file = file;
    this.fileName = UrlEncoder.QUERY_INSTANCE.encode(fileName, Charset.defaultCharset());
}

From source file:de.tudarmstadt.ukp.csniper.webapp.support.wicket.DownloadButton.java

License:Apache License

/**
 * Copied from DownloadLink/*w w w  .j a  va2s .  c  o  m*/
 */
@Override
public void onSubmit() {
    try {
        final File file = fileModel.getObject();

        String fileName = fileNameModel != null ? fileNameModel.getObject() : null;
        if (StringUtils.isEmpty(fileName)) {
            fileName = file.getName();
        }

        fileName = UrlEncoder.QUERY_INSTANCE.encode(fileName, getRequest().getCharset());

        IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file));
        getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) {
            @Override
            public void respond(IRequestCycle requestCycle) {
                super.respond(requestCycle);

                if (deleteAfter) {
                    FileUtils.deleteQuietly(file);
                }
            }
        }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT));
    } catch (Exception e) {
        error("Unable to export: " + ExceptionUtils.getRootCauseMessage(e));
    }
}

From source file:org.hippoecm.frontend.plugins.richtext.view.PreviewLinksBehavior.java

License:Apache License

@Override
public String internalLink(String link) {
    final AjaxRequestAttributes attributes = getAttributes();
    final Charset charset = RequestCycle.get().getRequest().getCharset();
    if (linkExists(link)) {
        if (encode) {
            link = UrlEncoder.QUERY_INSTANCE.encode(link, charset);
        }//  ww w. j  a  va2s .  c o m
        attributes.getExtraParameters().put("link", link);
        CharSequence asString = renderAjaxAttributes(getComponent(), attributes);
        return "href=\"#\" onclick='" + JS_PREVENT_DEFAULT + JS_STOP_EVENT + "Wicket.Ajax.get(" + asString
                + ");'";
    } else {
        String message = new ClassResourceModel("brokenlink-alert", PreviewLinksBehavior.class).getObject();
        return "class=\"brokenlink\" href=\"#\" onclick=\"alert('" + message + "');return false;\"";
    }
}

From source file:org.isisaddons.wicket.excel.cpt.ui.ExcelFileDownloadLink.java

License:Apache License

@Override
public void onClick() {
    final File file = getModelObject();
    if (file == null) {
        throw new IllegalStateException(getClass().getName() + " failed to retrieve a File object from model");
    }/*ww w .  j  a v a2 s.c  o  m*/

    String fileName = UrlEncoder.QUERY_INSTANCE.encode(this.xlsxFileName, getRequest().getCharset());

    final IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file)) {

        private static final long serialVersionUID = 1L;

        @Override
        public String getContentType() {
            return "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
        }
    };

    getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) {
        @Override
        public void respond(IRequestCycle requestCycle) {
            super.respond(requestCycle);
            Files.remove(file);
        }
    }.setFileName(fileName).setContentDisposition(ContentDisposition.ATTACHMENT));
}

From source file:org.onexus.website.api.pages.search.figures.FigureBox.java

License:Apache License

@Override
protected void onInitialize() {
    super.onInitialize();

    WebMarkupContainer toggle = new WebMarkupContainer("accordion-toggle");
    toggle.setOutputMarkupId(true);//from ww  w  .j a  v a2s. c om
    WebMarkupContainer body = new WebMarkupContainer("accordion-body");

    if (config.isOpen()) {
        body.add(new AttributeAppender("class", " in"));
    }

    String bodyId = getMarkupId() + "-body";
    body.setMarkupId(bodyId);
    toggle.add(new AttributeModifier("href", "#" + bodyId));

    toggle.add(new Label("label", config.getTitle()));

    Label description = new Label("description", config.getDescription());
    description.setEscapeModelStrings(false);
    description.setVisible(!Strings.isEmpty(config.getDescription()));
    body.add(description);

    if (config instanceof HtmlFigureConfig) {
        body.add(new HtmlFigurePanel("content", parentUri, (HtmlFigureConfig) config));
    } else if (config instanceof TableFigureConfig) {
        body.add(new TableFigurePanel("content", parentUri, selection, (TableFigureConfig) config));
    } else if (config instanceof BarFigureConfig) {
        body.add(new BarFigurePanel("content", parentUri, selection, (BarFigureConfig) config));
    } else {
        body.add(new Label("content", "Unknown figure type"));
    }

    SearchLink searchLink = config.getLink();
    WebMarkupContainer links = new WebMarkupContainer("links");
    if (searchLink != null) {

        // Create link url
        String prefix = getPage().getPageParameters().get(Website.PARAMETER_CURRENT_PAGE).isEmpty()
                ? WebsiteApplication.get().getWebPath() + "/"
                : "";
        String url = searchLink.getUrl();
        if (selection != null) {
            String parameter = selection instanceof SingleEntitySelection ? "pf=" : "pfc=";
            String varFilter = parameter
                    + UrlEncoder.QUERY_INSTANCE.encode(selection.toUrlParameter(false, null), "UTF-8");
            url = url.replace("$filter", varFilter);
        }

        WebMarkupContainer link = new WebMarkupContainer("link");
        link.add(new AttributeModifier("href", prefix + url));
        link.add(new Label("label", searchLink.getTitle()).setEscapeModelStrings(false));
        links.add(link);

    } else {
        links.setVisible(false);
    }
    body.add(links);

    add(toggle);
    add(body);
}

From source file:org.onexus.website.api.pages.search.figures.LinksBox.java

License:Apache License

private static String createVarFilter(IEntity entity, FilterConfig filterConfig) {

    if (filterConfig != null) {
        MultipleEntitySelection browserSelection = new MultipleEntitySelection(filterConfig);
        return "pfc=" + UrlEncoder.QUERY_INSTANCE.encode(browserSelection.toUrlParameter(false, null), "UTF-8");
    }// w w w .j a  v  a 2s. co  m

    if (entity != null) {
        SingleEntitySelection singleEntitySelection = new SingleEntitySelection(entity);
        return "pf="
                + UrlEncoder.QUERY_INSTANCE.encode(singleEntitySelection.toUrlParameter(false, null), "UTF-8");
    }

    return "";
}

From source file:org.onexus.website.api.widgets.tableviewer.decorators.utils.FieldDecorator.java

License:Apache License

private static String getPageSelectionParameter() {

    String cache = RequestCycle.get().getMetaData(FILTER_PARAMETER);

    if (cache == null) {
        ISelectionContributor selectionContributor = RequestCycle.get()
                .getMetaData(BrowserPageStatus.SELECTIONS);
        Iterator<IEntitySelection> selectionIt = selectionContributor.getEntitySelections().iterator();

        StringBuilder filterParameter = new StringBuilder();
        while (selectionIt.hasNext()) {

            IEntitySelection selection = selectionIt.next();
            if (selection instanceof SingleEntitySelection) {
                filterParameter.append("pf=");
            } else {
                filterParameter.append("pfc=");
            }/*w  w  w .j  a  v a  2  s  .  c  o  m*/

            filterParameter
                    .append(UrlEncoder.QUERY_INSTANCE.encode(selection.toUrlParameter(false, null), "UTF-8"));

            if (selectionIt.hasNext()) {
                filterParameter.append("&");
            }
        }

        cache = filterParameter.toString();
        RequestCycle.get().setMetaData(FILTER_PARAMETER, cache);
    }

    return cache;
}

From source file:ro.nextreports.server.service.DefaultSecurityService.java

License:Apache License

/**
 * A reset token looks like:/*  ww w  .  j a v  a  2s  . c o m*/
 * USERNAME-sep-DIGEST(USER_PASSWORD_HASH)-sep-currentTimeMillis
 */
public String generateResetToken(User user) {
    String encryptedToken = tokenEncryptor.encrypt(user.getUsername() + SEPARATOR
            + simpleDigester.digest(user.getPassword()) + SEPARATOR + System.currentTimeMillis());

    return UrlEncoder.QUERY_INSTANCE.encode(encryptedToken, HTTP.ISO_8859_1);
}