static void wps_print_ident_title_abstract(const char *identifier, const char *title, const char *abstract) { if(identifier) { fprintf(stdout,"\t\t\t\t<ows:Identifier>"); print_escaped_for_xml(stdout, identifier); fprintf(stdout,"</ows:Identifier>\n"); } else { G_fatal_error("Identifier not defined"); } if(title) { fprintf(stdout,"\t\t\t\t<ows:Title>"); print_escaped_for_xml(stdout, title); fprintf(stdout, "</ows:Title>\n"); } else { G_warning("Title not defined!"); fprintf(stdout,"\t\t\t\t<ows:Title>"); print_escaped_for_xml(stdout, "No title available"); fprintf(stdout, "</ows:Title>\n"); } if(abstract) { fprintf(stdout,"\t\t\t\t<ows:Abstract>"); print_escaped_for_xml(stdout, abstract); fprintf(stdout, "</ows:Abstract>\n"); } }
static void wps_print_process_description_begin(int store, int status, const char *identifier, const char *title, const char *abstract, const char **keywords, int num_keywords) { int i; fprintf(stdout,"\t<ProcessDescription wps:processVersion=\"1\" storeSupported=\"%s\" statusSupported=\"%s\">\n", (store?"true":"false"), (status?"true":"false")); if(identifier) { fprintf(stdout,"\t\t<ows:Identifier>"); print_escaped_for_xml(stdout, identifier); fprintf(stdout,"</ows:Identifier>\n"); } else { G_fatal_error("Identifier not defined"); } if(title) { fprintf(stdout,"\t\t<ows:Title>"); print_escaped_for_xml(stdout, title); fprintf(stdout, "</ows:Title>\n"); } else { G_warning("Title not defined!"); fprintf(stdout,"\t\t<ows:Title>"); print_escaped_for_xml(stdout, "No title available"); fprintf(stdout, "</ows:Title>\n"); } if(abstract) { fprintf(stdout,"\t\t<ows:Abstract>"); fprintf(stdout, "http://grass.osgeo.org/grass73/manuals/%s.html", identifier); fprintf(stdout, "</ows:Abstract>\n"); } for(i = 0; i < num_keywords; i++) { fprintf(stdout,"\t\t<ows:Metadata xlink:title=\""); print_escaped_for_xml(stdout, keywords[i]); fprintf(stdout, "\" />\n"); } }
/* extract custom-namespaced attributes if any */ static int mk_attribs(int cat, struct field_info *Fi, dbDriver * Driver, dbTable * Table, int attr_cols[], int attr_size, int do_attr) { int i, more; char buf[2000]; dbString dbstring; dbColumn *Column; dbCursor cursor; dbValue *Value; /* include cat in any case */ fprintf(fpsvg, "gg:cat=\"%d\" ", cat); /* skip attribs if none */ if (do_attr == 0) { return 1; } /* create SQL-string and query attribs */ db_init_string(&dbstring); sprintf(buf, "SELECT * FROM %s WHERE %s = %d", Fi->table, Fi->key, cat); db_set_string(&dbstring, buf); if (db_open_select_cursor(Driver, &dbstring, &cursor, DB_SEQUENTIAL) != DB_OK) { G_fatal_error(_("Cannot select attributes for cat=%d"), cat); } else { if (db_fetch(&cursor, DB_NEXT, &more) != DB_OK) { G_fatal_error(_("Unable to fetch data from table")); } /* extract attribs and data if wanted */ Table = db_get_cursor_table(&cursor); for (i = 0; i < attr_size; i++) { Column = db_get_table_column(Table, attr_cols[i]); Value = db_get_column_value(Column); db_convert_column_value_to_string(Column, &dbstring); strcpy(buf, db_get_column_name(Column)); fprintf(fpsvg, "gg:%s=\"", G_tolcase(buf)); print_escaped_for_xml(db_get_string(&dbstring)); fprintf(fpsvg, "\" "); } } return 1; }
static void wps_print_literal_input_output(int inout_type, int min, int max, const char *identifier, const char *title, const char *abstract, const char *datatype, int unitofmesure, const char **choices, int num_choices, const char *default_value, int type) { int i; char range[2][24]; char *str; if(inout_type == WPS_INPUT) fprintf(stdout,"\t\t\t<Input minOccurs=\"%i\" maxOccurs=\"%i\">\n", min, max); else if(inout_type == WPS_OUTPUT) fprintf(stdout,"\t\t\t<Output>\n"); wps_print_ident_title_abstract(identifier, title, abstract); fprintf(stdout,"\t\t\t\t<LiteralData>\n"); if(datatype) fprintf(stdout,"\t\t\t\t\t<ows:DataType ows:reference=\"xs:%s\">%s</ows:DataType>\n", datatype, datatype); if(unitofmesure) { fprintf(stdout,"\t\t\t\t\t<UOMs>\n"); fprintf(stdout,"\t\t\t\t\t\t<Default>\n"); fprintf(stdout,"\t\t\t\t\t\t\t<ows:UOM>meters</ows:UOM>\n"); fprintf(stdout,"\t\t\t\t\t\t</Default>\n"); fprintf(stdout,"\t\t\t\t\t\t<Supported>\n"); fprintf(stdout,"\t\t\t\t\t\t\t<ows:UOM>meters</ows:UOM>\n"); fprintf(stdout,"\t\t\t\t\t\t\t<ows:UOM>degrees</ows:UOM>\n"); fprintf(stdout,"\t\t\t\t\t\t</Supported>\n"); fprintf(stdout,"\t\t\t\t\t</UOMs>\n"); } if(num_choices == 0 || choices == NULL) fprintf(stdout,"\t\t\t\t\t<ows:AnyValue/>\n"); else { /* Check for range values */ if(strcmp(datatype, "integer") == 0 || strcmp(datatype, "float") == 0) { str = strtok((char*)choices[0], "-"); if(str != NULL) { G_snprintf(range[0], 24, "%s", str); str = strtok(NULL, "-"); if(str != NULL) { G_snprintf(range[1], 24, "%s", str); type = TYPE_RANGE; } } } fprintf(stdout,"\t\t\t\t\t<ows:AllowedValues>\n"); if(type == TYPE_RANGE) { fprintf(stdout,"\t\t\t\t\t\t<ows:Range ows:rangeClosure=\"closed\">\n"); fprintf(stdout,"\t\t\t\t\t\t\t<ows:MinimumValue>%s</ows:MinimumValue>\n", range[0]); fprintf(stdout,"\t\t\t\t\t\t\t<ows:MaximumValue>%s</ows:MaximumValue>\n", range[1]); fprintf(stdout,"\t\t\t\t\t\t</ows:Range>\n"); } else { for(i = 0; i < num_choices; i++) { fprintf(stdout,"\t\t\t\t\t\t<ows:Value>"); print_escaped_for_xml(stdout, choices[i]); fprintf(stdout,"</ows:Value>\n"); } } fprintf(stdout,"\t\t\t\t\t</ows:AllowedValues>\n"); } if(default_value) { fprintf(stdout,"\t\t\t\t\t<DefaultValue>"); print_escaped_for_xml(stdout, default_value); fprintf(stdout,"</DefaultValue>\n"); } fprintf(stdout,"\t\t\t\t</LiteralData>\n"); if(inout_type == WPS_INPUT) fprintf(stdout,"\t\t\t</Input>\n"); else if(inout_type == WPS_OUTPUT) fprintf(stdout,"\t\t\t</Output>\n"); }
/*! \brief Print module usage description in XML format. */ void G__usage_xml(void) { struct Option *opt; struct Flag *flag; char *type; char *s, *top; int i; const char *encoding; int new_prompt = 0; new_prompt = G__uses_new_gisprompt(); /* gettext converts strings to encoding returned by nl_langinfo(CODESET) */ #if defined(HAVE_LANGINFO_H) encoding = nl_langinfo(CODESET); #elif defined(__MINGW32__) && defined(USE_NLS) encoding = locale_charset(); #endif if (!encoding || strlen(encoding) == 0) encoding = "UTF-8"; #ifdef HAVE_ICONV_H src_enc = encoding; encoding = "UTF-8"; #endif if (!st->pgm_name) /* v.dave && r.michael */ st->pgm_name = G_program_name(); if (!st->pgm_name) st->pgm_name = "??"; fprintf(stdout, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", encoding); fprintf(stdout, "<!DOCTYPE task SYSTEM \"grass-interface.dtd\">\n"); fprintf(stdout, "<task name=\"%s\">\n", st->pgm_name); if (st->module_info.label) { fprintf(stdout, "\t<label>\n\t\t"); print_escaped_for_xml(stdout, st->module_info.label); fprintf(stdout, "\n\t</label>\n"); } if (st->module_info.description) { fprintf(stdout, "\t<description>\n\t\t"); print_escaped_for_xml(stdout, st->module_info.description); fprintf(stdout, "\n\t</description>\n"); } if (st->module_info.keywords) { fprintf(stdout, "\t<keywords>\n\t\t"); G__print_keywords(stdout, print_escaped_for_xml); fprintf(stdout, "\n\t</keywords>\n"); } /***** Don't use parameter-groups for now. We'll reimplement this later ***** when we have a concept of several mutually exclusive option ***** groups if (st->n_opts || st->n_flags) fprintf(stdout, "\t<parameter-group>\n"); ***** ***** *****/ if (st->n_opts) { opt = &st->first_option; while (opt != NULL) { /* TODO: make this a enumeration type? */ switch (opt->type) { case TYPE_INTEGER: type = "integer"; break; case TYPE_DOUBLE: type = "float"; break; case TYPE_STRING: type = "string"; break; default: type = "string"; break; } fprintf(stdout, "\t<parameter " "name=\"%s\" " "type=\"%s\" " "required=\"%s\" " "multiple=\"%s\">\n", opt->key, type, opt->required == YES ? "yes" : "no", opt->multiple == YES ? "yes" : "no"); if (opt->label) { fprintf(stdout, "\t\t<label>\n\t\t\t"); print_escaped_for_xml(stdout, opt->label); fprintf(stdout, "\n\t\t</label>\n"); } if (opt->description) { fprintf(stdout, "\t\t<description>\n\t\t\t"); print_escaped_for_xml(stdout, opt->description); fprintf(stdout, "\n\t\t</description>\n"); } if (opt->key_desc) { fprintf(stdout, "\t\t<keydesc>\n"); top = G_calloc(strlen(opt->key_desc) + 1, 1); strcpy(top, opt->key_desc); s = strtok(top, ","); for (i = 1; s != NULL; i++) { fprintf(stdout, "\t\t\t<item order=\"%d\">", i); print_escaped_for_xml(stdout, s); fprintf(stdout, "</item>\n"); s = strtok(NULL, ","); } fprintf(stdout, "\t\t</keydesc>\n"); G_free(top); } if (opt->gisprompt) { const char *atts[] = { "age", "element", "prompt", NULL }; top = G_calloc(strlen(opt->gisprompt) + 1, 1); strcpy(top, opt->gisprompt); s = strtok(top, ","); fprintf(stdout, "\t\t<gisprompt "); for (i = 0; s != NULL && atts[i] != NULL; i++) { fprintf(stdout, "%s=\"%s\" ", atts[i], s); s = strtok(NULL, ","); } fprintf(stdout, "/>\n"); G_free(top); } if (opt->def) { fprintf(stdout, "\t\t<default>\n\t\t\t"); print_escaped_for_xml(stdout, opt->def); fprintf(stdout, "\n\t\t</default>\n"); } if (opt->options) { /* TODO: * add something like * <range min="xxx" max="xxx"/> * to <values> */ i = 0; fprintf(stdout, "\t\t<values>\n"); while (opt->opts[i]) { fprintf(stdout, "\t\t\t<value>\n"); fprintf(stdout, "\t\t\t\t<name>"); print_escaped_for_xml(stdout, opt->opts[i]); fprintf(stdout, "</name>\n"); if (opt->descs && opt->opts[i] && opt->descs[i]) { fprintf(stdout, "\t\t\t\t<description>"); print_escaped_for_xml(stdout, opt->descs[i]); fprintf(stdout, "</description>\n"); } fprintf(stdout, "\t\t\t</value>\n"); i++; } fprintf(stdout, "\t\t</values>\n"); } if (opt->guisection) { fprintf(stdout, "\t\t<guisection>\n\t\t\t"); print_escaped_for_xml(stdout, opt->guisection); fprintf(stdout, "\n\t\t</guisection>\n"); } if (opt->guidependency) { fprintf(stdout, "\t\t<guidependency>\n\t\t\t"); print_escaped_for_xml(stdout, opt->guidependency); fprintf(stdout, "\n\t\t</guidependency>\n"); } /* TODO: * - key_desc? * - there surely are some more. which ones? */ opt = opt->next_opt; fprintf(stdout, "\t</parameter>\n"); } } if (st->n_flags) { flag = &st->first_flag; while (flag != NULL) { fprintf(stdout, "\t<flag name=\"%c\">\n", flag->key); if (flag->label) { fprintf(stdout, "\t\t<label>\n\t\t\t"); print_escaped_for_xml(stdout, flag->label); fprintf(stdout, "\n\t\t</label>\n"); } if (flag->suppress_required) fprintf(stdout, "\t\t<suppress_required/>\n"); if (flag->description) { fprintf(stdout, "\t\t<description>\n\t\t\t"); print_escaped_for_xml(stdout, flag->description); fprintf(stdout, "\n\t\t</description>\n"); } if (flag->guisection) { fprintf(stdout, " \t\t<guisection>\n\t\t\t"); print_escaped_for_xml(stdout, flag->guisection); fprintf(stdout, "\n\t\t</guisection>\n"); } flag = flag->next_flag; fprintf(stdout, "\t</flag>\n"); } } /***** Don't use parameter-groups for now. We'll reimplement this later ***** when we have a concept of several mutually exclusive option ***** groups if (st->n_opts || st->n_flags) fprintf(stdout, "\t</parameter-group>\n"); ***** ***** *****/ if (new_prompt) { /* overwrite */ fprintf(stdout, "\t<flag name=\"%s\">\n", "overwrite"); fprintf(stdout, "\t\t<description>\n\t\t\t"); print_escaped_for_xml(stdout, _("Allow output files to overwrite existing files")); fprintf(stdout, "\n\t\t</description>\n"); fprintf(stdout, "\t</flag>\n"); } /* verbose */ fprintf(stdout, "\t<flag name=\"%s\">\n", "verbose"); fprintf(stdout, "\t\t<description>\n\t\t\t"); print_escaped_for_xml(stdout, _("Verbose module output")); fprintf(stdout, "\n\t\t</description>\n"); fprintf(stdout, "\t</flag>\n"); /* quiet */ fprintf(stdout, "\t<flag name=\"%s\">\n", "quiet"); fprintf(stdout, "\t\t<description>\n\t\t\t"); print_escaped_for_xml(stdout, _("Quiet module output")); fprintf(stdout, "\n\t\t</description>\n"); fprintf(stdout, "\t</flag>\n"); fprintf(stdout, "</task>\n"); }