Example usage for org.apache.wicket.util.string StringValue toString

List of usage examples for org.apache.wicket.util.string StringValue toString

Introduction

In this page you can find the example usage for org.apache.wicket.util.string StringValue toString.

Prototype

@Override
public final String toString() 

Source Link

Usage

From source file:eu.esdihumboldt.hale.server.templates.war.pages.EditTemplatePage.java

License:Open Source License

@Override
protected void addControls() {
    StringValue idParam = getPageParameters().get(0);
    if (!idParam.isNull() && !idParam.isEmpty()) {
        String templateId = idParam.toString();

        OrientGraph graph = DatabaseHelper.getGraph();
        try {//from  w ww .ja  v  a2 s . c o  m
            Template template = null;
            try {
                template = Template.getByTemplateId(graph, templateId);
            } catch (NonUniqueResultException e) {
                log.error("Duplicate template representation: " + templateId, e);
            }
            if (template != null) {
                // get associated user
                Vertex v = template.getV();
                Iterator<Vertex> owners = v.getVertices(Direction.OUT, "owner").iterator();
                if (UserUtil.isAdmin() // user is admin
                        // or user is owner
                        || (owners.hasNext()
                                && UserUtil.getLogin().equals(new User(owners.next(), graph).getLogin()))) {
                    add(new TemplateForm("edit-form", false, templateId));
                } else {
                    throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_FORBIDDEN);
                }
            } else {
                throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND,
                        "Template not found.");
            }
        } finally {
            graph.shutdown();
        }
    } else
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST,
                "Template identifier must be specified.");
}

From source file:eu.esdihumboldt.hale.server.templates.war.pages.TemplatePage.java

License:Open Source License

@SuppressWarnings("serial")
@Override//from   www  .j  a v a  2 s.  c  om
protected void addControls(boolean loggedIn) {
    super.addControls(loggedIn);

    StringValue idParam = getPageParameters().get(0);
    if (!idParam.isNull() && !idParam.isEmpty()) {
        String templateId = idParam.toString();

        OrientGraph graph = DatabaseHelper.getGraph();
        try {
            Template template = null;
            try {
                template = Template.getByTemplateId(graph, templateId);
            } catch (NonUniqueResultException e) {
                log.error("Duplicate template representation: " + templateId, e);
            }
            if (template != null) {
                // name
                Label name = new Label("name", template.getName());
                add(name);

                // download
                String href = TemplateLocations.getTemplateDownloadUrl(templateId);
                ExternalLink download = new ExternalLink("download", href);
                add(download);

                // project location
                WebMarkupContainer project = new WebMarkupContainer("project");
                project.add(AttributeModifier.replace("value",
                        TemplateLocations.getTemplateProjectUrl(scavenger, templateId)));
                add(project);

                // author
                Label author = new Label("author", template.getAuthor());
                add(author);

                // edit-buttons container
                WebMarkupContainer editButtons = new WebMarkupContainer("edit-buttons");
                editButtons.setVisible(false);
                add(editButtons);

                // deleteDialog container
                WebMarkupContainer deleteDialog = new WebMarkupContainer("deleteDialog");
                deleteDialog.setVisible(false);
                add(deleteDialog);

                // user
                String userName;
                Vertex v = template.getV();
                boolean showEditPart = UserUtil.isAdmin();
                Iterator<Vertex> owners = v.getVertices(Direction.OUT, "owner").iterator();
                if (owners.hasNext()) {
                    User user = new User(owners.next(), graph);
                    userName = UserUtil.getDisplayName(user);

                    showEditPart = loggedIn && UserUtil.getLogin().equals(user.getLogin());
                } else {
                    userName = "Unregistered user";
                }

                // edit buttons
                if (showEditPart) {
                    editButtons.setVisible(true);
                    deleteDialog.setVisible(true);

                    // edit
                    editButtons.add(new BookmarkablePageLink<>("edit", EditTemplatePage.class,
                            new PageParameters().set(0, templateId)));

                    // update
                    editButtons.add(new BookmarkablePageLink<>("update", UpdateTemplatePage.class,
                            new PageParameters().set(0, templateId)));

                    // delete
                    deleteDialog.add(new DeleteTemplateLink("delete", templateId));
                }

                Label user = new Label("user", userName);
                add(user);

                // description
                String descr = template.getDescription();
                String htmlDescr = null;
                if (descr == null || descr.isEmpty()) {
                    descr = "No description for the project template available.";
                } else {
                    // convert markdown to
                    htmlDescr = new PegDownProcessor(Extensions.AUTOLINKS | Extensions.SUPPRESS_ALL_HTML
                            | Extensions.HARDWRAPS | Extensions.SMARTYPANTS).markdownToHtml(descr);
                }
                // description in pre
                Label description = new Label("description", descr);
                description.setVisible(htmlDescr == null);
                add(description);
                // description in div
                Label htmlDescription = new Label("html-description", htmlDescr);
                htmlDescription.setVisible(htmlDescr != null);
                htmlDescription.setEscapeModelStrings(false);
                add(htmlDescription);

                // invalid
                WebMarkupContainer statusInvalid = new WebMarkupContainer("invalid");
                statusInvalid.setVisible(!template.isValid());
                add(statusInvalid);

                // resources
                ResourcesPanel resources = new ResourcesPanel("resources", templateId);
                add(resources);

                // project popover
                WebMarkupContainer projectPopover = new WebMarkupContainer("project-popover");
                projectPopover.add(new HTMLPopoverBehavior(Model.of("Load template in HALE"),
                        new PopoverConfig().withPlacement(Placement.bottom)) {

                    @Override
                    public Component newBodyComponent(String markupId) {
                        return new ProjectURLPopover(markupId);
                    }

                });
                add(projectPopover);
            } else {
                throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND,
                        "Template not found.");
            }
        } finally {
            graph.shutdown();
        }
    } else
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST,
                "Template identifier must be specified.");
}

From source file:eu.esdihumboldt.hale.server.templates.war.pages.UpdateTemplatePage.java

License:Open Source License

@Override
protected void addControls() {
    StringValue idParam = getPageParameters().get(0);
    if (!idParam.isNull() && !idParam.isEmpty()) {
        String templateId = idParam.toString();

        OrientGraph graph = DatabaseHelper.getGraph();
        try {/*from w  w w .ja v  a 2 s  .  c  om*/
            Template template = null;
            try {
                template = Template.getByTemplateId(graph, templateId);
            } catch (NonUniqueResultException e) {
                log.error("Duplicate template representation: " + templateId, e);
            }
            if (template != null) {
                // get associated user
                Vertex v = template.getV();
                Iterator<Vertex> owners = v.getVertices(Direction.OUT, "owner").iterator();
                if (UserUtil.isAdmin() // user is admin
                        // or user is owner
                        || (owners.hasNext()
                                && UserUtil.getLogin().equals(new User(owners.next(), graph).getLogin()))) {
                    // template name
                    add(new Label("name", template.getName()));
                    // upload form
                    add(new TemplateUploadForm("upload-form", templateId));
                } else {
                    throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_FORBIDDEN);
                }
            } else {
                throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND,
                        "Template not found.");
            }
        } finally {
            graph.shutdown();
        }
    } else
        throw new AbortWithHttpErrorCodeException(HttpServletResponse.SC_BAD_REQUEST,
                "Template identifier must be specified.");
}

From source file:eu.uqasar.web.pages.BasePage.java

License:Apache License

private void configureLanguage(PageParameters pageParameters) {
    StringValue language = pageParameters.get("lang");
    if (!language.isEmpty()) {
        final String currentLanguage = Session.get().getLocale().getLanguage();
        final String newLanguage = language.toString();
        if (!currentLanguage.equalsIgnoreCase(newLanguage)) {
            final Locale newLocale = new Locale(language.toString());
            ResourceBundle.clearCache();
            UQSession.get().updateUserLocale(newLocale);
        }/* w ww  .  j  a va  2  s .  c o m*/
    }
}

From source file:eu.uqasar.web.pages.user.UserPage.java

License:Apache License

protected String getRequestedUsername() {
    StringValue id = getPageParameters().get("userName");
    return id.toString();
}

From source file:eu.uqasar.web.pages.user.UserPage.java

License:Apache License

private User getRequestedUser(final StringValue userName) {
    return getRequestedUser(userName.toString());
}

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   w  w  w .  jav a2s . 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
 *///  ww w.  ja v  a2  s .  c o  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);
}

From source file:gr.abiss.calipso.wicket.ItemViewPage.java

License:Open Source License

public ItemViewPage(PageParameters params) {
    logger.info("item id parsed from url params.get(0) = '" + params.get(0) + "', null: "
            + (params.get(0) == null));/*from   w ww  .j  av  a  2s. com*/
    logger.info("item id parsed from url params.get(\"0\")= '" + params.get("0") + "', null: "
            + (params.get("0") == null));
    logger.info("item id parsed from url params.get(\"itemId\")= '" + params.get("itemId") + "', null: "
            + (params.get("itemId") == null));
    org.apache.wicket.util.string.StringValue paramId = params.get("0");
    logger.info("paramId 1: " + paramId);
    if (StringUtils.isBlank(paramId + "") || "null".equals(paramId + "")) {
        paramId = params.get(0);
        logger.info("paramId 2: " + paramId);
    }
    if (StringUtils.isBlank(paramId + "") || "null".equals(paramId + "")) {
        paramId = params.get("itemId");
        logger.info("paramId 3: " + paramId);
    }
    if (StringUtils.isBlank(paramId + "") || "null".equals(paramId + "")) {
        throw new AbortWithHttpErrorCodeException(404);
    }
    String refId = paramId.toString();
    logger.info("refId: " + refId);
    logger.info("uniqueRefId: " + Item.getItemIdFromUniqueRefId(refId));

    setCurrentItemSearch(null);

    // TODO: is this needed?
    Item item = getCalipso().loadItem(Item.getItemIdFromUniqueRefId(refId));
    logger.info("item: " + item);
    if (item != null) {
        itemId = item.getId(); // required for itemRelatePanel
    } else {
        throw new AbortWithHttpErrorCodeException(404);
    }
    //breadcrumb navigation. stays static
    CalipsoBreadCrumbBar breadCrumbBar = new CalipsoBreadCrumbBar("breadCrumbBar", this);
    add(breadCrumbBar);

    //panels that change with navigation
    ItemViewPanel itemViewPanel = new ItemViewPanel("panel", breadCrumbBar, refId);
    add(itemViewPanel);
    breadCrumbBar.setActive(itemViewPanel);
}

From source file:io.ucoin.ucoinj.web.pages.registry.CurrencyPage.java

License:Open Source License

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

    StringValue parameCurrencyName = parameters.get(CURRENCY_PARAMETER);
    final String currencyName = parameCurrencyName.toString();

    setDefaultModel(new CompoundPropertyModel<Currency>(new LoadableDetachableModel<Currency>() {
        @Override//from   w ww .ja v a 2s .co m
        protected Currency load() {
            return ServiceLocator.instance().getCurrencyIndexerService().getCurrencyById(currencyName);
        }
    }));

    add(new Label("currencyName"));

    //add(new Label("memberCount"));
}