@Override public ObjectReference replaceParent(EntityReference oldParent, EntityReference newParent) { if (newParent == oldParent) { return this; } return new ObjectReference(this, oldParent, newParent); }
@Override public DocumentReference getDocumentReference() { return this.objectReference.getDocumentReference(); }
@Override public ObjectReference replaceParent(EntityReference newParent) { if (newParent == getParent()) { return this; } return new ObjectReference(this, newParent); }
/** * @return the reference of the document holding this object * @since 9.8RC1 */ public DocumentReference getDocumentReference() { return (DocumentReference) getParent(); } }
/** * @param wiki the wiki of the document where the parent object of this property is * @param space the space of the document where the parent object of this property is * @param page the document where the parent object of this property is * @param objectName the name of the parent object of this property * @param propertyName the name of the property to refer to */ public ObjectPropertyReference(String wiki, String space, String page, String objectName, String propertyName) { this(propertyName, new ObjectReference(wiki, space, page, objectName)); }
@Override public DocumentReference getDocumentReference() { return this.objectReference.getDocumentReference(); }
/** * Deprecated constructor. * @param wiki the wiki of the document where the parent object of this property is * @param space the space of the document where the parent object of this property is * @param page the document where the parent object of this property is * @param objectName the name of the parent object of this property * @param propertyName the name of the property to refer to */ @Deprecated public ObjectPropertyReference(String wiki, String space, String page, String objectName, String propertyName) { this(propertyName, new ObjectReference(wiki, space, page, objectName)); }
@Override public ObjectReference resolve(String objectReferenceRepresentation) { return new ObjectReference(this.entityReferenceResolver.resolve(objectReferenceRepresentation, EntityType.OBJECT)); } }
@Override public ObjectReference resolve(String objectReferenceRepresentation, Object... parameters) { return new ObjectReference(this.entityReferenceResolver.resolve(objectReferenceRepresentation, EntityType.OBJECT, parameters)); }
/** * {@inheritDoc} * * @see ObjectReferenceResolver#resolve(Object) */ public ObjectReference resolve(String objectReferenceRepresentation) { return new ObjectReference(entityReferenceResolver.resolve(objectReferenceRepresentation, EntityType.OBJECT)); } }
/** * {@inheritDoc} <br /> * Overridden to ensure that the parent of a property is always an object. * * @see org.xwiki.model.reference.EntityReference#setParent(org.xwiki.model.reference.EntityReference) */ @Override public void setParent(EntityReference parent) { if (parent == null || parent.getType() != EntityType.OBJECT) { throw new IllegalArgumentException("Invalid parent reference [" + parent + "] for an object property " + "reference"); } super.setParent(new ObjectReference(parent)); } }
/** * @param stringRepresentation an object reference specified as {@link String} (using the "wiki:space.page^object" * format and with special characters escaped where required) * @param hint the hint of the resolver to use in case any part of the reference is missing (no wiki specified, no * space or no page) * @param parameters extra parameters to pass to the resolver; you can use these parameters to resolve an object * reference relative to another entity reference * @return the corresponding typed {@link ObjectReference} object * @since 3.2M3 */ public ObjectReference resolveObject(String stringRepresentation, String hint, Object... parameters) { try { EntityReferenceResolver<String> resolver = this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, hint); return new ObjectReference(resolver.resolve(stringRepresentation, EntityType.OBJECT, parameters)); } catch (ComponentLookupException e) { return null; } }
/** * {@inheritDoc} * <p> * Overridden to ensure that the parent of a property is always an object. * </p> * * @see org.xwiki.model.reference.EntityReference#setParent(org.xwiki.model.reference.EntityReference) */ @Override protected void setParent(EntityReference parent) { if (parent instanceof ObjectReference) { super.setParent(parent); return; } if (parent == null || parent.getType() != EntityType.OBJECT) { throw new IllegalArgumentException("Invalid parent reference [" + parent + "] in an object property reference"); } super.setParent(new ObjectReference(parent)); }
@Override public void postMessageToGroup(String message, DocumentReference group) throws IllegalAccessError { if (!this.bridge.exists(group)) { throw new IllegalArgumentException("Target group does not exist"); } Event e = createMessageEvent(message, "groupMessage"); e.setRelatedEntity(new ObjectReference("XWiki.XWikiGroups", group)); e.setStream(this.serializer.serialize(group)); e.setImportance(Importance.MAJOR); this.stream.addEvent(e); }
@Override public void postDirectMessageToUser(String message, DocumentReference user) { if (!this.bridge.exists(user)) { throw new IllegalArgumentException("Target user does not exist"); } Event e = createMessageEvent(message, "directMessage"); e.setRelatedEntity(new ObjectReference("XWiki.XWikiUsers", user)); e.setStream(this.serializer.serialize(user)); e.setImportance(Importance.CRITICAL); this.stream.addEvent(e); }
/** * Disable Syntax Highlighting. * * @since 9.7RC1 */ public void disableSyntaxHighlighting() throws Exception { ObjectPropertyReference enabledPropertyReference = new ObjectPropertyReference("enabled", new ObjectReference("SyntaxHighlighting.ConfigurationClass[0]", new DocumentReference(getCurrentWiki(), "SyntaxHighlighting", "Configuration"))); Property property = new Property(); property.setValue("0"); TestUtils.assertStatusCodes( rest().executePut(ObjectPropertyResource.class, property, rest().toElements(enabledPropertyReference)), true, STATUS_ACCEPTED); } }
/** * Sets the value of an existing property of XWiki.XWikiPreferences. * * @param propertyName name of the property to set * @param value value to set to the property * @since 9.7RC1 */ public void setWikiPreference(String propertyName, String value) throws Exception { DocumentReference documentReference = new DocumentReference(getCurrentWiki(), "XWiki", "XWikiPreferences"); ObjectReference objectReference = new ObjectReference("XWiki.XWikiPreferences[0]", documentReference); Property property = RestTestUtils.property(propertyName, value); org.xwiki.rest.model.jaxb.Object preferenceObject = rest().get(objectReference, false); if (preferenceObject == null) { // The object does not exist, create it preferenceObject = RestTestUtils.object("XWiki.XWikiPreferences"); preferenceObject.withProperties(property); TestUtils.assertStatusCodes( rest().executePost(ObjectsResource.class, preferenceObject, rest().toElements(documentReference)), true, STATUS_CREATED); } else { // The object exist just set the property (faster than updating the whole object) ObjectPropertyReference propertyReference = new ObjectPropertyReference(propertyName, objectReference); TestUtils.assertStatusCodes( rest().executePut(ObjectPropertyResource.class, property, rest().toElements(propertyReference)), true, STATUS_ACCEPTED); } }