small correction to the below post: should be bobj.setStringValue("content", content); Glenn Everitt wrote:
Here is what I finally got to work:
public void createPanelForSpace(String uid, String spaceName, String wikiGroupName, XWikiContext context) throws XWikiException { //Get the Panels document to add a panel object XWikiDocument panelsDoc = context.getWiki().getDocument("Panels.WebHome", context); BaseObject bobj = panelsDoc.newObject("Panels.PanelClass", context);
//create a panel String panelName = spaceName+"Pnl"; bobj.setStringValue("name", panelName); bobj.setStringValue("type", "view"); bobj.setStringValue("description", "Dynamic Panel for " + spaceName); bobj.setStringValue("category", "Navigation"); //format the content of the panel String content = "#panelheader('" + spaceName + "Links')" + " * [Home>" + spaceName + ".WebHome]" + " <p style=\"font-size:0.75em;padding-left:8px;\"> \"$xwiki.getDocument(\"Panels." (Edit this panel) </p>" + " #panelfooter()"; bobj.setStringValue("context", content); context.getWiki().saveDocument(panelsDoc, context.getMessageTool().get("core.comment.createdUser"), context);
//add to left panel list in XWiki.XWikiPreferences XWikiDocument prefsDoc = context.getWiki().getDocument("XWiki.XWikiPreferences", context); BaseObject prefsObj = prefsDoc.getObject("XWiki.XWikiPreferences"); String csvLeftPanelList = prefsObj.getStringValue("leftPanels"); csvLeftPanelList = csvLeftPanelList + ",Panels."+panelName; prefsObj.setStringValue("leftPanels", csvLeftPanelList); context.getWiki().saveDocument(prefsDoc, context.getMessageTool().get("core.comment.createdUser"), context);
//give the group permission to panels XWikiDocument panelPrefsDoc = context.getWiki().getDocument("Panels.WebPreferences", context); BaseObject panelRightsObject = panelPrefsDoc.newObject("XWiki.XWikiGlobalRights", context); panelRightsObject.setLargeStringValue("groups", wikiGroupName); panelRightsObject.setStringValue("levels", "view"); panelRightsObject.setLargeStringValue("users", ""); panelRightsObject.setIntValue("allow", 1); }
-- View this message in context: http://www.nabble.com/How-can-I-dynamically-create-a-panel--tp16406339p18197... Sent from the XWiki- Dev mailing list archive at Nabble.com.