static axiom_node_t * axiom_stax_builder_create_om_comment( axiom_stax_builder_t * om_builder, const axutil_env_t * env) { axiom_node_t *comment_node = NULL; axis2_char_t *comment_value = NULL; axiom_node_t *parent = NULL; comment_value = axiom_xml_reader_get_value(om_builder->parser, env); if(!comment_value) { AXIS2_ERROR_SET(env->error, AXIS2_ERROR_XML_READER_ELEMENT_NULL, AXIS2_FAILURE); AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in reading comment"); return NULL; } if(axiom_node_is_complete(om_builder->lastnode, env)) { /* Last node is completed means, this node should be a sibling of last node */ parent = axiom_node_get_parent(om_builder->lastnode, env); } else { /* this node should be a child of last node */ parent = om_builder->lastnode; } axiom_comment_create(env, parent, comment_value, &comment_node); axiom_xml_reader_xml_free(om_builder->parser,env,comment_value); if(!comment_node) { AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Failed to create axiom element"); return NULL; } axiom_node_set_builder(comment_node, env, om_builder); om_builder->element_level++; om_builder->lastnode = comment_node; return comment_node; }
//----------------------------------------------------------------------------- void sp_update_lineage( const axutil_env_t * env, const sp_props *props, axiom_node_t *return_node, axiom_node_t *request_node, time_t request_time) { axiom_node_t *eom_node = rp_find_named_child(env, return_node, "EOMetadata", 1); if (NULL == eom_node) { rp_log_error(env, "*Warning S2P(%s:%d): %s node not found.\n", __FILE__, __LINE__, "EOMetadata"); return; } time_t lineage_time = 0; axiom_node_t *curr_lineage = sp_latest_named(env, eom_node, "lineage", &lineage_time); // TODO: should improve handling of insignificant whitespace. // grab some whitespace for future use axiom_node_t *lin_whsp_node = sp_get_last_text_node(curr_lineage, env); axiom_node_t *eom_whsp_node = sp_get_last_text_node(eom_node, env); const axis2_char_t *lin_whsp_str = sp_get_text_text(lin_whsp_node, env); const axis2_char_t *eom_whsp_str = sp_get_text_text(eom_whsp_node, env); int whspace_indent = SP_DEFAULT_WHSPACE; if (NULL != lin_whsp_str && NULL != eom_whsp_str) { whspace_indent = axutil_strlen(lin_whsp_str) - axutil_strlen(eom_whsp_str); if (whspace_indent < 0 || whspace_indent >12) { rp_log_error(env, "*Warning S2P: funny whitespace indent (%d) calculated.\n", whspace_indent); whspace_indent = SP_DEFAULT_WHSPACE; } } axis2_char_t curr_whspace[SP_MAX_LOCAL_STR_LEN]; strncpy(curr_whspace, lin_whsp_str, SP_MAX_LOCAL_STR_LEN-1); curr_whspace[SP_MAX_LOCAL_STR_LEN-1] = '\0'; // The most recent Lineage data is deleted only if it has been added // in the time period since we started processing this request. if (NULL != curr_lineage && lineage_time >= request_time) { // OK to delete lineage axiom_node_detach (curr_lineage, env); axiom_node_free_tree (curr_lineage, env); curr_lineage = NULL; lin_whsp_node = NULL; lin_whsp_str = NULL; } else { sp_add_whspace(env, eom_node, curr_whspace); } // Add a new lineage. here is an example: // <wcseo:lineage> // <wcseo:referenceGetCoverage> // <ows:ServiceReference xlink:href="http://www.someWCS.org"> // <ows:RequestMessage> // <wcs:GetCoverage service="WCS" version="2.0.0"> // <wcs:format>application/gml+xml</wcs:format> // <wcs:CoverageId>someEOCoverage1</wcs:CoverageId> // </wcs:GetCoverage> // </ows:RequestMessage> // </ows:ServiceReference> // </wcseo:referenceGetCoverage> // <gml:timePosition>2011-08-24T14:18:52Z</gml:timePosition> // </wcseo:lineage> // <wcseo:lineage> axiom_node_t *lineage_node = rp_add_child_el(env, eom_node, "lineage", NULL); sp_inc_whspace(curr_whspace, whspace_indent); sp_add_whspace(env, lineage_node, curr_whspace); // comment axiom_node_t *comment = axiom_node_create(env); axiom_comment_create ( env, lineage_node, "POST GetCoverage request added by SOAP-TO-POST proxy.", &comment); //<wcseo:referenceGetCoverage> axiom_node_t *ref_g1_node = rp_add_child_el(env, lineage_node, "referenceGetCoverage", curr_whspace); // <ows:ServiceReference xlink:href="http://www.someWCS.org"> sp_inc_whspace(curr_whspace, whspace_indent); sp_add_whspace(env, ref_g1_node, curr_whspace); axiom_namespace_t *ows_ns = sp_find_or_create_ns(env, return_node, SP_OWS_NAMESPACE_STR, "ows"); axiom_node_t *service_ref_node = axiom_node_create(env); axiom_element_t *service_ref_el = axiom_element_create( env, ref_g1_node, "ServiceReference", ows_ns, &service_ref_node); axiom_namespace_t *xlink_ns = sp_find_or_create_ns( env, return_node, SP_XLINK_NAMESPACE_STR, "xlink"); axiom_attribute_t *attr = axiom_attribute_create (env, "type", "simple", xlink_ns); axiom_element_add_attribute (service_ref_el, env, attr, service_ref_node); attr = axiom_attribute_create (env, "href", rp_getSoapOpsURL(env, props), xlink_ns); axiom_element_add_attribute (service_ref_el, env, attr, service_ref_node); //<ows:RequestMessage> axiom_node_t *req_msg_node = rp_add_child_el(env, service_ref_node, "RequestMessage", curr_whspace); sp_inc_whspace(curr_whspace, whspace_indent); // Detach the request GetCoverage element from its parent // and attach it here. axiom_node_t *gc_node = rp_find_named_node(env, request_node, "GetCoverage", 1); if (gc_node) { // TODO - pretty-up the the indentation to match current. sp_add_whspace(env, req_msg_node, curr_whspace); axiom_node_detach (gc_node, env); axiom_node_add_child (req_msg_node, env, gc_node); } // Adjust the indentation of closing tags sp_inc_whspace(curr_whspace, -whspace_indent); sp_add_whspace(env, req_msg_node, curr_whspace); sp_inc_whspace(curr_whspace, -whspace_indent); sp_add_whspace(env, service_ref_node, curr_whspace); sp_inc_whspace(curr_whspace, -whspace_indent); sp_add_whspace(env, ref_g1_node, curr_whspace); sp_inc_whspace(curr_whspace, -whspace_indent); //<gml:timePosition>2011-08-24T14:18:52Z</gml:timePosition> sp_add_whspace(env, lineage_node, curr_whspace); axiom_namespace_t *gml_ns = sp_find_or_create_ns( env, return_node, SP_GML_NAMESPACE_STR, "gml"); axiom_node_t *time_pos_node = axiom_node_create(env); axiom_element_t *time_pos_el = axiom_element_create( env, lineage_node, "timePosition", gml_ns, &time_pos_node); char tmbuf[22]; sp_time_str(tmbuf, time(NULL)); axiom_element_set_text(time_pos_el, env, tmbuf, time_pos_node); // Adjust the indentation of remaining closing tags sp_inc_whspace(curr_whspace, -whspace_indent); sp_add_whspace(env, lineage_node, curr_whspace); // Adjust whitespace before the element // that follows our new lineage element, whatever it may be. sp_add_whspace(env, eom_node, eom_whsp_str); // Delete the whitespace before any our insertions. axiom_node_detach (eom_whsp_node, env); axiom_node_free_tree (eom_whsp_node, env); }