Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to access Confluence page title and body from inside using plugin java code?

angela simmons August 8, 2012

Hi All,
I am trying to create my custom plugin which can help me extract out the Confluence ver 3.5 contents in XML format. I did analyse the XML Export option under Advanced, however the
XML it generates is quite cluttered with data i do not need.
My aim is to create an XML something like

<Title>Page Title :Test Title</Title>
<Body>[CDATA]Page Body...[CDATA]</Body>
<Version>1.0</Version>


So i have added my custom link in the advanced tab named Freeway Export like http://img844.imageshack.us/img844/4519/pagektg.jpg .
I have my custom Java class configured which is called on the Submit event seen in the UI .

public String doDefaultXmlFreeway() throws Exception
     {
      System.out.println("The call to doDefaultXmlFreeway has been made ");
      exportType = ImportExportManagerExtended.TYPE_FREEWAY;
      System.out.println("The contents to be exported >> " + getContentToBeExported().size());
      System.out.println("The contents available >> " + getContentTree().size());
      return doDefault();
     }



The console gave out the ouput like this:

[INFO] [talledLocalContainer] The call to doDefaultXmlFreeway has been made
[INFO] [talledLocalContainer] The contents to be exported >> 2
[INFO] [talledLocalContainer] The contents available >> 3

There were 3 contents listed in my space as seen in the UI image.If i checked 2 of the contents checkbox; the getContentToBeExported() showed the appropriate
number.

Now my next step is to somehow acquire the title and body of the pages so that i can use it for the xml conversion.
Can i get the title and body details from the contenTree in any way ?

1 answer

1 vote
Paul Curren
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 11, 2012

I probably need more information before I can help, but I'll have a go anyway.

Are you referring to the ContentTree class? This is the class of object we create in our own ExportSpaceAction.

The ContentTree contains references to the Page objects selected for export so you can access the properties you require straight from the Page objects. I would have thought all you really require for each Page though is the id though?

So as I said, I think more information is required about what you are trying to do before a satisfactory answer can be provided.

angela simmons August 12, 2012

Hey Paul,
Thank you so much for your attempts at helpig me out. Fortunately i was able to make my way out of this question to some extent and now i am trying to figure out how to navigate from this page. As you mentined i did extend the ExportSpaceAction
class and created my subclass named FreewayContentSelectionAction and I used the Page class to obtain the details like Title, Content etc. This is the method i used inside my class http://pastebin.com/zyieiSVc .

This method helped me in getting the title, version, content etc. Also it helped me acquire the contents into an XML as i needed and also zipped it.
Now the place ia m stuck now is navigation to the next page.

This is my atlassian-plugin.xml http://pastebin.com/YtQsG6Bv and i have the action and xwork for this class of mine i.e. FreewayContentSelectionAction. The method detailed above is called on the submit action.
But on the click of the submit of the selectContents.vm after i have , checked my contents (like in this image http://imageshack.us/f/100/custpage.jpg/ )

how do i get to a sample page that says "The contents you chose in your previous
page have now been zipped". This page i assume can be shown on 'success'
How should i mention the 'success' such that the successful submit from input lands me to the success page. Currently my attempts at having a sucess navigation somehow overpowers the input page

i.e if I have

<result name="success" type="velocity">/templates/example/resultPage.vm</result>

inside my atlassian-plugin.xml, the "input" page is not seen.

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 14, 2012

The name of the result that is selected is determined based on the value you return from the method of your action.

So, in your example, if you want the "input" result, the doDefaultXmlFreeway method should return "input".

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events