<commit_before>/*
 * 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_text.h>
#include <axiom_output.h>
#include <axutil_string.h>
#include "axiom_node_internal.h"
#include <axiom_xml_writer.h>
#include <axiom_output.h>
#include <axiom_attribute.h>
#include <axiom_namespace.h>
#include <axutil_base64.h>

static axis2_bool_t AXIS2_CALL
axiom_text_get_is_binary(axiom_text_t *om_text,
    const axutil_env_t *env);

static axis2_status_t AXIS2_CALL
axiom_text_serialize_start_part(axiom_text_t *om_text,
    const axutil_env_t *env,
    axiom_output_t *om_output);

struct axiom_text
{
    /** Text value */
    axutil_string_t *value;
    /** The following fields are for MTOM */
    axis2_char_t *mime_type;
    axis2_bool_t optimize;
    const axis2_char_t *localname;
    axis2_bool_t is_binary;
    axis2_char_t *content_id;
    axiom_attribute_t *om_attribute;
    axiom_namespace_t *ns;
    axiom_data_handler_t *data_handler;
};

AXIS2_EXTERN axiom_text_t *AXIS2_CALL
axiom_text_create(const axutil_env_t *env,
    axiom_node_t * parent,
    const axis2_char_t * value,
    axiom_node_t **node)
{
    axiom_text_t *om_text = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, node, NULL);

    *node = axiom_node_create(env);

    if (!(*node))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }
    om_text = (axiom_text_t *) AXIS2_MALLOC(env->allocator,
        sizeof(axiom_text_t));
    if (!om_text)
    {
        AXIS2_FREE(env->allocator, *node);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    om_text->mime_type = NULL;
    om_text->optimize = AXIS2_FALSE;
    om_text->localname = "Include";
    om_text->is_binary = AXIS2_FALSE;
    om_text->content_id = NULL;
    om_text->om_attribute = NULL;
    om_text->value = NULL;
    om_text->ns = NULL;
    om_text->data_handler = NULL;
    om_text->mime_type = NULL;

    om_text->ns = NULL;

    if (value)
    {
        om_text->value = axutil_string_create(env, value);
    }

    axiom_node_set_data_element((*node), env, om_text);
    axiom_node_set_node_type((*node), env, AXIOM_TEXT);
    axiom_node_set_complete((*node), env, AXIS2_FALSE);

    if (parent && axiom_node_get_node_type(parent, env) == AXIOM_ELEMENT)
    {
        axiom_node_add_child(parent, env, (*node));
    }

    return om_text;
}

AXIS2_EXTERN axiom_text_t *AXIS2_CALL
axiom_text_create_with_data_handler(const axutil_env_t *env,
    axiom_node_t * parent,
    axiom_data_handler_t* data_handler,
    axiom_node_t **node)
{

    axiom_text_t *om_text = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, data_handler, NULL);

    om_text = (axiom_text_t*)axiom_text_create(env, parent, NULL, node);
    if (!om_text)
    {
        return NULL;
    }
    om_text->optimize = AXIS2_TRUE;
    om_text->is_binary = AXIS2_TRUE;
    om_text->data_handler = data_handler;
    return om_text;
}

AXIS2_EXTERN void AXIS2_CALL
axiom_text_free(axiom_text_t * om_text,
    const axutil_env_t *env)
{
    AXIS2_ENV_CHECK(env, void);

    if (om_text->value)
    {
        axutil_string_free(om_text->value, env);
    }

    if (om_text->ns)
    {
        axiom_namespace_free(om_text->ns, env);
    }

    if (om_text->content_id)
    {
        AXIS2_FREE(env->allocator, om_text->content_id);
    }

    if (om_text->om_attribute)<commit_msg>Added the mime_type to be set in the axiom_text_create_with_data_handler.<commit_after>/*
 * 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_text.h>
#include <axiom_output.h>
#include <axutil_string.h>
#include "axiom_node_internal.h"
#include <axiom_xml_writer.h>
#include <axiom_output.h>
#include <axiom_attribute.h>
#include <axiom_namespace.h>
#include <axutil_base64.h>

static axis2_bool_t AXIS2_CALL
axiom_text_get_is_binary(axiom_text_t *om_text,
    const axutil_env_t *env);

static axis2_status_t AXIS2_CALL
axiom_text_serialize_start_part(axiom_text_t *om_text,
    const axutil_env_t *env,
    axiom_output_t *om_output);

struct axiom_text
{
    /** Text value */
    axutil_string_t *value;
    /** The following fields are for MTOM */
    axis2_char_t *mime_type;
    axis2_bool_t optimize;
    const axis2_char_t *localname;
    axis2_bool_t is_binary;
    axis2_char_t *content_id;
    axiom_attribute_t *om_attribute;
    axiom_namespace_t *ns;
    axiom_data_handler_t *data_handler;
};

AXIS2_EXTERN axiom_text_t *AXIS2_CALL
axiom_text_create(const axutil_env_t *env,
    axiom_node_t * parent,
    const axis2_char_t * value,
    axiom_node_t **node)
{
    axiom_text_t *om_text = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, node, NULL);

    *node = axiom_node_create(env);

    if (!(*node))
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }
    om_text = (axiom_text_t *) AXIS2_MALLOC(env->allocator,
        sizeof(axiom_text_t));
    if (!om_text)
    {
        AXIS2_FREE(env->allocator, *node);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }

    om_text->mime_type = NULL;
    om_text->optimize = AXIS2_FALSE;
    om_text->localname = "Include";
    om_text->is_binary = AXIS2_FALSE;
    om_text->content_id = NULL;
    om_text->om_attribute = NULL;
    om_text->value = NULL;
    om_text->ns = NULL;
    om_text->data_handler = NULL;
    om_text->mime_type = NULL;

    om_text->ns = NULL;

    if (value)
    {
        om_text->value = axutil_string_create(env, value);
    }

    axiom_node_set_data_element((*node), env, om_text);
    axiom_node_set_node_type((*node), env, AXIOM_TEXT);
    axiom_node_set_complete((*node), env, AXIS2_FALSE);

    if (parent && axiom_node_get_node_type(parent, env) == AXIOM_ELEMENT)
    {
        axiom_node_add_child(parent, env, (*node));
    }

    return om_text;
}

AXIS2_EXTERN axiom_text_t *AXIS2_CALL
axiom_text_create_with_data_handler(const axutil_env_t *env,
    axiom_node_t * parent,
    axiom_data_handler_t* data_handler,
    axiom_node_t **node)
{

    axiom_text_t *om_text = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    AXIS2_PARAM_CHECK(env->error, data_handler, NULL);

    om_text = (axiom_text_t*)axiom_text_create(env, parent, NULL, node);
    if (!om_text)
    {
        return NULL;
    }
    om_text->optimize = AXIS2_TRUE;
    om_text->is_binary = AXIS2_TRUE;
    om_text->data_handler = data_handler;
    om_text->mime_type = axiom_data_handler_get_content_type(data_handler, env);
    return om_text;
}

AXIS2_EXTERN void AXIS2_CALL
axiom_text_free(axiom_text_t * om_text,
    const axutil_env_t *env)
{
    AXIS2_ENV_CHECK(env, void);

    if (om_text->value)
    {
        axutil_string_free(om_text->value, env);
    }

    if (om_text->ns)
    {
        axiom_namespace_free(om_text->ns, env);
    }

    if (om_text->content_id)
    {
        AXIS2_FREE(env->allocator, om_text->content_id);
    }

    if (om_text->om_attribute)
{'fraction_non_alphanumeric': 0.0986757295206844, 'fraction_numerical': 0.009609750380874253, 'mean_word_length': 3.72797783933518, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1268533', 'n_tokens_mistral': 3257, 'n_tokens_neox': 3126, 'n_words': 666}