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:eu.uqasar.message.UQasarMessage.java

License:Apache License

private String getHomepageLink() {
    if (Application.exists()) {
        return UQasar.get().getHomePageUrl();
    } else {/*from   w  w  w  . j  a va2s  .  c  om*/
        return getBaseURL();
    }
}

From source file:eu.uqasar.message.UQasarMessage.java

License:Apache License

private String getLogoLink() {
    if (Application.exists()) {
        return UQasar.get().getHomePageUrl() + "/assets/img/uqasar-logo.png";
    } else {/*from   www .  jav a2  s  .c  o  m*/
        return getAssetURL("assets/img/uqasar-logo.png");
    }
}

From source file:name.martingeisse.wicket.helpers.Iframe.java

License:Open Source License

@Override
protected void onComponentTag(final ComponentTag tag) {
    super.onComponentTag(tag);
    if (tag.isOpenClose()) {
        tag.setType(TagType.OPEN);/*  w w w . ja  v  a 2 s. co  m*/
    }
    final Object modelObject = getDefaultModelObject();
    if (modelObject instanceof IResource) {
        tag.put("src", urlFor(IResourceListener.INTERFACE, contentParameters));
    } else if (modelObject instanceof ResourceReference) {
        final ResourceReference resourceReference = (ResourceReference) modelObject;
        if (resourceReference.canBeRegistered() && Application.exists()) {
            Application.get().getResourceReferenceRegistry().registerResourceReference(resourceReference);
        }
        tag.put("src", RequestCycle.get().urlFor(resourceReference, contentParameters));
    } else if (modelObject instanceof IPageProvider) {
        setSrcAttribute(tag, (IPageProvider) modelObject);
    } else if (modelObject instanceof IRequestablePage) {
        setSrcAttribute(tag, new PageProvider((IRequestablePage) modelObject));
    } else if (modelObject instanceof Class<?>) {
        final Class<?> c = (Class<?>) modelObject;
        if (Page.class.isAssignableFrom(c)) {
            setSrcAttribute(tag, new PageProvider(c.asSubclass(Page.class)));
        } else {
            throw new RuntimeException(
                    "cannot handle iframe model object: Class<" + c.getCanonicalName() + ">");
        }
    } else {
        throw new RuntimeException("cannot handle iframe model object: " + modelObject);
    }
}

From source file:net.dontdrinkandroot.extensions.wicket.headeritem.ExternalJQueryUiJsHeaderItem.java

License:Apache License

@Override
public List<HeaderItem> getDependencies() {
    final ResourceReference backingLibraryReference;
    if (Application.exists()) {
        backingLibraryReference = Application.get().getJavaScriptLibrarySettings().getJQueryReference();
    } else {/*from ww  w  . j  av  a  2  s .c  o m*/
        backingLibraryReference = JQueryResourceReference.getV3();
    }

    return Collections.singletonList(JavaScriptHeaderItem.forReference(backingLibraryReference));
}

From source file:net.dontdrinkandroot.wicket.bootstrap.headeritem.BootstrapJsHeaderItem.java

License:Apache License

@Override
public Iterable<? extends HeaderItem> getDependencies() {

    final ResourceReference backingLibraryReference;
    if (Application.exists()) {
        backingLibraryReference = Application.get().getJavaScriptLibrarySettings().getJQueryReference();
    } else {//  ww w  . jav a 2 s .c o  m
        backingLibraryReference = JQueryResourceReference.get();
    }

    return Arrays.asList(JavaScriptHeaderItem.forReference(backingLibraryReference));
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.IsisConverterLocator.java

License:Apache License

/**
 * Locates the best IConverter implementation for a given {@link org.apache.isis.core.metamodel.adapter.ObjectAdapter}
 *
 * @param objectAdapter The object adapter to locate converter for
 * @param wicketViewerSettings The date related settings
 * @return The best converter for the object adapter's type
 *//* ww  w.ja  va2  s.  c  om*/
public static IConverter<Object> findConverter(final ObjectAdapter objectAdapter,
        final WicketViewerSettings wicketViewerSettings) {

    final ObjectSpecification objectSpecification = objectAdapter.getSpecification();

    // only use Wicket IConverter for value types, not for domain objects.
    if (!objectSpecification.isValue()) {
        return null;
    }

    // explicitly exclude enums; this will force the titleString
    // to be used from Isis' EnumValueSemanticsProvider
    final Class<?> correspondingClass = objectSpecification.getCorrespondingClass();
    if (Enum.class.isAssignableFrom(correspondingClass)) {
        return null;
    }

    final RenderedAdjustedFacet renderedAdjustedFacet = objectSpecification
            .getFacet(RenderedAdjustedFacet.class);
    final int adjustBy = renderedAdjustedFacet != null ? renderedAdjustedFacet.value() : 0;

    IConverter converter = null;
    if (java.util.Date.class == correspondingClass) {
        converter = new DateConverterForJavaUtilDate(wicketViewerSettings, adjustBy);
    } else if (java.sql.Date.class == correspondingClass) {
        converter = new DateConverterForJavaSqlDate(wicketViewerSettings, adjustBy);
    } else if (org.apache.isis.applib.value.Date.class == correspondingClass) {
        converter = new DateConverterForApplibDate(wicketViewerSettings, adjustBy);
    } else if (org.apache.isis.applib.value.DateTime.class == correspondingClass) {
        converter = new DateConverterForApplibDateTime(wicketViewerSettings, adjustBy);
    } else if (org.joda.time.LocalDate.class == correspondingClass) {
        converter = new DateConverterForJodaLocalDate(wicketViewerSettings, adjustBy);
    } else if (org.joda.time.LocalDateTime.class == correspondingClass) {
        converter = new DateConverterForJodaLocalDateTime(wicketViewerSettings, adjustBy);
    } else if (org.joda.time.DateTime.class == correspondingClass) {
        converter = new DateConverterForJodaDateTime(wicketViewerSettings, adjustBy);
    } else if (java.sql.Timestamp.class == correspondingClass) {
        converter = new DateConverterForJavaSqlTimestamp(wicketViewerSettings, adjustBy);
    } else if (java.math.BigInteger.class == correspondingClass) {
        converter = BigIntegerConverter.INSTANCE;
    } else if (java.math.BigDecimal.class == correspondingClass) {
        final BigDecimalValueFacet facet = objectSpecification.getFacet(BigDecimalValueFacet.class);
        Integer scale = null;
        if (facet != null) {
            scale = facet.getScale();
        }
        converter = new BigDecimalConverterWithScale(scale).forViewMode();
    } else if (Application.exists()) {
        final IConverterLocator converterLocator = Application.get().getConverterLocator();
        converter = converterLocator.getConverter(correspondingClass);
    }

    return converter;
}

From source file:org.apache.isis.viewer.wicket.viewer.services.LocaleProviderWicket.java

License:Apache License

@Programmatic
@Override//from w w  w .jav a  2  s .  c  o m
public Locale getLocale() {
    // Request Cycle can be null, e.g. during the start of an application
    RequestCycle requestCycle = RequestCycle.get();

    if (!Application.exists() || requestCycle == null) {
        // eg if request from RO viewer
        return null;
    }
    return RequestCycle.get().getRequest().getLocale();
}

From source file:org.apache.openmeetings.db.util.ApplicationHelper.java

License:Apache License

public static IApplication ensureApplication(Long langId) {
    IApplication a = null;// w  ww. j av a  2s  .  com
    if (Application.exists()) {
        a = (IApplication) Application.get();
    } else {
        WebApplication app = (WebApplication) Application.get(wicketApplicationName);
        LabelDao.initLanguageMap();
        if (app == null) {
            try {
                app = (WebApplication) LabelDao.getAppClass().newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                log.error("Failed to create Application");
                return null;
            }
            app.setServletContext(new MockServletContext(app, null));
            app.setName(wicketApplicationName);
            ServletContext sc = app.getServletContext();
            OMContextListener omcl = new OMContextListener();
            omcl.contextInitialized(new ServletContextEvent(sc));
            XmlWebApplicationContext xmlContext = new XmlWebApplicationContext();
            xmlContext.setConfigLocation("classpath:openmeetings-applicationContext.xml");
            xmlContext.setServletContext(sc);
            xmlContext.refresh();
            sc.setAttribute(ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, xmlContext);
            app.setConfigurationType(RuntimeConfigurationType.DEPLOYMENT);
            ThreadContext.setApplication(app);
            app.initApplication();
        } else {
            ThreadContext.setApplication(app);
        }
        a = (IApplication) Application.get(wicketApplicationName);
    }
    if (ThreadContext.getRequestCycle() == null) {
        ServletWebRequest req = new ServletWebRequest(new MockHttpServletRequest((Application) a,
                new MockHttpSession(a.getServletContext()), a.getServletContext()), "");
        RequestCycleContext rctx = new RequestCycleContext(req, new MockWebResponse(), a.getRootRequestMapper(),
                a.getExceptionMapperProvider().get());
        ThreadContext.setRequestCycle(new RequestCycle(rctx));
    }
    if (ThreadContext.getSession() == null) {
        WebSession s = WebSession.get();
        if (langId > 0) {
            ((IWebSession) s).setLanguage(langId);
        }
    }
    return a;
}

From source file:org.brixcms.web.nodepage.BrixNodePageUrlCodingStrategy.java

License:Apache License

private Page getPage(PageInfo info) {
    Page page;//from ww w.ja  v a 2 s .c om

    if (Strings.isEmpty(info.getPageMapName()) && Application.exists()
            && Application.get().getSessionSettings().isPageIdUniquePerSession()) {
        page = Session.get().getPage(info.getPageId().intValue(),
                info.getVersionNumber() != null ? info.getVersionNumber().intValue() : 0);
    } else {
        page = Session.get().getPage(info.getPageMapName(), "" + info.getPageId(),
                info.getVersionNumber() != null ? info.getVersionNumber().intValue() : 0);
    }

    if (page != null && isBrixPage(page)) {
        return page;
    } else {
        return null;
    }
}

From source file:org.brixcms.web.nodepage.BrixNodePageUrlMapper.java

License:Apache License

private IManageablePage getPage(PageInfo info) {
    IManageablePage page;/*from  www. java2  s.c  om*/

    if (/*Strings.isEmpty(info.getPageMapName()) &&*/ Application.exists()
    /*&& Application.get().getSessionSettings().isPageIdUniquePerSession()*/) {
        page = Session.get().getPageManager()
                .getPage(info.getPageId()/*,
                                         info.getVersionNumber() != null ? info.getVersionNumber() : 0*/);
    } else {
        page = Session.get().getPageManager().getPage(/*info.getPageMapName(), "" +*/ info
                .getPageId()/*,
                            info.getVersionNumber() != null ? info.getVersionNumber() : 0*/);
    }

    if (page != null && isBrixPage(page)) {
        return page;
    } else {
        return null;
    }
}