Search in sources :

Example 1 with DominoDocument

use of com.ibm.xsp.model.domino.wrapped.DominoDocument in project org.openntf.domino by OpenNTF.

the class OpenntfDominoDocumentData method createDocument.

/**
 * creates a new document and wraps it in an OpenntfDominoDocument
 *
 * @return
 * @throws NotesException
 */
protected OpenntfDominoDocument createDocument() throws NotesException {
    Database db = openDatabase();
    String server = com.ibm.xsp.model.domino.DominoUtils.getCurrentDatabase().getServer();
    if (!(StringUtil.isEmpty(server))) {
        String currentUser = com.ibm.xsp.model.domino.DominoUtils.getCurrentSession().getEffectiveUserName();
        int i = db.queryAccessPrivileges(currentUser);
        if (((i & Database.DBACL_CREATE_DOCS) == 0) && ((i & Database.DBACL_WRITE_PUBLIC_DOCS) == 0)) {
            throw new NoAccessSignal("User " + currentUser + " is has not enough privileges to create documents in " + getDatabaseName());
        }
    }
    DominoDocument dominoDoc = DominoDocument.wrap(getDatabaseName(), db, getParentId(), getFormName(), getComputeWithForm(), getConcurrencyMode(), isAllowDeletedDocs(), getSaveLinksAs(), getWebQuerySaveAgent());
    OpenntfDominoDocument ntfDoc = wrap(dominoDoc, true);
    ntfDoc.setEditable(true);
    return ntfDoc;
}
Also used : Database(lotus.domino.Database) NoAccessSignal(com.ibm.xsp.acl.NoAccessSignal) DominoDocument(com.ibm.xsp.model.domino.wrapped.DominoDocument)

Example 2 with DominoDocument

use of com.ibm.xsp.model.domino.wrapped.DominoDocument in project org.openntf.domino by OpenNTF.

the class OpenntfDominoDocumentData method openDocument.

/**
 * Opens the document with the given noteId
 *
 * @param noteId
 * @return
 * @throws NotesException
 */
protected OpenntfDominoDocument openDocument(final String noteId) throws NotesException {
    Database db = openDatabase();
    boolean allowDelted = isAllowDeletedDocs();
    Document backendDoc = com.ibm.xsp.model.domino.DominoUtils.getDocumentById(db, noteId, allowDelted);
    if (backendDoc != null) {
    // BackendBridge.setNoRecycle(backendDoc.getParentDatabase().getParent(), backendDoc, true);
    }
    DominoDocument dominoDoc = DominoDocument.wrap(getDatabaseName(), backendDoc, getComputeWithForm(), getConcurrencyMode(), allowDelted, getSaveLinksAs(), getWebQuerySaveAgent());
    OpenntfDominoDocument ntfDoc = wrap(dominoDoc, false);
    boolean editMode = "editDocument".equals(getEffectiveAction());
    ntfDoc.setEditable(editMode);
    return ntfDoc;
}
Also used : Database(lotus.domino.Database) DominoDocument(com.ibm.xsp.model.domino.wrapped.DominoDocument) Document(lotus.domino.Document) DominoDocument(com.ibm.xsp.model.domino.wrapped.DominoDocument)

Example 3 with DominoDocument

use of com.ibm.xsp.model.domino.wrapped.DominoDocument in project org.openntf.domino by OpenNTF.

the class FormulaMethodBinding method invoke.

/**
 * Invokes the binding (and the formula)
 */
@SuppressWarnings("unchecked")
@Override
public Object invoke(final FacesContext ctx, final Object[] arg1) throws EvaluationException, MethodNotFoundException {
    boolean rootWasNull = false;
    if (ctx.getViewRoot() == null) {
        rootWasNull = true;
        ctx.setViewRoot(FacesUtil.getViewRoot(getComponent()));
    }
    // $NON-NLS-1$
    final DominoDocument dominoDoc = (DominoDocument) ExtLibUtil.resolveVariable(ctx, "currentDocument");
    Map<String, Object> dataMap = null;
    if (dominoDoc instanceof Map) {
        dataMap = (Map<String, Object>) dominoDoc;
    } else {
        dataMap = new DominoDocumentMapAdapter(dominoDoc);
    }
    try {
        FormulaContextXsp fctx = (FormulaContextXsp) Formulas.createContext(dataMap, Formulas.getParser());
        fctx.init(this.getComponent(), ctx);
        return getASTNode().solve(fctx);
    } catch (EvaluateException e) {
        throw new EvaluationException(e);
    } catch (FormulaParseException e) {
        throw new EvaluationException(e);
    } finally {
        if (rootWasNull) {
            ctx.setViewRoot(null);
        }
    }
}
Also used : EvaluateException(org.openntf.formula.EvaluateException) FormulaParseException(org.openntf.formula.FormulaParseException) DominoDocumentMapAdapter(org.openntf.domino.xsp.model.DominoDocumentMapAdapter) EvaluationException(javax.faces.el.EvaluationException) Map(java.util.Map) DominoDocument(com.ibm.xsp.model.domino.wrapped.DominoDocument)

Example 4 with DominoDocument

use of com.ibm.xsp.model.domino.wrapped.DominoDocument in project org.openntf.domino by OpenNTF.

the class FormulaValueBinding method getValue.

/**
 * returns the value after the formula was evaluated
 */
@SuppressWarnings("unchecked")
@Override
public Object getValue(final FacesContext ctx) throws EvaluationException, PropertyNotFoundException {
    boolean rootWasNull = false;
    if (ctx.getViewRoot() == null) {
        rootWasNull = true;
        ctx.setViewRoot(FacesUtil.getViewRoot(getComponent()));
    }
    // $NON-NLS-1$
    final DominoDocument dominoDoc = (DominoDocument) ExtLibUtil.resolveVariable(ctx, "currentDocument");
    Map<String, Object> dataMap = null;
    if (dominoDoc instanceof Map) {
        dataMap = (Map<String, Object>) dominoDoc;
    } else {
        dataMap = new DominoDocumentMapAdapter(dominoDoc);
    }
    List<Object> ret = null;
    try {
        FormulaContextXsp fctx = (FormulaContextXsp) Formulas.createContext(dataMap, Formulas.getParser());
        fctx.init(this.getComponent(), ctx);
        ret = getASTNode().solve(fctx);
    } catch (EvaluateException e) {
        throw new EvaluationException(e);
    } catch (FormulaParseException e) {
        throw new EvaluationException(e);
    } finally {
        if (rootWasNull) {
            ctx.setViewRoot(null);
        }
    }
    Object firstValue = ret.size() >= 1 ? ret.get(0) : null;
    // RPr: this is similar to the javascript binding
    Class<?> expectedType = getExpectedType();
    if (expectedType != null) {
        if (expectedType == String.class) {
            if (ret.isEmpty()) {
                return null;
            }
            if (ret.size() == 1) {
                return ret.get(0).toString();
            }
            return ret.toString();
        }
        if ((expectedType == Boolean.class) || (expectedType == Boolean.TYPE)) {
            return firstValue == null ? Boolean.FALSE : (Boolean) firstValue;
        }
        if ((expectedType == Character.class) || (expectedType == Character.TYPE)) {
            // $NON-NLS-1$
            String str = firstValue == null ? "" : firstValue.toString();
            if (str.length() > 0) {
                return new Character(str.charAt(0));
            }
        }
        if ((expectedType.isPrimitive()) || (Number.class.isAssignableFrom(expectedType))) {
            if ((expectedType == Double.class) || (expectedType == Double.TYPE)) {
                return firstValue == null ? 0d : ((Number) firstValue).doubleValue();
            }
            if ((expectedType == Integer.class) || (expectedType == Integer.TYPE)) {
                return firstValue == null ? 0 : ((Number) firstValue).intValue();
            }
            if ((expectedType == Long.class) || (expectedType == Long.TYPE)) {
                return firstValue == null ? 0l : ((Number) firstValue).longValue();
            }
            if ((expectedType == Byte.class) || (expectedType == Byte.TYPE)) {
                return firstValue == null ? (byte) 0 : ((Number) firstValue).byteValue();
            }
            if ((expectedType == Short.class) || (expectedType == Short.TYPE)) {
                return firstValue == null ? (short) 0 : ((Number) firstValue).shortValue();
            }
            if ((expectedType == Float.class) || (expectedType == Float.TYPE)) {
                return firstValue == null ? 0f : ((Number) firstValue).floatValue();
            }
        }
    }
    return convertToExpectedType(ctx, ret);
}
Also used : DominoDocumentMapAdapter(org.openntf.domino.xsp.model.DominoDocumentMapAdapter) EvaluationException(javax.faces.el.EvaluationException) EvaluateException(org.openntf.formula.EvaluateException) FormulaParseException(org.openntf.formula.FormulaParseException) Map(java.util.Map) DominoDocument(com.ibm.xsp.model.domino.wrapped.DominoDocument)

Aggregations

DominoDocument (com.ibm.xsp.model.domino.wrapped.DominoDocument)4 Map (java.util.Map)2 EvaluationException (javax.faces.el.EvaluationException)2 Database (lotus.domino.Database)2 DominoDocumentMapAdapter (org.openntf.domino.xsp.model.DominoDocumentMapAdapter)2 EvaluateException (org.openntf.formula.EvaluateException)2 FormulaParseException (org.openntf.formula.FormulaParseException)2 NoAccessSignal (com.ibm.xsp.acl.NoAccessSignal)1 Document (lotus.domino.Document)1