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?
Should I add this piece of code after the vArticle.save() statement?
When I did I get the following error:
Script22.groovy: 73: unable to resolve class XWikiDocument 
 @ line 73, column 15.
   XWikiDocument articleDoc = vArticle.getDocument();
                 ^
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

Reply via email to