Example usage for org.apache.wicket.util.value IValueMap getString

List of usage examples for org.apache.wicket.util.value IValueMap getString

Introduction

In this page you can find the example usage for org.apache.wicket.util.value IValueMap getString.

Prototype

String getString(final String key);

Source Link

Document

Retrieves a String by key.

Usage

From source file:com.gitblit.wicket.panels.ShockWaveComponent.java

License:Apache License

@Override
public void onComponentTag(ComponentTag tag) {
    // get options from the markup
    IValueMap valueMap = tag.getAttributes();

    // Iterate over valid options
    for (String s : optionNames) {
        if (valueMap.containsKey(s)) {
            // if option isn't set programmatically, set value from markup
            if (!attributes.containsKey(s) && !parameters.containsKey(s))
                setValue(s, valueMap.getString(s));
            // remove attribute - they are added in super.onComponentTag()
            // to
            // the right place as attribute or param
            valueMap.remove(s);//from   w w w.  j a v a 2s.  c  o m
        }
    }

    super.onComponentTag(tag);
}

From source file:com.servoy.j2db.server.headlessclient.dataui.StripHTMLTagsConverter.java

License:Open Source License

/**
 * @param bodyText/*from www.  j a v a2  s  . com*/
 * @param solution
 * @return
 */
@SuppressWarnings("nls")
public static StrippedText convertBodyText(Component component, CharSequence bodyText,
        FlattenedSolution solutionRoot) {
    StrippedText st = new StrippedText();
    if (RequestCycle.get() == null) {
        st.setBodyTxt(bodyText);
        return st;
    }

    ResourceReference rr = new ResourceReference("media"); //$NON-NLS-1$
    String solutionName = solutionRoot.getSolution().getName();

    StringBuffer bodyTxt = new StringBuffer(bodyText.length());
    XmlPullParser parser = new XmlPullParser();

    ICrypt urlCrypt = null;
    if (Application.exists())
        urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();

    try {
        parser.parse(new ByteArrayInputStream(bodyText.toString().getBytes("UTF8")), "UTF8"); //$NON-NLS-1$ //$NON-NLS-2$
        XmlTag me = (XmlTag) parser.nextTag();

        while (me != null) {
            CharSequence tmp = parser.getInputFromPositionMarker(me.getPos());
            if (tmp.toString().trim().length() > 0)
                bodyTxt.append(tmp);
            parser.setPositionMarker();

            String currentTagName = me.getName().toLowerCase();

            if (currentTagName.equals("script")) //$NON-NLS-1$
            {
                if (!me.isClose()) {
                    String srcUrl = (String) me.getAttributes().get("src"); //$NON-NLS-1$
                    if (srcUrl == null)
                        srcUrl = (String) me.getAttributes().get("SRC"); //$NON-NLS-1$
                    me = (XmlTag) parser.nextTag();
                    if (srcUrl != null) {
                        st.getJavascriptUrls()
                                .add(convertMediaReferences(srcUrl, solutionName, rr, "", true).toString());
                    } else {
                        if (me != null) {
                            st.getJavascriptScripts().add(parser.getInputFromPositionMarker(me.getPos()));
                            parser.setPositionMarker();
                        }
                    }
                } else {
                    me = (XmlTag) parser.nextTag();
                }
                continue;
            } else if (currentTagName.equals("style")) {
                if (me.isOpen()) {
                    me = (XmlTag) parser.nextTag();
                    List<CharSequence> styles = st.getStyles();
                    String style = parser.getInputFromPositionMarker(me.getPos()).toString().trim();
                    if (!"".equals(style) && !styles.contains(style)) {
                        styles.add(convertMediaReferences(style, solutionName, rr, "", false));
                    }
                    parser.setPositionMarker();
                } else {
                    me = (XmlTag) parser.nextTag();
                }
                continue;
            } else if (currentTagName.equals("link")) {
                if (me.isOpen() || me.isOpenClose()) {
                    String end = "\n";
                    if (me.isOpen())
                        end = "</link>\n";
                    st.getLinkTags().add(
                            convertMediaReferences(me.toXmlString(null) + end, solutionName, rr, "", false));
                }
                me = (XmlTag) parser.nextTag();
                continue;
            }
            if (ignoreTags.contains(currentTagName)) {
                if (currentTagName.equals("body") && (me.isOpen() || me.isOpenClose())) {
                    if (me.getAttributes().size() > 0) {
                        st.addBodyAttributes(me.getAttributes());
                    }
                    me = (XmlTag) parser.nextTag();
                } else {
                    me = (XmlTag) parser.nextTag();
                }
                continue;
            }

            if (currentTagName.equals("img") && component instanceof ILabel) {
                ILabel label = (ILabel) component;
                String onload = "Servoy.Utils.setLabelChildHeight('" + component.getMarkupId() + "', "
                        + label.getVerticalAlignment() + ");";
                onload = me.getAttributes().containsKey("onload")
                        ? me.getAttributes().getString("onload") + ";" + onload
                        : onload;
                me.getAttributes().put("onload", onload);
            }

            boolean ignoreOnclick = false;
            IValueMap attributeMap = me.getAttributes();
            // first transfer over the tabindex to anchor tags
            if (currentTagName.equals("a")) {
                int tabIndex = TabIndexHelper.getTabIndex(component);
                if (tabIndex != -1)
                    attributeMap.put("tabindex", Integer.valueOf(tabIndex));
            }
            // TODO attributes with casing?
            // now they have to be lowercase. (that is a xhtml requirement)
            for (String attribute : scanTags) {
                if (ignoreOnclick && attribute.equals("onclick")) //$NON-NLS-1$
                    continue;
                String src = attributeMap.getString(attribute);
                if (src == null) {
                    continue;
                }
                String lowercase = src.toLowerCase();
                if (lowercase.startsWith(MediaURLStreamHandler.MEDIA_URL_DEF)) {
                    String name = src.substring(MediaURLStreamHandler.MEDIA_URL_DEF.length());
                    if (name.startsWith(MediaURLStreamHandler.MEDIA_URL_BLOBLOADER)) {
                        String url = generateBlobloaderUrl(component, urlCrypt, name);
                        me.getAttributes().put(attribute, url);
                    } else {
                        String translatedUrl = MediaURLStreamHandler.getTranslatedMediaURL(solutionRoot,
                                lowercase);
                        if (translatedUrl != null) {
                            me.getAttributes().put(attribute, translatedUrl);
                        }
                    }
                } else if (component instanceof ISupportScriptCallback && lowercase.startsWith("javascript:")) {
                    String script = src;
                    if (script.length() > 13) {
                        String scriptName = script.substring(11);
                        if ("href".equals(attribute)) {
                            if (attributeMap.containsKey("externalcall")) {
                                attributeMap.remove("externalcall");
                            } else {
                                me.getAttributes().put("href", "#");
                                me.getAttributes().put("onclick",
                                        ((ISupportScriptCallback) component).getCallBackUrl(scriptName, true));
                                ignoreOnclick = true;
                            }
                        } else {
                            me.getAttributes().put(attribute, ((ISupportScriptCallback) component)
                                    .getCallBackUrl(scriptName, "onclick".equals(attribute)));
                        }
                    }
                } else if (component instanceof FormComponent<?> && lowercase.startsWith("javascript:")) {
                    String script = src;
                    if (script.length() > 13) {
                        String scriptName = script.substring(11);
                        if ("href".equals(attribute)) {
                            me.getAttributes().put("href", "#");
                            me.getAttributes().put("onclick",
                                    getTriggerJavaScript((FormComponent<?>) component, scriptName));
                            ignoreOnclick = true;
                        } else {
                            me.getAttributes().put(attribute,
                                    getTriggerJavaScript((FormComponent<?>) component, scriptName));
                        }
                    }
                }
            }
            bodyTxt.append(me.toString());
            me = (XmlTag) parser.nextTag();
        }
        bodyTxt.append(parser.getInputFromPositionMarker(-1));

        st.setBodyTxt(convertMediaReferences(convertBlobLoaderReferences(bodyTxt, component), solutionName, rr,
                "", false)); //$NON-NLS-1$
    } catch (ParseException ex) {
        Debug.error(ex);
        bodyTxt.append("<span style=\"color : #ff0000;\">"); //$NON-NLS-1$
        bodyTxt.append(ex.getMessage());
        bodyTxt.append(bodyText.subSequence(ex.getErrorOffset(),
                Math.min(ex.getErrorOffset() + 100, bodyText.length())));
        bodyTxt.append("</span></body></html>"); //$NON-NLS-1$
        st.setBodyTxt(bodyTxt);
    } catch (Exception ex) {
        Debug.error(ex);
        bodyTxt.append("<span style=\"color : #ff0000;\">"); //$NON-NLS-1$
        bodyTxt.append(ex.getMessage());
        bodyTxt.append("</span></body></html>"); //$NON-NLS-1$
        st.setBodyTxt(bodyTxt);
    }
    return st;
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebDataSubmitLink.java

License:Open Source License

/**
 * @see org.apache.wicket.markup.html.IHeaderContributor#renderHead(org.apache.wicket.markup.html.IHeaderResponse)
 *//*from w ww.  ja  v  a2  s  .c o  m*/
public void renderHead(IHeaderResponse response) {
    List<CharSequence> lst = strippedText.getJavascriptUrls();
    for (int i = 0; i < lst.size(); i++) {
        response.renderJavascriptReference(lst.get(i).toString());
    }
    lst = strippedText.getJavascriptScripts();
    for (int i = 0; i < lst.size(); i++) {
        response.renderJavascript(lst.get(i), "js_" + getMarkupId() + lst.get(i).hashCode()); //$NON-NLS-1$
    }
    lst = strippedText.getLinkTags();
    for (int i = 0; i < lst.size(); i++) {
        response.renderString(lst.get(i));
    }

    lst = strippedText.getStyles();
    for (CharSequence style : lst) {
        response.renderString(CSS_OPEN_TAG + style + CSS_CLOSE_TAG);
    }
    IValueMap map = strippedText.getBodyAttributes();
    if (map != null && map.size() > 0) {
        String onLoad = null;
        Iterator<String> iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            String attributeName = iterator.next();
            if (attributeName.equalsIgnoreCase("onload")) //$NON-NLS-1$
            {
                onLoad = map.getString(attributeName);
                iterator.remove();
                break;
            }
        }
        if (onLoad != null) {
            response.renderOnLoadJavascript(onLoad);
        }
        Page findPage = findPage();
        if (findPage instanceof MainPage) {
            ((MainPage) findPage).addBodyAttributes(map);
        }
    }
}

From source file:net.jawr.web.wicket.JawrJavascriptReference.java

License:Apache License

@Override
protected BundleRenderer createRenderer(ResourceBundlesHandler rsHandler, Boolean useRandomParam,
        ComponentTag tag) {/*from w  w w .jav a 2  s . c o  m*/

    final IValueMap attributes = tag.getAttributes();
    boolean async = attributes.getBoolean(JawrConstant.ASYNC_ATTR);
    boolean defer = attributes.getBoolean(JawrConstant.DEFER_ATTR);
    String type = attributes.getString(JawrConstant.TYPE_ATTR);
    return RendererFactory.getJsBundleRenderer(rsHandler, type, useRandomParam, async, defer);
}

From source file:net.jawr.web.wicket.JawrStylesheetReference.java

License:Apache License

@Override
protected BundleRenderer createRenderer(ResourceBundlesHandler rsHandler, Boolean useRandomParam,
        ComponentTag tag) {/*from   w  w  w.j a  v  a2s  . com*/

    final IValueMap attributes = tag.getAttributes();
    String media = attributes.getString(JawrConstant.MEDIA_ATTR);
    String title = attributes.getString(JawrConstant.TITLE_ATTR);
    boolean alternate = attributes.getBoolean(JawrConstant.ALTERNATE_ATTR);
    boolean displayAlternateStyles = attributes.getBoolean(JawrConstant.DISPLAY_ALTERNATE_ATTR);

    return RendererFactory.getCssBundleRenderer(rsHandler, useRandomParam, media, alternate,
            displayAlternateStyles, title);
}

From source file:net.jawr.web.wicket.JawrWicketLinkTagHandler.java

License:Apache License

/**
 * Checks if if tag ref is a correct one or not
 * //w  ww . jav a  2  s.co  m
 * @param tag
 *            the component tag
 * @return true if if tag ref is a correct one or not and that a component
 *         should be created
 */
private final boolean checkRef(ComponentTag tag) {
    boolean ok = false;
    if (!tag.getName().equals("a")) {
        IValueMap attributes = tag.getAttributes();
        String ref = attributes.getString("href");
        if (ref == null) {
            ref = attributes.getString("src");
        }

        if ((ref != null) && (isJawrImageTag(tag) || (ref.indexOf(":") == -1))) {
            ok = true;
        }

    }

    return ok;
}

From source file:org.hippoecm.frontend.dialog.DialogWindow.java

License:Apache License

private void internalShow(Dialog dialog) {
    this.dialog = dialog;
    dialog.setDialogService(this);
    setTitle(new EscapeHtmlStringModel(new StringWithoutLineBreaksModel(dialog.getTitle())));
    setContent(dialog.getComponent());//  w ww .j av  a  2s .  c o m
    setWindowClosedCallback(new Callback(dialog));

    IValueMap properties = dialog.getProperties();

    if (properties.containsKey("height") && properties.getString("height").equals("auto")) {
        setUseInitialHeight(false);
    } else {
        setUseInitialHeight(true);
        setInitialHeight(properties.getInt("height", 455));
    }

    setInitialWidth(properties.getInt("width", 850));
    setResizable(properties.getAsBoolean("resizable", false));

    String cssClasses = "hippo-dialog";
    if (isResizable()) {
        cssClasses += " hippo-dialog-resizable";
    }

    final String customCssClass = properties.getString("css-class-name", null);
    if (StringUtils.isNotEmpty(customCssClass)) {
        cssClasses += " " + customCssClass;
    }
    setCssClassName(cssClasses);

    AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
    if (target != null) {
        show(target);
    }
}

From source file:org.hippoecm.frontend.plugins.yui.layout.UnitSettings.java

License:Apache License

public UnitSettings(String position, IValueMap config) {
    this.position = position;
    if (config != null) {
        try {/* w  ww  .j av  a 2  s  . c o m*/
            PluginConfigMapper.populate(this, config);
        } catch (MappingException e) {
            throw new RuntimeException("invalid configuration");
        }
        id.setId(config.getString("id"));
        if (config.containsKey("body")) {
            body.setId(config.getString("body"));
        }
    }
}