Good morning :)
I added a listener on DocumentCreatingEvent, this listener will add an
object of type RevisionClass to every new document. (RevisionClass is under
RevisionSpace)
In onEvent i have doc.newObject("XWiki.RevisionClass"), i'm sure onEvent is
executed but when creating a new document, i can't find the object created
when doing edit-->object, in addition doc.newObject("blablabla") is
accepted and doesn't throw any exception.
I'm using the default Admin/admin user, should i execute the script in a
specific space or with specific rights ?
Nothing is displayed in my console, How can i make XWIKI tell me more about
what it is doing ?
I'm using Entreprise 6.0, would you please take a look at the attached
script ?
Best Regards,
Walid YAICH
2014-05-20 13:24 GMT+01:00 Jeremie BOUSQUET <[email protected]>:
> 2014-05-20 13:38 GMT+02:00 walid yaich <[email protected]>:
>
> > Thanks,
> >
> > I prefer the listener, because i don't want the user to edit the object,
> > the object revision will be set by admin when he/she push "approve" to
> set
> > the revision to show by default.
> >
> > The listener works fine now, but i can't find how to add an object to a
> > page in groovy, i want to this in groovy : #set($obj = $doc.newObject(
> > "XWiki.SomeClass")) , a helpful link as always please ?
> >
> >
> Hi,
> Groovy has the same default bindings as velocity, so you could write:
>
> def obj = doc.newObject("XWiki.SomeClass")
>
>
> >
> >
> >
> >
> > 2014-05-20 10:44 GMT+01:00 [email protected] <[email protected]>:
> >
> > > Hi Walid,
> > >
> > > Maybe this could help:
> > >
> > >
> >
> http://www.xwiki.org/xwiki/bin/view/FAQ/How+can+I+create+a+new+page+based+on+a+form
> > >
> > > If your users use this form to create pages, the pages they create will
> > > automatically have the proper XObjects added to them and they’ll
> directed
> > > in inline mode when creating the page, allowing them to fill the
> XObject
> > > data.
> > >
> > > Thanks
> > > -Vincent
> > >
> > > On 19 May 2014 at 22:16:01, walid yaich ([email protected]) wrote:
> > >
> > > Hello,
> > >
> > > First of all, Merci bcp Vincent for this How to implement "Approved
> > > Revisions"?<
> > >
> >
> http://www.xwiki.org/xwiki/bin/view/FAQ/How+to+implement+%22Approved+Revisions%22
> > >
> > >
> > >
> > >
> > > I was able to choose which revision to display by following the "how
> to",
> > > now i need to add the object automatically to any page in my wiki or at
> > > least any page in a given space
> > >
> > > Thanks in advance :)
> > >
> > >
> > _______________________________________________
> > devs mailing list
> > [email protected]
> > http://lists.xwiki.org/mailman/listinfo/devs
> >
> _______________________________________________
> devs mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/devs
>
= Logging Event Listener =
This example code shows how to implement an [[Event Listener>>http://code.xwiki.org/xwiki/bin/view/Modules/ObservationModule]] in Groovy that logs page updates in the ##Main.Logger## page.
{{velocity}}
{{html}}
#if ($request.confirm != "1")
<form method="get">
<input type="hidden" name="confirm" value="1"/>
<input type="submit" class="button" value="Register Event Listener"/>
</form>
#end
{{/html}}
{{/velocity}}
{{groovy}}
import org.xwiki.observation.*
import org.xwiki.observation.event.*
import com.xpn.xwiki.web.*
import com.xpn.xwiki.*
import org.xwiki.bridge.event.DocumentCreatingEvent
class OnDocumentCreationEventListener implements EventListener
{
def xwiki
def context
def currentdoc
OnDocumentCreationEventListener(xwiki, context, currentdoc)
{
this.xwiki = xwiki
this.context = context
this.currentdoc = currentdoc
}
String getName()
{
return "OnDocumentCreationEventListener"
}
List<Event> getEvents()
{
return Arrays.asList(new DocumentCreatingEvent())
}
void onEvent(Event event, Object source, Object data)
{
currentdoc.newObject("XWiki.RevisionClass")
// Prevent infinite recursion
if (source.fullName != "Main.Logger") {
def document = xwiki.getDocument("Main.Logger")
document.setContent("${document.getContent()}\n${source.fullName} has changed") // + "nb created object = " + nb_created_obj)
document.save("Logging event", true)
}
}
}
// Only register the listener if the user has passed confirm=1 in the URL. This is to prevent
// from unintentially re-registering the listener against the observation manager.
if (request.confirm == "1") {
// Register against the Observation Manager
def observation = Utils.getComponent(ObservationManager.class)
observation.removeListener("OnDocumentCreationEventListener")
observation.removeListener("logging")
def listener = new OnDocumentCreationEventListener(xwiki, xcontext, doc)
observation.addListener(listener)
println "{{info}}Listener is now registered {{/info}}"
}
{{/groovy}}
{{groovy}}
import org.xwiki.rendering.block.*
// Pretty print the first Groovy macro content.
println "{{code language=\"java\"}}${doc.getDocument().getXDOM().getChildrenByType(MacroBlock.class, true).get(1).getContent()}{{/code}}"
{{/groovy}}
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs