Hi Vivian,
Are you sure that you want to interact with XWiki the old way (using
plug-ins) ?
Have you read
http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents
or probably better for your needs
http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingMacros
?
The context is an XWikiContext object that was the old way of keeping
track of the current request, and it had to be passed around from
method to method, everywhere in the code. It is progressively being
replaced by an execution context managed by an execution manager
component.
In velocity, if you have programming rights, you may reach the
XWikiContext using the velocity context this way:
#set( $xcontext = $context.context )
In a plugins, if you read carefully the
http://platform.xwiki.org/xwiki/bin/view/DevGuide/CreatingPlugins
, you will notice that you have to extends XWikiDefaultPlugin and
implements an init method to receive the context that you will
passover to the constructor of your plugin API. This way, you will
have access to the context in your plugin API as needed through the
protected variable context that is initialized at construction time.
The plugin API should be instantiated newly for each call to the
getPluginApi method of your plugin. This way, the API represent the
contextual instance of your plugin during a given request while the
plugin itself is a singleton.
Regards,
Denis Gervalle
On Nov 8, 2009, at 9:10, Vivian Richard wrote:
Thank you very much Arun for your help. Actually I
have already
used velocity and was able to do whatever I needed through velocity.
But my requirements changed and now I need to do exactly the
same thing is pure java. If you can help me in that will really be
appreciated.
at the bottom of the following link
http://platform.xwiki.org/xwiki/bin/view/DevGuide/CreatingPlugins
this line of code
com.xpn.xwiki.doc.XWikiDocument doc =
context.getWiki().getDocument("theSpace.theDoc", context); // any
document
where this contest is coming from?
If I have a class how do I get the context?
On Sat, Nov 7, 2009 at 7:47 PM, Arun Reddy <vipunreddy.n(a)gmail.com>
wrote:
Hi Richard,
On Sun, Nov 8, 2009 at 6:14 AM, Vivian Richard <kanpsack(a)gmail.com>
wrote:
Hello devs,
got a really newbie question and sitting on it for hours.
Your help will be appreciated. All I am trying to do is
- writing a Java class which has a method - when called
with doc name/ID will return the document title. That is all.
If you are looking for a method which returns document title of a
particular
doc name/ID , You can use velocity to achive that easily on the fly
by
putting the code inside your wiki pages itself.
You can have a look at these :
velocity scripting guide :
http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting#HXWiki27sVelociā¦
XWiki API :
http://platform.xwiki.org/xwiki/bin/view/DevGuide/API
$doc.getTitle() -> to get title of current doc.
$xwiki.getDocument(java.lang.String web,java.lang.String
fullname).getTitle()
And many more methods, kindly check the API (link given above).
The following code is what Itried:
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.api.Api;
import com.xpn.xwiki.api.XWiki;
import com.xpn.xwiki.doc.XWikiDocument;
public class SampleService extends Api
{
public SampleService()
{
super(); /// I guess there should be XwikiContext
parameter in
the constructor
}
public String myDocTitle(String:name)
{
com.xpn.xwiki.doc.XWikiDocument docu =
context.getWiki().getDocument("theSpace.theDoc", context); // I
do
not where to get this context from
return docu.getTitle();
}
}
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
--
Best Regards,
Arun Reddy
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs