Example usage for org.apache.wicket.util.string Strings isTrue

List of usage examples for org.apache.wicket.util.string Strings isTrue

Introduction

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

Prototype

public static boolean isTrue(final String s) throws StringValueConversionException 

Source Link

Document

Converts the text in s to a corresponding boolean.

Usage

From source file:com.userweave.components.authorization.AuthOnlyCheckBox.java

License:Open Source License

/**
 * Processes the component tag./*  w w  w . j a  va 2  s  .  c  om*/
 * 
 * @param tag
 *            Tag to modify
 * @see org.apache.wicket.Component#onComponentTag(ComponentTag)
 */
@Override
protected void onComponentTag(final ComponentTag tag) {
    PackageResourceReference img;

    if (!isAuthorized) {
        tag.setName("img");

        final String value = getValue();
        if (value != null && value.equals("true")) {
            img = new PackageResourceReference(AuthOnlyCheckBox.class, "res/check.png");
        } else {
            img = new PackageResourceReference(AuthOnlyCheckBox.class, "res/uncheck.png");
        }
        CharSequence url = RequestCycle.get().urlFor(img, null);

        tag.put("src",
                RequestCycle.get().getOriginalResponse().encodeURL(Strings.replaceAll(url, "&", "&")));
    } else {
        checkComponentTag(tag, "input");
        checkComponentTagAttribute(tag, "type", "checkbox");

        final String value = getValue();
        if (value != null) {
            try {
                if (Strings.isTrue(value)) {
                    tag.put("checked", "checked");
                } else {
                    // In case the attribute was added at design time
                    tag.remove("checked");
                }
            } catch (StringValueConversionException e) {
                throw new WicketRuntimeException("Invalid boolean value \"" + value + "\"", e);
            }
        }

        // Should a roundtrip be made (have onSelectionChanged called) when the
        // checkbox is clicked?
        if (wantOnSelectionChangedNotifications()) {
            //            CharSequence url = urlFor(IOnChangeListener.INTERFACE);
            //   
            //            Form form = findParent(Form.class);
            //            if (form != null)
            //            {
            //               RequestContext rc = RequestContext.get();
            //               if (rc.isPortletRequest())
            //               {
            //                  // restore url back to real wicket path as its going to be interpreted by the
            //                  // form itself
            //                  url = ((PortletRequestContext)rc).getLastEncodedPath();
            //               }
            //               tag.put("onclick", form.getJsForInterfaceUrl(url));
            //            }
            //            else
            //            {
            //               // TODO: following doesn't work with portlets, should be posted to a dynamic hidden
            //               // form
            //               // with an ActionURL or something
            //               // NOTE: do not encode the url as that would give invalid
            //               // JavaScript
            //               tag.put("onclick", "window.location.href='" + url +
            //                  (url.toString().indexOf('?') > -1 ? "&" : "?") + getInputName() +
            //                  "=' + this.checked;");
            //            }

        }
    }

    super.onComponentTag(tag);
}

From source file:guru.mmp.application.web.template.components.CodeCategoryInputPanel.java

License:Apache License

private void setupEndPointContainer() {
    endPointContainer = new WebMarkupContainer("endPointContainer") {
        private static final long serialVersionUID = 1000000;

        @Override/*from   www. j  ava2 s .co  m*/
        protected void onConfigure() {
            super.onConfigure();

            setVisible(
                    CodeCategoryType.REMOTE_HTTP_SERVICE.getCodeAsString().equals(categoryTypeField.getValue())
                            || CodeCategoryType.REMOTE_WEB_SERVICE.getCodeAsString()
                                    .equals(categoryTypeField.getValue()));
        }
    };

    endPointContainer.setOutputMarkupId(true);
    endPointContainer.setOutputMarkupPlaceholderTag(true);
    add(endPointContainer);

    // The "endPoint" field
    endPointField = new TextFieldWithFeedback<String>("endPoint") {
        @Override
        protected void onConfigure() {
            super.onConfigure();

            setRequired(
                    (CodeCategoryType.REMOTE_HTTP_SERVICE.getCodeAsString().equals(categoryTypeField.getValue())
                            || CodeCategoryType.REMOTE_WEB_SERVICE.getCodeAsString()
                                    .equals(categoryTypeField.getValue())));
        }
    };
    endPointContainer.add(endPointField);

    // The "isEndPointSecure" field
    isEndPointSecureField = new CheckBox("isEndPointSecure");
    endPointContainer.add(isEndPointSecureField);

    // The "isCacheable" field
    isCacheableField = new CheckBox("isCacheable");

    isCacheableField.add(new AjaxFormComponentUpdatingBehavior("change") {
        private static final long serialVersionUID = 1000000;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            cacheExpiryField.setModelObject(null);

            target.add(cacheExpiryField);
        }
    });

    isCacheableField.setOutputMarkupId(true);
    endPointContainer.add(isCacheableField);

    // The "cacheExpiry" field
    cacheExpiryField = new TextFieldWithFeedback<Integer>("cacheExpiry") {
        @Override
        protected void onConfigure() {
            super.onConfigure();

            setRequired(Strings.isTrue(isCacheableField.getValue()));
            setEnabled(Strings.isTrue(isCacheableField.getValue()));
        }
    };

    endPointContainer.add(cacheExpiryField);
}

From source file:org.brixcms.plugin.site.resource.ResourceNodeHandler.java

License:Apache License

@Override
public void respond(IRequestCycle requestCycle) {
    boolean save = (this.save != null) ? this.save
            : Strings.isTrue(RequestCycle.get().getRequest().getRequestParameters()
                    .getParameterValue(SAVE_PARAMETER).toString());

    BrixFileNode node = (BrixFileNode) this.node.getObject();

    if (!SitePlugin.get().canViewNode(node, Action.Context.PRESENTATION)) {
        throw Brix.get().getForbiddenException();
    }/*  ww w. j  a  v  a 2  s. c  o m*/

    WebResponse response = (WebResponse) RequestCycle.get().getResponse();

    response.setContentType(node.getMimeType());

    Date lastModified = node.getLastModified();
    response.setLastModifiedTime(Time.valueOf(lastModified));

    try {
        final HttpServletRequest r = (HttpServletRequest) requestCycle.getRequest().getContainerRequest();
        String since = r.getHeader("If-Modified-Since");
        if (!save && since != null) {
            Date d = new Date(r.getDateHeader("If-Modified-Since"));

            // the weird toString comparison is to prevent comparing
            // milliseconds
            if (d.after(lastModified) || d.toString().equals(lastModified.toString())) {
                response.setContentLength(node.getContentLength());
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            }
        }
        String fileName = node.getName();
        long length = node.getContentLength();
        HttpServletResponse httpServletResponse = (HttpServletResponse) response.getContainerResponse();
        InputStream stream = node.getDataAsStream();

        new Streamer(length, stream, fileName, save, r, httpServletResponse).stream();
    } catch (Exception e) {
        log.error("Error writing resource data to content", e);
    }
}

From source file:org.brixcms.plugin.site.resource.ResourceRequestTarget.java

License:Apache License

public void respond(RequestCycle requestCycle) {
    boolean save = (this.save != null) ? this.save
            : Strings.isTrue(requestCycle.getRequest().getParameter(SAVE_PARAMETER));

    BrixFileNode node = (BrixFileNode) this.node.getObject();

    if (!SitePlugin.get().canViewNode(node, Action.Context.PRESENTATION)) {
        throw Brix.get().getForbiddenException();
    }/*from ww  w . j  ava  2s .  co m*/

    WebResponse response = (WebResponse) requestCycle.getResponse();

    response.setContentType(node.getMimeType());

    Date lastModified = node.getLastModified();
    response.setLastModifiedTime(Time.valueOf(lastModified));

    try {
        HttpServletRequest r = ((WebRequest) requestCycle.getRequest()).getHttpServletRequest();
        String since = r.getHeader("If-Modified-Since");
        if (!save && since != null) {
            Date d = new Date(r.getDateHeader("If-Modified-Since"));

            // the weird toString comparison is to prevent comparing milliseconds
            if (d.after(lastModified) || d.toString().equals(lastModified.toString())) {
                response.setContentLength(node.getContentLength());
                response.getHttpServletResponse().setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            }
        }
        String fileName = node.getName();
        long length = node.getContentLength();
        HttpServletRequest httpServletRequest = ((WebRequest) requestCycle.getRequest())
                .getHttpServletRequest();
        HttpServletResponse httpServletResponse = response.getHttpServletResponse();
        InputStream stream = node.getDataAsStream();

        new Streamer(length, stream, fileName, save, httpServletRequest, httpServletResponse).stream();
    } catch (Exception e) {
        log.error("Error writing resource data to content", e);
    }
}

From source file:org.sakaiproject.delegatedaccess.tool.pages.EditablePanelList.java

License:Educational Community License

public EditablePanelList(String id, IModel inputModel, final NodeModel nodeModel, final TreeNode node,
        final int userType, final int fieldType) {
    super(id);/*from  w ww.  j  a  v  a2s.co  m*/

    this.nodeModel = nodeModel;
    this.node = node;

    final WebMarkupContainer editableSpan = new WebMarkupContainer("editableSpan");
    editableSpan.setOutputMarkupId(true);
    final String editableSpanId = editableSpan.getMarkupId();
    add(editableSpan);

    AjaxLink<Void> saveEditableSpanLink = new AjaxLink<Void>("saveEditableSpanLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            target.appendJavascript("document.getElementById('" + editableSpanId + "').style.display='none';");
            //In order for the models to refresh, you have to call "expand" or "collapse" then "updateTree",
            //since I don't want to expand or collapse, I just call whichever one the node is already
            //Refreshing the tree will update all the models and information (like role) will be generated onClick
            if (((BaseTreePage) target.getPage()).getTree().getTreeState().isNodeExpanded(node)) {
                ((BaseTreePage) target.getPage()).getTree().getTreeState().expandNode(node);
            } else {
                ((BaseTreePage) target.getPage()).getTree().getTreeState().collapseNode(node);
            }
            ((BaseTreePage) target.getPage()).getTree().updateTree(target);
        }
    };
    editableSpan.add(saveEditableSpanLink);

    Label editableSpanLabel = new Label("editableNodeTitle", nodeModel.getNode().title);
    editableSpan.add(editableSpanLabel);

    WebMarkupContainer toolTableHeader = new WebMarkupContainer("toolTableHeader") {
        @Override
        public boolean isVisible() {
            return DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType;
        }
    };
    editableSpan.add(toolTableHeader);

    List<ListOptionSerialized[]> listOptions = new ArrayList<ListOptionSerialized[]>();

    final ListView<ListOptionSerialized[]> listView = new ListView<ListOptionSerialized[]>("list",
            listOptions) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<ListOptionSerialized[]> item) {
            ListOptionSerialized wrapper = item.getModelObject()[0];
            item.add(new Label("name", wrapper.getName()));
            //Auth Checkbox:
            final CheckBox checkBox = new CheckBox("authCheck", new PropertyModel(wrapper, "selected"));
            checkBox.setOutputMarkupId(true);
            checkBox.setOutputMarkupPlaceholderTag(true);
            final String checkBoxId = checkBox.getMarkupId();
            final String toolId = wrapper.getId();
            checkBox.add(new AjaxFormComponentUpdatingBehavior("onClick") {
                protected void onUpdate(AjaxRequestTarget target) {
                    if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) {
                        nodeModel.setAuthToolRestricted(toolId, isChecked());
                    }
                }

                private boolean isChecked() {
                    final String value = checkBox.getValue();
                    if (value != null) {
                        try {
                            return Strings.isTrue(value);
                        } catch (Exception e) {
                            return false;
                        }
                    }
                    return false;
                }
            });
            item.add(checkBox);
            if (nodeModel.isPublicToolRestricted(toolId) && !nodeModel.isAuthToolRestricted(toolId)) {
                //disable the auth option because public is already selected (only disable if it's not already selected)
                checkBox.setEnabled(false);
            }

            //Public Checkbox:
            ListOptionSerialized publicWrapper = item.getModelObject()[1];
            final CheckBox publicCheckBox = new CheckBox("publicCheck",
                    new PropertyModel(publicWrapper, "selected")) {
                @Override
                public boolean isVisible() {
                    return DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType;
                }
            };
            publicCheckBox.setOutputMarkupId(true);
            final String publicToolId = publicWrapper.getId();
            publicCheckBox.add(new AjaxFormComponentUpdatingBehavior("onClick") {
                protected void onUpdate(AjaxRequestTarget target) {
                    boolean checked = isPublicChecked();

                    if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) {
                        nodeModel.setPublicToolRestricted(publicToolId, checked);
                    }

                    if (checked) {
                        //if public is checked, we don't need the "auth" checkbox enabled (or selected).  Disabled and De-select it
                        checkBox.setModelValue(new String[] { "false" });
                        checkBox.setEnabled(false);
                        if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) {
                            nodeModel.setAuthToolRestricted(toolId, false);
                        }
                    } else {
                        checkBox.setEnabled(true);
                    }
                    target.addComponent(checkBox, checkBoxId);
                }

                private boolean isPublicChecked() {
                    final String value = publicCheckBox.getValue();
                    if (value != null) {
                        try {
                            return Strings.isTrue(value);
                        } catch (Exception e) {
                            return false;
                        }
                    }
                    return false;
                }
            });
            item.add(publicCheckBox);

        }
    };
    editableSpan.add(listView);

    AjaxLink<Void> restrictToolsLink = new AjaxLink<Void>("restrictToolsLink") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (!loadedFlag) {
                loadedFlag = true;
                List<ListOptionSerialized[]> listOptions = null;
                if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) {
                    listOptions = getNodeModelToolsList(nodeModel);
                }
                listView.setDefaultModelObject(listOptions);
                target.addComponent(editableSpan);
            }
            target.appendJavascript("document.getElementById('" + editableSpanId + "').style.display='';");
        }
    };
    add(restrictToolsLink);

    add(new WebComponent("noToolsSelectedWarning") {
        @Override
        public boolean isVisible() {
            return DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType
                    && nodeModel.getSelectedRestrictedAuthTools().isEmpty()
                    && nodeModel.getSelectedRestrictedPublicTools().isEmpty();
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.put("title", new ResourceModel("noToolsSelected").getObject());
        }
    });

    Label restrictToolsLinkLabel = new Label("restrictToolsSpan");
    if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) {
        if (DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType) {
            restrictToolsLinkLabel.setDefaultModel(new StringResourceModel("showToolsHeader", null));
        } else {
            restrictToolsLinkLabel.setDefaultModel(new StringResourceModel("restrictedToolsHeader", null));
        }
    }
    restrictToolsLink.add(restrictToolsLinkLabel);

    Label editToolsTitle = new Label("editToolsTitle");
    if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) {
        if (DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType) {
            editToolsTitle.setDefaultModel(new StringResourceModel("editableShowToolsTitle", null));
        } else {
            editToolsTitle.setDefaultModel(new StringResourceModel("editableRestrictedToolsTitle", null));
        }
    }
    editableSpan.add(editToolsTitle);

    Label editToolsInstructions = new Label("editToolsInstructions");
    if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) {
        if (DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType) {
            editToolsInstructions
                    .setDefaultModel(new StringResourceModel("editableShowToolsDescription", null));
        } else {
            editToolsInstructions
                    .setDefaultModel(new StringResourceModel("editableRestrictedToolsDescription", null));
        }
    }
    editableSpan.add(editToolsInstructions);

}

From source file:org.sakaiproject.profile2.tool.components.EnablingCheckBox.java

License:Educational Community License

public boolean isChecked() {

    final String value = getValue();

    if (value != null) {
        try {/*from  w w  w  . j  a v a  2  s  . c om*/
            return Strings.isTrue(value);
        } catch (StringValueConversionException e) {
            return false;
        }
    }
    return false;
}

From source file:org.wicketstuff.table.SelectableListItem.java

License:Apache License

/**
 * @param index/*from  w  w w  .  j a va 2s . c  o  m*/
 * @param model
 *            list item model, users parameter.
 * @param listSelectionModel
 *            Based on its state, the row selection is resolved. Ex: row css
 *            class will reflect the actual state.
 */
public SelectableListItem(int index, IModel<T> model, ListSelectionModel listSelectionModel) {
    super(index, model);
    setOutputMarkupId(true);
    add(TABLE_JS);
    this.listSelectionModel = listSelectionModel;
    this.add(new AjaxEventBehavior("onclick") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {
            onItemSelection(target, Strings.isTrue(getRequest().getParameter(SHIFT_P)),
                    Strings.isTrue(getRequest().getParameter(CTRL_P)));
        }

        @Override
        public CharSequence getCallbackUrl(boolean onlyTargetActivePage) {
            return super.getCallbackUrl(onlyTargetActivePage)
                    + String.format("&%s='+event.shiftKey+'&%s='+event.ctrlKey+'", SHIFT_P, CTRL_P);
        }

        @Override
        protected CharSequence getPreconditionScript() {
            if (preventSelectTwice) {
                return String.format("return Wicket.$('%s').isSelected == false", getComponent().getMarkupId());
            } else {
                return super.getPreconditionScript();
            }
        }
    });
}