public BaseProperty fromValue(Object value) { BaseProperty property = newProperty(); property.setValue(value); return property; }
@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); }
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 PropertyClass(String name, String prettyname, PropertyMetaClass xWikiClass) { super(); setName(name); setPrettyName(prettyname); setxWikiClass(xWikiClass); setUnmodifiable(false); setDisabled(false); }
public String displayView(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) { return (pclass == null) ? "" : pclass.displayView(pclass.getName(), prefix, object, context); }
public String displayHidden(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) { return (pclass == null) ? "" : pclass.displayHidden(pclass.getName(), prefix, object, context); }
String classType = xclassProperty.getClassType(); if (xclassProperty.getClass().getSimpleName().equals(classType + "Class")) { propertyFilter.beginWikiClassProperty(xclassProperty.getName(), classType, propertyParameters); Iterator<BaseProperty< ? >> it = xclassProperty.getSortedIterator(); while (it.hasNext()) { BaseProperty< ? > bprop = it.next(); propertyFilter.endWikiClassProperty(xclassProperty.getName(), classType, propertyParameters);
session .createQuery("select prop.name from PropertyClass as prop where prop.id.id = :id and prop.id.name= :name"); query.setInteger("id", property.getId()); query.setString("name", property.getName()); if (query.uniqueResult() == null) { isSave = true; prop2 = property; } else { prop2 = new PropertyClass(); prop2.setName(property.getName()); prop2.setObject(property.getObject()); ltransaction.rollback(); Object[] args = {property.getObject().getName()}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_CLASS, "Exception while saving class {0}", e, args);
@Override public Object clone() { PropertyClass pclass = (PropertyClass) super.clone(); pclass.setObject(getObject()); pclass.setClassType(getClassType()); return pclass; }
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); } }
BaseClass oldClass = (BaseClass) oldObject; for (PropertyClass newProperty : (Collection<PropertyClass>) getFieldList()) { String propertyName = newProperty.getName(); PropertyClass oldProperty = (PropertyClass) oldClass.get(propertyName); String propertyType = StringUtils.substringAfterLast(newProperty.getClassType(), "."); } else if (!oldProperty.equals(newProperty)) { difflist.add(new ObjectDiff(getClassName(), getNumber(), "", "changed", propertyName, propertyType, "", "")); String propertyName = oldProperty.getName(); PropertyClass newProperty = (PropertyClass) get(propertyName); String propertyType = StringUtils.substringAfterLast(oldProperty.getClassType(), ".");
for (java.lang.Object o : propertyClass.getProperties()) { BaseProperty baseProperty = (BaseProperty) o; Attribute attribute = objectFactory.createAttribute(); property.setName(propertyClass.getName()); property.setType(propertyClass.getClassType()); if (xwikiObject.get(propertyClass.getName()) != null) { property.setValue(xwikiObject.get(propertyClass.getName()).toFormString()); } else { property.setValue(""); propertyUri = UriBuilder.fromUri(baseUri).path(ObjectPropertyResource.class).build(doc.getWiki(), doc.getSpace(), doc.getName(), xwikiObject.getClassName(), xwikiObject.getNumber(), propertyClass.getName()) .toString();
protected String getFullQueryPropertyName() { return "obj." + getName(); } }
public boolean validateProperty(BaseProperty property, XWikiContext context) { String regexp = getValidationRegExp(); if ((regexp == null) || (regexp.trim().equals(""))) { return true; } String value = ((property == null) || (property.getValue() == null)) ? "" : property.getValue().toString(); try { if (context.getUtil().match(regexp, value)) { return true; } XWikiValidationStatus.addErrorToContext((getObject() == null) ? "" : getObject().getName(), getName(), getTranslatedPrettyName(context), getValidationMessage(), context); return false; } catch (Exception e) { XWikiValidationStatus.addExceptionToContext((getObject() == null) ? "" : getObject().getName(), getName(), e, context); return false; } }
public BaseProperty fromStringArray(String[] strings) { return fromString(strings[0]); }
PropertyClass newProperty = (PropertyClass) originalProperty.clone(); String name = newProperty.getName(); Map<String, ? > map = ((EditForm) form).getObject(name); newProperty.getxWikiClass(context).fromMap(map, newProperty); String newName = newProperty.getName(); newProperty.setName(newName);
BaseClass bclass = getXClass(context); PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName)); String propertyType = (pclass == null) ? "" : StringUtils.substringAfterLast(pclass.getClassType(), "."); if (pclass != null) { String newPropertyValue = (newProperty.getValue() instanceof String) ? newProperty.toText() : pclass.displayView( propertyName, this, context); difflist.add(new ObjectDiff(getClassName(), getNumber(), "", "added", propertyName, (newProperty.getValue() instanceof String) ? newProperty.toText() : pclass.displayView( propertyName, this, context); String oldPropertyValue = (oldProperty.getValue() instanceof String) ? oldProperty.toText() : pclass.displayView( propertyName, oldCollection, context); difflist.add(new ObjectDiff(getClassName(), getNumber(), "", "changed", propertyName, propertyType, BaseClass bclass = getXClass(context); PropertyClass pclass = (PropertyClass) ((bclass == null) ? null : bclass.getField(propertyName)); String propertyType = (pclass == null) ? "" : StringUtils.substringAfterLast(pclass.getClassType(), "."); (oldProperty.getValue() instanceof String) ? oldProperty.toText() : pclass.displayView( propertyName, oldCollection, context); difflist.add(new ObjectDiff(oldCollection.getClassName(), oldCollection.getNumber(), "",
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); } }
/** * Get the full name of the actual class of the wrapped {@link com.xpn.xwiki.objects.classes.PropertyClass}. The * returned value is the canonical class name of the runtime object representing this property definition, for * example {@code com.xpn.xwiki.objects.classes.StringClass}. * * @return the canonical class name of the wrapped property definition * @see #getType() {@code getType()} for a more user-friendly type */ public String getClassType() { return getBasePropertyClass().getClassType(); }
public BaseCollection fromValueMap(Map<String, ? > map, BaseCollection object) { for (PropertyClass property : (Collection<PropertyClass>) getFieldList()) { String name = property.getName(); Object formvalue = map.get(name); if (formvalue != null) { BaseProperty objprop; objprop = property.fromValue(formvalue); if (objprop != null) { objprop.setObject(object); object.safeput(name, objprop); } } } return object; }