Example usage for org.apache.wicket.core.util.string JavaScriptUtils escapeQuotes

List of usage examples for org.apache.wicket.core.util.string JavaScriptUtils escapeQuotes

Introduction

In this page you can find the example usage for org.apache.wicket.core.util.string JavaScriptUtils escapeQuotes.

Prototype

public static CharSequence escapeQuotes(final CharSequence input) 

Source Link

Document

Escape single and double quotes so that they can be part of e.g.

Usage

From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.behaviors.MultiUpdatingTimerBehavior.java

License:Apache License

/**
 * @param updateInterval/*from w ww. j ava  2s. c  om*/
 *            Duration between AJAX callbacks
 * @return JS script
 */
protected final String getJsTimeoutCall(final Duration updateInterval) {
    final CharSequence js = JavaScriptUtils.escapeQuotes(getCallbackScript());

    final String timeoutHandle = getTimeoutHandle();
    // this might look strange, but it is necessary for IE not to leak :(
    return timeoutHandle + " = setTimeout('" + js + "', " + updateInterval.getMilliseconds() + ')';
}

From source file:com.googlecode.wicket.kendo.ui.widget.notification.NotificationBehavior.java

License:Apache License

/**
 * Formats the message (escaping, etc)/*from   w ww  .  j a  v a 2s  . com*/
 *
 * @param message the message to format
 * @param level the level, ie: info, success, warning, error
 * @return the formated message
 */
protected CharSequence format(CharSequence message, String level) {
    return JavaScriptUtils.escapeQuotes(message);
}

From source file:guru.mmp.application.web.template.util.FeedbackUtil.java

License:Apache License

/**
 * Generate the Javascript to display the feedback for the specified component.
 *
 * @param id                     the id of the component to provide the feedback for
 * @param component              the component to generate the feedback JavaScript for
 * @param isAjaxRequest          is feedback being generated as part of an Ajax request
 * @param feedbackMessageClasses the additional CSS classes to apply to the feedback message
 *
 * @return the JavaScript to display the feedback message or <code>null</code>
 *         if there is no feedback for the specified component
 *///from  ww  w.  ja va  2  s  . c  om
public static String generateFeedbackJavaScript(String id, Component component, boolean isAjaxRequest,
        String feedbackMessageClasses) {
    if (component.hasFeedbackMessage()) {
        FeedbackMessages feedbackMessages = component.getFeedbackMessages();

        FeedbackMessage feedbackMessage = feedbackMessages.first();

        String feedbackClass = null;

        if (feedbackMessage.isError()) {
            feedbackClass = "has-error";
        } else if (feedbackMessage.isFatal()) {
            feedbackClass = "has-error";
        } else if (feedbackMessage.isWarning()) {
            feedbackClass = "has-warning";
        } else if (feedbackMessage.isInfo()) {
            feedbackClass = "has-info";
        } else if (feedbackMessage.isDebug()) {
            feedbackClass = "has-success";
        }

        String javaScript = String.format(
                isAjaxRequest ? SHOW_FORM_COMPONENT_FEEDBACK_JAVA_SCRIPT
                        : DOM_READY_SHOW_FORM_COMPONENT_FEEDBACK_JAVA_SCRIPT,
                id, feedbackClass, StringUtil.notNull(feedbackMessageClasses),
                JavaScriptUtils.escapeQuotes(feedbackMessage.getMessage().toString()));

        // Clear the feedback messages for the component
        for (FeedbackMessage componentFeedbackMessage : feedbackMessages) {
            componentFeedbackMessage.markRendered();
        }

        return javaScript;
    } else {
        if (isAjaxRequest) {
            return String.format(CLEAR_FORM_COMPONENT_FEEDBACK_JAVA_SCRIPT, id);
        }

        return null;
    }
}

From source file:org.alienlabs.hatchetharry.view.component.gui.ChatPanel.java

License:Open Source License

public ChatPanel(final String id) {
    super(id);/*from  ww w  .ja  va 2  s .  co  m*/
    Injector.get().inject(this);

    final Form<String> form = new Form<>("chatForm");

    final RequiredTextField<String> user = new RequiredTextField<>("user", new Model<>(""));
    user.setMarkupId("userName");
    user.setOutputMarkupId(true);
    form.add(user);
    final RequiredTextField<String> message = new RequiredTextField<>("message", new Model<>(""));
    message.setOutputMarkupId(true).setMarkupId("message");
    form.add(message);

    final AjaxButton button = new AjaxButton("submit") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> _form) {
            ChatPanel.LOGGER.info("submit");

            final String _user = JavaScriptUtils.escapeQuotes(_form.get("user").getDefaultModelObjectAsString())
                    .toString();
            final String _message = JavaScriptUtils
                    .escapeQuotes(_form.get("message").getDefaultModelObjectAsString()).toString();
            ChatPanel.LOGGER.info("user: " + _user + ", message: " + _message);

            final Long gameId = ChatPanel.this.persistenceService
                    .getPlayer(HatchetHarrySession.get().getPlayer().getId()).getGame().getId();

            final String chatMessage = _user + " said: " + _message;

            final ChatMessage msg = new ChatMessage();
            msg.setGameId(gameId);
            msg.setMessage(chatMessage);
            ChatPanel.this.persistenceService.saveChatMessage(msg);

            final List<BigInteger> allPlayersInGame = ChatPanel.this.persistenceService
                    .giveAllPlayersFromGame(gameId);
            final ChatCometChannel ccc = new ChatCometChannel(HatchetHarrySession.get().getPlayer(), _user,
                    gameId, chatMessage);
            EventBusPostService.post(allPlayersInGame, ccc);

        }
    };
    form.add(button);
    this.add(form);
}

From source file:org.apache.openmeetings.web.common.ConfirmCallListener.java

License:Apache License

public ConfirmCallListener(long id, String js) {
    onPrecondition("if (!confirm('" + JavaScriptUtils.escapeQuotes(WebSession.getString(id)) + "')) {" + js
            + "; hideBusyIndicator(); return false;}");
}

From source file:org.apache.openmeetings.web.components.MenuPanel.java

License:Apache License

public MenuPanel(String id, final MarkupContainer contents) {
    super(id);//w w  w. j a v a2  s  .c  om
    setMarkupId(id);

    final NaviBuilder man = Application.getBean(NaviBuilder.class);
    add(new ListView<Naviglobal>("mainItem",
            man.getMainMenu(WebSession.getUserLevel(), WebSession.getUserId(), WebSession.getLanguage())) {
        private static final long serialVersionUID = 2173926553418745231L;

        @Override
        protected void populateItem(ListItem<Naviglobal> item) {
            Naviglobal gl = item.getModelObject();
            item.add(new Label("label", gl.getLabel().getValue()).setRenderBodyOnly(true));

            item.add(new ListView<Navimain>("childItem", gl.getMainnavi()) {
                private static final long serialVersionUID = 3609635268338379087L;

                @Override
                protected void populateItem(ListItem<Navimain> item) {
                    Navimain m = item.getModelObject();
                    final String name = m.getLabel().getValue();
                    final String desc = m.getTooltip().getValue();
                    final MenuActions action = MenuActions.valueOf(m.getAction());
                    final MenuParams params = m.getParams() != null ? MenuParams.valueOf(m.getParams())
                            : MenuParams.publicTabButton;
                    final String hash = getHash(action, params);
                    item.add(new AjaxLink<Void>("link") {
                        private static final long serialVersionUID = 5632618935550133709L;
                        {
                            add(new Label("name", name));
                            add(new Label("description", desc));
                        }

                        public void onClick(AjaxRequestTarget target) {

                            BasePanel basePanel = null;

                            switch (action) {
                            case dashboardModuleStartScreen:
                                break;
                            case dashboardModuleCalendar:
                                basePanel = new CalendarPanel("child");
                                break;
                            case recordModule:
                                break;
                            case conferenceModuleRoomList:
                                basePanel = new UserRoomsPanel("child", params);
                                break;
                            case eventModuleRoomList:
                                break;
                            case moderatorModuleUser:
                                break;
                            case moderatorModuleRoom:
                                break;
                            case adminModuleUser:
                                basePanel = new UsersPanel("child");
                                break;
                            case adminModuleConnections:
                                break;
                            case adminModuleOrg:
                                basePanel = new GroupsPanel("child");
                                break;
                            case adminModuleRoom:
                                basePanel = new RoomsPanel("child");
                                break;
                            case adminModuleConfiguration:
                                basePanel = new ConfigsPanel("child");
                                break;
                            case adminModuleLanguages:
                                basePanel = new LangPanel("child");
                                break;
                            case adminModuleLDAP:
                                basePanel = new LdapsPanel("child");
                                break;
                            case adminModuleBackup:
                                basePanel = new BackupPanel("child");
                                break;
                            case adminModuleServers:
                                basePanel = new ServersPanel("child");
                                break;
                            }

                            if (basePanel != null) {
                                target.add(contents.replace(basePanel));
                                basePanel.onMenuPanelLoad(target);
                            }

                            target.appendJavaScript(
                                    "location.hash = '" + JavaScriptUtils.escapeQuotes(hash) + "';");
                        };
                    }.add(AttributeModifier.replace("href", hash)));
                }
            }.setReuseItems(true));
        }
    }.setReuseItems(true));

    add(new Behavior() {
        private static final long serialVersionUID = 9067610794087880297L;

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            String area = WebSession.get().getArea();
            if (area != null) { //hash passed from signin
                response.render(OnDomReadyHeaderItem
                        .forScript("$(\"a[href='" + JavaScriptUtils.escapeQuotes(area) + "']\").click();"));
                WebSession.get().setArea(null);
            } else {
                response.render(
                        OnDomReadyHeaderItem.forScript("$(\"a[href='\" + location.hash + \"']\").click();"));
            }
            super.renderHead(component, response);
        }
    });
}

From source file:org.isisaddons.wicket.summernote.cpt.ui.editor.SummernoteEditorPanel.java

License:Apache License

protected Component getComponentForRegular() {
    Fragment fragment = new Fragment("fragment", "regular", SummernoteEditorPanel.this);

    SummernoteEditorFacetAbstract editorFacet = getModel().getFacet(SummernoteEditorFacetAbstract.class);
    SummernoteConfig config = editorFacet.getConfig();

    fragment.add(new SummernoteEditor("editor", new TextFieldValueModel<>(this), config) {

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

            response.render(OnDomReadyHeaderItem.forScript(String.format("debugger;$('#%s').code('%s')",
                    getMarkupId(), JavaScriptUtils.escapeQuotes(getModelObject()))));
        }
    });
    return fragment;
}

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

License:Apache License

private static String jsStringOrNull(String s) {
    return (s == null) ? "null" : "'" + JavaScriptUtils.escapeQuotes(s) + "'";
}

From source file:org.wicketstuff.dashboard.web.util.ConfirmAjaxCallListener.java

License:Apache License

public ConfirmAjaxCallListener(String confirmMessage) {
    CharSequence message = JavaScriptUtils.escapeQuotes(confirmMessage);
    StringBuilder precondition = new StringBuilder("if(!confirm('").append(message)
            .append("')) { return false; };");
    onPrecondition(precondition);//from  w ww.  j  a  v a 2  s  . c  om
}

From source file:sf.wicklet.ext.behaviors.ajax.AjaxRefreshTimerBehavior.java

License:Apache License

/**
 * @param updateInterval/*from   ww  w.  j  a  v a2 s . com*/
 *            Duration between AJAX callbacks
 * @return JS script
 */
protected final String getJsTimeoutCall(final Duration updateInterval) {
    CharSequence js = getCallbackScript();
    js = JavaScriptUtils.escapeQuotes(js);
    final String timeoutHandle = getTimeoutHandle();
    // this might look strange, but it is necessary for IE not to leak :(
    return timeoutHandle + " = setTimeout('" + js + "', " + updateInterval.getMilliseconds() + ')';
}