### Eclipse Workspace Patch 1.0 #P xwiki-platform-core Index: xwiki-bridge/src/main/java/org/xwiki/bridge/DocumentAccessBridge.java =================================================================== --- xwiki-bridge/src/main/java/org/xwiki/bridge/DocumentAccessBridge.java (revision 22756) +++ xwiki-bridge/src/main/java/org/xwiki/bridge/DocumentAccessBridge.java (working copy) @@ -53,7 +53,7 @@ * @since 2.0M3 */ DocumentModelBridge getDocument(DocumentName documentName) throws Exception; - + /** * Get the different parts of a document name (wiki, space, page). * @@ -151,8 +151,8 @@ * @param className The name of the class. * @param objectNumber The number of the object from the given class. * @param propertyName The name of the property to retrieve. - * @return the property value or null if it doesn't exist or an error occurred while looking for the property - * (the document doesn't exist for example) + * @return the property value or null if it doesn't exist or an error occurred while looking for the property (the + * document doesn't exist for example) */ Object getProperty(String documentName, String className, int objectNumber, String propertyName); @@ -162,8 +162,8 @@ * @param documentName The name of the document to access. * @param className The name of the class. * @param propertyName The name of the property to retrieve. - * @return the property value or null if it doesn't exist or an error occurred while looking for the property - * (the document doesn't exist for example) + * @return the property value or null if it doesn't exist or an error occurred while looking for the property (the + * document doesn't exist for example) */ Object getProperty(String documentName, String className, String propertyName); @@ -173,8 +173,8 @@ * * @param documentName The name of the document to access. * @param propertyName The name of the property to retrieve. - * @return the property value or null if it doesn't exist or an error occurred while looking for the property - * (the document doesn't exist for example) + * @return the property value or null if it doesn't exist or an error occurred while looking for the property (the + * document doesn't exist for example) */ Object getProperty(String documentName, String propertyName); @@ -184,7 +184,7 @@ * @return the list of properties available in the passed document and class names */ List getProperties(String documentName, String className); - + /** * @param className The name of the class. * @param propertyName The name of the property. @@ -215,6 +215,21 @@ void setProperty(String documentName, String className, String propertyName, Object propertyValue) throws Exception; /** + * Sets the given property for the object found at index objectNumber (of the given class) attached to the + * document. If no such object exists, this method will create a new object of the given class, attach it to the + * document and set the property. + * + * @param documentName name of the document to access. + * @param className name of the class. + * @param objectNumber number of the object from the given class. + * @param propertyName name of the property to set. + * @param propertyValue value of the property to set. + * @throws Exception if the document cannot be accessed. + */ + void setProperty(String documentName, String className, int objectNumber, String propertyName, Object propertyValue) + throws Exception; + + /** * Returns the content of a document attachment. * * @param documentName The name of the document to access. Index: xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/scaffolding/MockDocumentAccessBridge.java =================================================================== --- xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/scaffolding/MockDocumentAccessBridge.java (revision 22756) +++ xwiki-rendering/xwiki-rendering-xwiki/src/test/java/org/xwiki/rendering/scaffolding/MockDocumentAccessBridge.java (working copy) @@ -196,6 +196,15 @@ /** * {@inheritDoc} + */ + public void setProperty(String documentName, String className, int objectNumber, String propertyName, + Object propertyValue) throws Exception + { + throw new RuntimeException("Not implemented"); + } + + /** + * {@inheritDoc} * * @see DocumentAccessBridge#getAttachmentContent(String, String) */ Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java (revision 22756) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java (working copy) @@ -280,4 +280,12 @@ public void setProperty(String arg0, String arg1, String arg2, Object arg3) throws Exception { } + + /** + * {@inheritDoc} + */ + public void setProperty(String arg0, String arg1, int arg2, String arg3, Object arg4) throws Exception + { + } + } Index: xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/MockDocumentAccessBridge.java =================================================================== --- xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/MockDocumentAccessBridge.java (revision 22756) +++ xwiki-officeimporter/src/test/java/org/xwiki/officeimporter/internal/MockDocumentAccessBridge.java (working copy) @@ -194,6 +194,15 @@ /** * {@inheritDoc} + */ + public void setProperty(String documentName, String className, int objectNumber, String propertyName, + Object propertyValue) throws Exception + { + throw new RuntimeException("Not implemented"); + } + + /** + * {@inheritDoc} * * @see DocumentAccessBridge#getURL(String, String, String, String) */ Index: xwiki-refactoring/src/test/java/org/xwiki/refactoring/internal/MockDocumentAccessBridge.java =================================================================== --- xwiki-refactoring/src/test/java/org/xwiki/refactoring/internal/MockDocumentAccessBridge.java (revision 22756) +++ xwiki-refactoring/src/test/java/org/xwiki/refactoring/internal/MockDocumentAccessBridge.java (working copy) @@ -193,6 +193,15 @@ /** * {@inheritDoc} + */ + public void setProperty(String documentName, String className, int objectNumber, String propertyName, + Object propertyValue) throws Exception + { + throw new RuntimeException("Not implemented"); + } + + /** + * {@inheritDoc} * * @see DocumentAccessBridge#getURL(String, String, String, String) */ Index: xwiki-core/src/main/java/com/xpn/xwiki/doc/DefaultDocumentAccessBridge.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/doc/DefaultDocumentAccessBridge.java (revision 22756) +++ xwiki-core/src/main/java/com/xpn/xwiki/doc/DefaultDocumentAccessBridge.java (working copy) @@ -107,8 +107,8 @@ { XWikiDocument currentDocument = getContext().getDoc(); - return currentDocument == null ? null : new DocumentName(currentDocument.getWikiName(), - currentDocument.getSpaceName(), currentDocument.getPageName()); + return currentDocument == null ? null : new DocumentName(currentDocument.getWikiName(), currentDocument + .getSpaceName(), currentDocument.getPageName()); } /** @@ -266,8 +266,9 @@ List result; try { XWikiContext xcontext = getContext(); - result = new ArrayList( - xcontext.getWiki().getDocument(documentName, xcontext).getObject(className).getFieldList()); + result = + new ArrayList(xcontext.getWiki().getDocument(documentName, xcontext).getObject(className) + .getFieldList()); } catch (Exception ex) { result = Collections.emptyList(); } @@ -311,9 +312,21 @@ public void setProperty(String documentName, String className, String propertyName, Object propertyValue) throws Exception { + setProperty(documentName, className, 0, propertyName, propertyValue); + } + + /** + * {@inheritDoc} + */ + public void setProperty(String documentName, String className, int objectNumber, String propertyName, + Object propertyValue) throws Exception + { XWikiContext xcontext = getContext(); XWikiDocument doc = xcontext.getWiki().getDocument(documentName, xcontext); - BaseObject obj = doc.getObject(className, true, xcontext); + BaseObject obj = doc.getObject(className, objectNumber); + if (obj == null) { + obj = doc.getObject(className, true, xcontext); + } if (obj != null) { obj.set(propertyName, propertyValue, xcontext); saveDocument(doc, String.format("Property [%s] set.", propertyName), true); @@ -328,7 +341,8 @@ public byte[] getAttachmentContent(String documentName, String attachmentName) throws Exception { XWikiContext xcontext = getContext(); - return xcontext.getWiki().getDocument(documentName, xcontext).getAttachment(attachmentName).getContent(xcontext); + return xcontext.getWiki().getDocument(documentName, xcontext).getAttachment(attachmentName) + .getContent(xcontext); } /** @@ -388,8 +402,9 @@ XWikiContext xcontext = getContext(); String attachmentURL; try { - attachmentURL = xcontext.getWiki().getAttachmentURL( - documentName == null ? xcontext.getDoc().getFullName() : documentName, attachmentName, xcontext); + attachmentURL = + xcontext.getWiki().getAttachmentURL( + documentName == null ? xcontext.getDoc().getFullName() : documentName, attachmentName, xcontext); } catch (XWikiException e) { // This cannot happen. There's a bug in the definition of XWiki.getAttachmentURL: it says it can generate // an exception but in fact no exception is raised in the current implementation. Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-useravatar/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-useravatar/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java (revision 22756) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-useravatar/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java (working copy) @@ -164,6 +164,15 @@ /** * {@inheritDoc} */ + public void setProperty(String documentName, String className, int objectNumber, String propertyName, + Object propertyValue) throws Exception + { + throw new RuntimeException("Not implemented"); + } + + /** + * {@inheritDoc} + */ public byte[] getAttachmentContent(String documentName, String attachmentName) throws Exception { throw new RuntimeException("Not implemented"); @@ -298,4 +307,5 @@ { throw new RuntimeException("Not implemented"); } + } Index: xwiki-chart/xwiki-chart-macro/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java =================================================================== --- xwiki-chart/xwiki-chart-macro/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java (revision 22756) +++ xwiki-chart/xwiki-chart-macro/src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java (working copy) @@ -288,4 +288,11 @@ public void setProperty(String arg0, String arg1, String arg2, Object arg3) throws Exception { } + + /** + * {@inheritDoc} + */ + public void setProperty(String arg0, String arg1, int arg2, String arg3, Object arg4) throws Exception + { + } }