Example usage for org.apache.wicket.util.template TextTemplate asString

List of usage examples for org.apache.wicket.util.template TextTemplate asString

Introduction

In this page you can find the example usage for org.apache.wicket.util.template TextTemplate asString.

Prototype

public String asString(Map<String, ?> variables) 

Source Link

Document

Interpolates the Map of variables with the content and returns the resulting String without replacing the content.

Usage

From source file:com.lyndir.lhunath.snaplog.webapp.page.util.LayoutPageUtils.java

License:Apache License

/**
 * Generate some JavaScript to track a user hit on the given component in the analytics tracker.
 *
 * @param trackComponent The component that we want to track a hit for.
 *
 * @return The JavaScript code that, when executed, will track the hit.
 *//*from w  w  w  .  j a va2  s  . c  o  m*/
public static String trackJS(final Component trackComponent) {

    checkNotNull(trackComponent, "Given trackComponent must not be null.");

    Map<String, Object> trackVariables = new HashMap<String, Object>();
    trackVariables.put("googleAnalyticsID", "UA-90535-10"); // TODO: Unhardcode.
    trackVariables.put("pageView", trackComponent.getClass().getSimpleName());

    TextTemplate trackJS = new JavaScriptTemplate(new PackagedTextTemplate(LayoutPage.class, "trackPage.js"));
    return trackJS.asString(trackVariables);
}

From source file:org.onexus.ui.authentication.persona.SignOutBehavior.java

License:Apache License

@Override
public void renderHead(final Component component, final IHeaderResponse response) {
    component.setOutputMarkupId(true);//from   www.ja v  a 2 s .c o m
    super.renderHead(component, response);

    final Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("componentId", component.getMarkupId());
    BrowserId personaId = SessionHelper.getBrowserId(Session.get());
    String userName = personaId == null ? "" : personaId.getEmail();
    variables.put("userName", userName);
    variables.put("callbackUrl", getCallbackUrl());

    final TextTemplate verifyTemplate = new PackageTextTemplate(VerifyBehavior.class, "signout.js.tmpl");
    String asString = verifyTemplate.asString(variables);

    response.render(GuestPanel.INCLUDE);
    response.render(OnDomReadyHeaderItem.forScript(asString));

}

From source file:org.onexus.ui.authentication.persona.VerifyBehavior.java

License:Apache License

@Override
public void renderHead(final Component component, final IHeaderResponse response) {
    component.setOutputMarkupId(true);/*from  w  w w  . j a  v a2 s  .  c  o  m*/
    super.renderHead(component, response);

    final Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("componentId", component.getMarkupId());
    variables.put("callbackUrl", getCallbackUrl());

    final TextTemplate verifyTemplate = new PackageTextTemplate(VerifyBehavior.class, "verify.js.tmpl");
    String asString = verifyTemplate.asString(variables);
    response.render(OnDomReadyHeaderItem.forScript(asString));
}

From source file:org.sakaiproject.wicket.markup.html.fckeditor.FCKEditorPanel.java

License:Educational Community License

/**
 * /*ww  w  .  jav  a 2s  . co m*/
 * @param id The wicket:id
 * @param model The data model
 * @param width The width of the rendered textarea
 * @param height The height of the rendered text area
 * @param toolbarSet The set of toolbars you want rendering, either basic of
 *                    default
 * @param collectionId The Sakai collection id for the FCKeditor to use
 */
public FCKEditorPanel(String id, IModel model, String width, String height, String toolbarSet,
        String collectionId) {
    super(id);

    TextArea textArea = new TextArea("editor", model) {
        protected void onModelChanged() {
            if (logger.isDebugEnabled())
                logger.debug("onModelChanged()");

            if (stripContainingParagraphTags) {
                String value = getModelValue();

                if (logger.isDebugEnabled())
                    logger.debug("Value Before:" + value);

                if (value.length() >= (ESCAPED_OPENING_P.length() + ESCAPED_CLOSING_P.length())) {
                    if (value.startsWith(ESCAPED_OPENING_P))
                        value = value.substring(ESCAPED_OPENING_P.length());

                    if (value.endsWith(ESCAPED_CLOSING_P))
                        value = value.substring(0, value.length() - ESCAPED_CLOSING_P.length());
                }

                if (logger.isDebugEnabled())
                    logger.debug("Value After:" + value);

                getModel().setObject(value);

                super.onModelChanged();
            }
        }
    };

    String textareaId = id + ((int) (Math.random() * 100));
    textArea.setMarkupId(textareaId);
    textArea.setOutputMarkupId(true);
    add(textArea);
    TextTemplate scriptTemplate = new PackagedTextTemplate(FCKEditorPanel.class, "FCKEditorScript.js");
    Map map = new MiniMap(5);
    map.put("width", width);
    map.put("height", height);
    map.put("toolbarSet", toolbarSet);
    map.put("textareaId", textareaId);
    map.put("collectionId", collectionId);

    String script = scriptTemplate.asString(map);
    Label scriptLabel = new Label("script", script);
    scriptLabel.setEscapeModelStrings(false);
    add(scriptLabel);
}

From source file:org.wicketstuff.datetime.extensions.yui.calendar.DatePicker.java

License:Apache License

/**
 * Renders yui & wicket calendar js module loading. It is done only once per page.
 * //from w  ww. j av  a2s . c  o m
 * @param response
 *            header response
 */
protected void renderHeadInit(IHeaderResponse response) {
    String key = "DatePickerInit.js";
    if (response.wasRendered(key)) {
        return;
    }

    // variables for YUILoader
    Map<String, Object> variables = new HashMap<>();
    variables.put("basePath", Strings.stripJSessionId(RequestCycle.get().urlFor(YUI, null).toString()) + "/");
    variables.put("Wicket.DateTimeInit.DatePath", RequestCycle.get().urlFor(WICKET_DATE, null));

    if (Application.get().usesDevelopmentConfig()) {
        variables.put("filter", "filter: \"RAW\",");
        variables.put("allowRollup", false);
    } else {
        variables.put("filter", "");
        variables.put("allowRollup", true);
    }

    TextTemplate template = new PackageTextTemplate(DatePicker.class, key);
    response.render(OnDomReadyHeaderItem.forScript(template.asString(variables)));

    response.markRendered(key);
}