use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class FeedPlugin method getAggregatorURLClass.
public BaseClass getAggregatorURLClass(XWikiContext context) throws XWikiException {
XWikiDocument doc;
boolean needsUpdate = false;
doc = context.getWiki().getDocument("XWiki.AggregatorURLClass", context);
BaseClass bclass = doc.getXClass();
if (context.get("initdone") != null) {
return bclass;
}
bclass.setName("XWiki.AggregatorURLClass");
if (!"internal".equals(bclass.getCustomMapping())) {
needsUpdate = true;
bclass.setCustomMapping("internal");
}
needsUpdate |= bclass.addTextField("name", "Name", 80);
needsUpdate |= bclass.addTextField("url", "url", 80);
needsUpdate |= bclass.addTextField("imgurl", "Image url", 80);
needsUpdate |= bclass.addDateField("date", "date", "dd/MM/yyyy HH:mm:ss");
needsUpdate |= bclass.addNumberField("nb", "nb", 5, "integer");
if (doc.getCreatorReference() == null) {
needsUpdate = true;
doc.setCreator(XWikiRightService.SUPERADMIN_USER);
}
if (doc.getAuthorReference() == null) {
needsUpdate = true;
doc.setAuthorReference(doc.getCreatorReference());
}
if (StringUtils.isBlank(doc.getTitle())) {
needsUpdate = true;
doc.setTitle("XWiki Aggregator URL Class");
}
if (StringUtils.isBlank(doc.getContent()) || !Syntax.XWIKI_2_0.equals(doc.getSyntax())) {
needsUpdate = true;
doc.setContent("{{include reference=\"XWiki.ClassSheet\" /}}");
doc.setSyntax(Syntax.XWIKI_2_0);
}
if (StringUtils.isBlank(doc.getParent())) {
needsUpdate = true;
doc.setParent("XWiki.XWikiClasses");
}
if (!doc.isHidden()) {
needsUpdate = true;
doc.setHidden(true);
}
if (needsUpdate) {
context.getWiki().saveDocument(doc, context);
}
return bclass;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class FeedPlugin method getFeedEntryClass.
public BaseClass getFeedEntryClass(XWikiContext context) throws XWikiException {
XWikiDocument doc;
boolean needsUpdate = false;
doc = context.getWiki().getDocument("XWiki.FeedEntryClass", context);
BaseClass bclass = doc.getXClass();
if (context.get("initdone") != null) {
return bclass;
}
bclass.setName("XWiki.FeedEntryClass");
if (!"internal".equals(bclass.getCustomMapping())) {
needsUpdate = true;
bclass.setCustomMapping("internal");
}
needsUpdate |= bclass.addTextField("title", "Title", 80);
needsUpdate |= bclass.addTextField("author", "Author", 40);
needsUpdate |= bclass.addTextField("feedurl", "Feed URL", 80);
needsUpdate |= bclass.addTextField("feedname", "Feed Name", 40);
needsUpdate |= bclass.addTextField("url", "URL", 80);
needsUpdate |= bclass.addTextField("category", "Category", 255);
needsUpdate |= bclass.addTextAreaField("content", "Content", 80, 10);
needsUpdate |= bclass.addTextAreaField("fullContent", "Full Content", 80, 10);
needsUpdate |= bclass.addTextAreaField("xml", "XML", 80, 10);
needsUpdate |= bclass.addDateField("date", "date", "dd/MM/yyyy HH:mm:ss");
needsUpdate |= bclass.addNumberField("flag", "Flag", 5, "integer");
needsUpdate |= bclass.addNumberField("read", "Read", 5, "integer");
needsUpdate |= bclass.addStaticListField("tags", "Tags", 1, true, true, "", null, null);
if (doc.getCreatorReference() == null) {
needsUpdate = true;
doc.setCreator(XWikiRightService.SUPERADMIN_USER);
}
if (doc.getAuthorReference() == null) {
needsUpdate = true;
doc.setAuthorReference(doc.getCreatorReference());
}
if (StringUtils.isBlank(doc.getTitle())) {
needsUpdate = true;
doc.setTitle("XWiki Feed Entry Class");
}
if (StringUtils.isBlank(doc.getContent()) || !Syntax.XWIKI_2_0.equals(doc.getSyntax())) {
needsUpdate = true;
doc.setContent("{{include reference=\"XWiki.ClassSheet\" /}}");
doc.setSyntax(Syntax.XWIKI_2_0);
}
if (StringUtils.isBlank(doc.getParent())) {
needsUpdate = true;
doc.setParent("XWiki.XWikiClasses");
}
if (!doc.isHidden()) {
needsUpdate = true;
doc.setHidden(true);
}
if (needsUpdate) {
context.getWiki().saveDocument(doc, context);
}
return bclass;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class BaseObjectEventGenerator method write.
@Override
public void write(BaseObject xobject, Object filter, BaseObjectFilter objectFilter, DocumentInstanceInputProperties properties) throws FilterException {
XWikiContext xcontext = this.xcontextProvider.get();
// > WikiObject
FilterEventParameters objectParameters = new FilterEventParameters();
objectParameters.put(WikiObjectFilter.PARAMETER_NAME, xobject.getName());
objectParameters.put(WikiObjectFilter.PARAMETER_CLASS_REFERENCE, xobject.getClassName());
objectParameters.put(WikiObjectFilter.PARAMETER_GUID, xobject.getGuid());
objectParameters.put(WikiObjectFilter.PARAMETER_NUMBER, xobject.getNumber());
objectFilter.beginWikiObject(xobject.getReference() != null ? xobject.getReference().getName() : null, objectParameters);
// Object class
BaseClass xclass = xobject.getXClass(xcontext);
((BaseClassEventGenerator) this.classEventGenerator).write(xclass, filter, objectFilter, properties);
// Properties
// Iterate over values/properties sorted by field name so that the values are
// exported to XML in a consistent order.
Iterator<BaseProperty<?>> it = xobject.getSortedIterator();
while (it.hasNext()) {
BaseProperty<?> xproperty = it.next();
String pname = xproperty.getName();
if (pname != null && !pname.trim().equals("")) {
((BasePropertyEventGenerator) this.propertyEventGenerator).write(xproperty, filter, (Map<String, Object>) properties);
}
}
// < WikiObject
objectFilter.endWikiObject(xobject.getReference().getName(), objectParameters);
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class UserInstanceOutputFilterStream method endGroupContainer.
@Override
public void endGroupContainer(String name, FilterEventParameters parameters) throws FilterException {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument groupDocument;
try {
groupDocument = getGroupDocument(name);
} catch (XWikiException e) {
throw new FilterException("Failed to get an XWikiDocument for group name [" + name + "]", e);
}
BaseClass groupClass;
try {
groupClass = xcontext.getWiki().getGroupClass(xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to get group class", e);
}
if (this.members.isEmpty()) {
// Put an empty member so that the document is "marked" as group
addMember("", groupDocument, groupClass, xcontext);
} else {
for (String member : this.members) {
addMember(member, groupDocument, groupClass, xcontext);
}
}
// Save
try {
xcontext.getWiki().saveDocument(groupDocument, this.properties.getSaveComment(), xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to save group document", e);
}
// Reset members
this.members = null;
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class UserInstanceOutputFilterStream method beginUser.
@Override
public void beginUser(String name, FilterEventParameters parameters) throws FilterException {
XWikiDocument userDocument;
try {
userDocument = getUserDocument(name);
// Safer to clone for thread safety and in case the save fail
userDocument = userDocument.clone();
} catch (XWikiException e) {
throw new FilterException("Failed to get an XWikiDocument for user name [" + name + "]", e);
}
Map<String, Object> map = new HashMap<String, Object>();
// First name
if (parameters.containsKey(PARAMETER_FIRSTNAME)) {
map.put("first_name", getString(PARAMETER_FIRSTNAME, parameters, ""));
}
// Last name
if (parameters.containsKey(PARAMETER_LASTNAME)) {
map.put("last_name", getString(PARAMETER_LASTNAME, parameters, ""));
}
// Email
if (parameters.containsKey(PARAMETER_EMAIL)) {
map.put("email", getString(PARAMETER_EMAIL, parameters, ""));
}
// Active
map.put("active", getBoolean(PARAMETER_ACTIVE, parameters, true) ? 1 : 0);
XWikiContext xcontext = this.xcontextProvider.get();
BaseClass userClass;
try {
userClass = xcontext.getWiki().getUserClass(xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to get user class", e);
}
BaseObject userObject = userDocument.getXObject(userClass.getReference());
if (userObject == null) {
// Create object
try {
userObject = userDocument.newXObject(userClass.getReference(), xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to create user object", e);
}
// Setup right on user profile
try {
xcontext.getWiki().protectUserPage(userDocument.getFullName(), "edit", userDocument, xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to initialize user", e);
}
}
// Update user properties
userClass.fromValueMap(map, userObject);
if (userDocument.isNew()) {
// Authors
userDocument.setCreatorReference(userDocument.getDocumentReference());
userDocument.setAuthorReference(userDocument.getDocumentReference());
userDocument.setContentAuthorReference(userDocument.getDocumentReference());
// Dates
if (this.properties.isVersionPreserved()) {
if (parameters.containsKey(UserFilter.PARAMETER_CREATION_DATE)) {
userDocument.setCreationDate(getDate(UserFilter.PARAMETER_CREATION_DATE, parameters, new Date()));
}
if (parameters.containsKey(UserFilter.PARAMETER_REVISION_DATE)) {
userDocument.setDate(getDate(UserFilter.PARAMETER_REVISION_DATE, parameters, new Date()));
userDocument.setContentUpdateDate(getDate(UserFilter.PARAMETER_REVISION_DATE, parameters, new Date()));
}
}
// Set false to force the date and authors we want
userDocument.setMetaDataDirty(false);
userDocument.setContentDirty(false);
}
// Save
try {
xcontext.getWiki().saveDocument(userDocument, this.properties.getSaveComment(), xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to save user document", e);
}
// Add the user to default groups
try {
xcontext.getWiki().setUserDefaultGroup(userDocument.getFullName(), xcontext);
} catch (XWikiException e) {
throw new FilterException("Failed to add user to default groups", e);
}
}
Aggregations