Search in sources :

Example 21 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class BaseClass method getDeprecatedObjectProperties.

/**
 * Retrieves deprecated properties of the given object compared to the class. A deprecated property is a property
 * which exists in the Object but doesn't exist anymore in the Class, or which has the wrong data type. This is used
 * for synchronization of existing or imported Objects with respect to the modifications of their associated Class.
 *
 * @param object the instance of this class where to look for undefined properties
 * @return an unmodifiable list containing the properties of the object which don't exist in the class
 * @since 2.4M2
 */
public List<BaseProperty> getDeprecatedObjectProperties(BaseObject object) {
    @SuppressWarnings("unchecked") Collection<BaseProperty> objectProperties = object.getFieldList();
    if (objectProperties == null) {
        return Collections.emptyList();
    }
    List<BaseProperty> deprecatedObjectProperties = new ArrayList<BaseProperty>();
    for (BaseProperty property : objectProperties) {
        if (safeget(property.getName()) == null) {
            deprecatedObjectProperties.add(property);
        } else {
            String propertyClass = ((PropertyClass) safeget(property.getName())).newProperty().getClassType();
            String objectPropertyClass = property.getClassType();
            if (!propertyClass.equals(objectPropertyClass)) {
                deprecatedObjectProperties.add(property);
            }
        }
    }
    return Collections.unmodifiableList(deprecatedObjectProperties);
}
Also used : ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 22 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class ComputedFieldClass method newProperty.

@Override
public BaseProperty newProperty() {
    BaseProperty property = new StringProperty();
    property.setName(getName());
    return property;
}
Also used : StringProperty(com.xpn.xwiki.objects.StringProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 23 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class PasswordClass method displayEdit.

@Override
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    input input = new input();
    input.setAttributeFilter(new XMLAttributeValueFilter());
    BaseProperty prop = (BaseProperty) object.safeget(name);
    // the property is set.
    if (prop != null && !StringUtils.isEmpty(prop.toText())) {
        input.setValue(FORM_PASSWORD_PLACEHODLER);
    }
    input.setType("password");
    input.setName(prefix + name);
    input.setID(prefix + name);
    input.setSize(getSize());
    input.setDisabled(isDisabled());
    buffer.append(input.toString());
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 24 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class PropertyClass method displayHidden.

@Override
public void displayHidden(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    input input = new input();
    input.setAttributeFilter(new XMLAttributeValueFilter());
    BaseProperty prop = (BaseProperty) object.safeget(name);
    if (prop != null) {
        input.setValue(prop.toText());
    }
    input.setType("hidden");
    input.setName(prefix + name);
    input.setID(prefix + name);
    buffer.append(input.toString());
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 25 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class PropertyClass method displayCustom.

public void displayCustom(StringBuffer buffer, String fieldName, String prefix, String type, BaseObject object, final XWikiContext context) throws XWikiException {
    String content = "";
    try {
        ScriptContext scontext = Utils.getComponent(ScriptContextManager.class).getCurrentScriptContext();
        scontext.setAttribute("name", fieldName, ScriptContext.ENGINE_SCOPE);
        scontext.setAttribute("prefix", prefix, ScriptContext.ENGINE_SCOPE);
        // The PropertyClass instance can be used to access meta properties in the custom displayer (e.g.
        // dateFormat, multiSelect). It can be obtained from the XClass of the given object but only if the property
        // has been added to the XClass. We need to have it in the Velocity context for the use case when an XClass
        // property needs to be previewed before being added to the XClass.
        scontext.setAttribute("field", new com.xpn.xwiki.api.PropertyClass(this, context), ScriptContext.ENGINE_SCOPE);
        scontext.setAttribute("object", new com.xpn.xwiki.api.Object(object, context), ScriptContext.ENGINE_SCOPE);
        scontext.setAttribute("type", type, ScriptContext.ENGINE_SCOPE);
        BaseProperty prop = (BaseProperty) object.safeget(fieldName);
        if (prop != null) {
            scontext.setAttribute("value", prop.getValue(), ScriptContext.ENGINE_SCOPE);
        } else {
            // The $value property can exist in the velocity context, we overwrite it to make sure we don't get a
            // wrong value in the displayer when the property does not exist yet.
            scontext.setAttribute("value", null, ScriptContext.ENGINE_SCOPE);
        }
        String customDisplayer = getCachedDefaultCustomDisplayer(context);
        if (StringUtils.isNotEmpty(customDisplayer)) {
            if (customDisplayer.equals(CLASS_DISPLAYER_IDENTIFIER)) {
                final String rawContent = getCustomDisplay();
                XWikiDocument classDocument = context.getWiki().getDocument(getObject().getDocumentReference(), context);
                final String classSyntax = classDocument.getSyntax().toIdString();
                // Using author reference since the document content is not relevant in this case.
                DocumentReference authorReference = classDocument.getAuthorReference();
                // Make sure we render the custom displayer with the rights of the user who wrote it (i.e. class
                // document author).
                content = renderContentInContext(rawContent, classSyntax, authorReference, context);
            } else if (customDisplayer.startsWith(DOCUMENT_DISPLAYER_IDENTIFIER_PREFIX)) {
                XWikiDocument displayerDoc = context.getWiki().getDocument(StringUtils.substringAfter(customDisplayer, DOCUMENT_DISPLAYER_IDENTIFIER_PREFIX), context);
                final String rawContent = displayerDoc.getContent();
                final String displayerDocSyntax = displayerDoc.getSyntax().toIdString();
                DocumentReference authorReference = displayerDoc.getContentAuthorReference();
                // Make sure we render the custom displayer with the rights of the user who wrote it (i.e. displayer
                // document content author).
                content = renderContentInContext(rawContent, displayerDocSyntax, authorReference, context);
            } else if (customDisplayer.startsWith(TEMPLATE_DISPLAYER_IDENTIFIER_PREFIX)) {
                content = context.getWiki().evaluateTemplate(StringUtils.substringAfter(customDisplayer, TEMPLATE_DISPLAYER_IDENTIFIER_PREFIX), context);
            }
        }
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CLASSES, XWikiException.ERROR_XWIKI_CLASSES_CANNOT_PREPARE_CUSTOM_DISPLAY, "Exception while preparing the custom display of " + fieldName, e, null);
    }
    buffer.append(content);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ScriptContext(javax.script.ScriptContext) ScriptContextManager(org.xwiki.script.ScriptContextManager) BaseProperty(com.xpn.xwiki.objects.BaseProperty) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

BaseProperty (com.xpn.xwiki.objects.BaseProperty)87 BaseObject (com.xpn.xwiki.objects.BaseObject)26 ArrayList (java.util.ArrayList)16 XWikiException (com.xpn.xwiki.XWikiException)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)12 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)12 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)11 XWikiContext (com.xpn.xwiki.XWikiContext)10 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 StringProperty (com.xpn.xwiki.objects.StringProperty)8 ListProperty (com.xpn.xwiki.objects.ListProperty)7 XWiki (com.xpn.xwiki.XWiki)5 BaseCollection (com.xpn.xwiki.objects.BaseCollection)5 LargeStringProperty (com.xpn.xwiki.objects.LargeStringProperty)5 List (java.util.List)5 Test (org.junit.Test)5 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)5 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)4 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)4