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:org.hippoecm.frontend.editor.layout.XmlLayoutDescriptor.java

License:Apache License

/**
 * Determine the name by use of properties files.  The lookup procedure uses the
 * variant properties file, if available, falling back to the no-variant 
 * <code>location + ".properties"</code> file.  The key that is used is the name
 * of the layout (i.e. the last part of its location path), initially tried with
 * the variant appended and falling back to the using the name itself as key if
 * this fails.  Finally, if no properties files are found, the name is returned.
 *//*from www . j  a  v a 2s.co m*/
public IModel<String> getName() {
    return new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override
        protected String load() {
            // Load the properties associated with the path
            IPropertiesFactory propertiesFactory = Application.get().getResourceSettings()
                    .getPropertiesFactory();

            Locale locale = Session.get().getLocale();
            String name = location.substring(location.lastIndexOf('/') + 1);
            ResourceNameIterator iterator = new ResourceNameIterator(location, null, variant, locale, null,
                    false);
            while (iterator.hasNext()) {
                String path = iterator.next();
                final Properties props = propertiesFactory.load(null, path);
                if (props != null) {
                    if (variant != null) {
                        // Lookup the value
                        String value = props.getString(name + "_" + variant);
                        if (value != null) {
                            return value;
                        }
                    }
                    String value = props.getString(name);
                    if (value != null) {
                        return value;
                    }
                }
            }
            return name;
        }

    };
}

From source file:org.hippoecm.frontend.HippoHeaderItem.java

License:Apache License

protected boolean isDevelopmentMode() {
    return Application.get().usesDeploymentConfig();
}

From source file:org.hippoecm.frontend.HippoTester.java

License:Apache License

public IPageManagerContext getPageManagerContext() {
    return ((Main) Application.get()).getPageManagerContext();
}

From source file:org.hippoecm.frontend.model.DetachMonitor.java

License:Apache License

private void writeObject(ObjectOutputStream output) throws IOException {
    if ((flags & ATTACHED) != 0) {
        // TODO: walk the stack to identify owner
        log.warn("Undetached DetachMonitor");
        if (RuntimeConfigurationType.DEPLOYMENT.equals(Application.get().getConfigurationType())) {
            detach();/*from  w  w  w.  ja  v  a2 s  . c om*/
        }
    }
    output.defaultWriteObject();
}

From source file:org.hippoecm.frontend.model.JcrItemModel.java

License:Apache License

private void writeObject(ObjectOutputStream output) throws IOException {
    if (isAttached()) {
        log.warn("Undetached JcrItemModel " + getPath());
        T object = this.getObject();
        if (object != null) {
            TraceMonitor.trace(object);//w  w w. ja  v  a  2  s .c o m
        }
        if (RuntimeConfigurationType.DEPLOYMENT.equals(Application.get().getConfigurationType())) {
            detach();
        }
    }
    output.defaultWriteObject();
}

From source file:org.hippoecm.frontend.model.JcrSessionModel.java

License:Apache License

public static Session login(UserCredentials credentials) throws LoginException, RepositoryException {
    Main main = (Main) Application.get();
    HippoRepository repository = main.getRepository();
    return repository.getRepository().login(credentials.getJcrCredentials());
}

From source file:org.hippoecm.frontend.plugin.impl.PluginContext.java

License:Apache License

private void writeObject(ObjectOutputStream output) throws IOException {
    if (stopping && Application.exists()) {
        if (Application.get().getConfigurationType().equals(RuntimeConfigurationType.DEVELOPMENT)) {
            throw new WicketRuntimeException("Stopped plugin is still being referenced: "
                    + (plugin != null ? plugin.getClass().getName() : "unknown"));
        }/*w w  w . ja  v a  2  s.c  om*/
    }
    output.defaultWriteObject();
}

From source file:org.hippoecm.frontend.plugin.impl.PluginFactory.java

License:Apache License

public IPlugin createPlugin(PluginContext context, IPluginConfig config) {
    String className = config.getString(IPlugin.CLASSNAME);
    IPlugin plugin = null;/*from   ww  w .j  a  v  a2 s  .  c om*/
    String message = null;
    if (className == null) {
        message = "No plugin classname configured, please set plugin configuration parameter "
                + IPlugin.CLASSNAME;
    } else {
        className = className.trim();
        ClassLoader loader = UserSession.get().getClassLoader();
        if (loader == null) {
            log.info("Unable to retrieve repository classloader, falling back to default classloader.");
            loader = getClass().getClassLoader();
        }
        try {
            @SuppressWarnings("unchecked")
            Class<? extends IPlugin> clazz = (Class<? extends IPlugin>) Class.forName(className, true, loader);
            Class<?>[] formalArgs = new Class[] { IPluginContext.class, IPluginConfig.class };
            Constructor<? extends IPlugin> constructor = clazz.getConstructor(formalArgs);
            Object[] actualArgs = new Object[] { context, config };
            plugin = constructor.newInstance(actualArgs);

        } catch (ClassNotFoundException e) {
            IResourceSettings resourceSettings = Application.get().getResourceSettings();
            IResourceStreamLocator locator = resourceSettings.getResourceStreamLocator();
            IResourceStream stream = locator.locate(null, className.replace('.', '/') + ".html");
            if (stream != null) {
                plugin = new LayoutPlugin(context, config, stream);
            } else {
                message = e.getClass().getName() + ": " + e.getMessage();
                log.error(message, e);
            }

        } catch (InvocationTargetException e) {
            if (e.getTargetException() instanceof RestartResponseException) {
                throw (RestartResponseException) e.getTargetException();
            }
            message = e.getTargetException().getClass().getName() + ": " + e.getTargetException().getMessage();
            log.error(message, e);
        } catch (Exception e) {
            message = e.getClass().getName() + ": " + e.getMessage();
            log.error(message, e);
        }
    }
    if (plugin == null && message != null) {
        message += "\nFailed to instantiate plugin class '" + className + "' for wicket id '"
                + config.getString(RenderService.WICKET_ID) + "' in plugin '" + config.getName() + "' ("
                + config + ")";

        // reset context, i.e. unregister everything that was registered so far
        context.reset();

        if (config.getString(RenderService.WICKET_ID) != null) {
            IPluginConfig errorConfig = new JavaPluginConfig();
            errorConfig.put(ErrorPlugin.ERROR_MESSAGE, message);
            errorConfig.put(RenderService.WICKET_ID, config.getString(RenderService.WICKET_ID));
            plugin = new ErrorPlugin(context, errorConfig);
        } else {
            log.error(message);
        }
    }
    return plugin;
}

From source file:org.hippoecm.frontend.PluginPage.java

License:Apache License

@Override
public void renderHead(final IHeaderResponse response) {
    Task pageRenderHeadTask = null;/*  w  ww.j a v a 2 s  . c  o  m*/

    try {
        if (HDC.isStarted()) {
            pageRenderHeadTask = HDC.getCurrentTask().startSubtask("PluginPage.renderHead");
        }

        super.renderHead(response);
        CoreLibrariesContributor.contribute(Application.get(), response);

        if (WebApplicationHelper.isDevelopmentMode()) {
            addDevelopmentModeCssClassToHtml(response);
        }
    } finally {
        if (pageRenderHeadTask != null) {
            pageRenderHeadTask.stop();
        }
    }
}

From source file:org.hippoecm.frontend.plugins.ckeditor.CKEditorPanel.java

License:Apache License

public static ResourceReference getCKEditorJsReference() {
    if (Application.get().getConfigurationType().equals(RuntimeConfigurationType.DEVELOPMENT)
            && CKEditorConstants.existsOnClassPath(CKEditorConstants.CKEDITOR_SRC_JS)) {
        log.info("Using non-optimized CKEditor sources.");
        return CKEditorConstants.CKEDITOR_SRC_JS;
    }//ww w  . j a v a  2  s .c  o  m
    log.info("Using optimized CKEditor sources");
    return CKEditorConstants.CKEDITOR_OPTIMIZED_JS;
}