Example usage for org.apache.wicket Application get

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

Introduction

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

Prototype

public static Application get() 

Source Link

Document

Get Application for current thread.

Usage

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;//from   www . java2  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;
}

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

License:Open Source License

public static Object[] getImageDisplayURL(IImageDisplay imageDisplay, boolean appendRandomParam) {
    String imgURL = null;//ww w  .  j a  v a 2 s  .co  m
    Boolean isRandomParamRemoved = Boolean.FALSE;

    if (imageDisplay instanceof Component) {
        MediaResource mr;
        Component imageDisplayComponent = (Component) imageDisplay;
        if ((mr = imageDisplay.getIcon()) != null) {
            CharSequence url = imageDisplayComponent.urlFor(ILatestVersionResourceListener.INTERFACE);
            if (appendRandomParam) {
                byte[] imageRawData = mr.getRawData();
                Checksum checksum = new CRC32();
                checksum.update(imageRawData, 0, imageRawData.length);
                url = url + "&r=" + checksum.getValue(); //$NON-NLS-1$
            } else
                isRandomParamRemoved = Boolean.TRUE;
            imgURL = Strings.replaceAll(imageDisplayComponent.getResponse().encodeURL(url), "&", "&") //$NON-NLS-1$//$NON-NLS-2$
                    .toString();
            if (imageDisplay.getMediaOptions() != 0 && imageDisplay.getMediaOptions() != 1) {
                imgURL = imgURL + "&option=" + imageDisplay.getMediaOptions() + "&w=" //$NON-NLS-1$//$NON-NLS-2$
                        + imageDisplay.getWebBounds().width + "&h=" + //$NON-NLS-1$
                        imageDisplay.getWebBounds().height;
            }
        } else if (imageDisplay.getIconReference() != null && imageDisplay.getMedia() != null) {
            String solutionName = J2DBGlobals.getServiceProvider().getSolution().getName();
            if (imageDisplay.getMediaOptions() != 0 && imageDisplay.getMediaOptions() != 1) {
                imgURL = imageDisplayComponent.urlFor(imageDisplay.getIconReference()) + "?id=" //$NON-NLS-1$
                        + imageDisplay.getMedia().getName() + "&s=" + solutionName + //$NON-NLS-1$
                        "&option=" + //$NON-NLS-1$
                        imageDisplay.getMediaOptions() + "&w=" + imageDisplay.getWebBounds().width + "&h=" //$NON-NLS-1$//$NON-NLS-2$
                        + imageDisplay.getWebBounds().height + "&l=" + //$NON-NLS-1$
                        (imageDisplay.getMedia().getMediaData() != null
                                ? +imageDisplay.getMedia().getMediaData().hashCode()
                                : 0);
            } else {
                imgURL = imageDisplayComponent.urlFor(imageDisplay.getIconReference()) + "?id=" //$NON-NLS-1$
                        + imageDisplay.getMedia().getName() + "&s=" + solutionName + //$NON-NLS-1$
                        "&l=" //$NON-NLS-1$
                        + (imageDisplay.getMedia().getMediaData() != null
                                ? +imageDisplay.getMedia().getMediaData().hashCode()
                                : 0);
            }
        } else if (imageDisplay.getIconUrl() != null) {
            imgURL = imageDisplay.getIconUrl();

        } else if (imageDisplay.getTextUrl() != null) {
            String mediaName = imageDisplay.getTextUrl()
                    .substring(MediaURLStreamHandler.MEDIA_URL_DEF.length());
            if (mediaName.startsWith(MediaURLStreamHandler.MEDIA_URL_BLOBLOADER)) {
                ICrypt urlCrypt = null;
                if (Application.exists())
                    urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();

                imgURL = StripHTMLTagsConverter.generateBlobloaderUrl(imageDisplayComponent, urlCrypt,
                        mediaName);
            }
        } else if (imageDisplay.getRolloverIconReference() != null || imageDisplay.getRolloverUrl() != null
                || imageDisplay.getRolloverMedia() != null) {
            imgURL = imageDisplayComponent.urlFor(TRANSPARENT_IMAGE).toString();
        }
    }

    return new Object[] { imgURL, isRandomParamRemoved };
}

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

License:Open Source License

protected static AttributeModifier getImageDisplayRolloverBehavior(final IImageDisplay imageDisplay) {
    if (imageDisplay instanceof Component) {
        final Component imageDisplayComponent = (Component) imageDisplay;

        return new AttributeModifier("onmouseover", true, new Model<String>() {
            private static final long serialVersionUID = 1L;

            @Override// www  .  j av  a2 s  .c o m
            public String getObject() {
                String solutionName = J2DBGlobals.getServiceProvider().getSolution().getName();
                String url = ""; //$NON-NLS-1$
                if (imageDisplay.getRolloverIconReference() != null
                        && imageDisplay.getRolloverMedia() != null) {
                    if (imageDisplay.getMediaOptions() != 0 && imageDisplay.getMediaOptions() != 1) {
                        url = imageDisplayComponent.urlFor(imageDisplay.getRolloverIconReference()) + "?id=" //$NON-NLS-1$
                                + imageDisplay.getRolloverMedia().getName() + "&s=" + solutionName + "&option=" + //$NON-NLS-2$
                        imageDisplay.getMediaOptions() + "&w=" + imageDisplay.getWebBounds().width + "&h=" //$NON-NLS-1$//$NON-NLS-2$
                                + imageDisplay.getWebBounds().height + "&l=" + (imageDisplay.getRolloverMedia().getMediaData() != null
                                ? +imageDisplay.getRolloverMedia().getMediaData().hashCode()
                                : 0);
                    } else {
                        url = imageDisplayComponent.urlFor(imageDisplay.getRolloverIconReference()) + "?id=" //$NON-NLS-1$
                                + imageDisplay.getRolloverMedia().getName() + "&s=" + solutionName + "&l=" + //$NON-NLS-2$
                        (imageDisplay.getRolloverMedia().getMediaData() != null
                                ? +imageDisplay.getRolloverMedia().getMediaData().hashCode()
                                : 0);
                    }
                } else if (imageDisplay.getRolloverUrl() != null) {
                    if (imageDisplay.getRolloverUrl().startsWith(MediaURLStreamHandler.MEDIA_URL_DEF)) {
                        String mediaName = imageDisplay.getRolloverUrl()
                                .substring(MediaURLStreamHandler.MEDIA_URL_DEF.length());
                        if (mediaName.startsWith(MediaURLStreamHandler.MEDIA_URL_BLOBLOADER)) {
                            ICrypt urlCrypt = null;
                            if (Application.exists())
                                urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();

                            url = StripHTMLTagsConverter.generateBlobloaderUrl(imageDisplayComponent, urlCrypt,
                                    mediaName);
                        }
                    } else
                        url = imageDisplay.getRolloverUrl();
                }

                return "Servoy.Rollover.onMouseOver('" + imageDisplayComponent.getMarkupId() + "_img','" + url //$NON-NLS-1$//$NON-NLS-2$
                        + "')"; //$NON-NLS-1$
            }
        }) {
            @Override
            protected String newValue(final String currentValue, final String replacementValue) {
                return replacementValue + ";" + currentValue;
            }
        };
    }
    return null;
}

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

License:Open Source License

/**
 * @see com.servoy.j2db.server.headlessclient.dataui.ISupportScriptCallback#getCallBackUrl(java.lang.String, boolean)
 *///from w ww.  j a  v  a 2  s  .  c  om
@SuppressWarnings("nls")
public CharSequence getCallBackUrl(String scriptName, boolean testDoubleClick) {
    boolean useAJAX = Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX"));
    if (useAJAX) {
        if (inlineScriptExecutor == null) {
            inlineScriptExecutor = new InlineScriptExecutorBehavior(this);
            add(inlineScriptExecutor);
        }

        AppendingStringBuffer asb = new AppendingStringBuffer(80);
        if (testDoubleClick) {
            asb.append("if (testDoubleClickId('");
            asb.append(getMarkupId());
            asb.append("')) { ");
        }

        asb.append("document.getElementById('").append(getMarkupId()).append("').focus();");
        asb.append("window.setTimeout(function() { wicketAjaxGet('");
        asb.append(inlineScriptExecutor.getCallbackUrl());

        ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
        asb.append("&snenc=");
        String escapedScriptName = Utils.stringReplace(Utils.stringReplace(scriptName, "\\\'", "\'"), "&quot;",
                "\"");
        asb.append(WicketURLEncoder.QUERY_INSTANCE.encode(urlCrypt.encryptUrlSafe(escapedScriptName)));

        for (String browserArgument : inlineScriptExecutor.getBrowserArguments(scriptName)) {
            asb.append("&").append(browserArgument).append("=' + ").append(browserArgument).append(" + '");
        }

        asb.append("');}, 0);");
        if (testDoubleClick) {
            asb.append("} ");
        }
        asb.append("return false;");
        return asb.toString();
    } else {
        return StripHTMLTagsConverter.getTriggerJavaScript(this, scriptName);
    }
}

From source file:com.servoy.j2db.server.headlessclient.eventthread.WicketEvent.java

License:Open Source License

/**
 * @param f//from   w  w  w  .j  av a 2  s .c o  m
 * @param scope
 * @param thisObject
 * @param args
 * @param focusEvent
 * @param throwException
 * @param scriptEngine TODO
 */
public WicketEvent(WebClient client, Runnable runnable) {
    super(runnable);
    this.client = client;
    requestCycle = RequestCycle.get();
    session = Session.get();
    serviceProvider = J2DBGlobals.getServiceProvider();
    application = Application.get();
    dirtyObjectsList = session.getDirtyObjectsList();
    touchedPages = session.getTouchedPages();
    httpThread = Thread.currentThread();
    pagesToRelease = ((WebClientSession) session).getPagesToRelease();
    if (pagesToRelease.size() > 0) {
        Debug.error("there are already locked pages for the wicket event, expect to be 0 " + pagesToRelease);
    }
}

From source file:com.servoy.j2db.server.headlessclient.jquery.JQueryLoader.java

License:Open Source License

public static void render(IHeaderResponse response) {
    if (Application.exists() && Application.get().getDebugSettings().isAjaxDebugModeEnabled()) {
        response.renderJavascriptReference(JQueryLoader.JS_JQUERY_DEBUG);
        response.renderJavascriptReference(JQueryLoader.JS_JQUERY_PLACEHOLDER_DEBUG);
    } else {/*  ww  w  .  jav a  2  s  .  com*/
        response.renderJavascriptReference(JQueryLoader.JS_JQUERY);
        response.renderJavascriptReference(JQueryLoader.JS_JQUERY_PLACEHOLDER);
    }
    response.renderJavascriptReference(JQueryLoader.JS_JQUERY_NUMPAD_DECIMAL);
    response.renderJavascriptReference(JQueryLoader.JS_MASKED_INPUT);
}

From source file:com.servoy.j2db.server.headlessclient.RedirectAjaxRequestTarget.java

License:Apache License

/**
 * @see org.apache.wicket.IRequestTarget#respond(org.apache.wicket.RequestCycle)
 *//*ww w  . j  av  a 2 s .  co m*/
public void respond(RequestCycle requestCycle) {
    WebResponse response = (WebResponse) requestCycle.getResponse();
    final String encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding();

    // Set content type based on markup type for page
    response.setCharacterEncoding(encoding);
    response.setContentType("text/xml; charset=" + encoding);

    // Make sure it is not cached by a client
    response.setDateHeader("Expires", System.currentTimeMillis());
    response.setHeader("Cache-Control", "no-cache, must-revalidate");
    response.setHeader("Pragma", "no-cache");

    CharSequence urlFor = RequestCycle.get().urlFor(page, null);
    response.write("<?xml version=\"1.0\" encoding=\"");
    response.write(encoding);
    response.write("\"?><ajax-response>");
    response.write("<evaluate");
    response.write(">");
    response.write("<![CDATA[");
    response.write(
            MainPage.getShowUrlScript(new ShowUrlInfo(urlFor.toString(), "_self", null, 0, true, false, true)));
    response.write("]]>");
    response.write("</evaluate>");
    response.write("</ajax-response>");
}

From source file:com.servoy.j2db.server.headlessclient.ServoyErrorPage.java

License:Open Source License

/**
 * @see org.apache.wicket.markup.IMarkupResourceStreamProvider#getMarkupResourceStream(org.apache.wicket.MarkupContainer, java.lang.Class)
 *//*from w  w  w .j  a v a2  s.co  m*/
public IResourceStream getMarkupResourceStream(MarkupContainer container, Class containerClass) {
    String htmlfile = Settings.getInstance().getProperty("servoy.webclient.error.page");
    Cookie[] cookies = ((WebRequest) RequestCycle.get().getRequest()).getCookies();
    if (cookies != null && cookies.length > 0) {
        for (Cookie element : cookies) {
            if ("servoy.webclient.error.page".equals(element.getName())) {
                htmlfile = WebClient.decodeCookieValue(element.getValue());
                break;
            }
        }
    }
    final IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
    return locator.locate(ServoyErrorPage.class, htmlfile);
}

From source file:com.servoy.j2db.server.headlessclient.ServoyPageExpiredPage.java

License:Open Source License

/**
 * @see org.apache.wicket.markup.IMarkupResourceStreamProvider#getMarkupResourceStream(org.apache.wicket.MarkupContainer, java.lang.Class)
 *//*w  ww.j  ava 2 s.  c o  m*/
public IResourceStream getMarkupResourceStream(MarkupContainer container, Class containerClass) {
    String htmlfile = Settings.getInstance().getProperty("servoy.webclient.pageexpired.page");

    Cookie[] cookies = ((WebRequest) RequestCycle.get().getRequest()).getCookies();
    if (cookies != null && cookies.length > 0) {
        for (Cookie element : cookies) {
            if ("servoy.webclient.pageexpired.page".equals(element.getName())) {
                htmlfile = WebClient.decodeCookieValue(element.getValue());
                break;
            }
        }
    }

    final IResourceStreamLocator locator = Application.get().getResourceSettings().getResourceStreamLocator();
    return locator.locate(ServoyPageExpiredPage.class, htmlfile);
}

From source file:com.servoy.j2db.server.headlessclient.SessionClient.java

License:Open Source License

static void onDestroy() {
    try {/*from ww w . ja  v a2s. c  o m*/
        if (wicket_app != null) {
            WebClientsApplication tmp = wicket_app;
            wicket_app = null;
            WicketFilter wicketFilter = tmp.getWicketFilter();
            if (wicketFilter != null) {
                wicketFilter.destroy();
            }
            if (Application.exists() && Application.get() == tmp) {
                Application.unset();
            }

            if (Session.exists() && Session.get() == wicket_session) {
                Session.unset();
            }
        } else {
            wicket_app = null;
            wicket_session = null;
        }
    } catch (Exception e) {
        Debug.error("on destroy", e);
    }
}