use of org.openntf.domino.exceptions.OpenNTFNotesException in project org.openntf.domino by OpenNTF.
the class Document method get.
/**
* Gets a value depending on the parameter 'key'. Key can either be a @Formula, a special value or an item name.
* <p>
* Possible values for the 'key' parameter:
* <dl>
* <dt>parentdocument</dt>
* <dd>Returns the parent document if this document is a response</dd>
* <dt>@accesseddate</dt>
* <dd>Indicates the time and date when the document was last accessed by a Notes client, whether for reading or editing as a
* java.util.Date.</dd>
* <dt>@modifieddate</dt>
* <dd>Returns a time-date value indicating when the document was modified initially as a java.util.Date</dd>
* <dt>@createddate</dt>
* <dd>Returns the time-date when the document was created as a java.util.Date</dd>
* </dl>
* </p>
*
* @param key
* @formula, item name or a special value from a list above
* @return value corresponding to the given 'key'
*/
@Override
public Object get(final Object key) {
// TODO NTF: Implement a read-only mode for Documents so we know in advance that our cache is valid
if (key == null) {
return null;
}
if (key instanceof CharSequence) {
String skey = key.toString().toLowerCase();
if ("parentdocument".equalsIgnoreCase(skey)) {
return this.getParentDocument();
}
if ("form".equalsIgnoreCase(skey)) {
return this.getFormName();
}
if (skey.indexOf("@") != -1) {
// TODO RPr: Should we REALLY detect all formulas, like "3+5" or "field[2]" ?
// TODO NTF: If so, we should change to looking for valid item names first, then trying to treat as formula
int pos = skey.indexOf('(');
if (pos != -1) {
skey = skey.substring(0, pos);
}
if ("@accessed".equals(skey)) {
return this.getLastAccessed();
}
if ("@modified".equals(skey)) {
return this.getLastModified();
}
if ("@created".equals(skey)) {
return this.getCreated();
}
if ("@accesseddate".equals(skey)) {
return this.getLastAccessedDate();
}
if ("@modifieddate".equals(skey)) {
return this.getLastModifiedDate();
}
if ("@createddate".equals(skey)) {
return this.getCreatedDate();
}
if ("@documentuniqueid".equals(skey)) {
return this.getUniversalID();
}
if ("@noteid".equals(skey)) {
return this.getNoteID();
}
if ("@doclength".equals(skey)) {
return this.getSize();
}
if ("@isresponsedoc".equals(skey)) {
return this.isResponse();
}
if ("@replicaid".equals(skey)) {
return this.getAncestorDatabase().getReplicaID();
}
if ("@responses".equals(skey)) {
DocumentCollection resp = this.getResponses();
if (resp == null) {
return 0;
}
return resp.getCount();
}
if ("@isnewdoc".equals(skey)) {
return this.isNewNote();
}
if ("@inheriteddocumentuniqueid".equals(skey)) {
org.openntf.domino.Document parent = this.getParentDocument();
if (parent == null) {
return "";
}
return parent.getUniversalID();
}
// TODO RPr: This should be replaced
// TODO NTF: Agreed when we can have an extensible switch for which formula engine to use
Formula formula = new Formula();
formula.setExpression(key.toString());
List<?> value = formula.getValue(this);
if (value.size() == 1) {
return value.get(0);
}
return value;
}
}
// TODO: What is the best way to use here without breaking everything?
// Object value = this.getItemValue(key.toString(), Object.class);
// Object value = this.getItemValue(key.toString(), Object[].class);
Object value = null;
String keyS = key.toString();
try {
value = this.getItemValue(keyS, Object.class);
} catch (OpenNTFNotesException e) {
if (e.getCause() instanceof NotesException || (e.getCause() != null && e.getCause().getCause() instanceof NotesException)) {
value = getFirstItem(keyS, true);
}
if (value == null) {
throw e;
}
}
if (value instanceof Vector) {
Vector<?> v = (Vector<?>) value;
if (v.size() == 1) {
return v.get(0);
}
}
return value;
// if (this.containsKey(key)) {
// Vector<Object> value = this.getItemValue(key.toString());
// if (value == null) {
// //TODO Throw an exception if the item data can't be read? Null implies the key doesn't exist
// return null;
// } else if (value.size() == 1) {
// return value.get(0);
// }
// return value;
// }
// return null;
}
use of org.openntf.domino.exceptions.OpenNTFNotesException in project org.openntf.domino by OpenNTF.
the class DatabaseDesign method setDatabaseProperties.
/* (non-Javadoc)
* @see org.openntf.domino.design.DatabaseDesign#setDatabaseProperties(java.util.Map)
*/
@Override
public void setDatabaseProperties(final Map<DbProperties, Boolean> props) {
// Capture and error for non-settable options
List<String> nonSettable = new ArrayList<>();
List<String> setterMethods = new ArrayList<>();
if (props.containsKey(DbProperties.DAOS_ENABLED)) {
nonSettable.add(DbProperties.DAOS_ENABLED.name());
}
if (props.containsKey(DbProperties.DOCUMENT_SUMMARY_16MB)) {
nonSettable.add(DbProperties.DOCUMENT_SUMMARY_16MB.name());
}
if (props.containsKey(DbProperties.ALLOW_DAS)) {
setterMethods.add(DbProperties.ALLOW_DAS.name());
}
if (props.containsKey(DbProperties.DB_IS_TEMPLATE)) {
setterMethods.add(DbProperties.DB_IS_TEMPLATE.name());
}
if (props.containsKey(DbProperties.INHERIT_FROM_TEMPLATE)) {
setterMethods.add(DbProperties.INHERIT_FROM_TEMPLATE.name());
}
if (props.containsKey(DbProperties.REPLICATE_UNREAD)) {
setterMethods.add(DbProperties.REPLICATE_UNREAD.name());
}
if (props.containsKey(DbProperties.MAX_REVISIONS)) {
setterMethods.add(DbProperties.MAX_REVISIONS.name());
}
if (props.containsKey(DbProperties.MAX_UPDATED_BY)) {
setterMethods.add(DbProperties.MAX_UPDATED_BY.name());
}
if (props.containsKey(DbProperties.SOFT_DELETE_EXPIRY)) {
nonSettable.add(DbProperties.SOFT_DELETE_EXPIRY.name());
}
if (!setterMethods.isEmpty() || !nonSettable.isEmpty()) {
// $NON-NLS-1$
String message = "";
if (!nonSettable.isEmpty()) {
message = "The following cannot be set programmatically but need admin processes to run: " + Strings.join(nonSettable, ",") + ". ";
}
if (!setterMethods.isEmpty()) {
message += "The following methods need to be set with specific setters in DatabaseDesign class: " + Strings.join(setterMethods, ",") + ".";
}
throw new OpenNTFNotesException(message);
}
XMLNode node = getDatabaseNode();
// Use Javascript is false, or missing in DXL if checked
if (props.containsKey(DbProperties.USE_JS)) {
if (props.get(DbProperties.USE_JS)) {
node.removeAttribute(DbProperties.USE_JS.getPropertyName());
} else {
// $NON-NLS-1$
node.setAttribute(DbProperties.USE_JS.getPropertyName(), "false");
}
}
// Require SSL is true if checked or missing in DXL
if (props.containsKey(DbProperties.REQUIRE_SSL)) {
if (props.get(DbProperties.REQUIRE_SSL)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.REQUIRE_SSL.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.REQUIRE_SSL.getPropertyName());
}
}
// Don't Allow URL Open is true if checked or missing in DXL
if (props.containsKey(DbProperties.NO_URL_OPEN)) {
if (props.get(DbProperties.NO_URL_OPEN)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.NO_URL_OPEN.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.NO_URL_OPEN.getPropertyName());
}
}
// $AllowPost8HTML is a node or not
if (props.containsKey(DbProperties.ENHANCED_HTML)) {
getIconNote().setEnhancedHTML(props.get(DbProperties.ENHANCED_HTML));
isIconDirty_ = true;
}
// $DisallowOpenInNBP is a node or not
if (props.containsKey(DbProperties.BLOCK_ICAA)) {
getIconNote().setBlockICAA(props.get(DbProperties.BLOCK_ICAA));
isIconDirty_ = true;
}
// Don't Allow Background Agents is false if checked or missing in DXL
if (props.containsKey(DbProperties.DISABLE_BACKGROUND_AGENTS)) {
if (props.get(DbProperties.DISABLE_BACKGROUND_AGENTS)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.DISABLE_BACKGROUND_AGENTS.getPropertyName(), "false");
} else {
node.removeAttribute(DbProperties.DISABLE_BACKGROUND_AGENTS.getPropertyName());
}
}
// Allow stored forms is false, or missing in DXL if checked
if (props.containsKey(DbProperties.ALLOW_STORED_FORMS)) {
if (props.get(DbProperties.ALLOW_STORED_FORMS)) {
node.removeAttribute(DbProperties.ALLOW_STORED_FORMS.getPropertyName());
} else {
// $NON-NLS-1$
node.setAttribute(DbProperties.ALLOW_STORED_FORMS.getPropertyName(), "false");
}
}
// Display Images After Loading is true if checked or missing in DXL
if (props.containsKey(DbProperties.DEFER_IMAGE_LOADING)) {
if (props.get(DbProperties.DEFER_IMAGE_LOADING)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.DEFER_IMAGE_LOADING.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.DEFER_IMAGE_LOADING.getPropertyName());
}
}
// Allow document locking is true if checked or missing in DXL
if (props.containsKey(DbProperties.ALLOW_DOC_LOCKING)) {
if (props.get(DbProperties.ALLOW_DOC_LOCKING)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.ALLOW_DOC_LOCKING.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.ALLOW_DOC_LOCKING.getPropertyName());
}
}
// Inherit OS theme is true if checked or missing in DXL
if (props.containsKey(DbProperties.INHERIT_OS_THEME)) {
if (props.get(DbProperties.INHERIT_OS_THEME)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.INHERIT_OS_THEME.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.INHERIT_OS_THEME.getPropertyName());
}
}
// Allow design locking is true if checked or missing in DXL
if (props.containsKey(DbProperties.ALLOW_DESIGN_LOCKING)) {
if (props.get(DbProperties.ALLOW_DESIGN_LOCKING)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.ALLOW_DESIGN_LOCKING.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.ALLOW_DESIGN_LOCKING.getPropertyName());
}
}
// Show in open dialog is false, or missing in DXL if checked
if (props.containsKey(DbProperties.SHOW_IN_OPEN_DIALOG)) {
if (props.get(DbProperties.SHOW_IN_OPEN_DIALOG)) {
node.removeAttribute(DbProperties.SHOW_IN_OPEN_DIALOG.getPropertyName());
} else {
// $NON-NLS-1$
node.setAttribute(DbProperties.SHOW_IN_OPEN_DIALOG.getPropertyName(), "false");
}
}
// Multi Db indexing is true if checked or missing in DXL
if (props.containsKey(DbProperties.MULTI_DB_INDEXING)) {
if (props.get(DbProperties.MULTI_DB_INDEXING)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.MULTI_DB_INDEXING.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.MULTI_DB_INDEXING.getPropertyName());
}
}
// Don't mark modified unread is false if checked or missing in DXL
if (props.containsKey(DbProperties.MODIFIED_NOT_UNREAD)) {
if (props.get(DbProperties.MODIFIED_NOT_UNREAD)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.MODIFIED_NOT_UNREAD.getPropertyName(), "false");
} else {
node.removeAttribute(DbProperties.MODIFIED_NOT_UNREAD.getPropertyName());
}
}
// Mark parent on reply or forward is true if checked or missing in DXL
if (props.containsKey(DbProperties.MARK_PARENT_REPLY_FORWARD)) {
if (props.get(DbProperties.MARK_PARENT_REPLY_FORWARD)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.MARK_PARENT_REPLY_FORWARD.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.MARK_PARENT_REPLY_FORWARD.getPropertyName());
}
}
// Advanced template is true if checked or missing in DXL
if (props.containsKey(DbProperties.ADVANCED_TEMPLATE)) {
if (props.get(DbProperties.ADVANCED_TEMPLATE)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.ADVANCED_TEMPLATE.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.ADVANCED_TEMPLATE.getPropertyName());
}
}
// Multilingual is true if checked or missing in DXL
if (props.containsKey(DbProperties.MULTILINGUAL)) {
if (props.get(DbProperties.MULTILINGUAL)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.MULTILINGUAL.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.MULTILINGUAL.getPropertyName());
}
}
// Don't maintain unread is false, or missing in DXL if checked
if (props.containsKey(DbProperties.DONT_MAINTAIN_UNREAD)) {
if (props.get(DbProperties.DONT_MAINTAIN_UNREAD)) {
node.removeAttribute(DbProperties.DONT_MAINTAIN_UNREAD.getPropertyName());
} else {
// $NON-NLS-1$
node.setAttribute(DbProperties.DONT_MAINTAIN_UNREAD.getPropertyName(), "false");
}
}
// Optimize document table map is true if checked or missing in DXL
if (props.containsKey(DbProperties.OPTIMIZE_DOC_MAP)) {
if (props.get(DbProperties.OPTIMIZE_DOC_MAP)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.OPTIMIZE_DOC_MAP.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.OPTIMIZE_DOC_MAP.getPropertyName());
}
}
// Don't overwrite free space is false if checked or missing in DXL
if (props.containsKey(DbProperties.DONT_OVERWRITE_FREE_SPACE)) {
if (props.get(DbProperties.DONT_OVERWRITE_FREE_SPACE)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.DONT_OVERWRITE_FREE_SPACE.getPropertyName(), "false");
} else {
node.removeAttribute(DbProperties.DONT_OVERWRITE_FREE_SPACE.getPropertyName());
}
}
// Maintain last accessed is true if checked or missing in DXL
if (props.containsKey(DbProperties.MAINTAIN_LAST_ACCESSED)) {
if (props.get(DbProperties.MAINTAIN_LAST_ACCESSED)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.MAINTAIN_LAST_ACCESSED.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.MAINTAIN_LAST_ACCESSED.getPropertyName());
}
}
// Disable transaction logging is false if checked or missing in DXL
if (props.containsKey(DbProperties.DISABLE_TRANSACTION_LOGGING)) {
if (props.get(DbProperties.DISABLE_TRANSACTION_LOGGING)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.DISABLE_TRANSACTION_LOGGING.getPropertyName(), "false");
} else {
node.removeAttribute(DbProperties.DISABLE_TRANSACTION_LOGGING.getPropertyName());
}
}
// Don't support specialized response hierarchy is false if checked or missing in DXL
if (props.containsKey(DbProperties.NO_SPECIAL_RESPONSE_HIERARCHY)) {
if (props.get(DbProperties.NO_SPECIAL_RESPONSE_HIERARCHY)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.NO_SPECIAL_RESPONSE_HIERARCHY.getPropertyName(), "false");
} else {
node.removeAttribute(DbProperties.NO_SPECIAL_RESPONSE_HIERARCHY.getPropertyName());
}
}
// LZ1 compression is true if checked or missing in DXL
if (props.containsKey(DbProperties.USE_LZ1)) {
if (props.get(DbProperties.USE_LZ1)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.USE_LZ1.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.USE_LZ1.getPropertyName());
}
}
// Don't allow headline monitoring is false if checked or missing in DXL
if (props.containsKey(DbProperties.NO_HEADLINE_MONITORING)) {
if (props.get(DbProperties.NO_HEADLINE_MONITORING)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.NO_HEADLINE_MONITORING.getPropertyName(), "false");
} else {
node.removeAttribute(DbProperties.NO_HEADLINE_MONITORING.getPropertyName());
}
}
// Allow more fields is true if checked or missing in DXL
if (props.containsKey(DbProperties.ALLOW_MORE_FIELDS)) {
if (props.get(DbProperties.ALLOW_MORE_FIELDS)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.ALLOW_MORE_FIELDS.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.ALLOW_MORE_FIELDS.getPropertyName());
}
}
// Support response thread hierarchy is true if checked or missing in DXL
if (props.containsKey(DbProperties.SUPPORT_RESPONSE_THREADS)) {
if (props.get(DbProperties.SUPPORT_RESPONSE_THREADS)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.SUPPORT_RESPONSE_THREADS.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.SUPPORT_RESPONSE_THREADS.getPropertyName());
}
}
// Don't allow simple search is true if checked or missing in DXL
if (props.containsKey(DbProperties.NO_SIMPLE_SEARCH)) {
if (props.get(DbProperties.NO_SIMPLE_SEARCH)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.NO_SIMPLE_SEARCH.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.NO_SIMPLE_SEARCH.getPropertyName());
}
}
// Compress design is true if checked or missing in DXL
if (props.containsKey(DbProperties.COMPRESS_DESIGN)) {
if (props.get(DbProperties.COMPRESS_DESIGN)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.COMPRESS_DESIGN.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.COMPRESS_DESIGN.getPropertyName());
}
}
// Compress data is true if checked or missing in DXL
if (props.containsKey(DbProperties.COMPRESS_DATA)) {
if (props.get(DbProperties.COMPRESS_DATA)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.COMPRESS_DATA.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.COMPRESS_DATA.getPropertyName());
}
}
// Disable view auto update is true if checked or missing in DXL
if (props.containsKey(DbProperties.NO_AUTO_VIEW_UPDATE)) {
if (props.get(DbProperties.NO_AUTO_VIEW_UPDATE)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.NO_AUTO_VIEW_UPDATE.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.NO_AUTO_VIEW_UPDATE.getPropertyName());
}
}
// $DisableViewExport is a node or not
if (props.containsKey(DbProperties.NO_EXPORT_VIEW)) {
getIconNote().setEnhancedHTML(props.get(DbProperties.NO_EXPORT_VIEW));
isIconDirty_ = true;
}
// Allow soft deletions is true if checked or missing in DXL
if (props.containsKey(DbProperties.ALLOW_SOFT_DELETE)) {
if (props.get(DbProperties.ALLOW_SOFT_DELETE)) {
// $NON-NLS-1$
node.setAttribute(DbProperties.ALLOW_SOFT_DELETE.getPropertyName(), "true");
} else {
node.removeAttribute(DbProperties.ALLOW_SOFT_DELETE.getPropertyName());
}
}
// $LaunchXPageRunOnServer is a node or not
if (props.containsKey(DbProperties.LAUNCH_XPAGE_ON_SERVER)) {
getIconNote().setEnhancedHTML(props.get(DbProperties.LAUNCH_XPAGE_ON_SERVER));
isIconDirty_ = true;
}
}
use of org.openntf.domino.exceptions.OpenNTFNotesException in project org.openntf.domino by OpenNTF.
the class DesignClassTest method testDesignFactory.
// @Test
public void testDesignFactory() throws IOException {
Session sess = Factory.getSession(SessionType.CURRENT);
DbDirectory dir = sess.getDbDirectory("");
for (Database db : dir) {
try {
db.open();
} catch (OpenNTFNotesException e) {
e.printStackTrace();
}
if (db.isOpen()) {
System.out.println("DB under test" + db);
testDb(db);
}
}
// Database db = sess.getDatabase("D:/Daten/notesdaten_9/localdb/proglib4work2.nsf");
// Database db = sess.getDatabase("D:/Daten/notesdaten_9/localdb/empty.ns9");
}
use of org.openntf.domino.exceptions.OpenNTFNotesException in project org.openntf.domino by OpenNTF.
the class Database method isDesignProtected.
public boolean isDesignProtected() {
if (designProtected_ == null) {
Document iconNote = getDocumentByID(org.openntf.domino.design.impl.DatabaseDesign.ICON_NOTE);
designProtected_ = Boolean.FALSE;
try {
if (iconNote != null) {
DxlExporter exporter = getAncestorSession().createDxlExporter();
exporter.exportDxl(iconNote);
}
} catch (OpenNTFNotesException e) {
designProtected_ = Boolean.TRUE;
}
}
return designProtected_.booleanValue();
}
use of org.openntf.domino.exceptions.OpenNTFNotesException in project org.openntf.domino by OpenNTF.
the class LogFormatterFileDefault method format.
/*
* (non-Javadoc)
*
* @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
*/
@Override
public String format(final LogRecord logRecord) {
StringBuffer sb = new StringBuffer();
sb.append(Logging.dateToString(new Date(logRecord.getMillis())));
sb.append(" [");
sb.append(logRecord.getLevel().getName());
sb.append("]: ");
sb.append("Log from " + logRecord.getLoggerName());
sb.append('\n');
Throwable t = logRecord.getThrown();
StackTraceElement ste = null;
if (t != null) {
StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
ste = stes[0];
}
}
sb.append(" ");
sb.append(logRecord.getMessage());
boolean levelSevere = (logRecord.getLevel().intValue() >= Level.SEVERE.intValue());
if (ste != null || levelSevere) {
sb.append(" - ");
}
if (ste != null) {
sb.append(ste.getClassName() + "." + ste.getMethodName());
} else if (levelSevere) {
sb.append("***NO STACK TRACE***");
}
sb.append('\n');
if (logRecord.getThrown() instanceof OpenNTFNotesException) {
LogRecordAdditionalInfo lrai = new LogRecordAdditionalInfo(logRecord);
lrai.writeToLog(sb);
}
if (t != null && ste != null) {
// Of course superfluous: t!=null, but otherwise we get a warning
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
sb.append(" ");
sb.append(sw.toString().replace("\r\n", "\n"));
sb.append("\n");
}
return sb.toString();
}
Aggregations