how to insert dynamic row in table of confluence page using java dynamically

i have created one java program (used main method only) for parsing some website content using i want to insert that data into confluence page through my code.i have a separate code which update my page content by new content.but i want to insert row dynamically with my value in page of confluence.i have shared my code where i used put( ) method.on the place of this what should i use...


public class Main {
 private static final String BASE_URL = "";
 private static final String USERNAME = "xxxxxx";
 private static final String PASSWORD = "xxxxxx";
 private static final String ENCODING = "utf-8";

 private static String getContentRestUrl(final Long contentId,
 final String[] expansions) throws UnsupportedEncodingException {
 final String expand = URLEncoder.encode(
 StringUtils.join(expansions, ","), ENCODING);
 return String
 BASE_URL, contentId, expand,
 URLEncoder.encode(PASSWORD, ENCODING));

 public static void main(final String[] args) throws Exception {
 final long pageId = 00000000;
 HttpClient client = new DefaultHttpClient();
 // Get current page version
 String pageObj = null;
 HttpEntity pageEntity = null;
 try {
 HttpGet getPageRequest = new HttpGet(getContentRestUrl(pageId,
 new String[] { "", "version", "ancestors" }));
HttpResponse getPageResponse = client.execute(getPageRequest);
 pageEntity = getPageResponse.getEntity();
 pageObj = IOUtils.toString(pageEntity.getContent());
 } finally {
 if (pageEntity != null) {

 // Parse response into JSON
 JSONObject page = new JSONObject(pageObj);

 .put("value","removing my existing data and set new one");

 int currentVersion = page.getJSONObject("version").getInt("number");
 page.getJSONObject("version").put("number", currentVersion + 1);

 // Send update request
 HttpEntity putPageEntity = null;

 try {
 HttpPut putPageRequest = new HttpPut(getContentRestUrl(pageId,
 new String[] {}));

 StringEntity entity = new StringEntity(page.toString(),

 HttpResponse putPageResponse = client.execute(putPageRequest);
 putPageEntity = putPageResponse.getEntity();

 } finally {

1 answer

1 accepted

Hey, do you think of something like this?

// List
		ArrayList<String[]> people = new ArrayList<String[]>();
		people.add(new String[] { "Alice", "Director", "San Diego", "23" });
		people.add(new String[] { "Bob", "Chairman", "Austin", "24" });
		people.add(new String[] { "Darth", "Sith Lord", "Las Vegas", "56" });
		String middleText = null;
		for (String[] person : people) {
			middleText = middleText + "<tr>" + "<td>" + person[0] + "</td>"
					+ "<td>" + person[1] + "</td>" + "<td>" + person[2]
					+ "</td>" + "<td>" + person[3] + "</td>" + "</tr>";
		String text = "<body>"
				+ "<h1>Products</h1>"
				+ "<table>"
				+ "<tr>"
				+ "<th>Name</th><th>Position</th><th>Residence</th><th>Age</th>"
				+ "</tr>" + middleText + "</table>" + "</body>" + "<p> </p>"
				+ "<p> </p>" + "<p>"
				+ "<ac:structured-macro ac:name='gallery'>"
				+ "<ac:parameter ac:name='columns'>1</ac:parameter>"
				+ "</ac:structured-macro>" + "</p>";
page.getJSONObject("body").getJSONObject("storage").put("value", text);

Thank you so much J.D.i really appreciate your help. now i am able to insert rows dynamically in table.this code will be run as a schedule job to get some data from some sites and put in this table as a week based or day to day problem is suppose first day i run my code and it get 10 records and put in table in 10 rows.whenn next day again i will run my code and if it will get 10 more records.than i want that this 10 record will add after old 10 records.if you give any sample code like above it will very helpfull.again Thanks for your help.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

377 views 20 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you