use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method getXClass.
/**
* @since 2.2M1
*/
public BaseClass getXClass() {
if (this.xClass == null) {
BaseClass emptyClass = new BaseClass();
// Make sure not to cause any false document versions if this document is saved.
emptyClass.setDirty(false);
this.setXClass(emptyClass);
}
return this.xClass;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method readObjectsFromForm.
public void readObjectsFromForm(EditForm eform, XWikiContext context) throws XWikiException {
for (DocumentReference reference : getXObjects().keySet()) {
List<BaseObject> oldObjects = getXObjects(reference);
List<BaseObject> newObjects = new ArrayList<BaseObject>();
while (newObjects.size() < oldObjects.size()) {
newObjects.add(null);
}
for (int i = 0; i < oldObjects.size(); i++) {
BaseObject oldobject = oldObjects.get(i);
if (oldobject != null) {
BaseClass baseclass = oldobject.getXClass(context);
BaseObject newobject = (BaseObject) baseclass.fromMap(eform.getObject(LOCAL_REFERENCE_SERIALIZER.serialize(baseclass.getDocumentReference()) + "_" + i), oldobject);
newobject.setNumber(oldobject.getNumber());
newobject.setGuid(oldobject.getGuid());
newobject.setOwnerDocument(this);
newObjects.set(newobject.getNumber(), newobject);
}
}
getXObjects().put(reference, newObjects);
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method getClassDiff.
public List<List<ObjectDiff>> getClassDiff(XWikiDocument fromDoc, XWikiDocument toDoc, XWikiContext context) {
List<List<ObjectDiff>> difflist = new ArrayList<List<ObjectDiff>>();
BaseClass oldClass = fromDoc.getXClass();
BaseClass newClass = toDoc.getXClass();
if ((newClass == null) && (oldClass == null)) {
return difflist;
}
List<ObjectDiff> dlist = newClass.getDiff(oldClass, context);
if (!dlist.isEmpty()) {
difflist.add(dlist);
}
return difflist;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method readObjectsFromFormUpdateOrCreate.
/**
* Create and/or update objects in a document given a list of HTTP parameters of the form {@code
* <spacename>.<classname>_<number>_<propertyname>}. If the object already exists, the field is replace by the given
* value. If the object doesn't exist in the document, it is created then the property {@code <propertyname>} is
* initialized with the given value. An object is only created if the given {@code <number>} is 'one-more' than the
* existing number of objects. For example, if the document already has 2 objects of type {@code Space.Class}, then
* it will create a new object only with {@code Space.Class_2_prop=something}. Every other parameter like {@code
* Space.Class_42_prop=foobar} for example, will be ignore.
*
* @param eform is form information that contains all the query parameters
* @param context
* @throws XWikiException
* @since 7.1M1
*/
public void readObjectsFromFormUpdateOrCreate(EditForm eform, XWikiContext context) throws XWikiException {
Map<DocumentReference, SortedMap<Integer, Map<String, String[]>>> fromRequest = parseRequestUpdateOrCreate(eform.getRequest(), context);
for (Entry<DocumentReference, SortedMap<Integer, Map<String, String[]>>> requestClassEntries : fromRequest.entrySet()) {
DocumentReference requestClassReference = requestClassEntries.getKey();
SortedMap<Integer, Map<String, String[]>> requestObjectMap = requestClassEntries.getValue();
for (Entry<Integer, Map<String, String[]>> requestObjectEntry : requestObjectMap.entrySet()) {
Integer requestObjectNumber = requestObjectEntry.getKey();
Map<String, String[]> requestObjectPropertyMap = requestObjectEntry.getValue();
BaseObject oldObject = getXObject(requestClassReference, requestObjectNumber);
if (oldObject == null) {
// Create the object only if it has been numbered one more than the number of existing objects
if (requestObjectPropertyMap != null) {
oldObject = newXObject(requestClassReference, context);
} else {
break;
}
}
BaseClass baseClass = oldObject.getXClass(context);
BaseObject newObject = (BaseObject) baseClass.fromMap(requestObjectPropertyMap, oldObject);
newObject.setNumber(oldObject.getNumber());
newObject.setGuid(oldObject.getGuid());
newObject.setOwnerDocument(this);
setXObject(requestObjectNumber, newObject);
}
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XWikiDocument method convertSyntax.
/**
* Convert the current document content from its current syntax to the new syntax passed as parameter.
*
* @param targetSyntax the syntax to convert to (e.g. {@code xwiki/2.0}, {@code xhtml/1.0}, etc)
* @throws XWikiException if an exception occurred during the conversion process
*/
public void convertSyntax(Syntax targetSyntax, XWikiContext context) throws XWikiException {
// convert content
setContent(performSyntaxConversion(getContent(), getDocumentReference(), getSyntax(), targetSyntax));
// convert objects
Map<DocumentReference, List<BaseObject>> objectsByClass = getXObjects();
for (List<BaseObject> objects : objectsByClass.values()) {
for (BaseObject bobject : objects) {
if (bobject != null) {
BaseClass bclass = bobject.getXClass(context);
for (Object fieldClass : bclass.getProperties()) {
if (fieldClass instanceof TextAreaClass && ((TextAreaClass) fieldClass).isWikiContent()) {
TextAreaClass textAreaClass = (TextAreaClass) fieldClass;
LargeStringProperty field = (LargeStringProperty) bobject.getField(textAreaClass.getName());
if (field != null) {
field.setValue(performSyntaxConversion(field.getValue(), getDocumentReference(), getSyntax(), targetSyntax));
}
}
}
}
}
}
// change syntax
setSyntax(targetSyntax);
}
Aggregations