Example usage for org.apache.wicket Application exists

List of usage examples for org.apache.wicket Application exists

Introduction

In this page you can find the example usage for org.apache.wicket Application exists.

Prototype

public static boolean exists() 

Source Link

Document

Checks if the Application threadlocal is set in this thread

Usage

From source file:com.googlecode.wicket.jquery.ui.kendo.KendoAbstractBehavior.java

License:Apache License

/**
 * Gets the {@link IKendoUILibrarySettings}
 *
 * @return null if Application's {@link IJavaScriptLibrarySettings} is not an instance of {@link IKendoUILibrarySettings}
 *//*from   w  w w  .j  av a  2s . c  o  m*/
private static IKendoUILibrarySettings getLibrarySettings() {
    if (Application.exists()
            && (Application.get().getJavaScriptLibrarySettings() instanceof IKendoUILibrarySettings)) {
        return (IKendoUILibrarySettings) Application.get().getJavaScriptLibrarySettings();
    }

    return KendoUILibrarySettings.get();
}

From source file:com.googlecode.wicket.jquery.ui.plugins.emoticons.EmoticonsBehavior.java

License:Apache License

/**
 * Gets the {@link IEmoticonsLibrarySettings}
 *
 * @return Default {@link IEmoticonsLibrarySettings} if Application's {@link IJavaScriptLibrarySettings} is not an instance of {@link IEmoticonsLibrarySettings}
 *//*from   ww w .  jav  a 2  s  .  c  om*/
private static IEmoticonsLibrarySettings getLibrarySettings() {
    if (Application.exists()
            && (Application.get().getJavaScriptLibrarySettings() instanceof IEmoticonsLibrarySettings)) {
        return (IEmoticonsLibrarySettings) Application.get().getJavaScriptLibrarySettings();
    }

    return EmoticonsLibrarySettings.get();
}

From source file:com.googlecode.wicket.jquery.ui.plugins.fixedheadertable.FixedHeaderTableBehavior.java

License:Apache License

/**
 * Gets the {@link IFixedHeaderTableLibrarySettings}
 *
 * @return null if Application's {@link IJavaScriptLibrarySettings} is not an instance of {@link IFixedHeaderTableLibrarySettings}
 *///from  w  w  w  . j  av  a  2 s. c om
private static IFixedHeaderTableLibrarySettings getLibrarySettings() {
    if (Application.exists()
            && (Application.get().getJavaScriptLibrarySettings() instanceof IFixedHeaderTableLibrarySettings)) {
        return (IFixedHeaderTableLibrarySettings) Application.get().getJavaScriptLibrarySettings();
    }

    return FixedHeaderTableLibrarySettings.get();
}

From source file:com.googlecode.wicket.jquery.ui.plugins.sfmenu.SfMenuBehavior.java

License:Apache License

/**
 * Gets the {@link ISuperfishLibrarySettings}
 *
 * @return Default internal {@link ISuperfishLibrarySettings} if {@link Application}'s {@link IJavaScriptLibrarySettings} is not an instance of {@link ISuperfishLibrarySettings}
 *//*from w  w  w .jav  a 2  s  . co m*/
private static ISuperfishLibrarySettings getLibrarySettings() {
    if (Application.exists()
            && (Application.get().getJavaScriptLibrarySettings() instanceof ISuperfishLibrarySettings)) {
        return (ISuperfishLibrarySettings) Application.get().getJavaScriptLibrarySettings();
    }

    return SuperfishLibrarySettings.get();
}

From source file:com.googlecode.wicket.jquery.ui.plugins.whiteboard.WhiteboardBehavior.java

License:Apache License

private static IWhiteboardLibrarySettings getLibrarySettings() {
    if (Application.exists()
            && (Application.get().getJavaScriptLibrarySettings() instanceof IWhiteboardLibrarySettings)) {
        return (IWhiteboardLibrarySettings) Application.get().getJavaScriptLibrarySettings();
    }/*from ww  w  . j  av  a2 s .  co  m*/

    return null;
}

From source file:com.googlecode.wicket.jquery.ui.plugins.wysiwyg.WysiwygBehavior.java

License:Apache License

/**
 * Gets the {@link IWysiwygLibrarySettings}
 *
 * @return Default {@link IWysiwygLibrarySettings} if Application's {@link IJavaScriptLibrarySettings} is not an instance of {@link IWysiwygLibrarySettings}
 *//*w  ww . ja  va2 s. com*/
private static IWysiwygLibrarySettings getLibrarySettings() {
    if (Application.exists()
            && (Application.get().getJavaScriptLibrarySettings() instanceof IWysiwygLibrarySettings)) {
        return (IWysiwygLibrarySettings) Application.get().getJavaScriptLibrarySettings();
    }

    return WysiwygLibrarySettings.get();
}

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

License:Open Source License

public void setResizeImage(ResourceReference resourceReference) {
    if (resizeBar instanceof Image && Application.exists()) {
        ((Image) resizeBar).setImageResourceReference(resourceReference);
    }//from w  ww  .ja va 2s.  c o  m
}

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

License:Open Source License

/**
 * @param bodyText/*from   ww  w .  jav a2 s.  c  o m*/
 * @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.StripHTMLTagsConverter.java

License:Open Source License

public static String getBlobLoaderUrlPart(Request request) {
    String url = request.getParameter(BLOB_LOADER_PARAM);
    if (url != null) {
        // old url
        if (url.equals("true")) //$NON-NLS-1$
        {/*from   w  w  w  . jav  a2  s  . co m*/
            url = request.getURL();
        } else {
            // encrypted
            if (Application.exists()) {
                try {
                    ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
                    url = urlCrypt.decryptUrlSafe(url);
                    url = url.replace("&amp;", "&"); //$NON-NLS-1$ //$NON-NLS-2$
                } catch (Exception e) {
                    Debug.error("Error decrypting blobloader url: " + url, e);
                }
            }
        }
    }
    return url;
}

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

License:Open Source License

@SuppressWarnings("nls")
public static CharSequence convertBlobLoaderReferences(CharSequence text, Component component) {
    if (text != null) {
        String txt = text.toString();
        int index = txt.indexOf("media:///servoy_blobloader?");
        if (index == -1)
            return txt;
        ICrypt urlCrypt = null;/*  www  .  ja  v a  2 s . c o  m*/
        if (Application.exists())
            urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();

        if (urlCrypt != null) {
            while (index != -1) {
                // just try to search for the ending quote
                int index2 = Utils.firstIndexOf(txt, new char[] { '\'', '"', ' ', '\t', ')' }, index);

                // if ending can't be resolved don't encrypt it.
                if (index2 == -1)
                    return Strings.replaceAll(text, "media:///servoy_blobloader?",
                            RequestCycle.get().urlFor(component, IResourceListener.INTERFACE) + "&"
                                    + BLOB_LOADER_PARAM + "=true&");

                String bloburl = generateBlobloaderUrl(component, urlCrypt,
                        txt.substring(index + "media:///".length(), index2));
                txt = txt.substring(0, index) + bloburl + txt.substring(index2);

                index = txt.indexOf("media:///servoy_blobloader?", index + 1);
            }
            return txt;
        }
    }
    if (RequestCycle.get() != null)
        return Strings.replaceAll(text, "media:///servoy_blobloader?",
                RequestCycle.get().urlFor(component, IResourceListener.INTERFACE) + "&" + BLOB_LOADER_PARAM
                        + "=true&");
    return text;
}