public BaseProperty fromStringArray(String[] strings) { return fromString(strings[0]); }
public BaseCollection fromMap(Map<String, ? > map, BaseCollection object) { for (PropertyClass property : (Collection<PropertyClass>) getFieldList()) { String name = property.getName(); Object formvalues = map.get(name); if (formvalues != null) { BaseProperty objprop; if (formvalues instanceof String[]) { objprop = property.fromStringArray(((String[]) formvalues)); } else { objprop = property.fromString(formvalues.toString()); } if (objprop != null) { objprop.setObject(object); object.safeput(name, objprop); } } } return object; }
public BaseProperty newPropertyfromXML(Element ppcel) { String value = ppcel.getText(); return fromString(value); }
@Override public void onWikiClassPropertyField(String name, String value, FilterEventParameters parameters) throws WikiStreamException { PropertyClass propertyClass; try { propertyClass = (PropertyClass) this.currentClassPropertyMeta.get(name); } catch (XWikiException e) { throw new WikiStreamException(String.format( "Failed to get definition of field [%s] for property type [%s]", name, this.currentClassProperty.getClassType()), e); } BaseProperty< ? > field = propertyClass.fromString(value); this.currentClassProperty.safeput(name, field); }
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); } }
/** * 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); } }
photoAttachmentFullName)) { PropertyClass avatarProperty = (PropertyClass) userClass.getField("avatar"); userObj.safeput("avatar", avatarProperty.fromString(photoAttachmentFullName)); return true; userObj.safeput("avatar", avatarProperty.fromString("")); return true;