use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class RightsManager method removeUserOrGroupFromAllRights.
/**
* Remove all references to provided user or group from all rights documents.
*
* @param userOrGroupWiki the name of the wiki of the use or group.
* @param userOrGroupSpace the name of the space of the use or group.
* @param userOrGroupName the name of the use or group.
* @param user indicate if it is a user or a group.
* @param context the XWiki context.
* @throws XWikiException error when browsing rights.
*/
public void removeUserOrGroupFromAllRights(String userOrGroupWiki, String userOrGroupSpace, String userOrGroupName, boolean user, XWikiContext context) throws XWikiException {
List<String> parameterValues = new ArrayList<String>();
String fieldName;
if (user) {
fieldName = RIGHTSFIELD_USERS;
} else {
fieldName = RIGHTSFIELD_GROUPS;
}
BaseClass rightClass = context.getWiki().getRightsClass(context);
BaseClass globalRightClass = context.getWiki().getGlobalRightsClass(context);
String fieldTypeName = ((PropertyClass) rightClass.get(fieldName)).newProperty().getClass().getSimpleName();
StringBuilder where = new StringBuilder(", BaseObject as obj" + ", " + fieldTypeName + " as prop where doc.fullName=obj.name" + " and (obj.className=? or obj.className=?)");
parameterValues.add(rightClass.getName());
parameterValues.add(globalRightClass.getName());
where.append(" and obj.id=prop.id.id");
where.append(" and prop.name=?");
parameterValues.add(fieldName);
where.append(" and prop.value like ?");
if (context.getWikiId() == null || context.getWikiId().equalsIgnoreCase(userOrGroupWiki)) {
if (userOrGroupSpace == null || userOrGroupSpace.equals(DEFAULT_USERORGROUP_SPACE)) {
parameterValues.add(HQLLIKE_ALL_SYMBOL + userOrGroupName + HQLLIKE_ALL_SYMBOL);
} else {
parameterValues.add(HQLLIKE_ALL_SYMBOL + userOrGroupSpace + SPACEPAGENAME_SEP + userOrGroupName + HQLLIKE_ALL_SYMBOL);
}
} else {
parameterValues.add(HQLLIKE_ALL_SYMBOL + userOrGroupWiki + WIKIFULLNAME_SEP + userOrGroupName + HQLLIKE_ALL_SYMBOL);
}
List<XWikiDocument> documentList = context.getWiki().getStore().searchDocuments(where.toString(), parameterValues, context);
for (XWikiDocument groupDocument : documentList) {
if (removeUserOrGroupFromAllRights(groupDocument, userOrGroupWiki, userOrGroupSpace, userOrGroupName, user, context)) {
context.getWiki().saveDocument(groupDocument, context);
}
}
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class DefaultClassPropertyValuesProvider method getPropertyType.
private String getPropertyType(ClassPropertyReference propertyReference) throws XWikiRestException {
try {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument document = xcontext.getWiki().getDocument(propertyReference.getParent(), xcontext);
BaseClass xclass = document.getXClass();
PropertyInterface xproperty = xclass.get(propertyReference.getName());
if (xproperty instanceof PropertyClass) {
return ((PropertyClass) xproperty).getClassType();
} else {
throw new XWikiRestException(String.format("No such property [%s].", this.entityReferenceSerializer.serialize(propertyReference)));
}
} catch (XWikiException e) {
throw new XWikiRestException(String.format("Failed to determine the property type for [{}].", this.entityReferenceSerializer.serialize(propertyReference)));
}
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class XWikiDocument method displayForm.
/**
* @since 2.2M1
*/
public String displayForm(DocumentReference classReference, XWikiContext context) {
List<BaseObject> objects = getXObjects(classReference);
if (objects == null) {
return "";
}
BaseObject firstobject = null;
Iterator<BaseObject> foit = objects.iterator();
while ((firstobject == null) && foit.hasNext()) {
firstobject = foit.next();
}
if (firstobject == null) {
return "";
}
BaseClass bclass = firstobject.getXClass(context);
if (bclass.getPropertyList().size() == 0) {
return "";
}
StringBuilder result = new StringBuilder();
result.append("{table}\n");
boolean first = true;
for (String propertyName : bclass.getPropertyList()) {
if (first == true) {
first = false;
} else {
result.append("|");
}
PropertyClass pclass = (PropertyClass) bclass.getField(propertyName);
result.append(pclass.getPrettyName());
}
result.append("\n");
for (int i = 0; i < objects.size(); i++) {
BaseObject object = objects.get(i);
if (object != null) {
first = true;
for (String propertyName : bclass.getPropertyList()) {
if (first == true) {
first = false;
} else {
result.append("|");
}
String data = display(propertyName, object, context);
data = data.trim();
data = data.replaceAll("\n", " ");
if (data.length() == 0) {
result.append(" ");
} else {
result.append(data);
}
}
result.append("\n");
}
}
result.append("{table}\n");
return result.toString();
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class XWikiDocument method displayTooltip.
public String displayTooltip(String fieldname, BaseObject obj, XWikiContext context) {
String result = "";
try {
PropertyClass pclass = (PropertyClass) obj.getXClass(context).get(fieldname);
String tooltip = pclass.getTooltip(context);
if ((tooltip != null) && (!tooltip.trim().equals(""))) {
String img = "<img src=\"" + context.getWiki().getSkinFile("info.gif", context) + "\" class=\"tooltip_image\" align=\"middle\" />";
result = context.getWiki().addTooltip(img, tooltip, context);
}
} catch (Exception e) {
}
return result;
}
use of com.xpn.xwiki.objects.classes.PropertyClass in project xwiki-platform by xwiki.
the class XWikiDocument method displayPrettyName.
public String displayPrettyName(String fieldname, boolean showMandatory, boolean before, BaseObject obj, XWikiContext context) {
try {
PropertyClass pclass = (PropertyClass) obj.getXClass(context).get(fieldname);
String dprettyName = "";
if (showMandatory) {
dprettyName = context.getWiki().addMandatory(context);
}
if (before) {
return dprettyName + pclass.getPrettyName(context);
} else {
return pclass.getPrettyName(context) + dprettyName;
}
} catch (Exception e) {
return "";
}
}
Aggregations