Search in sources :

Example 6 with RichTextItem

use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.

the class JsonGraphWriter method outObject.

@Override
public void outObject(Object paramObject) throws IOException, JsonException {
    // + (paramObject == null ? "NULL" : paramObject.getClass().getName()));
    try {
        if (paramObject != null) {
            Class<?> objClass = paramObject.getClass();
            IJsonWriterAdapter adapter = factory_.getJsonWriterAdapter(objClass);
            if (adapter != null) {
                paramObject = adapter.toJson(paramObject);
            }
        }
        if (paramObject == null) {
            super.outNull();
        // } else if (paramObject instanceof Term) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Term) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        // } else if (paramObject instanceof Value) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Value) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        // } else if (paramObject instanceof RichTextReference) {
        // JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (RichTextReference) paramObject, parameters_,
        // isCollectionRoute_);
        // super.outObject(adapter);
        } else if (paramObject instanceof EdgeFrame) {
            JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (EdgeFrame) paramObject, parameters_, isCollectionRoute_);
            super.outObject(adapter);
        } else if (paramObject instanceof VertexFrame) {
            JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (VertexFrame) paramObject, parameters_, isCollectionRoute_);
            super.outObject(adapter);
        } else if (paramObject instanceof Class<?>) {
            String className = ((Class<?>) paramObject).getName();
            super.outStringLiteral(className);
        } else if (paramObject instanceof RichTextItem) {
            outRichTextItem((RichTextItem) paramObject);
        } else if (paramObject instanceof Enum) {
            String className = ((Enum<?>) paramObject).getClass().getName();
            String enumName = ((Enum<?>) paramObject).name();
        } else if (paramObject instanceof NoteCoordinate) {
            String nc = ((NoteCoordinate) paramObject).toString();
            super.outStringLiteral(nc);
        } else if (paramObject instanceof org.openntf.domino.impl.View.DominoColumnInfo) {
            String itemName = ((org.openntf.domino.impl.View.DominoColumnInfo) paramObject).getItemName();
            super.outStringLiteral(itemName);
        } else if (paramObject instanceof Set) {
            // System.out.println("TEMP DEBUG outObject received a Set");
            outArrayLiteral(((Set) paramObject).toArray());
        } else if (paramObject instanceof DateTime) {
            outDateLiteral((DateTime) paramObject);
        } else if (paramObject instanceof DateRange) {
            outDateRangeLiteral((DateRange) paramObject);
        } else if (paramObject instanceof NoteCoordinate) {
            outNoteCoordinate((NoteCoordinate) paramObject);
        } else if (paramObject instanceof Throwable) {
            outException((Throwable) paramObject);
        } else {
            // Class<?> clazz = paramObject.getClass();
            // String name = clazz.getName();
            super.outObject(paramObject);
        }
    } catch (UserAccessException uae) {
        throw uae;
    } catch (RuntimeException re) {
        throw re;
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : NoteCoordinate(org.openntf.domino.big.impl.NoteCoordinate) EdgeFrame(com.tinkerpop.frames.EdgeFrame) Set(java.util.Set) JsonFrameAdapter(org.openntf.domino.rest.resources.frames.JsonFrameAdapter) IJsonWriterAdapter(org.openntf.domino.rest.json.JsonGraphFactory.IJsonWriterAdapter) UserAccessException(org.openntf.domino.exceptions.UserAccessException) DateTime(org.openntf.domino.DateTime) DateRange(org.openntf.domino.DateRange) VertexFrame(com.tinkerpop.frames.VertexFrame) RichTextItem(org.openntf.domino.RichTextItem)

Example 7 with RichTextItem

use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.

the class Document method writeStackTraceToItem.

private void writeStackTraceToItem(final String itemname, final Throwable t) {
    List<String> trace = throwableToList(t);
    RichTextItem rti = createRichTextItem(itemname);
    for (String line : trace) {
        if (line.startsWith("Caused by")) {
            rti.addPageBreak();
            rti.addNewLine();
        } else {
            rti.appendText(line);
            rti.addNewLine();
        }
    }
}
Also used : RichTextItem(org.openntf.domino.RichTextItem)

Example 8 with RichTextItem

use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.

the class Document method createRichTextItem.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Document#createRichTextItem(java.lang.String)
	 */
@Override
public RichTextItem createRichTextItem(final String name) {
    checkMimeOpen(name);
    beginEdit();
    RichTextItem ret = null;
    try {
        ret = fromLotus(getDelegate().createRichTextItem(name), RichTextItem.SCHEMA, this);
        markDirty(name, true);
    } catch (NotesException e) {
        DominoUtils.handleException(e, this);
    }
    return ret;
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) RichTextItem(org.openntf.domino.RichTextItem)

Example 9 with RichTextItem

use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.

the class DocumentScanner method processDocument.

public void processDocument(final Document doc) {
    try {
        if (doc != null && !doc.isDeleted()) {
            docCount_++;
            Map<CharSequence, Item.Type> typeMap = getFieldTypeMap();
            Vector<Item> items = doc.getItems();
            boolean hasReaders = doc.hasReaders();
            // $NON-NLS-1$ //$NON-NLS-2$
            String address = doc.getUniversalID() + (hasReaders ? "1" : "0") + doc.getFormName();
            // System.out.println("TEMP DEBUG processing document " + doc.getMetaversalID() + " with " + items.size() + " items.");
            for (Item item : items) {
                if (item != null) {
                    CaseInsensitiveString name = new CaseInsensitiveString(item.getName());
                    if (!(name.startsWith("$") && getIgnoreDollar())) {
                        // }
                        try {
                            boolean isRT = false;
                            String value = null;
                            Vector<Object> values = null;
                            RichTextItem rti = null;
                            switch(item.getTypeEx()) {
                                case AUTHORS:
                                case READERS:
                                case NAMES:
                                case TEXT:
                                    value = item.getValueString();
                                    values = item.getValues();
                                    break;
                                case RICHTEXT:
                                    rti = (RichTextItem) item;
                                    isRT = true;
                                    break;
                                default:
                            }
                            if (value != null && value.length() > 0 && !DominoUtils.isNumber(value)) {
                                if (item.isNames() || DominoUtils.isHierarchicalName(value)) {
                                    if (values != null && !values.isEmpty()) {
                                        for (Object o : values) {
                                            if (o instanceof String) {
                                                CharSequence parmName = caseSensitive_ ? (String) o : new CaseInsensitiveString((String) o);
                                                processName(parmName, name, doc.getAncestorSession(), address);
                                            }
                                        }
                                    }
                                } else {
                                    itemCount_++;
                                    if (values != null && !values.isEmpty()) {
                                        for (Object o : values) {
                                            processValue(name, o, address);
                                        }
                                    } else {
                                        processTextValue(name, value, address);
                                    }
                                }
                            }
                            if (isTrackRichTextLocation() && isRT) {
                                processRichText(name, rti, address);
                            } else {
                            // System.out.println("TEMP DEBUG Not processing item " + name);
                            }
                            if (isTrackFieldTypes()) {
                                if (!typeMap.containsKey(name)) {
                                    typeMap.put(name, item.getTypeEx());
                                }
                            }
                        } catch (Exception e) {
                            Database db = doc.getAncestorDatabase();
                            System.err.println("Unable to scan item: " + name + " in Document " + doc.getNoteID() + " in database " + db.getApiPath() + " due to an " + e.getClass().getName() + " with message " + e.getMessage());
                            e.printStackTrace();
                        }
                    }
                }
            }
            setLastDocModDate(doc.getLastModifiedDate());
            setChanged();
            notifyObservers(ScanStatus.RUNNING);
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) RichTextItem(org.openntf.domino.RichTextItem) Item(org.openntf.domino.Item) RichTextItem(org.openntf.domino.RichTextItem) Database(org.openntf.domino.Database)

Example 10 with RichTextItem

use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.

the class XspOpenLogItem method writeToLog.

/*
	 * This is the method that does the actual logging to the OpenLog database. You'll notice that I actually have a Database parameter,
	 * which is normally a reference to the OpenLog database that you're using. However, it occurred to me that you might want to use this
	 * class to write to an alternate log database at times, so I left you that option (although you're stuck with the field names used by
	 * the OpenLog database in that case).
	 * 
	 * This method creates a document in the log database, populates the fields of that document with the values in our global variables,
	 * and adds some associated information about any Document that needs to be referenced. If you do decide to send log information to an
	 * alternate database, you can just call this method manually after you've called logError or logEvent, and it will write everything to
	 * the database of your choice.
	 */
@Override
public boolean writeToLog() {
    boolean retval = false;
    try {
        Database db;
        Document logDoc;
        RichTextItem rtitem;
        Database docDb;
        if (null == Factory.getSession(SessionType.CURRENT).getCurrentDatabase()) {
            if (!StringUtil.equals(super.getCurrentDatabasePath(), "")) {
                // $NON-NLS-1$
                reinitialiseSettings();
            }
        } else {
            if (!StringUtil.equals(super.getCurrentDatabasePath(), Factory.getSession(SessionType.CURRENT).getCurrentDatabase().getFilePath())) {
                reinitialiseSettings();
            }
        }
        if (StringUtil.isEmpty(getLogEmail())) {
            db = getLogDb();
        } else {
            // $NON-NLS-1$
            db = Factory.getSession(SessionType.NATIVE).getDatabase(getThisServer(), "mail.box", false);
        }
        if (db == null) {
            System.out.println("Could not retrieve database at path " + getLogDbName());
            return false;
        }
        logDoc = db.createDocument();
        // $NON-NLS-1$
        rtitem = logDoc.createRichTextItem("LogDocInfo");
        // $NON-NLS-1$
        logDoc.appendItemValue("Form", super.getLogFormName());
        Throwable ee = getBase();
        // $NON-NLS-1$
        String errMsg = "";
        if (null != ee) {
            StackTraceElement ste = ee.getStackTrace()[0];
            if (ee instanceof NotesException) {
                // $NON-NLS-1$
                logDoc.replaceItemValue("LogErrorNumber", ((NotesException) ee).id);
                errMsg = ((NotesException) ee).text;
            } else if ("Interpret exception".equals(ee.getMessage()) && ee instanceof com.ibm.jscript.JavaScriptException) {
                // $NON-NLS-1$
                com.ibm.jscript.InterpretException ie = (com.ibm.jscript.InterpretException) ee;
                errMsg = "Expression Language Interpret Exception " + ie.getExpressionText();
            } else {
                errMsg = ee.getMessage();
            }
            if (LogType.TYPE_EVENT.getValue().equals(getEventType())) {
                if (!getSuppressEventStack()) {
                    // $NON-NLS-1$
                    logDoc.replaceItemValue("LogStackTrace", getStackTrace(ee));
                }
            } else {
                // $NON-NLS-1$
                logDoc.replaceItemValue("LogStackTrace", getStackTrace(ee));
            }
            // $NON-NLS-1$
            logDoc.replaceItemValue("LogErrorLine", ste.getLineNumber());
            // $NON-NLS-1$ //$NON-NLS-2$
            logDoc.replaceItemValue("LogFromMethod", ste.getClass() + "." + ste.getMethodName());
        }
        if ("".equals(errMsg)) {
            errMsg = getMessage();
        } else {
            errMsg += " - " + getMessage();
        }
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogErrorMessage", errMsg);
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogEventTime", getEventTime());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogEventType", getEventType());
        // If greater than 32k, put in logDocInfo
        if (getMessage().length() > 32000) {
            rtitem.appendText(getMessage());
            rtitem.addNewLine();
        } else {
            // $NON-NLS-1$
            logDoc.replaceItemValue("LogMessage", getMessage());
        }
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogSeverity", getSeverity().getName());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogFromDatabase", getCurrentDatabase().getFilePath());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogFromServer", getThisServer());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogFromAgent", getThisAgent());
        // $NON-NLS-1$ //$NON-NLS-2$
        logDoc.replaceItemValue("LogAgentLanguage", "Java");
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogUserName", Factory.getSession(SessionType.CURRENT).getUserName());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogEffectiveName", Factory.getSession(SessionType.CURRENT).getEffectiveUserName());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogAccessLevel", getAccessLevel());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogUserRoles", getUserRoles());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogClientVersion", getClientVersion());
        // $NON-NLS-1$
        logDoc.replaceItemValue("LogAgentStartTime", getStartTime());
        if (getErrDoc() != null) {
            docDb = getErrDoc().getParentDatabase();
            rtitem.appendText("The document associated with this event is:");
            rtitem.addNewLine(1);
            rtitem.appendText("Server: " + docDb.getServer());
            rtitem.addNewLine(1);
            rtitem.appendText("Database: " + docDb.getFilePath());
            rtitem.addNewLine(1);
            rtitem.appendText("UNID: " + getErrDoc().getUniversalID());
            rtitem.addNewLine(1);
            rtitem.appendText("Note ID: " + getErrDoc().getNoteID());
            rtitem.addNewLine(1);
            rtitem.appendText("DocLink: ");
            rtitem.appendDocLink(super.getErrDoc(), getErrDoc().getUniversalID());
        }
        // make sure Depositor-level users can add documents too
        // $NON-NLS-1$ //$NON-NLS-2$
        logDoc.appendItemValue("$PublicAccess", "1");
        if (StringUtil.isNotEmpty(getLogEmail())) {
            // $NON-NLS-1$
            logDoc.replaceItemValue("Recipients", getLogEmail());
        }
        // Set expiry date, if defined
        if (!StringUtil.isEmpty(getLogExpireDate())) {
            try {
                Integer expiryPeriod = new Integer(getLogExpireDate());
                Calendar expTime = Calendar.getInstance();
                expTime.setTime(getStartTime());
                expTime.add(Calendar.DAY_OF_YEAR, expiryPeriod);
                // $NON-NLS-1$
                logDoc.replaceItemValue("ExpireDate", expTime.getTime());
            } catch (Throwable t) {
                // $NON-NLS-1$
                logDoc.replaceItemValue(// $NON-NLS-1$
                "ArchiveFlag", "WARNING: Xsp Properties in the application has a non-numeric value for xsp.openlog.expireDate, so cannot be set to auto-expire");
            }
        }
        logDoc.save(true);
        retval = true;
    } catch (Throwable t) {
        DominoUtils.handleException(t);
    } finally {
        _errDoc = null;
        _errDocUnid = null;
    }
    return retval;
}
Also used : Calendar(java.util.Calendar) Document(org.openntf.domino.Document) NotesException(lotus.domino.NotesException) RichTextItem(org.openntf.domino.RichTextItem) Database(org.openntf.domino.Database)

Aggregations

RichTextItem (org.openntf.domino.RichTextItem)10 NotesException (lotus.domino.NotesException)4 Database (org.openntf.domino.Database)4 Document (org.openntf.domino.Document)4 DateTime (org.openntf.domino.DateTime)3 Item (org.openntf.domino.Item)3 UserAccessException (org.openntf.domino.exceptions.UserAccessException)3 EdgeFrame (com.tinkerpop.frames.EdgeFrame)2 VertexFrame (com.tinkerpop.frames.VertexFrame)2 Set (java.util.Set)2 Vector (java.util.Vector)2 DateRange (org.openntf.domino.DateRange)2 Session (org.openntf.domino.Session)2 NoteCoordinate (org.openntf.domino.big.impl.NoteCoordinate)2 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)2 IJsonWriterAdapter (org.openntf.domino.rest.json.JsonGraphFactory.IJsonWriterAdapter)2 JsonFrameAdapter (org.openntf.domino.rest.resources.frames.JsonFrameAdapter)2 JsonException (com.ibm.commons.util.io.json.JsonException)1 JsonReference (com.ibm.commons.util.io.json.JsonReference)1 JsonWriter (com.ibm.commons.util.io.json.util.JsonWriter)1