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);
}
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;
}
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());
}
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());
}
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);
}
Aggregations