Search in sources :

Example 6 with PropertyClass

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);
        }
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Example 7 with PropertyClass

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)));
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) PropertyInterface(com.xpn.xwiki.objects.PropertyInterface) XWikiRestException(org.xwiki.rest.XWikiRestException) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiContext(com.xpn.xwiki.XWikiContext) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) XWikiException(com.xpn.xwiki.XWikiException)

Example 8 with PropertyClass

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("&nbsp;");
                } else {
                    result.append(data);
                }
            }
            result.append("\n");
        }
    }
    result.append("{table}\n");
    return result.toString();
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ToString(org.suigeneris.jrcs.util.ToString) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 9 with PropertyClass

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;
}
Also used : ToString(org.suigeneris.jrcs.util.ToString) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) XWikiException(com.xpn.xwiki.XWikiException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DifferentiationFailedException(org.suigeneris.jrcs.diff.DifferentiationFailedException) ExecutionContextException(org.xwiki.context.ExecutionContextException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) MissingParserException(org.xwiki.rendering.parser.MissingParserException) IOException(java.io.IOException) ParseException(org.xwiki.rendering.parser.ParseException) TransformationException(org.xwiki.rendering.transformation.TransformationException) QueryException(org.xwiki.query.QueryException)

Example 10 with PropertyClass

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 "";
    }
}
Also used : ToString(org.suigeneris.jrcs.util.ToString) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) XWikiException(com.xpn.xwiki.XWikiException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DifferentiationFailedException(org.suigeneris.jrcs.diff.DifferentiationFailedException) ExecutionContextException(org.xwiki.context.ExecutionContextException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) MissingParserException(org.xwiki.rendering.parser.MissingParserException) IOException(java.io.IOException) ParseException(org.xwiki.rendering.parser.ParseException) TransformationException(org.xwiki.rendering.transformation.TransformationException) QueryException(org.xwiki.query.QueryException)

Aggregations

PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)28 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)16 XWikiException (com.xpn.xwiki.XWikiException)8 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)7 BaseObject (com.xpn.xwiki.objects.BaseObject)5 BaseProperty (com.xpn.xwiki.objects.BaseProperty)5 ToString (org.suigeneris.jrcs.util.ToString)5 XWiki (com.xpn.xwiki.XWiki)4 ArrayList (java.util.ArrayList)4 QueryException (org.xwiki.query.QueryException)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 DifferentiationFailedException (org.suigeneris.jrcs.diff.DifferentiationFailedException)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 ExecutionContextException (org.xwiki.context.ExecutionContextException)3 MissingParserException (org.xwiki.rendering.parser.MissingParserException)3 ParseException (org.xwiki.rendering.parser.ParseException)3 TransformationException (org.xwiki.rendering.transformation.TransformationException)3 HashMap (java.util.HashMap)2