<commit_before># --
# Copyright (C) 2001-2017 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::System::SysConfig::XML;

use strict;
use warnings;

our @ObjectDependencies = (
    'Kernel::System::Log',
    'Kernel::System::XML::Simple',
);

use Kernel::System::VariableCheck qw( :all );

=head1 NAME

Kernel::System::SysConfig::XML - Manage system configuration settings in XML.

=head1 PUBLIC INTERFACE

=head2 new()

Create an object. Do not use it directly, instead use:

    use Kernel::System::ObjectManager;
    local $Kernel::OM = Kernel::System::ObjectManager->new();
    my $SysConfigXMLObject = $Kernel::OM->Get('Kernel::System::SysConfig::XML');

=cut

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    return $Self;
}

=head2 SettingParse()

Parses XML Setting into Perl structure.

    my $PerlStructure = $SysConfigXMLObject->SettingParse(
        SettingXML => '
            <Setting Name="Test" Required="1" Valid="1">
                <Description Translatable="1">Test.</Description>
                <Navigation>Core::Ticket</Navigation>
                <Value>
                    <Item ValueType="String" ValueRegex=".*">123</Item>
                </Value>
            </Setting>
        ',
    );

Returns:

    my $PerlStructure = {
        Description => [
            {
                Content      => 'Test.',
                Translatable => '1',
            },
        ],
        Name  => 'Test',
        Required => '1',
        Value => [
            {
                Item => [
                    {
                        ValueRegex => '.*',
                        ValueType  => 'String',
                        Content    => '123',
                    },
                ],
            },
        ],
        Navigation => [
            {
                Content => 'Core::Ticket',
            },
        ],
        Valid => '1',
    };

=cut

sub SettingParse {
    my ( $Type, %Param ) = @_;

    if ( !defined $Param{SettingXML} || !length $Param{SettingXML} ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Need parameter SettingXML!",
        );
        return;
    }

    if ( !IsString( $Param{SettingXML} ) ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Parameter SettingXML needs to be a string!",
        );
        return;
    }

    my $SettingXML = $Param{SettingXML};

    # Escape '
    $SettingXML =~ s{'}{\'}gs;

    my $XMLSimpleObject = $Kernel::OM->Get('Kernel::System::XML::Simple');
    my $PerlStructure   = $XMLSimpleObject->XMLIn(
        XMLInput => $SettingXML,
        Options  => {
            KeepRoot     => 1,
            ForceArray   => 1,
            ForceContent => 1,
            ContentKey   => 'Content',
        },
    );

    if (<commit_msg>Revert "Escape quotes from XML files (SysConfig/XML.pm)."<commit_after># --
# Copyright (C) 2001-2017 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::System::SysConfig::XML;

use strict;
use warnings;

our @ObjectDependencies = (
    'Kernel::System::Log',
    'Kernel::System::XML::Simple',
);

use Kernel::System::VariableCheck qw( :all );

=head1 NAME

Kernel::System::SysConfig::XML - Manage system configuration settings in XML.

=head1 PUBLIC INTERFACE

=head2 new()

Create an object. Do not use it directly, instead use:

    use Kernel::System::ObjectManager;
    local $Kernel::OM = Kernel::System::ObjectManager->new();
    my $SysConfigXMLObject = $Kernel::OM->Get('Kernel::System::SysConfig::XML');

=cut

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    return $Self;
}

=head2 SettingParse()

Parses XML Setting into Perl structure.

    my $PerlStructure = $SysConfigXMLObject->SettingParse(
        SettingXML => '
            <Setting Name="Test" Required="1" Valid="1">
                <Description Translatable="1">Test.</Description>
                <Navigation>Core::Ticket</Navigation>
                <Value>
                    <Item ValueType="String" ValueRegex=".*">123</Item>
                </Value>
            </Setting>
        ',
    );

Returns:

    my $PerlStructure = {
        Description => [
            {
                Content      => 'Test.',
                Translatable => '1',
            },
        ],
        Name  => 'Test',
        Required => '1',
        Value => [
            {
                Item => [
                    {
                        ValueRegex => '.*',
                        ValueType  => 'String',
                        Content    => '123',
                    },
                ],
            },
        ],
        Navigation => [
            {
                Content => 'Core::Ticket',
            },
        ],
        Valid => '1',
    };

=cut

sub SettingParse {
    my ( $Type, %Param ) = @_;

    if ( !defined $Param{SettingXML} || !length $Param{SettingXML} ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Need parameter SettingXML!",
        );
        return;
    }

    if ( !IsString( $Param{SettingXML} ) ) {
        $Kernel::OM->Get('Kernel::System::Log')->Log(
            Priority => 'error',
            Message  => "Parameter SettingXML needs to be a string!",
        );
        return;
    }

    my $XMLSimpleObject = $Kernel::OM->Get('Kernel::System::XML::Simple');
    my $PerlStructure   = $XMLSimpleObject->XMLIn(
        XMLInput => $Param{SettingXML},
        Options  => {
            KeepRoot     => 1,
            ForceArray   => 1,
            ForceContent => 1,
            ContentKey   => 'Content',
        },
    );

    if (
{'fraction_non_alphanumeric': 0.14940686117345303, 'fraction_numerical': 0.008656620711766592, 'mean_word_length': 1.77659101023587, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '3719731', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1752, 'n_words': 410}