/** * @since 2.2.3 */ public void setProperty(EntityReference classReference, String fieldName, BaseProperty value) { BaseObject bobject = prepareXObject(classReference); bobject.safeput(fieldName, value); }
property.setName(name); property.setObject(this); safeput(name, property);
private void setProperty(BaseObject userObject, String key, Object value, XWikiContext xcontext) { BaseClass bclass = userObject.getXClass(xcontext); PropertyClass pclass = (PropertyClass) bclass.get(key); BaseProperty prop = null; if (pclass != null) { if (value instanceof String) { // In case the LDAP side in a String go trough property class fromString to be safe prop = pclass.fromString((String) value); } else if (value instanceof Collection && pclass instanceof StringClass) { // In case the LDAP side is a list and XWiki size is a String, assume we want the first element prop = pclass.fromValue(((Collection) value).iterator().next()); } else { // Default behavior: try to put whatever we get as it is prop = pclass.fromValue(value); } } // TODO: else generate new property based on the type of the value instead of relying on what is already // there if (prop != null) { userObject.safeput(key, prop); } }
@Override public void onWikiObjectProperty(String name, Object value, FilterEventParameters parameters) throws WikiStreamException { PropertyClassInterface propertyclass = (PropertyClassInterface) getCurrentXClass().safeget(name); if (propertyclass != null) { // Bulletproofing using PropertyClassInterface#fromString when a String is passed (in case it's not really a // String property) PropertyInterface property = value instanceof String ? propertyclass.fromString((String) value) : propertyclass.fromValue(value); this.currentXObject.safeput(name, property); } else { // TODO: Log something ? } } }
/** * add tags to the document. */ public void setTags(String tagsStr, XWikiContext context) throws XWikiException { BaseClass tagsClass = context.getWiki().getTagClass(context); StaticListClass tagProp = (StaticListClass) tagsClass.getField(XWikiConstant.TAG_CLASS_PROP_TAGS); BaseObject tags = getObject(XWikiConstant.TAG_CLASS, true, context); tags.safeput(XWikiConstant.TAG_CLASS_PROP_TAGS, tagProp.fromString(tagsStr)); setMetaDataDirty(true); }
/** * Create and add the main tag property to the provided tag object. The new property corresponds to the definition * in the tag class, but in case of an error, the default type is a relational-stored list. * * @param tagObject the target tag object * @param context the current request context * @return the created property * @see #TAG_PROPERTY */ private BaseProperty createTagProperty(BaseObject tagObject, XWikiContext context) { BaseProperty tagProperty; try { BaseClass tagClass = context.getWiki().getClass(TAG_CLASS, context); PropertyClass tagPropertyDefinition = (PropertyClass) tagClass.getField(TAG_PROPERTY); tagProperty = tagPropertyDefinition.newProperty(); } catch (XWikiException ex) { LOGGER.warn("Failed to properly create tag property for the tag object, creating a default one"); tagProperty = new DBStringListProperty(); } tagProperty.setName(TAG_PROPERTY); tagProperty.setObject(tagObject); tagObject.safeput(TAG_PROPERTY, tagProperty); return tagProperty; }
/** * Modify the value of the field <code>fieldName</code> of the managed object's class. * <p> * This method makes sure the right property type between LargeStringProperty and StringProperty is used. * * @param fieldName the name of the field from the managed object's class where to find the value. * @param value the new value of the field <code>fieldName</code> of the managed object's class. * @see com.xpn.xwiki.doc.XWikiDocument#setStringValue(java.lang.String,java.lang.String,java.lang.String) */ public void setStringValue(String fieldName, String value) { BaseObject obj = getBaseObject(true); if (obj != null) { PropertyClass pclass = (PropertyClass) this.sclass.getBaseClass().get(fieldName); if (pclass != null) { BaseProperty prop = (BaseProperty) obj.safeget(fieldName); prop = pclass.fromString(value); if (prop != null) { obj.safeput(fieldName, prop); } } } }
public void set(String fieldname, java.lang.Object value, XWikiContext context) { BaseClass bclass = getXClass(context); PropertyClass pclass = (PropertyClass) bclass.get(fieldname); BaseProperty prop = (BaseProperty) safeget(fieldname); if ((value instanceof String) && (pclass != null)) { prop = pclass.fromString((String) value); } else { if ((prop == null) && (pclass != null)) { prop = pclass.newProperty(); } if (prop != null) { prop.setValue(value); } } if (prop != null) { safeput(fieldname, prop); } }
/** * Overwrite current BaseObject fields with provided one. Only provided non null fields are copied. * * @param sdoc the document to merge. */ public void mergeObject(DefaultXObjectDocument sdoc) { if (getXClassManager() != sdoc.getXClassManager()) { return; } BaseObject obj1 = getBaseObject(true); BaseObject obj2 = sdoc.getBaseObject(false); for (Object fieldNameObj : obj2.getPropertyList()) { String fieldName = (String) fieldNameObj; Object fieldValue2 = obj2.safeget(fieldName); if (fieldValue2 != null) { obj1.safeput(fieldName, (PropertyInterface) ((BaseElement) fieldValue2).clone()); } } }
newObject.removeField(hc.getName()); newObject.setFieldsToRemove(Collections.emptyList()); newObject.safeput("hc", hc);
newObject.removeField(hc.getName()); newObject.setFieldsToRemove(Collections.emptyList()); newObject.safeput("hc", hc);
object.safeput(NEW_ONSET_NAME, newOnset);
object.safeput(NEW_ONSET_NAME, newOnset);
object.safeput(NEW_ONSET_NAME, newOnset);