use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class DefaultMailTemplateManager method getMailObjectsCount.
private int getMailObjectsCount(DocumentReference templateReference, DocumentReference mailClassReference) throws MessagingException {
XWikiContext context = this.xwikiContextProvider.get();
int objectsCount;
try {
List<BaseObject> objects = context.getWiki().getDocument(templateReference, context).getXObjects(mailClassReference);
if (objects != null) {
objectsCount = objects.size();
} else {
objectsCount = 0;
}
} catch (XWikiException e) {
throw new MessagingException(String.format("Failed to find number of [%s] objects in Document [%s]", mailClassReference, templateReference), e);
}
return objectsCount;
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class DefaultModelBridge method setStartDateForUser.
@Override
public void setStartDateForUser(DocumentReference userReference, Date startDate) throws NotificationException {
try {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
XWikiDocument document = xwiki.getDocument(userReference, context);
List<BaseObject> objects = document.getXObjects(NOTIFICATION_PREFERENCE_CLASS);
if (objects != null) {
for (BaseObject object : objects) {
if (object != null) {
object.setDateValue(START_DATE_FIELD, startDate);
}
}
}
// Make this change a minor edit so it's not displayed, by default, in notifications
xwiki.saveDocument(document, NOTIFICATION_START_DATE_UPDATE_COMMENT, true, context);
} catch (Exception e) {
throw new NotificationException(String.format(SET_USER_START_DATE_ERROR_MESSAGE, userReference), e);
}
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class DefaultModelBridge method getNotificationPreferences.
private List<NotificationPreference> getNotificationPreferences(DocumentReference document, String providerHint) throws NotificationException {
XWikiContext context = contextProvider.get();
XWiki xwiki = context.getWiki();
final DocumentReference notificationPreferencesClass = NOTIFICATION_PREFERENCE_CLASS.setWikiReference(document.getWikiReference());
List<NotificationPreference> preferences = new ArrayList<>();
try {
XWikiDocument doc = xwiki.getDocument(document, context);
List<BaseObject> preferencesObj = doc.getXObjects(notificationPreferencesClass);
if (preferencesObj != null) {
for (BaseObject obj : preferencesObj) {
if (obj != null) {
String objFormat = obj.getStringValue(FORMAT_FIELD);
Date objStartDate = obj.getDateValue(START_DATE_FIELD);
Map<NotificationPreferenceProperty, Object> properties = extractNotificationPreferenceProperties(obj);
notificationPreferenceBuilder.prepare();
notificationPreferenceBuilder.setProperties(properties);
notificationPreferenceBuilder.setStartDate((objStartDate != null) ? objStartDate : doc.getCreationDate());
notificationPreferenceBuilder.setFormat(StringUtils.isNotBlank(objFormat) ? NotificationFormat.valueOf(objFormat.toUpperCase()) : NotificationFormat.ALERT);
notificationPreferenceBuilder.setTarget(document);
notificationPreferenceBuilder.setProviderHint(providerHint);
notificationPreferenceBuilder.setEnabled(obj.getIntValue(NOTIFICATION_ENABLED_FIELD, 0) != 0);
notificationPreferenceBuilder.setCategory(NotificationPreferenceCategory.DEFAULT);
preferences.add(notificationPreferenceBuilder.build());
}
}
}
} catch (Exception e) {
throw new NotificationException(String.format("Failed to get the notification preferences from the document [%s].", document), e);
}
return preferences;
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class WikiSkinUtils method getSkinResourceFromDocumentSkin.
private Resource<?> getSkinResourceFromDocumentSkin(String resource, XWikiDocument skinDocument, Skin skin) {
if (skinDocument != null) {
// Try to find a XWikiSkinFileOverrideClass object
BaseObject obj = skinDocument.getXObject(XWikiSkinFileOverrideClassDocumentInitializer.DOCUMENT_REFERENCE, XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_PATH, resource, false);
if (obj != null) {
ObjectPropertyReference reference = new ObjectPropertyReference(XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_CONTENT, obj.getReference());
return new ObjectPropertyWikiResource(getPath(reference), skin, reference, skinDocument.getAuthorReference(), this.xcontextProvider, obj.getLargeStringValue(XWikiSkinFileOverrideClassDocumentInitializer.PROPERTY_CONTENT));
}
// Try parsing the object property
BaseProperty<ObjectPropertyReference> property = getSkinResourceProperty(resource, skinDocument);
if (property != null) {
ObjectPropertyReference reference = property.getReference();
return new ObjectPropertyWikiResource(getPath(reference), skin, reference, skinDocument.getAuthorReference(), this.xcontextProvider, (String) property.getValue());
}
// Try parsing a document attachment
// Convert "/" into "." in order to support wiki skin attachments to override some resources located in
// subdirectories.
String normalizedResourceName = StringUtils.replaceChars(resource, '/', '.');
XWikiAttachment attachment = skinDocument.getAttachment(normalizedResourceName);
if (attachment != null) {
AttachmentReference reference = attachment.getReference();
return new AttachmentWikiResource(getPath(reference), skin, reference, attachment.getAuthorReference(), this.xcontextProvider);
}
}
return null;
}
use of com.xpn.xwiki.objects.BaseObject in project xwiki-platform by xwiki.
the class WikiSkinUtils method getSkinResourceProperty.
private BaseProperty<ObjectPropertyReference> getSkinResourceProperty(String resource, XWikiDocument skinDocument) {
// Try parsing the object property
BaseObject skinObject = skinDocument.getXObject(SKINCLASS_REFERENCE);
if (skinObject != null) {
BaseProperty<ObjectPropertyReference> resourceProperty = (BaseProperty<ObjectPropertyReference>) skinObject.safeget(resource);
// If not found try by replacing '/' with '.'
if (resourceProperty == null) {
String escapedTemplateName = StringUtils.replaceChars(resource, '/', '.');
resourceProperty = (BaseProperty<ObjectPropertyReference>) skinObject.safeget(escapedTemplateName);
}
if (resourceProperty != null) {
Object value = resourceProperty.getValue();
if (value instanceof String && StringUtils.isNotEmpty((String) value)) {
return resourceProperty;
}
}
}
return null;
}
Aggregations