use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class XClassMigratorListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
XClassPropertyUpdatedEvent propertyEvent = (XClassPropertyUpdatedEvent) event;
XWikiDocument newDocument = (XWikiDocument) source;
XWikiDocument previousDocument = newDocument.getOriginalDocument();
PropertyClass newPropertyClass = (PropertyClass) newDocument.getXClass().getField(propertyEvent.getReference().getName());
PropertyClass previousPropertyClass = (PropertyClass) previousDocument.getXClass().getField(propertyEvent.getReference().getName());
if (newPropertyClass != null && previousPropertyClass != null) {
BaseProperty newProperty = newPropertyClass.newProperty();
BaseProperty previousProperty = previousPropertyClass.newProperty();
// New and previous class property generate different kind of properties
if (newProperty.getClass() != previousProperty.getClass()) {
try {
migrate(newPropertyClass);
} catch (QueryException e) {
this.logger.error("Failed to migrate XClass property [{}]", newPropertyClass.getReference(), e);
}
}
}
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class ObjectAddAction method action.
@Override
public boolean action(XWikiContext context) throws XWikiException {
// CSRF prevention
if (!csrfTokenCheck(context)) {
return false;
}
XWiki xwiki = context.getWiki();
XWikiResponse response = context.getResponse();
DocumentReference userReference = context.getUserReference();
XWikiDocument doc = context.getDoc();
ObjectAddForm oform = (ObjectAddForm) context.getForm();
String className = oform.getClassName();
EntityReference classReference = this.relativeResolver.resolve(className, EntityType.DOCUMENT);
BaseObject object = doc.newXObject(classReference, context);
BaseClass baseclass = object.getXClass(context);
// The request parameter names that correspond to object fields must NOT specify the object number because the
// object number is not known before the object is added. The following is a good parameter name:
// Space.Class_property. As a consequence we use only the class name to extract the object from the request.
Map<String, String[]> objmap = oform.getObject(className);
// We need to have a string in the map for each field for the object to be correctly created.
// Otherwise, queries using the missing properties will fail to return this object.
@SuppressWarnings("unchecked") Collection<PropertyClass> fields = baseclass.getFieldList();
for (PropertyClass property : fields) {
String name = property.getName();
if (objmap.get(name) == null) {
objmap.put(name, EMPTY_PROPERTY);
}
}
// Load the object properties that are defined in the request.
baseclass.fromMap(objmap, object);
doc.setAuthorReference(userReference);
if (doc.isNew()) {
doc.setCreatorReference(userReference);
}
xwiki.saveDocument(doc, localizePlainOrKey("core.comment.addObject"), true, context);
// If this is an ajax request, no need to redirect.
if (Utils.isAjaxRequest(context)) {
context.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
return false;
}
// forward to edit
String redirect = Utils.getRedirect("edit", "editor=object", "xcontinue", "xredirect");
// If the redirect URL contains the xobjectNumber parameter then inject the number of the added object as its
// value so that the target page knows which object was added.
redirect = XOBJECT_NUMBER_PARAMETER.matcher(redirect).replaceFirst("$1xobjectNumber=" + object.getNumber() + "$2");
sendRedirect(response, redirect);
return false;
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class DocumentUnifiedDiffBuilder method addClassPropertyDiffs.
private void addClassPropertyDiffs(BaseClass previousClass, BaseClass nextClass, DocumentUnifiedDiff documentDiff) {
// Check the properties that have been deleted or modified.
for (String propertyName : previousClass.getPropertyList()) {
PropertyClass previousProperty = (PropertyClass) previousClass.get(propertyName);
PropertyClass nextProperty = (PropertyClass) nextClass.get(propertyName);
addClassPropertyDiff(previousProperty, nextProperty, documentDiff);
}
// Check the properties that have been added.
for (String propertyName : nextClass.getPropertyList()) {
PropertyClass previousProperty = (PropertyClass) previousClass.get(propertyName);
PropertyClass nextProperty = (PropertyClass) nextClass.get(propertyName);
if (previousProperty == null) {
addClassPropertyDiff(previousProperty, nextProperty, documentDiff);
}
}
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class XWiki method getPropertyClassFromName.
public PropertyClass getPropertyClassFromName(String propPath, XWikiContext context) {
int i1 = propPath.indexOf('_');
if (i1 == -1) {
return null;
} else {
String className = propPath.substring(0, i1);
String propName = propPath.substring(i1 + 1);
try {
return (PropertyClass) getDocument(className, context).getXClass().get(propName);
} catch (XWikiException e) {
return null;
}
}
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class XWikiStats method fromXML.
/**
* Initialize statistics object from XML schema.
*
* @param oel the XML root node containing statistics datas.
* @throws XWikiException error when parsing XML schema.
*/
public void fromXML(Element oel) throws XWikiException {
Element cel = oel.element("class");
BaseClass bclass = new BaseClass();
if (cel != null) {
bclass.fromXML(cel);
setClassName(bclass.getName());
}
setName(oel.element(XMLNODE_NAME).getText());
List<?> list = oel.elements(XMLNODE_PROPERTY);
for (int i = 0; i < list.size(); i++) {
Element pcel = (Element) ((Element) list.get(i)).elements().get(0);
String name = pcel.getName();
PropertyClass pclass = (PropertyClass) bclass.get(name);
if (pclass != null) {
BaseProperty property = pclass.newPropertyfromXML(pcel);
property.setName(name);
property.setObject(this);
safeput(name, property);
}
}
}
Aggregations