Coverage Report

Created: 2025-11-09 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/propertysetter.cpp
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
#include <log4cxx/logstring.h>
19
#include <log4cxx/config/propertysetter.h>
20
#include <log4cxx/helpers/object.h>
21
#include <log4cxx/helpers/loglog.h>
22
#include <log4cxx/helpers/optionconverter.h>
23
#include <log4cxx/spi/optionhandler.h>
24
#include <log4cxx/helpers/properties.h>
25
#include <log4cxx/appender.h>
26
#include <log4cxx/layout.h>
27
#include <log4cxx/helpers/pool.h>
28
29
using namespace LOG4CXX_NS;
30
using namespace LOG4CXX_NS::helpers;
31
using namespace LOG4CXX_NS::spi;
32
using namespace LOG4CXX_NS::config;
33
34
4
PropertySetter::PropertySetter(const helpers::ObjectPtr& obj1) : obj(obj1)
35
4
{
36
4
}
37
38
void PropertySetter::setProperties(const helpers::ObjectPtr& obj,
39
  helpers::Properties& properties,
40
  const LogString& prefix,
41
  Pool& p)
42
4
{
43
4
  PropertySetter(obj).setProperties(properties, prefix, p);
44
4
}
log4cxx::config::PropertySetter::setProperties(std::__1::shared_ptr<log4cxx::helpers::Object> const&, log4cxx::helpers::Properties&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, log4cxx::helpers::Pool&)
Line
Count
Source
42
2
{
43
2
  PropertySetter(obj).setProperties(properties, prefix, p);
44
2
}
log4cxx::config::PropertySetter::setProperties(std::__1::shared_ptr<log4cxx::helpers::Object> const&, log4cxx::helpers::Properties&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, log4cxx::helpers::Pool&)
Line
Count
Source
42
2
{
43
2
  PropertySetter(obj).setProperties(properties, prefix, p);
44
2
}
45
46
47
void PropertySetter::setProperties(helpers::Properties& properties,
48
  const LogString& prefix,
49
  Pool& p)
50
4
{
51
4
  size_t len = prefix.length();
52
53
4
  for (auto key : properties.propertyNames())
54
16
  {
55
    // handle only properties that start with the desired frefix.
56
16
    if (key.find(prefix) == 0)
57
6
    {
58
      // ignore key if it contains dots after the prefix
59
6
      if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
60
2
      {
61
2
        continue;
62
2
      }
63
64
4
      LogString value = OptionConverter::findAndSubst(key, properties);
65
4
      key = key.substr(len);
66
67
4
      if (key == LOG4CXX_STR("layout")
68
2
        && obj != 0
69
2
        && obj->instanceof(Appender::getStaticClass()))
70
2
      {
71
2
        continue;
72
2
      }
73
74
2
      setProperty(key, value, p);
75
2
    }
76
16
  }
77
78
4
  activate(p);
79
4
}
log4cxx::config::PropertySetter::setProperties(log4cxx::helpers::Properties&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, log4cxx::helpers::Pool&)
Line
Count
Source
50
2
{
51
2
  size_t len = prefix.length();
52
53
2
  for (auto key : properties.propertyNames())
54
8
  {
55
    // handle only properties that start with the desired frefix.
56
8
    if (key.find(prefix) == 0)
57
3
    {
58
      // ignore key if it contains dots after the prefix
59
3
      if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
60
1
      {
61
1
        continue;
62
1
      }
63
64
2
      LogString value = OptionConverter::findAndSubst(key, properties);
65
2
      key = key.substr(len);
66
67
2
      if (key == LOG4CXX_STR("layout")
68
1
        && obj != 0
69
1
        && obj->instanceof(Appender::getStaticClass()))
70
1
      {
71
1
        continue;
72
1
      }
73
74
1
      setProperty(key, value, p);
75
1
    }
76
8
  }
77
78
2
  activate(p);
79
2
}
log4cxx::config::PropertySetter::setProperties(log4cxx::helpers::Properties&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, log4cxx::helpers::Pool&)
Line
Count
Source
50
2
{
51
2
  size_t len = prefix.length();
52
53
2
  for (auto key : properties.propertyNames())
54
8
  {
55
    // handle only properties that start with the desired frefix.
56
8
    if (key.find(prefix) == 0)
57
3
    {
58
      // ignore key if it contains dots after the prefix
59
3
      if (key.find(0x2E /* '.' */, len + 1) != LogString::npos)
60
1
      {
61
1
        continue;
62
1
      }
63
64
2
      LogString value = OptionConverter::findAndSubst(key, properties);
65
2
      key = key.substr(len);
66
67
2
      if (key == LOG4CXX_STR("layout")
68
1
        && obj != 0
69
1
        && obj->instanceof(Appender::getStaticClass()))
70
1
      {
71
1
        continue;
72
1
      }
73
74
1
      setProperty(key, value, p);
75
1
    }
76
8
  }
77
78
2
  activate(p);
79
2
}
80
81
void PropertySetter::setProperty(const LogString& option,
82
  const LogString& value,
83
  Pool&)
84
2
{
85
2
  if (value.empty())
86
0
  {
87
0
    return;
88
0
  }
89
90
2
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
91
2
  {
92
2
    if (LogLog::isDebugEnabled())
93
0
    {
94
0
      LogLog::debug(LOG4CXX_STR("Setting option name=[") +
95
0
        option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
96
0
    }
97
2
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
98
2
    handler->setOption(option, value);
99
2
  }
100
2
}
log4cxx::config::PropertySetter::setProperty(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, log4cxx::helpers::Pool&)
Line
Count
Source
84
1
{
85
1
  if (value.empty())
86
0
  {
87
0
    return;
88
0
  }
89
90
1
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
91
1
  {
92
1
    if (LogLog::isDebugEnabled())
93
0
    {
94
0
      LogLog::debug(LOG4CXX_STR("Setting option name=[") +
95
0
        option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
96
0
    }
97
1
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
98
1
    handler->setOption(option, value);
99
1
  }
100
1
}
log4cxx::config::PropertySetter::setProperty(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, log4cxx::helpers::Pool&)
Line
Count
Source
84
1
{
85
1
  if (value.empty())
86
0
  {
87
0
    return;
88
0
  }
89
90
1
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
91
1
  {
92
1
    if (LogLog::isDebugEnabled())
93
0
    {
94
0
      LogLog::debug(LOG4CXX_STR("Setting option name=[") +
95
0
        option + LOG4CXX_STR("], value=[") + value + LOG4CXX_STR("]"));
96
0
    }
97
1
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
98
1
    handler->setOption(option, value);
99
1
  }
100
1
}
101
102
void PropertySetter::activate(Pool& p)
103
8
{
104
8
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
105
8
  {
106
8
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
107
8
    handler->activateOptions(p);
108
8
  }
109
8
}
log4cxx::config::PropertySetter::activate(log4cxx::helpers::Pool&)
Line
Count
Source
103
4
{
104
4
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
105
4
  {
106
4
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
107
4
    handler->activateOptions(p);
108
4
  }
109
4
}
log4cxx::config::PropertySetter::activate(log4cxx::helpers::Pool&)
Line
Count
Source
103
4
{
104
4
  if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass()))
105
4
  {
106
4
    OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj);
107
4
    handler->activateOptions(p);
108
4
  }
109
4
}