Re: [xwiki-users] Create spaces and page in toplevel space via Java component

2015-11-25 Thread gervwyk
Thanks this was exactly what I was looking for. The new structure did cause
some confusion. The "WebHome" concept was confusing until I read the links. 

Thank for clarifying that. 
-Gerrie



--
View this message in context: 
http://xwiki.475771.n2.nabble.com/Create-spaces-and-page-in-toplevel-space-via-Java-component-tp7596969p7596980.html
Sent from the XWiki- Users mailing list archive at Nabble.com.
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


[xwiki-users] Create spaces and page in toplevel space via Java component

2015-11-25 Thread gervwyk
Hello.
How would I create a new space under Main or the toplevel entity from a java
component. So far I'm doing this, but not sure.. 

DocumentReference docref = new
DocumentReference(serverName,pageSpace,pageName);
if(xwiki.exists( docref, xcontext)){
//skip create do other stuff
}else{ 
   XWikiDocument doc = new XWikiDocument(docref);
   doc.setTitle(pageName);
   DocumentReference docrefparent = new
DocumentReference(serverName,pageSpace,"WebHome");
   doc.setParentReference(docrefparent);
   xwiki.saveDocument(doc, xcontext);
}
Where:
serverName = $request.serverName
pageSpace = "Main"
pageName = "NewPage"

is there anything else I need to set on the document or am I referencing
wrong? Not sure why it is not creating the page..



--
View this message in context: 
http://xwiki.475771.n2.nabble.com/Create-spaces-and-page-in-toplevel-space-via-Java-component-tp7596969.html
Sent from the XWiki- Users mailing list archive at Nabble.com.
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] Create spaces and page in toplevel space via Java component

2015-11-25 Thread Marius Dumitru Florea
On Wed, Nov 25, 2015 at 10:54 AM, gervwyk  wrote:

> Hello.
> How would I create a new space under Main or the toplevel entity from a
> java
> component. So far I'm doing this, but not sure..
>
> DocumentReference docref = new
> DocumentReference(serverName,pageSpace,pageName);
> if(xwiki.exists( docref, xcontext)){
> //skip create do other stuff
> }else{
>XWikiDocument doc = new XWikiDocument(docref);
>doc.setTitle(pageName);
>DocumentReference docrefparent = new
> DocumentReference(serverName,pageSpace,"WebHome");
>doc.setParentReference(docrefparent);
>xwiki.saveDocument(doc, xcontext);
> }
> Where:
>


> serverName = $request.serverName
>

The first parameter is the wiki name, not the server name. If I print
$request.serverName in Velocity I get "localhost" which is not the wiki
name ("xwiki" for the main wiki in my case). $xcontext.database should give
you the name of the current wiki.

Hope this helps,
Marius


> pageSpace = "Main"
> pageName = "NewPage"
>
> is there anything else I need to set on the document or am I referencing
> wrong? Not sure why it is not creating the page..
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/Create-spaces-and-page-in-toplevel-space-via-Java-component-tp7596969.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> ___
> 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


Re: [xwiki-users] Create spaces and page in toplevel space via Java component

2015-11-25 Thread Eduard Moraru
Hi,

Depending on what you want to achieve, you could create various types of
pages:

- Top level document (non-terminal): new DocumentReference("myWiki",
"myTopLevelPage", "WebHome")
- Second level document (non-terminal), under the "Main" space: new
DocumentReference("myWiki", Arrays.asList("Main", "SecondLevelPage"),
"WebHome")
- Deeper level document (non-terminal): new DocumentReference("myWiki",
Arrays.asList("TopLevelParentPage", "SecondLevelParentPage", ,
"MyDeeperLevelPage"), "WebHome")

- Top level terminal document, under the "Main" space: new
DocumentReference("myWiki", "Main", "MyTerminalPage")
- Deeper level terminal document: new DocumentReference("myWiki",
Arrays.asList("TopLevelParentPage", "SecondLevelParentPage", ,
"MyDeeperLevelParent"), "MyTerminalPage")

There are various signatures of the DocumentReference constructor [1], the
general rules are that:
* you need to know if you are creating a terminal or a non-terminal
document and
* to understand that:
** the name of the non-terminal document is actually the last space name
(in its document reference, with the page name always being "WebHome") and
that
** the name of a terminal document is simply its page name (in its document
reference).

Also note that in 7.2 we have deprecated the parent-child notion and that
the setParentReference call you are performing is now deprecated (will go
away soon). The parent of a document is now resulting from its reference
[2].

Hope this helped and that it did not confuse you more :)
-Eduard

--
[1]
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-model/src/main/java/org/xwiki/model/reference/DocumentReference.java
[2] http://platform.xwiki.org/xwiki/bin/view/Features/ContentOrganization

On Wed, Nov 25, 2015 at 2:11 PM, Marius Dumitru Florea <
mariusdumitru.flo...@xwiki.com> wrote:

> On Wed, Nov 25, 2015 at 10:54 AM, gervwyk  wrote:
>
> > Hello.
> > How would I create a new space under Main or the toplevel entity from a
> > java
> > component. So far I'm doing this, but not sure..
> >
> > DocumentReference docref = new
> > DocumentReference(serverName,pageSpace,pageName);
> > if(xwiki.exists( docref, xcontext)){
> > //skip create do other stuff
> > }else{
> >XWikiDocument doc = new XWikiDocument(docref);
> >doc.setTitle(pageName);
> >DocumentReference docrefparent = new
> > DocumentReference(serverName,pageSpace,"WebHome");
> >doc.setParentReference(docrefparent);
> >xwiki.saveDocument(doc, xcontext);
> > }
> > Where:
> >
>
>
> > serverName = $request.serverName
> >
>
> The first parameter is the wiki name, not the server name. If I print
> $request.serverName in Velocity I get "localhost" which is not the wiki
> name ("xwiki" for the main wiki in my case). $xcontext.database should give
> you the name of the current wiki.
>
> Hope this helps,
> Marius
>
>
> > pageSpace = "Main"
> > pageName = "NewPage"
> >
> > is there anything else I need to set on the document or am I referencing
> > wrong? Not sure why it is not creating the page..
> >
> >
> >
> > --
> > View this message in context:
> >
> http://xwiki.475771.n2.nabble.com/Create-spaces-and-page-in-toplevel-space-via-Java-component-tp7596969.html
> > Sent from the XWiki- Users mailing list archive at Nabble.com.
> > ___
> > 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
>
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users