summaryrefslogtreecommitdiffstats
path: root/axiom/src/parser/libxml2
diff options
context:
space:
mode:
authorGravatar gmcdonald2010-02-13 01:32:03 +0000
committerGravatar gmcdonald2010-02-13 01:32:03 +0000
commit0425aadc78680e53000fd0108b540d6eca048516 (patch)
tree8ec7ab8e015d454c5ec586dfc91e05a2dce1cfc0 /axiom/src/parser/libxml2
downloadaxis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.gz
axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.bz2
Moving axis svn, part of TLP move INFRA-2441
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'axiom/src/parser/libxml2')
-rw-r--r--axiom/src/parser/libxml2/Makefile.am17
-rw-r--r--axiom/src/parser/libxml2/libxml2_reader_wrapper.c949
-rw-r--r--axiom/src/parser/libxml2/libxml2_writer_wrapper.c1571
3 files changed, 2537 insertions, 0 deletions
diff --git a/axiom/src/parser/libxml2/Makefile.am b/axiom/src/parser/libxml2/Makefile.am
new file mode 100644
index 0000000..a5b4c75
--- /dev/null
+++ b/axiom/src/parser/libxml2/Makefile.am
@@ -0,0 +1,17 @@
+lib_LTLIBRARIES = libaxis2_parser.la
+
+
+libaxis2_parser_la_SOURCES = ../xml_reader.c ../xml_writer.c \
+ libxml2_reader_wrapper.c libxml2_writer_wrapper.c
+
+libaxis2_parser_la_LIBADD = @LIBXML2_LIBS@ \
+ ../../../../util/src/libaxutil.la
+
+libaxis2_parser_la_LDFLAGS = -version-info $(VERSION_NO)
+libaxis2_libxml2_la_LDFLAGS = -version-info $(VERSION_NO)
+
+
+INCLUDES = -I$(top_builddir)/include \
+ -I$(top_builddir)/src/parser \
+ -I ../../../../util/include \
+ @LIBXML2_CFLAGS@
diff --git a/axiom/src/parser/libxml2/libxml2_reader_wrapper.c b/axiom/src/parser/libxml2/libxml2_reader_wrapper.c
new file mode 100644
index 0000000..2510d49
--- /dev/null
+++ b/axiom/src/parser/libxml2/libxml2_reader_wrapper.c
@@ -0,0 +1,949 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axiom_xml_reader.h>
+#include <libxml/xmlreader.h>
+#include <libxml/parser.h>
+#include <axutil_utils_defines.h>
+#include <axutil_utils.h>
+#include <string.h>
+#include <axutil_string.h>
+
+
+int AXIS2_CALL axis2_libxml2_reader_wrapper_next(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+void AXIS2_CALL axis2_libxml2_reader_wrapper_free(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+int AXIS2_CALL axis2_libxml2_reader_wrapper_get_attribute_count(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_name_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i);
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i);
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_value_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i);
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_value(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+int AXIS2_CALL axis2_libxml2_reader_wrapper_get_namespace_count(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_namespace_uri_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i);
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_prefix(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_name(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_pi_target(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_pi_data(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_dtd(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+void AXIS2_CALL axis2_libxml2_reader_wrapper_xml_free(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ void *data);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_char_set_encoding(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_reader_wrapper_get_namespace_uri(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_namespace_uri_by_prefix(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ axis2_char_t * prefix);
+
+axis2_status_t
+axis2_libxml2_reader_wrapper_fill_maps(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env);
+
+void
+axis2_libxml2_reader_wrapper_error_handler(
+ void *arg,
+ const char *msg,
+ int severities,
+ void *locator_ptr);
+
+static int
+axis2_libxml2_reader_wrapper_read_input_callback(
+ void *ctx,
+ char *buffer,
+ int size);
+
+static int
+axis2_libxml2_reader_wrapper_close_input_callback(
+ void *ctx);
+
+typedef struct axis2_libxml2_reader_wrapper_impl_t
+{
+ axiom_xml_reader_t parser;
+
+ xmlTextReaderPtr reader;
+
+ int current_event;
+ int current_attribute_count;
+ int current_namespace_count;
+ int event_map[18];
+
+ void *ctx;
+ /* assuming that max ns and attribute will be 20 */
+
+ int *namespace_map;
+ int *attribute_map;
+
+ AXIS2_READ_INPUT_CALLBACK read_input_callback;
+
+ AXIS2_CLOSE_INPUT_CALLBACK close_input_callback;
+
+} axis2_libxml2_reader_wrapper_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(p) ((axis2_libxml2_reader_wrapper_impl_t*)p)
+#define AXIS2_IMPL_TO_INTF(p) &(p->parser)
+
+static const axiom_xml_reader_ops_t axiom_xml_reader_ops_var = { axis2_libxml2_reader_wrapper_next,
+ axis2_libxml2_reader_wrapper_free, axis2_libxml2_reader_wrapper_get_attribute_count,
+ axis2_libxml2_reader_wrapper_get_attribute_name_by_number,
+ axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number,
+ axis2_libxml2_reader_wrapper_get_attribute_value_by_number,
+ axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number,
+ axis2_libxml2_reader_wrapper_get_value, axis2_libxml2_reader_wrapper_get_namespace_count,
+ axis2_libxml2_reader_wrapper_get_namespace_uri_by_number,
+ axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number,
+ axis2_libxml2_reader_wrapper_get_prefix, axis2_libxml2_reader_wrapper_get_name,
+ axis2_libxml2_reader_wrapper_get_pi_target, axis2_libxml2_reader_wrapper_get_pi_data,
+ axis2_libxml2_reader_wrapper_get_dtd, axis2_libxml2_reader_wrapper_xml_free,
+ axis2_libxml2_reader_wrapper_get_char_set_encoding,
+ axis2_libxml2_reader_wrapper_get_namespace_uri,
+ axis2_libxml2_reader_wrapper_get_namespace_uri_by_prefix };
+
+static axis2_status_t
+axis2_libxml2_reader_wrapper_init_map(
+ axis2_libxml2_reader_wrapper_impl_t * parser)
+{
+ int i = 0;
+ if(parser)
+ {
+ for(i = 0; i < 18; i++)
+ {
+ parser->event_map[i] = -1;
+ }
+
+ parser->event_map[XML_READER_TYPE_ELEMENT] = AXIOM_XML_READER_START_ELEMENT;
+ parser->event_map[XML_READER_TYPE_DOCUMENT] = AXIOM_XML_READER_START_DOCUMENT;
+ parser->event_map[XML_READER_TYPE_TEXT] = AXIOM_XML_READER_CHARACTER;
+ parser->event_map[XML_READER_TYPE_CDATA] = AXIOM_XML_READER_CHARACTER;
+ parser->event_map[XML_READER_TYPE_SIGNIFICANT_WHITESPACE] = AXIOM_XML_READER_SPACE;
+ parser->event_map[XML_READER_TYPE_WHITESPACE] = AXIOM_XML_READER_SPACE;
+ parser->event_map[XML_READER_TYPE_END_ELEMENT] = AXIOM_XML_READER_END_ELEMENT;
+ parser->event_map[XML_READER_TYPE_ENTITY_REFERENCE] = AXIOM_XML_READER_ENTITY_REFERENCE;
+ parser->event_map[XML_READER_TYPE_END_ENTITY] = AXIOM_XML_READER_SPACE;
+ parser->event_map[XML_READER_TYPE_ENTITY] = AXIOM_XML_READER_SPACE;
+ parser->event_map[XML_READER_TYPE_PROCESSING_INSTRUCTION]
+ = AXIOM_XML_READER_PROCESSING_INSTRUCTION;
+ parser->event_map[XML_READER_TYPE_COMMENT] = AXIOM_XML_READER_COMMENT;
+ parser->event_map[XML_READER_TYPE_DOCUMENT_TYPE] = AXIOM_XML_READER_DOCUMENT_TYPE;
+ return AXIS2_SUCCESS;
+ }
+ return AXIS2_FAILURE;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axiom_xml_reader_init()
+{
+ xmlInitParser();
+ return AXIS2_SUCCESS;
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axiom_xml_reader_cleanup()
+{
+ xmlCleanupParser();
+ return AXIS2_SUCCESS;
+}
+
+static axis2_libxml2_reader_wrapper_impl_t*
+libxml2_reader_wrapper_create(
+ const axutil_env_t *env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
+ wrapper_impl = (axis2_libxml2_reader_wrapper_impl_t *)AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_libxml2_reader_wrapper_impl_t));
+
+ if(!wrapper_impl)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create libxml2 reader wrapper");
+ return NULL;
+ }
+ memset(wrapper_impl, 0, sizeof(axis2_libxml2_reader_wrapper_impl_t));
+ wrapper_impl->attribute_map = NULL;
+ wrapper_impl->namespace_map = NULL;
+ wrapper_impl->close_input_callback = NULL;
+ wrapper_impl->read_input_callback = NULL;
+ wrapper_impl->ctx = NULL;
+ wrapper_impl->current_namespace_count = 0;
+ wrapper_impl->current_attribute_count = 0;
+ wrapper_impl->current_event = -1;
+ return wrapper_impl;
+}
+
+AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL
+axiom_xml_reader_create_for_file(
+ const axutil_env_t * env,
+ char *filename,
+ const axis2_char_t * encoding)
+{
+
+ axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
+ AXIS2_ENV_CHECK(env, NULL);
+ AXIS2_PARAM_CHECK(env->error, filename, NULL);
+
+ wrapper_impl = libxml2_reader_wrapper_create(env);
+ if(!wrapper_impl)
+ {
+ return NULL;
+ }
+
+ wrapper_impl->reader = xmlReaderForFile(filename, encoding, XML_PARSE_RECOVER);
+ if(!(wrapper_impl->reader))
+ {
+ AXIS2_FREE(env->allocator, wrapper_impl);
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ xmlTextReaderSetErrorHandler(wrapper_impl->reader,
+ (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler, (void *)env);
+ wrapper_impl->current_event = -1;
+ wrapper_impl->ctx = NULL;
+ axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
+
+ wrapper_impl->parser.ops = &axiom_xml_reader_ops_var;
+ return &(wrapper_impl->parser);
+}
+
+AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL
+axiom_xml_reader_create_for_io(
+ const axutil_env_t * env,
+ AXIS2_READ_INPUT_CALLBACK read_input_callback,
+ AXIS2_CLOSE_INPUT_CALLBACK close_input_callback,
+ void *ctx,
+ const axis2_char_t * encoding)
+{
+ axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
+
+ AXIS2_ENV_CHECK(env, NULL);
+
+ if(!read_input_callback)
+ {
+ return NULL;
+ }
+
+ wrapper_impl = libxml2_reader_wrapper_create(env);
+ if(!wrapper_impl)
+ {
+ return NULL;
+ }
+ wrapper_impl->close_input_callback = NULL;
+ wrapper_impl->read_input_callback = NULL;
+ wrapper_impl->read_input_callback = read_input_callback;
+ wrapper_impl->close_input_callback = close_input_callback;
+ wrapper_impl->ctx = ctx;
+ if(wrapper_impl->close_input_callback)
+ {
+ wrapper_impl->reader = xmlReaderForIO(axis2_libxml2_reader_wrapper_read_input_callback,
+ axis2_libxml2_reader_wrapper_close_input_callback, wrapper_impl, NULL, encoding,
+ XML_PARSE_RECOVER);
+ }
+ else
+ {
+ wrapper_impl->reader = xmlReaderForIO(axis2_libxml2_reader_wrapper_read_input_callback,
+ NULL, wrapper_impl, NULL, encoding, XML_PARSE_RECOVER);
+ }
+ if(!(wrapper_impl->reader))
+ {
+ AXIS2_FREE(env->allocator, wrapper_impl);
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ xmlTextReaderSetErrorHandler(wrapper_impl->reader,
+ (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler, (void *)env);
+
+ wrapper_impl->current_event = -1;
+
+ axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
+
+ wrapper_impl->parser.ops = &axiom_xml_reader_ops_var;
+ return &(wrapper_impl->parser);
+}
+
+AXIS2_EXTERN axiom_xml_reader_t *AXIS2_CALL
+axiom_xml_reader_create_for_memory(
+ const axutil_env_t * env,
+ void *container,
+ int size,
+ const axis2_char_t * encoding,
+ int type)
+{
+ axis2_libxml2_reader_wrapper_impl_t *wrapper_impl = NULL;
+
+ AXIS2_PARAM_CHECK(env->error, container, NULL);
+
+ wrapper_impl = libxml2_reader_wrapper_create(env);
+ if(!wrapper_impl)
+ {
+ return NULL;
+ }
+ wrapper_impl->close_input_callback = NULL;
+ wrapper_impl->read_input_callback = NULL;
+ wrapper_impl->ctx = NULL;
+
+ if(AXIS2_XML_PARSER_TYPE_BUFFER == type)
+ {
+ wrapper_impl->reader = xmlReaderForMemory((axis2_char_t *)container, size, NULL, encoding,
+ XML_PARSE_RECOVER);
+ }
+ else if(AXIS2_XML_PARSER_TYPE_DOC == type)
+ {
+ wrapper_impl->reader = xmlReaderWalker((xmlDocPtr)container);
+ }
+ else
+ {
+ AXIS2_FREE(env->allocator, wrapper_impl);
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_XML_PARSER_INVALID_MEM_TYPE, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ if(!(wrapper_impl->reader))
+ {
+ AXIS2_FREE(env->allocator, wrapper_impl);
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_READER, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ if(AXIS2_XML_PARSER_TYPE_BUFFER == type)
+ {
+ xmlTextReaderSetErrorHandler(wrapper_impl->reader,
+ (xmlTextReaderErrorFunc)axis2_libxml2_reader_wrapper_error_handler, (void *)env);
+ }
+
+ wrapper_impl->current_event = -1;
+
+ axis2_libxml2_reader_wrapper_init_map(wrapper_impl);
+
+ wrapper_impl->parser.ops = &axiom_xml_reader_ops_var;
+ return &(wrapper_impl->parser);
+}
+
+int AXIS2_CALL
+axis2_libxml2_reader_wrapper_next(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ int ret_val = 0;
+ int node = 2;
+ int empty_check = 0;
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl;
+ AXIS2_ENV_CHECK(env, -1);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ ret_val = xmlTextReaderRead(parser_impl->reader);
+ if(ret_val == 0)
+ {
+ AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "xml stream is over ");
+ }
+ if(ret_val == -1)
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, " error occurred in reading xml stream ");
+ return -1;
+ }
+
+ if(ret_val == 1)
+ {
+ node = xmlTextReaderNodeType(parser_impl->reader);
+ parser_impl->current_event = parser_impl->event_map[node];
+ parser_impl->current_attribute_count = 0;
+ parser_impl->current_namespace_count = 0;
+
+ if(node == XML_READER_TYPE_ELEMENT)
+ {
+ empty_check = xmlTextReaderIsEmptyElement(parser_impl->reader);
+ axis2_libxml2_reader_wrapper_fill_maps(parser, env);
+ }
+ if(empty_check == 1)
+ {
+ parser_impl->current_event = AXIOM_XML_READER_EMPTY_ELEMENT;
+ return AXIOM_XML_READER_EMPTY_ELEMENT;
+ }
+ return parser_impl->event_map[node];
+ }
+ else
+ {
+ return -1;
+ }
+}
+
+/**
+ * If your application crashes here, it may be due to an earlier call to
+ * xmlCleanupParser() function. In client API, op_client create function has a call
+ * to axiom_xml_reader_init and op_client_free function has a call to axiom_xml_reader_cleanup
+ * function. You can avoid the call to axiom_xml_reader_cleanup using
+ * axis2_options_set_xml_parser_reset function in client API.
+ * refer to jira issue: https://issues.apache.org/jira/browse/AXIS2C-884
+ */
+void AXIS2_CALL
+axis2_libxml2_reader_wrapper_free(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ if(parser_impl->ctx)
+ {
+ AXIS2_FREE(env->allocator, parser_impl->ctx);
+ }
+
+ if(parser_impl->reader)
+ {
+ xmlTextReaderClose(parser_impl->reader);
+ xmlFreeTextReader(parser_impl->reader);
+ }
+ if(parser_impl->namespace_map)
+ {
+ AXIS2_FREE(env->allocator, parser_impl->namespace_map);
+ parser_impl->namespace_map = NULL;
+ }
+ if(parser_impl->attribute_map)
+ {
+ AXIS2_FREE(env->allocator, parser_impl->attribute_map);
+ parser_impl->attribute_map = NULL;
+ }
+ AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(parser));
+ return;
+}
+
+int AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_count(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ if(parser_impl->current_event == AXIOM_XML_READER_START_ELEMENT || parser_impl->current_event
+ == AXIOM_XML_READER_EMPTY_ELEMENT)
+ {
+ return parser_impl->current_attribute_count;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_name_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl;
+ AXIS2_ENV_CHECK(env, NULL);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+
+ if(parser_impl->current_attribute_count > 0 && parser_impl->current_attribute_count >= i)
+ {
+ int ret =
+ xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->attribute_map[i]);
+ if(ret == 1)
+ {
+ return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader);
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_prefix_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ AXIS2_ENV_CHECK(env, NULL);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+
+ if(parser_impl->current_attribute_count > 0 && parser_impl->current_attribute_count >= i)
+ {
+ int ret =
+ xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->attribute_map[i]);
+ if(ret == 1)
+ {
+ return (axis2_char_t *)xmlTextReaderPrefix(parser_impl->reader);
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_value_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i)
+{
+
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl;
+ AXIS2_ENV_CHECK(env, NULL);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+
+ if(parser_impl->current_attribute_count > 0 && parser_impl->current_attribute_count >= i)
+ {
+ int ret =
+ xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->attribute_map[i]);
+ if(ret == 1)
+ {
+ return (axis2_char_t *)xmlTextReaderValue(parser_impl->reader);
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_attribute_namespace_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl;
+ AXIS2_ENV_CHECK(env, NULL);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+
+ if(parser_impl->current_attribute_count > 0 && parser_impl->current_attribute_count >= i)
+ {
+ int ret =
+ xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->attribute_map[i]);
+
+ if(ret == 1)
+ {
+ return (axis2_char_t *)xmlTextReaderNamespaceUri(parser_impl-> reader);
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_value(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+
+ AXIS2_ENV_CHECK(env, NULL);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ return (axis2_char_t *)xmlTextReaderValue(parser_impl->reader);
+
+}
+
+int AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_namespace_count(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ if(parser_impl->current_event == AXIOM_XML_READER_START_ELEMENT || parser_impl->current_event
+ == AXIOM_XML_READER_EMPTY_ELEMENT)
+ {
+ return parser_impl->current_namespace_count;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_namespace_uri_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ AXIS2_ENV_CHECK(env, NULL);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+
+ if(parser_impl->current_namespace_count > 0 && parser_impl->current_namespace_count >= i)
+ {
+
+ int ret =
+ xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->namespace_map[i]);
+ if(ret == 1)
+ {
+ return (axis2_char_t *)xmlTextReaderValue(parser_impl->reader);
+ }
+ else
+ return NULL;
+ }
+ return NULL;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_namespace_prefix_by_number(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ int i)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ AXIS2_ENV_CHECK(env, NULL);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+
+ if(parser_impl->current_namespace_count > 0 && parser_impl->current_namespace_count >= i)
+ {
+ int ret =
+ xmlTextReaderMoveToAttributeNo(parser_impl->reader, parser_impl->namespace_map[i]);
+
+ if(ret == 1)
+ {
+ return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader);
+ }
+ else
+ {
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_prefix(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ xmlTextReaderMoveToElement(parser_impl->reader);
+ return (axis2_char_t *)xmlTextReaderPrefix(parser_impl->reader);
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_name(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ xmlTextReaderMoveToElement(parser_impl->reader);
+ return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader);
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_pi_target(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ if(parser_impl->current_event == AXIOM_XML_READER_PROCESSING_INSTRUCTION)
+ {
+ return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader);
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_dtd(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ if(parser_impl->current_event == AXIOM_XML_READER_DOCUMENT_TYPE)
+ {
+ return (axis2_char_t *)xmlTextReaderLocalName(parser_impl->reader);
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_pi_data(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ if(parser_impl->current_event == AXIOM_XML_READER_PROCESSING_INSTRUCTION)
+ {
+ return (axis2_char_t *)xmlTextReaderValue(parser_impl->reader);
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+void AXIS2_CALL
+axis2_libxml2_reader_wrapper_xml_free(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ void *data)
+{
+ AXIS2_ENV_CHECK(env, void);
+ if(data)
+ xmlFree(data);
+ return;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_char_set_encoding(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *reader_impl = NULL;
+ reader_impl = AXIS2_INTF_TO_IMPL(parser);
+ return (axis2_char_t *)xmlTextReaderConstEncoding(reader_impl->reader);
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_namespace_uri(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ return (axis2_char_t *)xmlTextReaderNamespaceUri(parser_impl->reader);
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_reader_wrapper_get_namespace_uri_by_prefix(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env,
+ axis2_char_t * prefix)
+{
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+ if(!prefix || axutil_strcmp(prefix, "") == 0)
+ {
+ return NULL;
+ }
+ return (axis2_char_t *)xmlTextReaderLookupNamespace(parser_impl->reader,
+ (const xmlChar *)prefix);
+}
+
+axis2_status_t
+axis2_libxml2_reader_wrapper_fill_maps(
+ axiom_xml_reader_t * parser,
+ const axutil_env_t * env)
+{
+ int libxml2_attribute_count = 0;
+ int attr_count = 0;
+ int ns_count = 0;
+ int i = 0;
+ char *q_name = NULL;
+ axis2_libxml2_reader_wrapper_impl_t *parser_impl = NULL;
+ int map_size = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ parser_impl = AXIS2_INTF_TO_IMPL(parser);
+
+ libxml2_attribute_count = xmlTextReaderAttributeCount(parser_impl->reader);
+ if(libxml2_attribute_count == 0)
+ {
+ parser_impl->current_attribute_count = 0;
+ parser_impl->current_namespace_count = 0;
+ return AXIS2_SUCCESS;
+ }
+ map_size = libxml2_attribute_count + 1;
+ if(parser_impl->namespace_map)
+ {
+ AXIS2_FREE(env->allocator, parser_impl->namespace_map);
+ parser_impl->namespace_map = NULL;
+ }
+ if(parser_impl->attribute_map)
+ {
+ AXIS2_FREE(env->allocator, parser_impl->attribute_map);
+ parser_impl->attribute_map = NULL;
+ }
+ parser_impl->attribute_map = AXIS2_MALLOC(env->allocator, sizeof(int) * map_size);
+ memset(parser_impl->attribute_map, 0, map_size * sizeof(int));
+
+ parser_impl->namespace_map = AXIS2_MALLOC(env->allocator, sizeof(int) * map_size);
+ memset(parser_impl->namespace_map, 0, map_size * sizeof(int));
+
+ for(i = 0; i < map_size; i++)
+ {
+ parser_impl->namespace_map[i] = -1;
+ parser_impl->attribute_map[i] = -1;
+ }
+
+ for(i = 0; i < libxml2_attribute_count; i++)
+ {
+ xmlTextReaderMoveToAttributeNo(parser_impl->reader, i);
+ q_name = (char *)xmlTextReaderName(parser_impl->reader);
+ if(q_name)
+ {
+ if((strcmp(q_name, "xmlns") == 0) || (strncmp(q_name, "xmlns:", 6) == 0))
+ {
+ /* found a namespace */
+ ns_count++;
+ parser_impl->namespace_map[ns_count] = i;
+ }
+ else
+ {
+ /* found an attribute */
+ attr_count++;
+ parser_impl->attribute_map[attr_count] = i;
+ }
+
+ xmlFree(q_name);
+ q_name = NULL;
+ }
+
+ parser_impl->current_attribute_count = attr_count;
+ parser_impl->current_namespace_count = ns_count;
+ }
+ return AXIS2_SUCCESS;
+}
+
+static int
+axis2_libxml2_reader_wrapper_read_input_callback(
+ void *ctx,
+ char *buffer,
+ int size)
+{
+ return ((axis2_libxml2_reader_wrapper_impl_t *)ctx)-> read_input_callback(buffer, size,
+ ((axis2_libxml2_reader_wrapper_impl_t *)ctx)->ctx);
+}
+
+void
+axis2_libxml2_reader_wrapper_error_handler(
+ void *arg,
+ const char *msg,
+ int severities,
+ void *locator_ptr)
+{
+ const axutil_env_t *env = NULL;
+ env = (const axutil_env_t *)arg;
+
+ switch(severities)
+ {
+ case XML_PARSER_SEVERITY_VALIDITY_WARNING:
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s VALIDITY WARNTING", msg);
+ }
+ break;
+ case XML_PARSER_SEVERITY_VALIDITY_ERROR:
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s -- VALIDITY ERROR", msg);
+ }
+ break;
+ case XML_PARSER_SEVERITY_WARNING:
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s -- VALIDITY ERROR", msg);
+ }
+ break;
+ case XML_PARSER_SEVERITY_ERROR:
+ {
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "%s -- SEVERITY_ERROR", msg);
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+static int
+axis2_libxml2_reader_wrapper_close_input_callback(
+ void *ctx)
+{
+ return ((axis2_libxml2_reader_wrapper_impl_t *)ctx)-> close_input_callback(
+ ((axis2_libxml2_reader_wrapper_impl_t *)ctx)-> ctx);
+}
diff --git a/axiom/src/parser/libxml2/libxml2_writer_wrapper.c b/axiom/src/parser/libxml2/libxml2_writer_wrapper.c
new file mode 100644
index 0000000..4c889d4
--- /dev/null
+++ b/axiom/src/parser/libxml2/libxml2_writer_wrapper.c
@@ -0,0 +1,1571 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <libxml/xmlwriter.h>
+#include <axutil_utils.h>
+#include <axutil_utils_defines.h>
+#include <axutil_env.h>
+#include <axiom_xml_writer.h>
+#include <axutil_string.h>
+#include <string.h>
+#include <axutil_stack.h>
+#include <axutil_hash.h>
+#include <axutil_array_list.h>
+
+/*******************************************************************************/
+
+#define ENCODING "ISO-8859-1"
+
+#define AXIS2_XMLNS_NAMESPACE_URI "http://www.w3.org/XML/1998/namespace"
+#define AXIS2_XMLNS_PREFIX "xml"
+
+typedef struct uri_prefix_element
+{
+ axis2_char_t *prefix;
+
+ axis2_char_t *uri;
+
+ axis2_char_t *real_prefix;
+
+ axis2_char_t *key;
+
+} uri_prefix_element_t;
+
+typedef struct axis2_libxml2_writer_wrapper_impl
+{
+ axiom_xml_writer_t writer;
+
+ xmlTextWriterPtr xml_writer;
+
+ xmlBufferPtr buffer;
+
+ xmlDocPtr doc;
+
+ int writer_type;
+
+ axis2_char_t *encoding;
+
+ int is_prefix_defaulting;
+
+ int compression;
+
+ axutil_stack_t *stack;
+
+ axis2_bool_t in_empty_element;
+
+ axis2_bool_t in_start_element;
+
+ axutil_hash_t *uri_prefix_map;
+
+ uri_prefix_element_t *default_lang_namespace;
+
+} axis2_libxml2_writer_wrapper_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(p) ((axis2_libxml2_writer_wrapper_impl_t*)p)
+
+void AXIS2_CALL axis2_libxml2_writer_wrapper_free(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_element(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_end_start_element(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_element_with_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * namespace_uri);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * namespace_uri,
+ axis2_char_t * prefix);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_empty_element(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_empty_element_with_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * namespace_uri);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * namespace_uri,
+ axis2_char_t * prefix);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_end_element(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_end_document(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_attribute(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * value);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_attribute_with_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * value,
+ axis2_char_t * namespace_uri);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * value,
+ axis2_char_t * namespace_uri,
+ axis2_char_t * prefix);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * prefix,
+ axis2_char_t * namespace_uri);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_default_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * namespace_uri);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_comment(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * value);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_processing_instruction(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * target);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_processing_instruction_data(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * target,
+ axis2_char_t * data);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_cdata(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * data);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_dtd(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * dtd);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_entity_ref(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * name);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_document(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_document_with_version(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * version);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * encoding,
+ axis2_char_t * version);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_characters(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * text);
+
+axis2_char_t *AXIS2_CALL axis2_libxml2_writer_wrapper_get_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * uri);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_set_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * prefix,
+ axis2_char_t * uri);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_set_default_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * uri);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_encoded(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * text,
+ int in_attr);
+
+void *AXIS2_CALL axis2_libxml2_writer_wrapper_get_xml(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+unsigned int AXIS2_CALL axis2_libxml2_writer_wrapper_get_xml_size(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_flush(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+int AXIS2_CALL axis2_libxml2_writer_wrapper_get_type(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_raw(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * content);
+
+static axis2_status_t
+axis2_libxml2_writer_wrapper_push(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ const axis2_char_t * uri,
+ const axis2_char_t * prefix);
+
+static axis2_bool_t
+axis2_libxml2_writer_wrapper_is_namespace_declared(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * key);
+
+static void
+uri_prefix_element_free(
+ uri_prefix_element_t * up_element,
+ const axutil_env_t * env);
+
+static uri_prefix_element_t *
+uri_prefix_element_create(
+ const axutil_env_t * env,
+ const axis2_char_t * uri,
+ const axis2_char_t * prefix,
+ const axis2_char_t * real_prefix,
+ const axis2_char_t * key);
+
+static void
+create_key_from_uri_prefix(
+ const axutil_env_t * env,
+ const axis2_char_t * uri,
+ const axis2_char_t * prefix,
+ axis2_char_t * array);
+
+static axis2_char_t *
+axis2_libxml2_writer_wrapper_find_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * uri);
+
+static uri_prefix_element_t *
+axis2_libxml2_writer_wrapper_find_prefix_in_context(
+ axutil_array_list_t * context,
+ const axutil_env_t * env,
+ axis2_char_t * uri);
+
+static const axiom_xml_writer_ops_t axiom_xml_writer_ops_var = { axis2_libxml2_writer_wrapper_free,
+ axis2_libxml2_writer_wrapper_write_start_element,
+ axis2_libxml2_writer_wrapper_end_start_element,
+ axis2_libxml2_writer_wrapper_write_start_element_with_namespace,
+ axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix,
+ axis2_libxml2_writer_wrapper_write_empty_element,
+ axis2_libxml2_writer_wrapper_write_empty_element_with_namespace,
+ axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix,
+ axis2_libxml2_writer_wrapper_write_end_element,
+ axis2_libxml2_writer_wrapper_write_end_document, axis2_libxml2_writer_wrapper_write_attribute,
+ axis2_libxml2_writer_wrapper_write_attribute_with_namespace,
+ axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix,
+ axis2_libxml2_writer_wrapper_write_namespace,
+ axis2_libxml2_writer_wrapper_write_default_namespace,
+ axis2_libxml2_writer_wrapper_write_comment,
+ axis2_libxml2_writer_wrapper_write_processing_instruction,
+ axis2_libxml2_writer_wrapper_write_processing_instruction_data,
+ axis2_libxml2_writer_wrapper_write_cdata, axis2_libxml2_writer_wrapper_write_dtd,
+ axis2_libxml2_writer_wrapper_write_entity_ref,
+ axis2_libxml2_writer_wrapper_write_start_document,
+ axis2_libxml2_writer_wrapper_write_start_document_with_version,
+ axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding,
+ axis2_libxml2_writer_wrapper_write_characters, axis2_libxml2_writer_wrapper_get_prefix,
+ axis2_libxml2_writer_wrapper_set_prefix, axis2_libxml2_writer_wrapper_set_default_prefix,
+ axis2_libxml2_writer_wrapper_write_encoded, axis2_libxml2_writer_wrapper_get_xml,
+ axis2_libxml2_writer_wrapper_get_xml_size, axis2_libxml2_writer_wrapper_get_type,
+ axis2_libxml2_writer_wrapper_write_raw, axis2_libxml2_writer_wrapper_flush };
+
+AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL
+axiom_xml_writer_create(
+ const axutil_env_t * env,
+ axis2_char_t * filename,
+ axis2_char_t * encoding,
+ int is_prefix_default,
+ int compression)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ AXIS2_ENV_CHECK(env, NULL);
+ writer_impl = (axis2_libxml2_writer_wrapper_impl_t *)AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_libxml2_writer_wrapper_impl_t));
+ if(!writer_impl)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create an XML writer wrapper");
+ return NULL;
+ }
+ writer_impl->xml_writer = xmlNewTextWriterFilename(filename, compression);
+
+ if(!(writer_impl->xml_writer))
+ {
+ AXIS2_FREE(env->allocator, writer_impl);
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_WRITER, AXIS2_FAILURE);
+ return NULL;
+ }
+ writer_impl->buffer = NULL;
+ writer_impl->encoding = NULL;
+ writer_impl->compression = 0;
+ writer_impl->in_empty_element = AXIS2_FALSE;
+ writer_impl->in_start_element = AXIS2_FALSE;
+ writer_impl->stack = NULL;
+ writer_impl->uri_prefix_map = NULL;
+ writer_impl->default_lang_namespace = NULL;
+
+ writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_FILE;
+ writer_impl->compression = compression;
+
+ if(encoding)
+ {
+ writer_impl->encoding = axutil_strdup(env, encoding);
+ }
+ else
+ {
+ writer_impl->encoding = axutil_strdup(env, ENCODING);
+ }
+
+ writer_impl->uri_prefix_map = axutil_hash_make(env);
+ if(!(writer_impl->uri_prefix_map))
+ {
+ axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create URI prefix hash map");
+ return NULL;
+ }
+ writer_impl->writer.ops = &axiom_xml_writer_ops_var;
+ return &(writer_impl->writer);
+}
+
+AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL
+axiom_xml_writer_create_for_memory(
+ const axutil_env_t * env,
+ axis2_char_t * encoding,
+ int is_prefix_default,
+ int compression,
+ int type)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ AXIS2_ENV_CHECK(env, NULL);
+ writer_impl = (axis2_libxml2_writer_wrapper_impl_t *)AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_libxml2_writer_wrapper_impl_t));
+ if(!writer_impl)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create writer wrapper");
+ return NULL;
+ }
+
+ writer_impl->encoding = NULL;
+ writer_impl->buffer = NULL;
+ writer_impl->doc = NULL;
+ writer_impl->in_empty_element = AXIS2_FALSE;
+ writer_impl->in_start_element = AXIS2_FALSE;
+ writer_impl->stack = NULL;
+ writer_impl->uri_prefix_map = NULL;
+ writer_impl->default_lang_namespace = NULL;
+ writer_impl->compression = compression;
+
+ if(AXIS2_XML_PARSER_TYPE_BUFFER == type)
+ {
+ writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_BUFFER;
+ writer_impl->buffer = xmlBufferCreate();
+ if(!(writer_impl->buffer))
+ {
+ axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Cannot create a buffer for writer wrapper");
+ return NULL;
+ }
+
+ writer_impl->xml_writer = xmlNewTextWriterMemory(writer_impl->buffer, 0);
+ }
+ else if(AXIS2_XML_PARSER_TYPE_DOC == type)
+ {
+ writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_DOC;
+ writer_impl->xml_writer = xmlNewTextWriterDoc(&writer_impl->doc, 0);
+ }
+ else
+ {
+ axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_XML_PARSER_INVALID_MEM_TYPE, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ if(!(writer_impl->xml_writer))
+ {
+ axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_WRITER, AXIS2_FAILURE);
+ return NULL;
+ }
+
+ if(encoding)
+ {
+ writer_impl->encoding = axutil_strdup(env, encoding);
+ }
+ else
+ {
+ writer_impl->encoding = axutil_strdup(env, ENCODING);
+ }
+
+ writer_impl->uri_prefix_map = axutil_hash_make(env);
+ if(!(writer_impl->uri_prefix_map))
+ {
+ axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create URI prefix hash map");
+ return NULL;
+ }
+ writer_impl->stack = axutil_stack_create(env);
+ if(!(writer_impl->stack))
+ {
+ axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+ "No memory. Cannot create the stack for writer wrapper");
+ return NULL;
+ }
+
+ writer_impl->writer.ops = &axiom_xml_writer_ops_var;
+
+ return &(writer_impl->writer);
+}
+
+void AXIS2_CALL
+axis2_libxml2_writer_wrapper_free(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ if(writer_impl->xml_writer)
+ {
+ xmlFreeTextWriter(writer_impl->xml_writer);
+ writer_impl->xml_writer = NULL;
+ }
+ if(writer_impl->buffer)
+ {
+ xmlBufferFree(writer_impl->buffer);
+ writer_impl->buffer = NULL;
+ }
+ if(writer_impl->encoding)
+ {
+ AXIS2_FREE(env->allocator, writer_impl->encoding);
+ writer_impl->encoding = NULL;
+ }
+ if(writer_impl->uri_prefix_map)
+ {
+ axutil_hash_free(writer_impl->uri_prefix_map, env);
+ writer_impl->uri_prefix_map = NULL;
+ }
+ if(writer_impl->stack)
+ {
+ axutil_stack_free(writer_impl->stack, env);
+ writer_impl->stack = NULL;
+ }
+ if(writer_impl->default_lang_namespace)
+ {
+ uri_prefix_element_free(writer_impl->default_lang_namespace, env);
+ writer_impl->default_lang_namespace = NULL;
+ }
+
+ AXIS2_FREE(env->allocator, writer_impl);
+ writer_impl = NULL;
+ return;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_element(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname)
+{
+ int status = 0;
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ writer_impl->in_start_element = AXIS2_TRUE;
+
+ status = xmlTextWriterStartElement(writer_impl->xml_writer, (xmlChar *)localname);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_ELEMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_end_start_element(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ /* nothing to do ,
+ it is automatically taken care by the libxml2 writer */
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_element_with_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * namespace_uri)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ status = xmlTextWriterStartElementNS(writer_impl->xml_writer,
+ NULL, BAD_CAST localname, NULL);
+
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_element_with_namespace_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * namespace_uri,
+ axis2_char_t * prefix)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ writer_impl->in_start_element = AXIS2_TRUE;
+
+ status = xmlTextWriterStartElementNS(writer_impl->xml_writer,
+ BAD_CAST prefix,
+ BAD_CAST localname, BAD_CAST NULL);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE_PREFIX,
+ AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_empty_element(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname)
+{
+ int status = 0;
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ status = xmlTextWriterStartElement(writer_impl->xml_writer, (xmlChar *)localname);
+
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ status = xmlTextWriterEndElement(writer_impl->xml_writer);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_empty_element_with_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * namespace_uri)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ status = xmlTextWriterStartElementNS(writer_impl->xml_writer,
+ NULL, BAD_CAST localname,
+ BAD_CAST namespace_uri);
+
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ status = xmlTextWriterEndElement(writer_impl->xml_writer);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_empty_element_with_namespace_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * namespace_uri,
+ axis2_char_t * prefix)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ status = xmlTextWriterStartElementNS(writer_impl->xml_writer,
+ BAD_CAST prefix,
+ BAD_CAST localname, BAD_CAST NULL);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_ELEMENT_WITH_NAMESPACE_PREFIX,
+ AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ status = xmlTextWriterEndElement(writer_impl->xml_writer);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_EMPTY_ELEMENT_WITH_NAMESPACE_PREFIX,
+ AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_end_element(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ writer_impl->in_start_element = AXIS2_FALSE;
+ /* write an empty element in case the element is empty,
+ status = xmlTextWriterFullEndElement(writer_impl->xml_writer);
+ Above call write it like <a></a>.
+ Call below will write it like <a/> */
+ status = xmlTextWriterEndElement(writer_impl->xml_writer);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_END_ELEMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_end_document(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterEndDocument(writer_impl->xml_writer);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_END_DOCUMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_attribute(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * value)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ if(!value)
+ {
+ value = "";
+ }
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterWriteAttribute(writer_impl->xml_writer,
+ BAD_CAST localname, BAD_CAST value);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_attribute_with_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * value,
+ axis2_char_t * namespace_uri)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE);
+
+ if(!value)
+ {
+ value = "";
+ }
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterWriteAttributeNS(writer_impl->xml_writer,
+ NULL, BAD_CAST localname,
+ BAD_CAST NULL, BAD_CAST value);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_attribute_with_namespace_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * localname,
+ axis2_char_t * value,
+ axis2_char_t * namespace_uri,
+ axis2_char_t * prefix)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, localname, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE);
+
+ if(!value)
+ {
+ value = "";
+ }
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterWriteAttributeNS(writer_impl->xml_writer,
+ BAD_CAST prefix, BAD_CAST localname,
+ BAD_CAST NULL, BAD_CAST value);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE_PREFIX, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+/** need to work on this */
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * prefix,
+ axis2_char_t * namespace_uri)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ char *xmlnsprefix = NULL;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ if(prefix && (axutil_strcmp(prefix, "") != 0))
+ {
+ xmlnsprefix = (axis2_char_t *)AXIS2_MALLOC(env->allocator, (sizeof(char) * (axutil_strlen(
+ prefix) + 7)));
+ sprintf(xmlnsprefix, "xmlns:%s", prefix);
+ }
+ else
+ {
+ xmlnsprefix = axutil_strdup(env, "xmlns");
+ }
+
+ status = xmlTextWriterWriteAttribute(writer_impl->xml_writer,
+ BAD_CAST xmlnsprefix,
+ BAD_CAST namespace_uri);
+ AXIS2_FREE(env->allocator, xmlnsprefix);
+ xmlnsprefix = NULL;
+
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_ATTRIBUTE_WITH_NAMESPACE_PREFIX, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+
+ AXIS2_FREE(env->allocator, xmlnsprefix);
+ xmlnsprefix = NULL;
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_default_namespace(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * namespace_uri)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ axis2_char_t *xmlns = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, namespace_uri, AXIS2_FAILURE)
+ xmlns = AXIS2_MALLOC(env->allocator,
+ sizeof(axis2_char_t) * (strlen("xmlns") + 1));
+ sprintf(xmlns, "xmlns");
+ status = xmlTextWriterWriteAttribute(writer_impl->xml_writer,
+ (const xmlChar *) xmlns,
+ BAD_CAST namespace_uri);
+
+ if(xmlns)
+ {
+ AXIS2_FREE(env->allocator, xmlns);
+ xmlns = NULL;
+ }
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_DEFAULT_NAMESPACE, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_comment(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * value)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, value, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterWriteComment(writer_impl->xml_writer, BAD_CAST value);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_COMMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_processing_instruction(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * target)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, target, AXIS2_FAILURE);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ status = xmlTextWriterStartPI(writer_impl->xml_writer, BAD_CAST target);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_PROCESSING_INSTRUCTION, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_processing_instruction_data(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * target,
+ axis2_char_t * data)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, target, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ status = xmlTextWriterWritePI(writer_impl->xml_writer,
+ BAD_CAST target, BAD_CAST data);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_PROCESSING_INSTRUCTION, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_cdata(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * data)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, data, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ status = xmlTextWriterWriteCDATA(writer_impl->xml_writer, BAD_CAST data);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_CDATA, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_dtd(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * dtd)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, dtd, AXIS2_FAILURE);
+
+ status = xmlTextWriterStartDTD(writer_impl->xml_writer,
+ BAD_CAST dtd, NULL, NULL);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_DTD, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_entity_ref(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * name)
+{
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, name, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_document(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_writer_wrapper_impl_t *wrapper_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ wrapper_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterStartDocument(wrapper_impl->xml_writer, NULL, NULL, NULL);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_document_with_version(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * version)
+{
+ axis2_libxml2_writer_wrapper_impl_t *wrapper_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, version, AXIS2_FAILURE);
+
+ wrapper_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterStartDocument(wrapper_impl->xml_writer, version, NULL, NULL);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_start_document_with_version_encoding(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * encoding,
+ axis2_char_t * version)
+{
+ axis2_libxml2_writer_wrapper_impl_t *wrapper_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+
+ wrapper_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterStartDocument(wrapper_impl->xml_writer, version, encoding, NULL);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_characters(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * text)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, text, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ status = xmlTextWriterWriteString(writer_impl->xml_writer, BAD_CAST text);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_START_DOCUMENT, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}
+
+axis2_char_t *AXIS2_CALL
+axis2_libxml2_writer_wrapper_get_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * uri)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ AXIS2_PARAM_CHECK(env->error, uri, NULL);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ if(!uri || axutil_strcmp(uri, "") == 0)
+ {
+ return NULL;
+ }
+ return axis2_libxml2_writer_wrapper_find_prefix(writer, env, uri);
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_set_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * prefix,
+ axis2_char_t * uri)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+
+ axis2_bool_t is_declared = AXIS2_FALSE;
+ axis2_char_t key[1024];
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, prefix, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, uri, AXIS2_FAILURE);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ if(axutil_strcmp(uri, "") == 0)
+ {
+ return AXIS2_FAILURE;
+ }
+
+ create_key_from_uri_prefix(env, uri, prefix, key);
+
+ is_declared = axis2_libxml2_writer_wrapper_is_namespace_declared(writer, env, key);
+ if(!is_declared)
+ {
+ return axis2_libxml2_writer_wrapper_push(writer, env, uri, prefix);
+ }
+ return AXIS2_FAILURE;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_set_default_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * uri)
+{
+ axis2_bool_t is_declared = AXIS2_FALSE;
+
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, uri, AXIS2_FAILURE);
+ if(axutil_strcmp(uri, "") == 0)
+ {
+ return AXIS2_FAILURE;
+ }
+ is_declared = axis2_libxml2_writer_wrapper_is_namespace_declared(writer, env, uri);
+ if(!is_declared)
+ {
+ return axis2_libxml2_writer_wrapper_push(writer, env, uri, NULL);
+ }
+ return AXIS2_FAILURE;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_encoded(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * text,
+ int in_attr)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, text, AXIS2_FAILURE);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ return AXIS2_FAILURE;
+}
+
+void *AXIS2_CALL
+axis2_libxml2_writer_wrapper_get_xml(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ if(writer_impl->writer_type == AXIS2_XML_PARSER_TYPE_BUFFER)
+ {
+ int output_bytes = 0;
+ output_bytes = xmlTextWriterFlush(writer_impl->xml_writer);
+ return writer_impl->buffer->content;
+ }
+ else if(writer_impl->writer_type == AXIS2_XML_PARSER_TYPE_DOC)
+ {
+ return (void *)writer_impl->doc;
+ }
+ else if(writer_impl->writer_type == AXIS2_XML_PARSER_TYPE_FILE)
+ {
+ return NULL;
+ }
+
+ return NULL;
+}
+
+unsigned int AXIS2_CALL
+axis2_libxml2_writer_wrapper_get_xml_size(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ if(writer_impl->writer_type == AXIS2_XML_PARSER_TYPE_BUFFER)
+ {
+ return writer_impl->buffer->use;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_flush(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ if(writer_impl->xml_writer)
+ {
+ int ret = 0;
+ ret = xmlTextWriterFlush(writer_impl->xml_writer);
+ if(ret > -1)
+ return AXIS2_SUCCESS;
+ }
+
+ return AXIS2_FAILURE;
+}
+
+int AXIS2_CALL
+axis2_libxml2_writer_wrapper_get_type(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ return writer_impl->writer_type;
+}
+
+static axis2_status_t
+axis2_libxml2_writer_wrapper_push(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ const axis2_char_t * uri,
+ const axis2_char_t * prefix)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ axutil_array_list_t *current_list = NULL;
+ axis2_char_t key[1024];
+ const axis2_char_t *temp_prefix = NULL;
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ if(!prefix || axutil_strcmp(prefix, "") == 0)
+ {
+ temp_prefix = "default";
+ }
+ else
+ {
+ temp_prefix = prefix;
+ }
+
+ if(writer_impl->stack)
+ {
+ current_list = (axutil_array_list_t *)axutil_stack_get(writer_impl->stack, env);
+
+ if(current_list)
+ {
+ uri_prefix_element_t *ele = NULL;
+ create_key_from_uri_prefix(env, uri, prefix, key);
+
+ ele = uri_prefix_element_create(env, uri, temp_prefix, prefix, key);
+ if(ele)
+ {
+ axutil_array_list_add(current_list, env, ele);
+ axutil_hash_set(writer_impl->uri_prefix_map, ele->key, AXIS2_HASH_KEY_STRING,
+ ele->prefix);
+ }
+ }
+ }
+ return AXIS2_SUCCESS;
+}
+
+static axis2_bool_t
+axis2_libxml2_writer_wrapper_is_namespace_declared(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * key)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ AXIS2_ENV_CHECK(env, AXIS2_FALSE);
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ if(writer_impl->uri_prefix_map && NULL != key)
+ {
+ void *ret = NULL;
+ ret = axutil_hash_get(writer_impl->uri_prefix_map, key, AXIS2_HASH_KEY_STRING);
+ if(ret)
+ {
+ return AXIS2_TRUE;
+ }
+ }
+ return AXIS2_FALSE;
+}
+
+static void
+uri_prefix_element_free(
+ uri_prefix_element_t * up_element,
+ const axutil_env_t * env)
+{
+ if(up_element)
+ {
+ if(up_element->uri)
+ {
+ AXIS2_FREE(env->allocator, up_element->uri);
+ up_element->uri = NULL;
+ }
+ if(up_element->prefix)
+ {
+ AXIS2_FREE(env->allocator, up_element->prefix);
+ up_element->prefix = NULL;
+ }
+ if(up_element->key)
+ {
+ AXIS2_FREE(env->allocator, up_element->key);
+ up_element->key = NULL;
+ }
+ if(up_element->real_prefix)
+ {
+ AXIS2_FREE(env->allocator, up_element->real_prefix);
+ up_element->real_prefix = NULL;
+ }
+ AXIS2_FREE(env->allocator, up_element);
+ up_element = NULL;
+ }
+ return;
+}
+
+static uri_prefix_element_t *
+uri_prefix_element_create(
+ const axutil_env_t * env,
+ const axis2_char_t * uri,
+ const axis2_char_t * prefix,
+ const axis2_char_t * real_prefix,
+ const axis2_char_t * key)
+{
+ uri_prefix_element_t *up_element = NULL;
+ up_element = (uri_prefix_element_t *)AXIS2_MALLOC(env->allocator, sizeof(uri_prefix_element_t));
+
+ if(!uri)
+ {
+ return NULL;
+ }
+
+ if(!up_element)
+ {
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create URI prefix element %s",
+ uri);
+ return NULL;
+ }
+ up_element->key = NULL;
+ up_element->prefix = NULL;
+ up_element->uri = NULL;
+ up_element->real_prefix = NULL;
+
+ up_element->uri = axutil_strdup(env, uri);
+ if(!up_element->uri)
+ {
+ uri_prefix_element_free(up_element, env);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+ up_element->prefix = axutil_strdup(env, prefix);
+ if(prefix && !up_element->prefix)
+ {
+ uri_prefix_element_free(up_element, env);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+ up_element->key = axutil_strdup(env, key);
+ if(key && !up_element->key)
+ {
+ uri_prefix_element_free(up_element, env);
+ AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+ return NULL;
+ }
+ up_element->real_prefix = axutil_strdup(env, real_prefix);
+
+ return up_element;
+}
+
+static void
+create_key_from_uri_prefix(
+ const axutil_env_t * env,
+ const axis2_char_t * uri,
+ const axis2_char_t * prefix,
+ axis2_char_t * array)
+{
+ if(!prefix)
+ {
+ prefix = "";
+ }
+ sprintf(array, "%s%s%s", uri, "|", prefix);
+}
+
+static axis2_char_t *
+axis2_libxml2_writer_wrapper_find_prefix(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * uri)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int size = 0;
+ int i = 0;
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+
+ if(!writer_impl->stack)
+ {
+ return NULL;
+ }
+ size = axutil_stack_size(writer_impl->stack, env);
+ if(size <= 0)
+ {
+ return NULL;
+ }
+
+ for(i = size - 1; i < 0; i--)
+ {
+ axutil_array_list_t *context = NULL;
+ void *value = NULL;
+ value = axutil_stack_get_at(writer_impl->stack, env, i);
+ if(value)
+ {
+ uri_prefix_element_t *up_ele = NULL;
+ context = (axutil_array_list_t *)value;
+ up_ele = axis2_libxml2_writer_wrapper_find_prefix_in_context(context, env, uri);
+ if(up_ele)
+ {
+ return up_ele->real_prefix;
+ }
+ }
+ }
+ return NULL;
+}
+
+static uri_prefix_element_t *
+axis2_libxml2_writer_wrapper_find_prefix_in_context(
+ axutil_array_list_t * context,
+ const axutil_env_t * env,
+ axis2_char_t * uri)
+{
+ int size = 0;
+ int i = 0;
+ if(!context)
+ {
+ return NULL;
+ }
+ size = axutil_array_list_size(context, env);
+ for(i = 0; i < size; i++)
+ {
+ uri_prefix_element_t *ele = NULL;
+ void *value = NULL;
+ value = axutil_array_list_get(context, env, i);
+ if(value)
+ {
+ ele = (uri_prefix_element_t *)value;
+ if(ele->uri && axutil_strcmp(uri, ele->uri))
+ {
+ return ele;
+ }
+ }
+ }
+ return NULL;
+}
+
+axis2_status_t AXIS2_CALL
+axis2_libxml2_writer_wrapper_write_raw(
+ axiom_xml_writer_t * writer,
+ const axutil_env_t * env,
+ axis2_char_t * content)
+{
+ axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
+ int status = 0;
+ AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+ AXIS2_PARAM_CHECK(env->error, content, AXIS2_FAILURE);
+
+ writer_impl = AXIS2_INTF_TO_IMPL(writer);
+ status = xmlTextWriterWriteRaw(writer_impl->xml_writer, BAD_CAST content);
+ if(status < 0)
+ {
+ AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_WRITING_DATA_SOURCE, AXIS2_FAILURE);
+ return AXIS2_FAILURE;
+ }
+ return AXIS2_SUCCESS;
+}