use of com.xpn.xwiki.objects.meta.MetaClass in project xwiki-platform by xwiki.
the class PropAddAction 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();
XWikiDocument doc = context.getDoc();
XWikiForm form = context.getForm();
String propName = ((PropAddForm) form).getPropName();
if (!Util.isValidXMLElementName(propName)) {
context.put("message", "action.addClassProperty.error.invalidName");
response.setStatus(HttpServletResponse.SC_BAD_REQUEST, localizePlainOrKey("action.addClassProperty.error.invalidName"));
return true;
}
String propType = ((PropAddForm) form).getPropType();
BaseClass bclass = doc.getXClass();
bclass.setName(doc.getFullName());
if (bclass.get(propName) != null) {
context.put("message", "action.addClassProperty.error.alreadyExists");
List<String> parameters = new ArrayList<String>();
parameters.add(propName);
context.put("messageParameters", parameters);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST, localizePlainOrKey("action.addClassProperty.error.alreadyExists", parameters.toArray()));
return true;
} else {
MetaClass mclass = xwiki.getMetaclass();
PropertyMetaClass pmclass = (PropertyMetaClass) mclass.get(propType);
if (pmclass != null) {
PropertyClass pclass = (PropertyClass) pmclass.newObject(context);
pclass.setObject(bclass);
pclass.setName(propName);
pclass.setPrettyName(propName);
bclass.put(propName, pclass);
doc.setAuthorReference(context.getUserReference());
if (doc.isNew()) {
doc.setCreatorReference(context.getUserReference());
}
doc.setMetaDataDirty(true);
xwiki.saveDocument(doc, localizePlainOrKey("core.comment.addClassProperty"), true, context);
}
}
// forward to edit
String redirect = Utils.getRedirect("edit", "editor=class", context);
sendRedirect(response, redirect);
return false;
}
use of com.xpn.xwiki.objects.meta.MetaClass in project xwiki-platform by xwiki.
the class BaseClass method setName.
/**
* {@inheritDoc}
* <p>
* Note: BaseElement#setName() does not support setting reference anymore since 2.4M2. This was broken and has been
* replaced by this overridden method. See XWIKI-5285
* </p>
*
* @deprecated since 2.2M2 use {@link #setDocumentReference(org.xwiki.model.reference.DocumentReference)}
*/
@Deprecated
@Override
public void setName(String name) {
if (this instanceof MetaClass || this instanceof PropertyMetaClass) {
super.setName(name);
} else {
DocumentReference reference = getDocumentReference();
if (reference != null) {
EntityReference relativeReference = getRelativeEntityReferenceResolver().resolve(name, EntityType.DOCUMENT);
reference = new DocumentReference(relativeReference.extractReference(EntityType.DOCUMENT).getName(), new SpaceReference(relativeReference.extractReference(EntityType.SPACE).getName(), reference.getParent().getParent()));
} else {
reference = getCurrentMixedDocumentReferenceResolver().resolve(name);
}
setDocumentReference(reference);
}
setDirty(true);
}
use of com.xpn.xwiki.objects.meta.MetaClass in project xwiki-platform by xwiki.
the class PropertyClass method getxWikiClass.
public BaseClass getxWikiClass() {
if (this.pMetaClass == null) {
MetaClass metaClass = MetaClass.getMetaClass();
this.pMetaClass = (PropertyMetaClass) metaClass.get(getClassType());
}
return this.pMetaClass;
}
Aggregations