Search in sources :

Example 1 with ApplicationEx

use of com.ibm.xsp.application.ApplicationEx in project org.openntf.xsp.jakartaee by OpenNTF.

the class NSFCDIProvider method getCDI.

@SuppressWarnings("unchecked")
@Override
public synchronized CDI<Object> getCDI() {
    CDI<Object> result = null;
    CDIContainerUtility util = LibraryUtil.findRequiredExtension(CDIContainerUtility.class);
    String databasePath = util.getThreadContextDatabasePath();
    if (StringUtil.isNotEmpty(databasePath)) {
        try {
            NotesSession session = new NotesSession();
            try {
                NotesDatabase database = session.getDatabase(databasePath);
                if (database != null) {
                    database.open();
                    try {
                        result = (CDI<Object>) util.getContainer(database);
                    } finally {
                        database.recycle();
                    }
                }
            } finally {
                session.recycle();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    if (result != null) {
        return result;
    }
    ApplicationEx application = ApplicationEx.getInstance();
    if (application != null) {
        result = (CDI<Object>) util.getContainer(application);
    }
    if (result != null) {
        return result;
    }
    try {
        NotesDatabase database = ContextInfo.getServerDatabase();
        if (database != null) {
            result = (CDI<Object>) util.getContainer(database);
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
    if (result != null) {
        return result;
    }
    // Check in any available locator extensions
    List<CDIContainerLocator> locators = LibraryUtil.findExtensions(CDIContainerLocator.class);
    NotesSession session = new NotesSession();
    try {
        for (CDIContainerLocator locator : locators) {
            String nsfPath = locator.getNsfPath();
            if (StringUtil.isNotEmpty(nsfPath)) {
                try {
                    NotesDatabase database = session.getDatabaseByPath(nsfPath);
                    try {
                        database.open();
                        result = (CDI<Object>) util.getContainer(database);
                        if (result != null) {
                            return result;
                        }
                    } finally {
                        if (database != null) {
                            database.recycle();
                        }
                    }
                } catch (NotesAPIException | IOException e) {
                    // Log and move on
                    e.printStackTrace();
                }
            }
            String bundleId = locator.getBundleId();
            if (StringUtil.isNotEmpty(bundleId)) {
                Optional<Bundle> bundle = LibraryUtil.getBundle(bundleId);
                if (bundle.isPresent()) {
                    return (CDI<Object>) util.getContainer(bundle.get());
                }
            }
        }
    } finally {
        try {
            session.recycle();
        } catch (NotesAPIException e) {
        // Ignore
        }
    }
    return null;
}
Also used : CDIContainerUtility(org.openntf.xsp.cdi.ext.CDIContainerUtility) CDIContainerLocator(org.openntf.xsp.cdi.ext.CDIContainerLocator) Bundle(org.osgi.framework.Bundle) CDI(jakarta.enterprise.inject.spi.CDI) IOException(java.io.IOException) NotesDatabase(com.ibm.designer.domino.napi.NotesDatabase) NotesSession(com.ibm.designer.domino.napi.NotesSession) ApplicationEx(com.ibm.xsp.application.ApplicationEx) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException)

Example 2 with ApplicationEx

use of com.ibm.xsp.application.ApplicationEx in project org.openntf.xsp.jakartaee by OpenNTF.

the class NSFCdiInjectorFactory method lookupBeanManager.

@Override
@SuppressWarnings("nls")
protected BeanManager lookupBeanManager() {
    ApplicationEx application = ApplicationEx.getInstance();
    if (application != null) {
        return ContainerUtil.getBeanManager(application);
    }
    NotesContext ctx = NotesContext.getCurrentUnchecked();
    if (ctx != null) {
        try {
            NotesDatabase database = ctx.getNotesDatabase();
            if (database != null) {
                return ContainerUtil.getBeanManager(database);
            }
        } catch (NotesAPIException e) {
            throw new RuntimeException(e);
        }
    }
    throw new IllegalStateException("Unable to locate active application!");
}
Also used : NotesDatabase(com.ibm.designer.domino.napi.NotesDatabase) ApplicationEx(com.ibm.xsp.application.ApplicationEx) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException)

Example 3 with ApplicationEx

use of com.ibm.xsp.application.ApplicationEx in project org.openntf.domino by OpenNTF.

the class FormulaContextXsp method getValueBinding.

/**
 * Create a value binding for {@link #getField(String)} and {@link #setField(String, ValueHolder)}
 *
 * @param variable
 *            the variableName, like <code>"document2.Form"</code>
 * @return a {@link ValueBinding}
 */
protected ValueBinding getValueBinding(final String variable) {
    ValueBinding ret = valueBindings.get(variable);
    if (ret == null) {
        ApplicationEx app = (ApplicationEx) context.getApplication();
        // $NON-NLS-1$ //$NON-NLS-2$
        ret = app.createValueBinding("#{" + variable + "}");
        if ((ret instanceof ValueBindingEx)) {
            ValueBindingEx valueEx = (ValueBindingEx) ret;
            valueEx.setComponent(component);
            // TODO RPr: What to set here
            valueEx.setSourceReferenceId(null);
            valueEx.setExpectedType(Object.class);
        } else if ((ret instanceof ComponentBindingObject)) {
            ((ComponentBindingObject) ret).setComponent(component);
        }
        valueBindings.put(variable, ret);
    }
    return ret;
}
Also used : ValueBindingEx(com.ibm.xsp.binding.ValueBindingEx) ApplicationEx(com.ibm.xsp.application.ApplicationEx) ValueBinding(javax.faces.el.ValueBinding) ComponentBindingObject(com.ibm.xsp.binding.ComponentBindingObject)

Example 4 with ApplicationEx

use of com.ibm.xsp.application.ApplicationEx in project org.openntf.xsp.jakartaee by OpenNTF.

the class AbstractXspLifecycleServlet method service.

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setBufferSize(0);
    initializeSessionAsSigner();
    FacesContext facesContext = null;
    try {
        if (!initialized) {
            // initialization has do be done after NotesContext is initialized with session to support SessionAsSigner operations
            doInit(config);
            initialized = true;
        }
        facesContext = getFacesContext(request, response);
        FacesContextEx exc = (FacesContextEx) facesContext;
        ApplicationEx application = exc.getApplicationEx();
        this.doService(request, response, application);
    } catch (NoAccessSignal t) {
        throw t;
    } catch (Throwable t) {
        try (PrintWriter w = response.getWriter()) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            XSPErrorPage.handleException(w, t, request.getRequestURL().toString(), false);
        } catch (javax.servlet.ServletException e) {
            throw new IOException(e);
        } catch (IllegalStateException e) {
            // Happens when the writer or output has already been opened
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    } finally {
        if (facesContext != null) {
            releaseContext(facesContext);
        }
    }
}
Also used : ServletException(jakarta.servlet.ServletException) FacesContext(javax.faces.context.FacesContext) FacesContextEx(com.ibm.xsp.context.FacesContextEx) ApplicationEx(com.ibm.xsp.application.ApplicationEx) NoAccessSignal(com.ibm.xsp.acl.NoAccessSignal) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 5 with ApplicationEx

use of com.ibm.xsp.application.ApplicationEx in project org.openntf.domino by OpenNTF.

the class OpenntfDominoImplicitObjectFactory method createImplicitObjects.

/**
 * Creates the "cheap" objects
 */
@Override
public void createImplicitObjects(final FacesContextEx ctx) {
    if (!implicitsDone_) {
        implicitsDone_ = true;
        if (!ODAPlatform.isAPIEnabled(null))
            return;
        Session session = Factory.getSession(SessionType.CURRENT);
        Database db = session.getCurrentDatabase();
        Map<String, Object> ecMap = TypedUtil.getRequestMap(ctx.getExternalContext());
        // $NON-NLS-1$
        ecMap.put("openSession", session);
        // $NON-NLS-1$
        ecMap.put("openDatabase", db);
        // Attach NSA
        if (ODAPlatform.isAppFlagSet("nsa")) {
            // $NON-NLS-1$
            Application app = ctx.getApplication();
            if (app instanceof ApplicationEx) {
                NSA.INSTANCE.registerApplication((ApplicationEx) app);
                NSA.INSTANCE.registerSession((ApplicationEx) app, (HttpSession) ctx.getExternalContext().getSession(true));
            }
        }
    }
}
Also used : ApplicationEx(com.ibm.xsp.application.ApplicationEx) Database(org.openntf.domino.Database) Application(javax.faces.application.Application) HttpSession(javax.servlet.http.HttpSession) Session(org.openntf.domino.Session)

Aggregations

ApplicationEx (com.ibm.xsp.application.ApplicationEx)5 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)2 NotesDatabase (com.ibm.designer.domino.napi.NotesDatabase)2 IOException (java.io.IOException)2 NotesSession (com.ibm.designer.domino.napi.NotesSession)1 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)1 NoAccessSignal (com.ibm.xsp.acl.NoAccessSignal)1 ComponentBindingObject (com.ibm.xsp.binding.ComponentBindingObject)1 ValueBindingEx (com.ibm.xsp.binding.ValueBindingEx)1 FacesContextEx (com.ibm.xsp.context.FacesContextEx)1 CDI (jakarta.enterprise.inject.spi.CDI)1 ServletException (jakarta.servlet.ServletException)1 PrintWriter (java.io.PrintWriter)1 Application (javax.faces.application.Application)1 FacesContext (javax.faces.context.FacesContext)1 ValueBinding (javax.faces.el.ValueBinding)1 HttpSession (javax.servlet.http.HttpSession)1 Database (org.openntf.domino.Database)1 Session (org.openntf.domino.Session)1 CDIContainerLocator (org.openntf.xsp.cdi.ext.CDIContainerLocator)1