use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.
the class Document method toJson.
@Override
public String toJson(final boolean compact) {
StringWriter sw = new StringWriter();
JsonWriter jw = new JsonWriter(sw, compact);
try {
jw.startObject();
jw.outStringProperty("@unid", getUniversalID());
jw.outStringProperty("@noteid", getNoteID());
jw.outStringProperty("@replicaid", getParentDatabase().getReplicaID());
jw.outStringProperty("@metaversalid", getMetaversalID());
try {
jw.outStringProperty("@created", getCreated().toGMTISO());
jw.outStringProperty("@lastmodified", getLastModified().toGMTISO());
jw.outStringProperty("@lastaccessed", getLastAccessed().toGMTISO());
} catch (Exception e) {
DominoUtils.handleException(e, "Exception trying to index Dates.");
}
Set<String> keys = keySet();
for (String key : keys) {
Item currItem = getFirstItem(key);
// A beer to anyone who can work out how this could happen, except for the person who identified it!
if (null != currItem) {
Type itemType = currItem.getTypeEx();
try {
if (itemType == Type.ATTACHMENT) {
jw.outProperty(key, "ATTACHMENT");
} else if (itemType == Type.AUTHORS || itemType == Type.READERS || itemType == Type.NAMES || itemType == Type.TEXT || itemType == Type.NUMBERS) {
Vector<Object> values = currItem.getValues();
if (values.size() == 1) {
jw.outProperty(key, values.elementAt(0));
} else {
jw.outProperty(key, values);
}
} else if (itemType == Type.DATETIMES) {
Vector<DateTime> values = currItem.getValueDateTimeArray();
if (values.size() == 1) {
jw.outProperty(key, values.get(0).toGMTISO());
} else {
jw.outProperty(key, TypeUtils.toStrings(values));
}
} else if (itemType == Type.EMBEDDEDOBJECT) {
jw.outProperty(key, "EMBEDDED_OBJECT");
} else if (itemType == Type.RICHTEXT) {
RichTextItem rtItem = (RichTextItem) currItem;
jw.outProperty(key, rtItem.getUnformattedText());
} else if (itemType == Type.MIME_PART) {
MIMEEntity mimeEntity = currItem.getMIMEEntity();
if (mimeEntity != null) {
jw.outProperty(key, mimeEntity.getContentAsText());
} else {
jw.outProperty(key, "MIME_PART null");
}
}
} catch (Exception e) {
DominoUtils.handleException(e, this);
// NTF - temporary
e.printStackTrace();
}
}
// if (currItem.getMIMEEntity() == null) {
// jw.outProperty(key, currItem.getText());
// } else {
// String abstractedText = currItem.abstractText(0, false, false);
// if (null == abstractedText) {
// jw.outProperty(key, "**MIME ITEM, VALUE CANNOT BE DECODED TO JSON**");
// } else {
// jw.outProperty(key, abstractedText);
// }
// }
// Now output attachments
jw.outProperty("@attachments", getAttachmentNames());
}
jw.endObject();
jw.flush();
} catch (IOException e) {
DominoUtils.handleException(e, this);
return null;
} catch (JsonException e) {
DominoUtils.handleException(e, this);
return null;
}
return sw.toString();
}
use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.
the class BaseOpenLogItem method writeToLog.
/* (non-Javadoc)
* @see org.openntf.domino.logging.OpenLogItem#writeToLog()
*/
@Override
public boolean writeToLog() {
Database currDb = Factory.getSession(SessionType.CURRENT).getCurrentDatabase();
// Current database may be null from Xots
if (null == currDb) {
if (!StringUtil.equals(getCurrentDatabasePath(), "")) {
reinitialiseSettings();
}
} else {
if (!StringUtil.equals(getCurrentDatabasePath(), Factory.getSession(SessionType.CURRENT).getCurrentDatabase().getFilePath())) {
reinitialiseSettings();
}
}
// exit early if there is no database
Database db = getLogDb();
if (db == null) {
return false;
}
boolean retval = false;
Document logDoc = null;
RichTextItem rtitem = null;
Database docDb = null;
try {
logDoc = db.createDocument();
logDoc.appendItemValue("Form", _logFormName);
Throwable ee = getBase();
if (ee != null) {
StackTraceElement ste = ee.getStackTrace()[0];
if (ee instanceof NotesException) {
logDoc.replaceItemValue("LogErrorNumber", ((NotesException) ee).id);
logDoc.replaceItemValue("LogErrorMessage", ((NotesException) ee).text);
} else {
// Fixed next line
logDoc.replaceItemValue("LogErrorMessage", getMessage());
}
logDoc.replaceItemValue("LogErrorLine", ste.getLineNumber());
logDoc.replaceItemValue("LogFromMethod", ste.getClassName() + "." + ste.getMethodName());
}
if (LogType.TYPE_EVENT.getValue().equals(getEventType())) {
if (!getSuppressEventStack()) {
logDoc.replaceItemValue("LogStackTrace", getStackTrace(ee));
}
} else {
logDoc.replaceItemValue("LogStackTrace", getStackTrace(ee));
}
logDoc.replaceItemValue("LogSeverity", getSeverity().getName());
logDoc.replaceItemValue("LogEventTime", getEventTime());
logDoc.replaceItemValue("LogEventType", getEventType());
logDoc.replaceItemValue("LogMessage", getMessage());
logDoc.replaceItemValue("LogFromDatabase", getCurrentDatabasePath());
logDoc.replaceItemValue("LogFromServer", getThisServer());
logDoc.replaceItemValue("LogFromAgent", getThisAgent());
// Fixed next line
logDoc.replaceItemValue("LogAgentLanguage", "Java");
logDoc.replaceItemValue("LogUserName", Factory.getSession(SessionType.CURRENT).getUserName());
logDoc.replaceItemValue("LogEffectiveName", Factory.getSession(SessionType.CURRENT).getEffectiveUserName());
logDoc.replaceItemValue("LogAccessLevel", getAccessLevel());
logDoc.replaceItemValue("LogUserRoles", getUserRoles());
logDoc.replaceItemValue("LogClientVersion", getClientVersion());
logDoc.replaceItemValue("LogAgentStartTime", getStartTime());
if (getErrDoc() != null) {
docDb = getErrDoc().getParentDatabase();
rtitem = logDoc.createRichTextItem("LogDocInfo");
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(_errDoc, getErrDoc().getUniversalID());
}
// make sure Depositor-level users can add documents too
logDoc.appendItemValue("$PublicAccess", "1");
logDoc.save(true);
retval = true;
} catch (Exception e) {
debugPrint(e);
retval = false;
} finally {
_errDoc = null;
_errDocUnid = null;
}
return retval;
}
use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.
the class RichTextItemReplaceAttachmentText method run.
@Override
public void run() {
Session session = Factory.getSession(SessionType.NATIVE);
Database db = session.getDatabase("", "sarmy/USSBulletins.nsf");
Document doc = db.getDocumentByUNID("5F96214CFE92013D86258027007687FA");
RichTextItem rtItem = (RichTextItem) doc.getFirstItem("BulletinText");
rtItem.replaceAttachment("Feature Requests 2008.ods", "c:/data/Feature Requests 2008.ods");
rtItem.compact();
doc.save(true, true);
}
use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.
the class JsonGraphWriter method outLiteral.
@Override
protected void outLiteral(Object paramObject, final boolean paramBoolean) throws IOException, JsonException {
// paramObject.getClass().getName()));
if (paramObject != null) {
Class<?> objClass = paramObject.getClass();
IJsonWriterAdapter adapter = factory_.getJsonWriterAdapter(objClass);
if (adapter != null) {
paramObject = adapter.toJson(paramObject);
}
}
if (this.getFactory().isNull(paramObject)) {
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 VertexFrame) {
JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (VertexFrame) paramObject, parameters_, isCollectionRoute_);
outObject(adapter);
} else if (paramObject instanceof EdgeFrame) {
JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (EdgeFrame) paramObject, parameters_, isCollectionRoute_);
outObject(adapter);
} else if (paramObject instanceof Class<?>) {
String className = ((Class) paramObject).getName();
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();
outStringLiteral(className + " " + enumName);
} else if (paramObject instanceof CharSequence) {
outStringLiteral(paramObject.toString());
} else if (paramObject instanceof Set) {
// System.out.println("TEMP DEBUG Got a set!");
outArrayLiteral(((Set) paramObject).toArray());
} else if (this.getFactory().isString(paramObject)) {
outStringLiteral(this.getFactory().getString(paramObject));
} else if (this.getFactory().isNumber(paramObject)) {
outNumberLiteral(this.getFactory().getNumber(paramObject));
} else if (this.getFactory().isBoolean(paramObject)) {
outBooleanLiteral(this.getFactory().getBoolean(paramObject));
} else if (this.getFactory().isObject(paramObject)) {
outObject(paramObject, paramBoolean);
} else if (this.getFactory().isArray(paramObject)) {
outArrayLiteral(paramObject, paramBoolean);
} else if (paramObject instanceof JsonReference) {
outReference((JsonReference) paramObject);
} else if (paramObject instanceof DateTime) {
DateTime dt = (DateTime) paramObject;
outDateLiteral_(dt.toJavaDate());
} else if (paramObject instanceof DateRange) {
DateRange dt = (DateRange) paramObject;
outDateRangeLiteral(dt);
} else if (paramObject instanceof NoteCoordinate) {
outNoteCoordinate((NoteCoordinate) paramObject);
} else if (paramObject instanceof Date) {
outDateLiteral_((Date) paramObject);
} else {
outStringLiteral("JsonGenerator cannot process unknown type of " + ((paramObject != null) ? paramObject.getClass().getName() : "<null>"));
}
}
use of org.openntf.domino.RichTextItem in project org.openntf.domino by OpenNTF.
the class DElement method getProperty.
@SuppressWarnings("unchecked")
@Override
public <T> T getProperty(final String propertyName, final Class<T> type) {
// TODO NTF cached properties should be automatically reset if the base Document is known to have changed
// if ("form".equalsIgnoreCase(propertyName)) {
// System.out.println("Getting form value now...");
// }
Object result = null;
Map<String, Object> props = getProps();
result = props.get(propertyName);
Map<String, Object> delegate = getDelegate();
if (result == null || Deferred.INSTANCE.equals(result)) {
try {
if (delegate instanceof Document) {
Document doc = (Document) delegate;
doc.closeMIMEEntities(false);
doc.setAutoMime(AutoMime.WRAP_ALL);
if (doc.hasItem(propertyName)) {
Item item = doc.getFirstItem(propertyName);
if (item instanceof RichTextItem && Object.class.equals(type)) {
result = item;
} else {
try {
result = doc.getItemValue(propertyName, type);
} catch (Throwable t) {
// System.out.println("TEMP DEBUG didn't get property " + propertyName + " with type " + type.getSimpleName()
// + " because of a " + t.getClass().getSimpleName() + ": " + t.getMessage());
}
}
}
if (result == null || Deferred.INSTANCE.equals(result)) {
try {
Object raw = doc.get(propertyName);
if (raw instanceof Vector) {
if (((Vector<?>) raw).isEmpty()) {
props.put(propertyName, Null.INSTANCE);
return null;
}
}
result = TypeUtils.objectToClass(raw, type, doc.getAncestorSession());
} catch (Throwable t) {
if (log_.isLoggable(Level.FINE)) {
log_.log(Level.FINE, "Invalid property for document " + propertyName, t);
}
}
}
} else if (delegate instanceof SessionDescendant) {
Session s = ((SessionDescendant) delegate).getAncestorSession();
result = TypeUtils.convertToTarget(delegate.get(propertyName), type, s);
} else if (delegate != null) {
try {
result = TypeUtils.convertToTarget(delegate.get(propertyName), type, null);
} catch (Throwable t) {
t.printStackTrace();
}
}
if (result == null) {
props.put(propertyName, Null.INSTANCE);
} else if (result instanceof Serializable) {
props.put(propertyName, result);
} else {
if (log_.isLoggable(Level.FINE)) {
log_.log(Level.FINE, "Got a value from the document but it's not Serializable. It's a " + result.getClass().getName());
}
props.put(propertyName, result);
}
} catch (UserAccessException uae) {
throw uae;
} catch (Exception e) {
log_.log(Level.WARNING, "Exception occured attempting to get value from document for " + propertyName + " so we cannot return a value", e);
}
} else if (result == Null.INSTANCE) {
} else {
if (result != null && !type.isAssignableFrom(result.getClass())) {
try {
// Map<String, Object> delegate = getDelegate();
if (delegate instanceof Document) {
Document doc = (Document) delegate;
Item item = doc.getFirstItem(propertyName);
if (item instanceof RichTextItem && Object.class.equals(type)) {
result = ((RichTextItem) item).getUnformattedText();
} else {
result = doc.getItemValue(propertyName, type);
}
((Document) delegate).closeMIMEEntities(false);
} else if (delegate instanceof SessionDescendant) {
Session s = ((SessionDescendant) delegate).getAncestorSession();
result = TypeUtils.convertToTarget(delegate.get(propertyName), type, s);
} else if (delegate != null) {
Object chk = delegate.get(propertyName);
if (chk != null) {
result = TypeUtils.convertToTarget(delegate.get(propertyName), type, null);
}
}
if (result == null) {
props.put(propertyName, Null.INSTANCE);
} else if (result instanceof Serializable) {
props.put(propertyName, result);
} else {
log_.log(Level.FINE, "Got a value from the document but it's not Serializable. It's a " + result.getClass().getName());
props.put(propertyName, result);
}
} catch (UserAccessException uae) {
throw uae;
} catch (Exception e) {
if (result != null) {
log_.log(Level.WARNING, "Exception occured attempting to get value from document for " + propertyName + " but we have a value in the cache of type " + result.getClass().getName() + " when we were looking for a " + type.getName(), e);
}
}
}
}
if (result == Null.INSTANCE) {
result = null;
}
if (delegate instanceof Document && delegate != null) {
((Document) delegate).closeMIMEEntities();
}
// }
if (result == Deferred.INSTANCE) {
// System.out.println("Returning Deferred INSTANCE for property " + propertyName);
}
return (T) result;
}
Aggregations