com.atlassian.confluence.plugins.restapi.resources
Class ContentResource

java.lang.Object
  extended by com.atlassian.confluence.plugins.restapi.resources.ContentResource

public class ContentResource
extends Object

REST wrapper for the ContentService. Provides methods for finding, creating, modifying and deleting Content.


Constructor Summary
ContentResource(ContentService contentService, SpaceService spaceService, ContentMacroService contentMacroService, ContentTrashService contentTrashService, CQLSearchService searchService)
           
 
Method Summary
 Content createContent(Content newContent)
          Creates a new piece of Content.
 javax.ws.rs.core.Response delete(ContentId contentId, ContentStatus status)
          Trashes or purges a piece of Content, based on its ContentType and ContentStatus.
 PageResponse<Content> getContent(String type, String spaceKey, String title, List<ContentStatus> statuses, String postingDay, String expand, int start, int limit, javax.ws.rs.core.UriInfo uriInfo)
          Returns a paginated list of Content.
 Content getContentById(ContentId id, List<ContentStatus> statuses, Integer version, String expand)
          Returns a piece of Content.
 History getHistory(ContentId contentId, String expand)
          Returns the history of a particular piece of content
 MacroInstance getMacroBodyByHash(ContentId contentId, int versionId, String hash)
          Returns the body of a macro (in storage format) with the given hash.
 PageResponse<Content> search(String cql, String cqlcontext, String expand, int start, int limit, javax.ws.rs.core.UriInfo uriInfo)
          Fetch a list of content using the Confluence Query Language (CQL).
 Content update(ContentId contentId, Content content)
          Updates a piece of Content, or restores if it is trashed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentResource

public ContentResource(ContentService contentService,
                       SpaceService spaceService,
                       ContentMacroService contentMacroService,
                       ContentTrashService contentTrashService,
                       CQLSearchService searchService)
Method Detail

getContentById

@PublicApi
public Content getContentById(ContentId id,
                                        List<ContentStatus> statuses,
                                        Integer version,
                                        String expand)
                       throws ServiceException

Returns a piece of Content.

Example request URI(s):

  • http://example.com/rest/api/content/1234?expand=space,body.view,version,container
  • http://example.com/rest/api/content/1234?status=any

Parameters:
id - the id of the content
statuses - list of Content statuses to filter results on. Default value: [current]
expand - A comma separated list of properties to expand on the content. Default value: history,space,version We can also specify some extensions such as extensions.inlineProperties (for getting inline comment-specific properties) or extensions.resolution for the resolution status of each comment in the results
Returns:
a JSON representation of the content, or a 404 NOT FOUND if there is no content with the given id or if the user is not permitted.
Throws:
ServiceException

createContent

@PublicApi
public Content createContent(Content newContent)
                      throws ServiceException

Creates a new piece of Content.

Parameters:
newContent - content to be created
Returns:
content created
Throws:
ServiceException

getContent

@PublicApi
public PageResponse<Content> getContent(String type,
                                                  String spaceKey,
                                                  String title,
                                                  List<ContentStatus> statuses,
                                                  String postingDay,
                                                  String expand,
                                                  int start,
                                                  int limit,
                                                  @Context
                                                  javax.ws.rs.core.UriInfo uriInfo)
                                 throws ServiceException

Returns a paginated list of Content.

Example request URI(s):

  • http://example.com/rest/api/content?spaceKey=TST&Title=Cheese&expand=space,body.view,version,container
  • http://example.com/rest/api/content?type=blogpost&spaceKey=TST&title=Bacon&postingDay=2014-02-13&expand=space,body.view,version,container

Parameters:
type - the content type to return. Default value: page. Valid values: page, blogpost.
spaceKey - the space key to find content under.
title - the title of the page to find. Required for page type.
statuses - list of statuses the content to be found is in. Defaults to current is not specified. If set to 'any', content in 'current' and 'trashed' status will be fetched. Does not support 'historical' status for now.
postingDay - the posting day of the blog post. Required for blogpost type. Format: yyyy-mm-dd. Example: 2013-02-13
expand - a comma separated list of properties to expand on the content. Default value: history,space,version.
start - the start point of the collection to return
limit - the limit of the number of items to return, this may be restricted by fixed system limits
uriInfo - (injected) information about the request URI
Returns:
a JSON representation of the list of content, or a 404 NOT FOUND if the user is not permitted.
Throws:
ServiceException

search

public PageResponse<Content> search(String cql,
                                    String cqlcontext,
                                    String expand,
                                    int start,
                                    int limit,
                                    @Context
                                    javax.ws.rs.core.UriInfo uriInfo)

Fetch a list of content using the Confluence Query Language (CQL). See : Advanced searching using CQL

For example :

Example request URI(s):

  • http://localhost:8080/confluence/rest/api/content/search?cql=creator=currentUser()&cqlcontext={%22spaceKey%22:%22TST%22, %22contentId%22:%2255%22}
  • http://localhost:8080/confluence/rest/api/content/search?cql=space=DEV%20AND%20label=docs&expand=space,metadata.labels&limit=10

Parameters:
cql - a cql query string to use to locate content
cqlcontext - the context to execute a cql search in, this is the json serialized form of SearchContext
expand - a comma separated list of properties to expand on the content.
start - the start point of the collection to return
limit - the limit of the number of items to return, this may be restricted by fixed system limits
uriInfo - (injected) information about the request URI
Returns:
a JSON representation of the list of content, or a 404 NOT FOUND if the user is not permitted.
Throws:
ServiceException

getHistory

@PublicApi
public History getHistory(ContentId contentId,
                                    String expand)
                   throws ServiceException

Returns the history of a particular piece of content

Example request URI(s):

  • http://example.com/rest/api/content/1234/history

Parameters:
contentId - the id of the content
expand - the properties on content history to expand
Returns:
a JSON representation of the content history
Throws:
ServiceException

getMacroBodyByHash

@PublicApi
public MacroInstance getMacroBodyByHash(ContentId contentId,
                                                  int versionId,
                                                  String hash)
                                 throws ServiceException

Returns the body of a macro (in storage format) with the given hash. This resource is primarily used by connect applications that require the body of macro to perform their work.

The hash is generated by connect during render time of the local macro holder and is usually only relevant during the scope of one request. For optimisation purposes, this hash will usually live for multiple requests.

Parameters:
contentId - a string containing the id of the content
versionId - the version of the content which the hash belongs
hash - the hash of the macro body
Returns:
the raw macro body in storage format
Throws:
ServiceException

update

@PublicApi
public Content update(ContentId contentId,
                                Content content)
               throws ServiceException

Updates a piece of Content, or restores if it is trashed.

The body contains the representation of the content. Must include the new version number.

To restore a piece of content that has the status of trashed the content must have it's version incremented, and status set to current. No other field modifications will be performed when restoring a piece of content from the trash.

{"id": "557059","status": "current","version": {"number": 2}}

Parameters:
contentId - the id of the content
content - the content being updated
Returns:
a JSON representation of the content, or a 404 NOT FOUND if there is no content with the given id or if the user is not permitted.
Throws:
ServiceException

delete

@PublicApi
public javax.ws.rs.core.Response delete(ContentId contentId,
                                                  ContentStatus status)
                                 throws ServiceException
Trashes or purges a piece of Content, based on its ContentType and ContentStatus.

There are three cases:

  • If the content is trashable and its status is ContentStatus.CURRENT, it will be trashed.
  • If the content is trashable, its status is ContentStatus.TRASHED and the "status" query parameter in the request is "trashed", the content will be purged from the trash and deleted permanently.
  • If the content is not trashable it will be deleted permanently without being trashed.

Parameters:
contentId - the id of the content
Throws:
ServiceException


Copyright © 2003–2015 Atlassian. All rights reserved.