org.modeshape.web.jcr.rest.client.json
Class JsonRestClient

java.lang.Object
  extended by org.modeshape.web.jcr.rest.client.json.JsonRestClient
All Implemented Interfaces:
IRestClient

public final class JsonRestClient
extends Object
implements IRestClient

The JsonRestClient class is an implementation of IRestClient that works with the ModeShape REST server that uses JSON as its interface protocol.


Constructor Summary
JsonRestClient()
           
 
Method Summary
 Map<String,NodeType> getNodeTypes(Repository repository)
          Obtains the ModeShape node types defined within the specified workspace.
 Collection<Repository> getRepositories(Server server)
          Obtains the ModeShape repositories defined within the specified server.
 URL getUrl(File file, String path, Workspace workspace)
          
 Collection<Workspace> getWorkspaces(Repository repository)
          Obtains the workspaces defined within the specified ModeShape respository.
static void main(String[] args)
           
 boolean pathExists(Workspace workspace, String path, File file)
           
 Status publish(Workspace workspace, String path, File file)
          Publishes, or uploads, a local file to the workspace at the specified path.
 Status publish(Workspace workspace, String path, File file, boolean useVersioning)
          Publishes, or uploads, a local file to the workspace at the specified path.
 List<QueryRow> query(Workspace workspace, String language, String statement)
          Executes the given query in the workspace.
 List<QueryRow> query(Workspace workspace, String language, String statement, int offset, int limit)
          Executes the given query in the workspace.
 List<QueryRow> query(Workspace workspace, String language, String statement, int offset, int limit, Map<String,String> variables)
          Executes the given query in the workspace.
 Status unpublish(Workspace workspace, String path, File file)
          Unpublishes, or deletes, the resource at the specified path in the workspace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonRestClient

public JsonRestClient()
Method Detail

getRepositories

public Collection<Repository> getRepositories(Server server)
                                       throws Exception
Obtains the ModeShape repositories defined within the specified server.

Specified by:
getRepositories in interface IRestClient
Parameters:
server - the server whose repositories are being requested (never null)
Returns:
the repositories within the specified server (never null)
Throws:
Exception - if there is a problem obtaining the repositories
See Also:
IRestClient.getRepositories(org.modeshape.web.jcr.rest.client.domain.Server)

getNodeTypes

public Map<String,NodeType> getNodeTypes(Repository repository)
                                  throws Exception
Obtains the ModeShape node types defined within the specified workspace.

Specified by:
getNodeTypes in interface IRestClient
Parameters:
repository - for whose node types are being requested (never null)
Returns:
the node types defined within the specified workspace (never null)
Throws:
Exception - if there is a problem obtaining the node types
See Also:
IRestClient.getNodeTypes(org.modeshape.web.jcr.rest.client.domain.Repository)

getUrl

public URL getUrl(File file,
                  String path,
                  Workspace workspace)
           throws Exception

Specified by:
getUrl in interface IRestClient
Parameters:
file - the file whose URL is being requested (never null)
path - the path in the ModeShape workspace where the file is/could be located (never null)
workspace - the workspace where the file is/could be located (never null)
Returns:
the workspace URL for the specified file (never null)
Throws:
Exception - if there is a problem obtaining the URL or if the file is a directory
See Also:
IRestClient.getUrl(java.io.File, java.lang.String, org.modeshape.web.jcr.rest.client.domain.Workspace)

getWorkspaces

public Collection<Workspace> getWorkspaces(Repository repository)
                                    throws Exception
Obtains the workspaces defined within the specified ModeShape respository.

Specified by:
getWorkspaces in interface IRestClient
Parameters:
repository - the repository whose workspaces are being requested (never null)
Returns:
the workspaces within the specified repository (never null)
Throws:
Exception - if there is a problem obtaining the workspaces
See Also:
IRestClient.getWorkspaces(org.modeshape.web.jcr.rest.client.domain.Repository)

pathExists

public boolean pathExists(Workspace workspace,
                          String path,
                          File file)
                   throws Exception
Parameters:
workspace - the workspace being checked (never null)
path - the path in workspace (never null)
file - the file being checked (never null)
Returns:
true if the file exists in the workspace at the specified path
Throws:
Exception - if there is a problem checking the existence of the file

publish

public Status publish(Workspace workspace,
                      String path,
                      File file)
Publishes, or uploads, a local file to the workspace at the specified path. This method does not utilize any versioning, and is equivalent to calling "publish(workspace,path,file,false) ".

Specified by:
publish in interface IRestClient
Parameters:
workspace - the workspace where the resource will be published (never null)
path - the unencoded path to the folder where the file will be published (never null)
file - the resource being published (never null)
Returns:
a status of the publishing operation outcome (never null)
See Also:
IRestClient.publish(org.modeshape.web.jcr.rest.client.domain.Workspace, java.lang.String, java.io.File)

publish

public Status publish(Workspace workspace,
                      String path,
                      File file,
                      boolean useVersioning)
Publishes, or uploads, a local file to the workspace at the specified path. This method allows the client to specify whether the uploaded file should be versioned. If so, this method will add the "mix:versionable" mixin to the "nt:file" node, and subsequent attempts to re-publish will result in new versions in the version history of the file. If no versioning is to be done, then no version history is maintained for the file, and subsequent attemps to re-publish will simply overwrite any existing content.

Specified by:
publish in interface IRestClient
Parameters:
workspace - the workspace where the resource will be published (never null)
path - the unencoded path to the folder where the file will be published (never null)
file - the resource being published (never null)
useVersioning - true if the uploaded file should be versioned, or false if no JCR versioning be used
Returns:
a status of the publishing operation outcome (never null)
See Also:
IRestClient.publish(org.modeshape.web.jcr.rest.client.domain.Workspace, java.lang.String, java.io.File, boolean)

unpublish

public Status unpublish(Workspace workspace,
                        String path,
                        File file)
Unpublishes, or deletes, the resource at the specified path in the workspace. If a file being unpublished is not found in the workspace an info status is returned.

Specified by:
unpublish in interface IRestClient
Parameters:
workspace - the workspace where the resource will be unpublished (never null)
path - the unencoded path to the folder where the file is published (never null)
file - the file being unpublished (never null)
Returns:
a status of the unpublishing operation outcome (never null)
See Also:
IRestClient.unpublish(org.modeshape.web.jcr.rest.client.domain.Workspace, java.lang.String, java.io.File)

query

public List<QueryRow> query(Workspace workspace,
                            String language,
                            String statement)
                     throws Exception
Description copied from interface: IRestClient
Executes the given query in the workspace.

Specified by:
query in interface IRestClient
Parameters:
workspace - the workspace where the resource will be unpublished (never null)
language - the JCR query language to use (never null)
statement - the query itself (never null)
Returns:
the list of rows returned by the query (never null)
Throws:
Exception - if there is a problem obtaining the workspaces

query

public List<QueryRow> query(Workspace workspace,
                            String language,
                            String statement,
                            int offset,
                            int limit)
                     throws Exception
Description copied from interface: IRestClient
Executes the given query in the workspace.

Specified by:
query in interface IRestClient
Parameters:
workspace - the workspace where the resource will be unpublished (never null)
language - the JCR query language to use (never null)
statement - the query itself (never null)
offset - the first row to be returned; if this value is negative, rows are returned starting with the first row
limit - the maximum number of rows to be returned; if this value is negative, all rows are returned
Returns:
the list of rows returned by the query (never null)
Throws:
Exception - if there is a problem obtaining the workspaces

query

public List<QueryRow> query(Workspace workspace,
                            String language,
                            String statement,
                            int offset,
                            int limit,
                            Map<String,String> variables)
                     throws Exception
Executes the given query in the workspace.

Specified by:
query in interface IRestClient
Parameters:
workspace - the workspace where the resource will be unpublished (never null)
language - the JCR query language to use (never null)
statement - the query itself (never null)
offset - the first row to be returned; if this value is negative, rows are returned starting with the first row
limit - the maximum number of rows to be returned; if this value is negative, all rows are returned
variables - the query variables; may be null
Returns:
the list of rows returned by the query (never null)
Throws:
Exception - if there is a problem obtaining the workspaces
See Also:
IRestClient.query(org.modeshape.web.jcr.rest.client.domain.Workspace, java.lang.String, java.lang.String, int, int, java.util.Map)

main

public static void main(String[] args)


Copyright © 2008-2011 JBoss, a division of Red Hat. All Rights Reserved.