- Main Page
- Data Structures
- Files

- File List
- Globals

# jasperserver/marshaller.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
    00022 #include "marshaller.h"
    00023 #include <libxml/xmlwriter.h>
    00024
    00025 int jasperserver_resource_descriptor_marshal(xmlTextWriterPtr writer, jasperserver_resource_descriptor_t *res);
    00026 int jasperserver_resource_property_marshal(xmlTextWriterPtr writer, jasperserver_resource_property_t *res);
    00027 int jasperserver_parameter_marshal(xmlTextWriterPtr writer, jasperserver_parameter_t *param);
    00028
    00029
    00030 int jasperserver_request_marshal(jasperserver_request_t *request, jasperserver_string_t *buffer)
    00031 {
    00032      int rc;
    00033      xmlTextWriterPtr writer;
    00034      xmlBufferPtr buf;
    00035      jasperserver_argument_t *argument;
    00036      jasperserver_resource_descriptor_t *res;
    00037
    00038      /* Create a new XML buffer, to which the XML document will be
    00039      * written */
    00040      buf = xmlBufferCreate();
    00041      if (buf == NULL) {
    00042         printf("testXmlwriterMemory: Error creating the xml buffer\n");
    00043         return -1;
    00044      }
    00045
    00046      /* Create a new XmlWriter for memory, with no compression.
    00047      * Remark: there is no compression for this kind of xmlTextWriter */
    00048      writer = xmlNewTextWriterMemory(buf, 0);
    00049      if (writer == NULL) {
    00050         printf("testXmlwriterMemory: Error creating the xml writer\n");
    00051         return -1;
    00052      }
    00053      xmlTextWriterSetIndent(writer, 1);
    00054      xmlTextWriterSetIndentString(writer, BAD_CAST "  ");
    00055      /* Start the document with the xml default for the version,
    00056      * encoding ISO 8859-1 and the default for the standalone
    00057      * declaration. */
    00058     rc = xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
    00059     if (rc < 0) {
    00060         printf("testXmlwriterMemory: Error at xmlTextWriterStartDocument\n");
    00061         return -1;
    00062     }
    00063
    00064     /* request tag */
    00065     rc = xmlTextWriterStartElement(writer, BAD_CAST "request");
    00066     if (rc < 0) {
    00067         printf("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
    00068         return -1;
    00069     }
    00070     /* request -> operationName */
    00071     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "operationName",
    00072                                      JS_UTFSTR( request->opertation ));
    00073     if (rc < 0) {
    00074         printf("testXmlwriterMemory: Error at xmlTextWriterWriteAttribute\n");
    00075         return -1;
    00076     }
    00077
    00078     if (JS_NOTNULL( request->locale ))
    00079     {
    00080           rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "locale",
    00081                                       JS_UTFSTR( request->locale ));
    00082           if (rc < 0) {
    00083                 printf("testXmlwriterMemory: Error at xmlTextWriterWriteAttribute\n");
    00084                 return -1;
    00085            }
    00086     }
    00087
    00088     for (argument = request->arguments; argument; argument = argument->next)
    00089     {
    00090          rc = xmlTextWriterStartElement(writer, BAD_CAST "argument");
    00091          if (rc < 0) {
    00092             printf("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
    00093             return -1;
    00094          }
    00095
    00096          /* argument -> name */
    00097         rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", JS_UTFSTR(argument->name) );
    00098         if (rc < 0) {
    00099             printf("testXmlwriterMemory: Error at xmlTextWriterWriteAttribute\n");
    00100             return -1;
    00101         }
    00102
    00103          if (JS_NOTNULL(argument->value))
    00104          {
    00105              rc = xmlTextWriterWriteCDATA(writer, JS_UTFSTR(argument->value));
    00106              if (rc < 0) {
    00107                 printf("xmlTextWriterWriteCDATA: Error at xmlTextWriterWriteCDATA\n");
    00108                 return -1;
    00109              }
    00110
    00111          }
    00112
    00113          rc = xmlTextWriterEndElement(writer); // End element argument
    00114          if (rc < 0) {
    00115             printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
    00116             return -1;
    00117          }
    00118      }
    00119
    00120      for (res = request->resource; res; res = res->next)
    00121      {
    00122         rc = jasperserver_resource_descriptor_marshal(writer, res); // End element request
    00123         if (rc < 0) {
    00124            printf("jasperserver_resource_descriptor_marshall: Error at jasperserver_resource_descriptor_marshall\n");
    00125            return -1;
    00126         }
    00127      }
    00128
    00129      rc = xmlTextWriterEndElement(writer); // End element request
    00130      if (rc < 0) {
    00131         printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
    00132         return -1;
    00133      }
    00134      rc = xmlTextWriterEndDocument(writer);
    00135      if (rc < 0) {
    00136         printf("testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
    00137         return -1;
    00138      }
    00139
    00140      xmlFreeTextWriter(writer);
    00141      jasperserver_string_append(buffer, BAD_CAST buf->content);
    00142      return buffer->buffer->use;
    00143 }
    00144
    00163 int jasperserver_resource_descriptor_marshal(xmlTextWriterPtr writer, jasperserver_resource_descriptor_t *res)
    00164 {
    00165     int rc = 0;
    00166     jasperserver_resource_property_t *resourceProperty = NULL;
    00167     jasperserver_resource_descriptor_t *resourceDescriptor = NULL;
    00168     jasperserver_parameter_t *parameter = NULL;
    00169
    00170     /* resourceDescriptor tag */
    00171     rc = xmlTextWriterStartElement(writer, BAD_CAST "resourceDescriptor");
    00172     if (rc < 0) {
    00173         printf("xmlTextWriterStartElement resourceDescriptor: Error at xmlTextWriterStartElement\n");
    00174         return -1;
    00175     }
    00176
    00177     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", JS_UTFSTR( res->name ) );
    00178     if (rc < 0) {
    00179         printf("xmlTextWriterWriteAttribute name: Error at xmlTextWriterWriteAttribute\n");
    00180         return -1;
    00181     }
    00182
    00183     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "wsType", JS_UTFSTR(res->wsType) );
    00184     if (rc < 0) {
    00185         printf("xmlTextWriterWriteAttribute wsType: Error at xmlTextWriterWriteAttribute\n");
    00186         return -1;
    00187     }
    00188
    00189     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "uriString", JS_UTFSTR(res->uriString) );
    00190     if (rc < 0) {
    00191         printf("xmlTextWriterWriteAttribute uriString: Error at xmlTextWriterWriteAttribute\n");
    00192         return -1;
    00193     }
    00194
    00195     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "isNew",  BAD_CAST ((res->isNew) ?  "true" : "false") );
    00196     if (rc < 0) {
    00197         printf("xmlTextWriterWriteAttribute isNew: Error at xmlTextWriterWriteAttribute\n");
    00198         return -1;
    00199     }
    00200
    00201     rc = xmlTextWriterWriteElement(writer, BAD_CAST "label", JS_UTFSTR(res->label) );
    00202     if (rc < 0) {
    00203         printf("xmlTextWriterWriteElement label: Error at xmlTextWriterWriteElement\n");
    00204         return -1;
    00205     }
    00206
    00207     if (JS_NOTNULL( res->description ))
    00208     {
    00209           rc = xmlTextWriterWriteElement(writer, BAD_CAST "description",
    00210                                       JS_UTFSTR(res->description));
    00211           if (rc < 0) {
    00212                 printf("xmlTextWriterWriteElement: Error at xmlTextWriterWriteElement\n");
    00213                 return -1;
    00214            }
    00215     }
    00216
    00217     for (resourceProperty = res->properties; resourceProperty; resourceProperty = resourceProperty->next)
    00218      {
    00219         rc = jasperserver_resource_property_marshal(writer, resourceProperty); // End element request
    00220         if (rc < 0) {
    00221            printf("jasperserver_resource_property_marshall: Error at jasperserver_resource_property_marshall\n");
    00222            return -1;
    00223         }
    00224      }
    00225
    00226    for (resourceDescriptor = res->children; resourceDescriptor; resourceDescriptor = resourceDescriptor->next)
    00227      {
    00228         rc = jasperserver_resource_descriptor_marshal(writer, resourceDescriptor); // End element request
    00229         if (rc < 0) {
    00230            printf("jasperserver_resource_descriptor_marshall: Error at jasperserver_resource_descriptor_marshall\n");
    00231            return -1;
    00232         }
    00233      }
    00234
    00235    for (parameter = res->parameters; parameter; parameter = parameter->next)
    00236      {
    00237         rc = jasperserver_parameter_marshal(writer, parameter); // End element request
    00238         if (rc < 0) {
    00239            printf("jasperserver_parameter_marshall: Error at jasperserver_parameter_marshall\n");
    00240            return -1;
    00241         }
    00242      }
    00243
    00244    rc = xmlTextWriterEndElement(writer); // End element resourceDescriptor
    00245     if (rc < 0) {
    00246         printf("xmlTextWriterStartElement resourceDescriptor: Error at xmlTextWriterStartElement\n");
    00247         return -1;
    00248     }
    00249
    00250    return 0;
    00251 }
    00252
    00253
    00270 int jasperserver_resource_property_marshal(xmlTextWriterPtr writer, jasperserver_resource_property_t *res)
    00271 {
    00272     int rc = 0;
    00273     jasperserver_resource_property_t *resourceProperty = NULL;
    00274     /* resourceDescriptor tag */
    00275     rc = xmlTextWriterStartElement(writer, BAD_CAST "resourceProperty");
    00276     if (rc < 0) {
    00277         printf("xmlTextWriterStartElement resourceDescriptor: Error at xmlTextWriterStartElement\n");
    00278         return -1;
    00279     }
    00280
    00281     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", JS_UTFSTR( res->name ) );
    00282     if (rc < 0) {
    00283         printf("xmlTextWriterWriteAttribute name: Error at xmlTextWriterWriteAttribute\n");
    00284         return -1;
    00285     }
    00286
    00287     if (JS_NOTNULL( res->value ))
    00288     {
    00289           rc = xmlTextWriterWriteElement(writer, BAD_CAST "value", JS_UTFSTR(res->value));
    00290           if (rc < 0) {
    00291                 printf("xmlTextWriterWriteElement value: Error at xmlTextWriterWriteElement\n");
    00292                 return -1;
    00293            }
    00294     }
    00295
    00296     for (resourceProperty = res->properties; resourceProperty; resourceProperty = resourceProperty->next)
    00297      {
    00298         rc = jasperserver_resource_property_marshal(writer, resourceProperty); // End element request
    00299         if (rc < 0) {
    00300            printf("jasperserver_resource_property_marshall: Error at jasperserver_resource_property_marshall\n");
    00301            return -1;
    00302         }
    00303      }
    00304
    00305     rc = xmlTextWriterEndElement(writer);  // End element resourceProperty
    00306     if (rc < 0) {
    00307         printf("xmlTextWriterStartElement resourceDescriptor: Error at xmlTextWriterStartElement\n");
    00308         return -1;
    00309     }
    00310
    00311    return 0;
    00312 }
    00313
    00314
    00315
    00333 int jasperserver_parameter_marshal(xmlTextWriterPtr writer, jasperserver_parameter_t *param)
    00334 {
    00335     int rc = 0;
    00336     /* parameter tag */
    00337     rc = xmlTextWriterStartElement(writer, BAD_CAST "parameter");
    00338     if (rc < 0) {
    00339         printf("xmlTextWriterStartElement resourceDescriptor: Error at xmlTextWriterStartElement\n");
    00340         return -1;
    00341     }
    00342
    00343     rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "name", JS_UTFSTR( param->name ) );
    00344     if (rc < 0) {
    00345         printf("xmlTextWriterWriteAttribute name: Error at xmlTextWriterWriteAttribute\n");
    00346         return -1;
    00347     }
    00348
    00349     if (param->isListItem)
    00350     {
    00351         rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "isListItem", BAD_CAST "true" );
    00352         if (rc < 0) {
    00353             printf("xmlTextWriterWriteAttribute isListItem: Error at xmlTextWriterWriteAttribute\n");
    00354             return -1;
    00355         }
    00356     }
    00357
    00358     if (JS_NOTNULL( param->value ))
    00359     {
    00360           rc = xmlTextWriterWriteCDATA(writer, JS_UTFSTR(param->value));
    00361           if (rc < 0) {
    00362                 printf("xmlTextWriterWriteElement value: Error at xmlTextWriterWriteElement\n");
    00363                 return -1;
    00364            }
    00365     }
    00366
    00367     rc = xmlTextWriterEndElement(writer);  // End element parameter
    00368     if (rc < 0) {
    00369         printf("xmlTextWriterStartElement parameter: Error at xmlTextWriterStartElement\n");
    00370         return -1;
    00371     }
    00372
    00373    return 0;
    00374 }
    00375