It wouldn't work to copy the document with the class into each space? If I were to go about creating classes, I would use the same technique that the XWiki core uses to create the comments class. Note that you will have to have programming rights and in groovy or velocity you will need to call doc.getDocument() to get the underlying XWikiDocument.
Example: public BaseClass getCommentsClass(XWikiContext context) throws XWikiException { XWikiDocument doc; boolean needsUpdate = false; doc = getDocument("XWiki.XWikiComments", context); BaseClass bclass = doc.getXClass(); if (context.get("initdone") != null) { return bclass; } bclass.setName("XWiki.XWikiComments"); needsUpdate |= bclass.addTextField("author", "Author", 30); needsUpdate |= bclass.addTextAreaField("highlight", "Highlighted Text", 40, 2); needsUpdate |= bclass.addNumberField("replyto", "Reply To", 5, "integer"); needsUpdate |= bclass.addDateField("date", "Date"); needsUpdate |= bclass.addTextAreaField("comment", "Comment", 40, 5); needsUpdate |= setClassDocumentFields(doc, "XWiki Comment Class"); if (needsUpdate) { saveDocument(doc, context); } return bclass; } Mike Davis wrote: > > > >> Similar question has appeared in this list earlier with no good answer. >> Though I suspect, this approach seems necessary is due to weak design. >> Can you describe use case why it seems necessary in place of database >> list, >> where you can set hql query for filtering necessary elements? >> >> Valdis > > Essentially I'm creating a sort of template for a space that I will want to > duplicate later. I have scripts that create objects from a spreadsheet > specifically for a certain class in this space. > > Rather than duplicating the class by hand on the next space I want these > scripts/objects on, I'd like to be able to quickly and safely duplicate the > class, so I wanted to write a quick groovy script to do it. > > If there is an easier way of doing this, I'd appreciate any ideas. > > -Mike > >>> I want to create properties for a new class on a blank document with >>> groovy. I can do the following: >>> >>> def doc = xwiki.getDocument("space.docname") >>> c = doc.getxWikiClass(); >>> >>> and look at elements of a class that already exists by doing: >>> >>> prop = c.get('propertyname') >>> >>> propToEdit = prop.getPropertyClass >>> >>> propToEdit.setValues('a|b|c') >>> >>> >>> >>> But, how can I add a new property to a class that has no existing >>> properties/fields? >>> >>> >>> >>> Thanks, >>> >>> -Mike > _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users