I do not understand, sorry... This is how I tried it; {{groovy}} vArticle = xwiki.getDocument("CdlsArticle.cdl18_anticonceptie") vArticle.setContent('{{include document="CdlsArticle.ArticlePostSheet"/}}') vArticle.setParent("CdlsArticle.WebHome") vArticle.set("language","nl") vArticle.set("translation","1") ... some other code... vObjArticle.set("published",'1') vObjArticle.set("hidden",'0') vObjArticle.set("category",['CdlsArticle.Nieuws']) import com.xpn.xwiki.doc.XWikiDocument; XWikiDocument articleDoc = vArticle.getDocument(); articleDoc.setAuthor('XWiki.MiekevanLeeuwen'); articleDoc.setCreator('XWiki.MiekevanLeeuwen'); articleDoc.setContentDirty(false); articleDoc.setMetaDataDirty(false); xwiki.getXWiki().saveDocument(articleDoc, xcontext.getContext); {{/groovy}} Get error: at org.xwiki.rendering.macro.script.AbstractJSR223ScriptMacro.evaluate(AbstractJSR223ScriptMacro.java:201) at org.xwiki.rendering.macro.script.AbstractJSR223ScriptMacro.evaluate(AbstractJSR223ScriptMacro.java:50) at org.xwiki.rendering.macro.script.AbstractScriptMacro.execute(AbstractScriptMacro.java:200) at org.xwiki.rendering.macro.script.AbstractJSR223ScriptMacro.execute(AbstractJSR223ScriptMacro.java:137) at org.xwiki.rendering.macro.script.AbstractJSR223ScriptMacro.execute(AbstractJSR223ScriptMacro.java:50) at org.xwiki.rendering.internal.transformation.MacroTransformation.transformOnce(MacroTransformation.java:174) at org.xwiki.rendering.internal.transformation.MacroTransformation.transform(MacroTransformation.java:119) at org.xwiki.rendering.internal.transformation.DefaultTransformationManager.performTransformations(DefaultTransformationManager.java:72) at com.xpn.xwiki.doc.XWikiDocument.performSyntaxConversion(XWikiDocument.java:6992) at com.xpn.xwiki.doc.XWikiDocument.performSyntaxConversion(XWikiDocument.java:6967) at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:795) at com.xpn.xwiki.doc.XWikiDocument.getRenderedContent(XWikiDocument.java:809) at com.xpn.xwiki.api.Document.getRenderedContent(Document.java:484) at sun.reflect.GeneratedMethodAccessor336.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389) at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378) at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270) at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:252) at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:493) at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:71) at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:142) at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:106) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:191) at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:156) at com.xpn.xwiki.render.XWikiVelocityRenderer.evaluate(XWikiVelocityRenderer.java:116) at com.xpn.xwiki.XWiki.parseTemplate(XWiki.java:1845) at com.xpn.xwiki.XWiki.evaluateTemplate(XWiki.java:1773) at com.xpn.xwiki.XWiki.parseTemplate(XWiki.java:1741) at com.xpn.xwiki.api.XWiki.parseTemplate(XWiki.java:740) at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389) at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378) at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270) at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:252) at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:332) at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72) at org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:212) at org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:247) at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:175) at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72) at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87) at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:106) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:191) at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:156) at com.xpn.xwiki.render.XWikiVelocityRenderer.evaluate(XWikiVelocityRenderer.java:116) at com.xpn.xwiki.XWiki.parseTemplate(XWiki.java:1845) at com.xpn.xwiki.XWiki.evaluateTemplate(XWiki.java:1773) at com.xpn.xwiki.web.Utils.parseTemplate(Utils.java:154) at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:224) at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:115) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) at com.xpn.xwiki.wysiwyg.server.filter.ConversionFilter.doFilter(ConversionFilter.java:152) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:118) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.xpn.xwiki.plugin.webdav.XWikiDavFilter.doFilter(XWikiDavFilter.java:68) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.xpn.xwiki.web.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFilter.java:295) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at com.xpn.xwiki.web.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:112) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:915) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) Caused by: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:118) at org.xwiki.rendering.macro.script.AbstractJSR223ScriptMacro.eval(AbstractJSR223ScriptMacro.java:260) at org.xwiki.rendering.macro.script.AbstractJSR223ScriptMacro.evaluate(AbstractJSR223ScriptMacro.java:191) ... 93 more Caused by: javax.script.ScriptException: java.lang.NullPointerException at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:112) ... 95 more Caused by: java.lang.NullPointerException at com.xpn.xwiki.XWiki.saveDocument(XWiki.java:1331) at com.xpn.xwiki.XWiki.saveDocument(XWiki.java:1320) at com.xpn.xwiki.XWiki.saveDocument(XWiki.java:1315) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129) at Script10.run(Script10.groovy:78) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315) ... 96 more
Op 11 apr 2010, om 00:41 heeft Sergiu Dumitriu het volgende geschreven: On 04/10/2010 10:41 PM, Gerritjan Koekkoek wrote: > Hi, > Most of your advise was accurate and has helped, > Thank you, > > XWikiDocument articleDoc = vArticle.getDocument(); > articleDoc.setAuthor(user); > articleDoc.setCreator(user); > aticleDoc.setContentDirty(false); > aticleDoc.setMetaDataDirty(false); > xwiki.getXWiki().saveDocument(articleDoc, xcontext.getContext); > > In Groovy; should I add the semicolon at the end of each line? I think it's optional. I prefer adding them. > Should I add this piece of code after the vArticle.save() statement? You should not keep the vArticle.save() line, since the block that I gave you is exactly for saving the document. > When I did I get the following error: > Script22.groovy: 73: unable to resolve class XWikiDocument > @ line 73, column 15. > XWikiDocument articleDoc = vArticle.getDocument(); You should import com.xpn.xwiki.doc.XWikiDocument; > ^ > the category and hidden tip did work > > Op 6 apr 2010, om 21:45 heeft Sergiu Dumitriu het volgende geschreven: > > On 04/03/2010 01:34 PM, Gerritjan Koekkoek wrote: >> Hi, >> >> I try to convert a website in xwiki.blog application >> For each page I create a groovy script that creates a blog post >> The script is successful with three exceptions; >> >> 1) Would like to maintain the original author >> So I create a xwiki.user (this works) >> Then I would like to set the document property with >> {{groovy}} >> ... (the first part of the script) >> vArticle.set("creator",'XWiki.FamilievandenMeulengraaf') >> vArticle.save() >> {{/groovy}} >> >> But looking at the post it still has creator as the user running the code > > Using the public API it's impossible to set a different creator/author > than the current user. You need to get into the internal objects, and do > something like: > > XWikiDocument articleDoc = vArticle.getDocument(); > articleDoc.setAuthor(user); > articleDoc.setCreator(user); > aticleDoc.setContentDirty(false); > aticleDoc.setMetaDataDirty(false); > xwiki.getXWiki().saveDocument(articleDoc, xcontext.getContext); > >> 2) Categories >> I've created a few categories in the blog application >> So I would like to set the category attribute, where the class-attribute >> definition of the post = Database Tree >> >> {{groovy}} >> ... >> vObjArticle.set("Category",'???') >> ... >> {{/groovy}} >> Does any body know what to put in '???', since a category can be multiple >> entries ??? > > If you want to put just one category, you can use the document name > where the category is defined (in the blog each category is a document, > look at the existing categories to see how they look like): > > vObjArticle.set('Category', 'Blog.MyNiceCategory') > > If you want to put multiple entries, you can use an array: > > vObjArticle.set('Category', ['Blog.Cat1', 'Blog.Cat2']) > >> 3) >> When I run the script a postpage is created, I see a link in the new >> documents frame. >> When I go to it it displays OK, but when I go to the blog application it >> does not show in the blog indexes (recently, categories (explained under 2)) >> or historical) >> Only when I go to the page, click edit object and directly click save it >> will show up in he blog >> What could be the reason for this, > > Try also setting a value for the 'isHidden' property. > >> The code looks like (XXXX = title of the post) >> {{groovy}} >> vArticle = xwiki.getDocument("CdlsArticle.XXXXXX") >> vArticle.setContent('{{include >> document="CdlsArticle.ArticlePostSheet"/}}') >> vArticle.setParent("CdlsArticle.WebHome") >> vArticle.set("language","nl") >> vArticle.set("translation","1") >> vObjArticle = >> vArticle.getObject("CdlsArticle.ArticlePostClass",true) >> ... >> def vTitle = "XXXXX" >> vObjArticle.set("title",vTitle) >> ... >> def vExtractHeader = '....' >> def vExtractText = '....' >> def vExtractPicture = 'image:photo.cdl...@xxxx.jpg >> vObjArticle.set("extract",vExtractHeader + vExtractText + >> vExtractPicture) >> .. etcetera >> .. >> vObjArticle.set("published",'1') >> vArticle.save() >> {{/groovy}} > -- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users