- Main Page
- Data Structures
- Files

- File List
- Globals

# samples/jslist.c

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (C) 2007 JasperSoft http://www.jaspersoft.com
    00003  *
    00004  * This program is free software; you can redistribute it and/or modify
    00005  * it under the terms of the GNU General Public License as published by
    00006  * the Free Software Foundation; either version 2 of the License, or
    00007  * (at your option) any later version.
    00008  *
    00009  * This program is distributed WITHOUT ANY WARRANTY; and without the
    00010  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00011  * See the GNU General Public License for more details.
    00012  *
    00013  * You should have received a copy of the GNU General Public License
    00014  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
    00015  * or write to:
    00016  *
    00017  * Free Software Foundation, Inc.,
    00018  * 59 Temple Place - Suite 330,
    00019  * Boston, MA  USA  02111-1307
    00020  */
    00021
    00030 #include <jasperserver.h>
    00031
    00032 const char server[] = "http://127.0.0.1:8080/jasperserver/services/repository";
    00033
    00039 void list_directory(char *dir)
    00040 {
    00041       jasperserver_request_t *request = NULL;
    00042       jasperserver_server_t *jasperServer = NULL;
    00043       jasperserver_resource_descriptor_t *res = NULL;
    00044       jasperserver_operation_result_t *operationResult = NULL;
    00045
    00046       // Create a new structure of type jasperserver_server_t to save the
    00047       // server url and credentials.
    00048       jasperServer = jasperserver_server_new();
    00049       jasperserver_string_cset(jasperServer->url, server);
    00050       jasperserver_string_cset(jasperServer->username, "tomcat");
    00051       jasperserver_string_cset(jasperServer->password, "tomcat");
    00052
    00053       // Create a new structure of type jasperserver_request_t to store
    00054       // the request information like the resource to list
    00055       request = jasperserver_request_new();
    00056
    00057       //Creating and populating a new resource_descriptor...
    00058       res = jasperserver_resource_descriptor_new();
    00059       request->resource = res;
    00060       jasperserver_string_cset(res->wsType, JS_TYPE_FOLDER);
    00061       jasperserver_string_cset(res->uriString, dir);
    00062
    00063       // Call the web service
    00064       operationResult = jasperserver_ws_list(jasperServer, request);
    00065
    00066       if (operationResult->returnCode == 0)
    00067       {
    00068          printf("Server version: %s, Return code: '%d', Return message '%s'\n", JS_CSTR( operationResult->version),  operationResult->returnCode, JS_CSTR( operationResult->returnMessage ));
    00069          printf("Repository directory: %s\n\n", JS_CSTR( request->resource->uriString));
    00070          fflush( stdout );
    00071
    00072          for (res = operationResult->resources; res; res = res->next)
    00073          {
    00074             // Print the list of found objects in the specified directory
    00075             printf("%s%s \t%s\n", ((!xmlStrcmp(JS_UTFSTR( res->wsType ), JS_TYPE_FOLDER )) ? "<DIR> " : ""), JS_UTFSTR( res->name ), JS_UTFSTR( res->label ));
    00076          }
    00077       }
    00078       else
    00079       {
    00080           printf("Error executing the service: %d (%s)", operationResult->returnCode, JS_UTFSTR(operationResult->returnMessage) );
    00081
    00082       }
    00083
    00084       // Clean up the allocated resources....
    00085       jasperserver_server_free( jasperServer );
    00086       jasperserver_request_free( request );
    00087       jasperserver_operation_result_free( operationResult );
    00088
    00089 }
    00090
    00091
    00092 int main(int argc, char **argv)
    00093 {
    00094    char *dir = "/";
    00095    printf("JasperServer list sample (C) 2007 JasperSoft Corp.!\n");
    00096
    00097    if (argc > 1)
    00098    {
    00099      dir = argv[1];
    00100    }
    00101    else
    00102    {
    00103      printf("Repository path not specified. Using root (/) as default.\n\n");
    00104    }
    00105    list_directory(dir);
    00106
    00107   return 0;
    00108 }