我已经写了一个Java程序(只使用主法)发送使用JSON HTML内容的表中插入数据。 我有我的对象在单独的程序中的一些数据,我想以编程方式导入我的Atlassian Confluence页面的。 我仍然只能在页面内插入静态HTML内容和数据。 我从未与json合作过。 如何在表格的行中插入数据。如何在Atlassian的合流页面使用Java
public class Example {
\t private static final String BASE_URL = "www.example.com";
\t private static final String USERNAME = "xxxxx";
\t private static final String PASSWORD = "xxxxx";
\t private static final String ENCODING = "utf-8";
\t
\t static HttpResponse putPageResponse;
\t static HttpEntity putPageEntity = null;
\t private static String getContentRestUrl(final Long contentId,
\t \t \t final String[] expansions) throws UnsupportedEncodingException {
\t \t \t final String expand = URLEncoder.encode(StringUtils.join(expansions, ","), ENCODING);
\t \t return String
\t \t \t \t .format("%s/rest/api/content/%s?expand=%s&os_authType=basic&os_username=%s&os_password=%s",
\t \t \t \t \t \t BASE_URL, contentId, expand,
\t \t \t \t \t \t URLEncoder.encode(USERNAME, ENCODING),
\t \t \t \t \t \t URLEncoder.encode(PASSWORD, ENCODING));
\t }
\t public static void main(final String[] args) throws Exception {
\t \t final long pageId = 00000000;
\t \t HttpClient client = new DefaultHttpClient();
\t \t // Get current page version
\t \t String pageObj = null;
\t \t HttpEntity pageEntity = null;
\t \t try {
\t \t \t HttpGet getPageRequest = new HttpGet(getContentRestUrl(pageId,
\t \t \t \t \t new String[] { "body.storage", "version", "ancestors" }));
\t \t \t
\t \t \t HttpResponse getPageResponse = client.execute(getPageRequest);
\t \t \t
\t \t \t pageEntity = getPageResponse.getEntity();
\t \t \t pageObj = IOUtils.toString(pageEntity.getContent());
\t \t
\t \t } finally {
\t \t \t if (pageEntity != null) {
\t \t \t \t EntityUtils.consume(pageEntity);
\t \t \t }
\t \t }
\t \t // Parse response into JSON
\t \t JSONObject page = new JSONObject(pageObj);
\t \t try {
\t
\t \t **page.getJSONObject("body").getJSONObject("storage")
\t \t .put("value","<b>html content here<b>");**
\t \t <!--if i try to write any thing in second param of put() than it replace the all content of body with that.-->
\t \t
\t \t int currentVersion = page.getJSONObject("version").getInt("number");
\t \t page.getJSONObject("version").put("number", currentVersion + 1);
\t \t // Send update request
\t \t
\t \t \t HttpPut putPageRequest = new HttpPut(getContentRestUrl(pageId,
\t \t \t \t \t new String[] {}));
\t \t \t StringEntity entity = new StringEntity(page.toString(),
\t \t \t \t \t ContentType.APPLICATION_JSON);
\t \t \t putPageRequest.setEntity(entity);
\t \t \t putPageResponse = client.execute(putPageRequest);
\t \t \t System.out.println("");
\t \t \t EntityUtils.consume(putPageEntity);
\t \t
\t \t \t
\t \t } catch(Exception e) {
\t \t \t System.out.println("exception is: "+e);
\t \t }
\t }
}
** 如果任何一个份额,任何示例代码,会在我非常有帮助。 我在我的页面中有以下表格。
__________________________________________ |
| S.no |书名|书籍作者|发布日期|价格
| _____ | ________ | ___________ | __________ | ______ |
在这个网站上还有很多其他的问题处理所有这些主题 - 例如,我想你可以在这里快速搜索“Java REST”,并找到很多答案。 – mskfisher 2014-10-31 12:54:22
'REST - > JSON'听起来很不错。 – EpicPandaForce 2014-10-31 13:02:37