/src/logging-log4cxx/src/main/cpp/propertysetter.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 0 | PropertySetter::PropertySetter(const helpers::ObjectPtr& obj1) : obj(obj1) |
35 | 0 | { |
36 | 0 | } |
37 | | |
38 | | void PropertySetter::setProperties(const helpers::ObjectPtr& obj, |
39 | | helpers::Properties& properties, |
40 | | const LogString& prefix, |
41 | | Pool& p) |
42 | 0 | { |
43 | 0 | PropertySetter(obj).setProperties(properties, prefix, p); |
44 | 0 | } |
45 | | |
46 | | |
47 | | void PropertySetter::setProperties(helpers::Properties& properties, |
48 | | const LogString& prefix, |
49 | | Pool& p) |
50 | 0 | { |
51 | 0 | size_t len = prefix.length(); |
52 | |
|
53 | 0 | for (auto key : properties.propertyNames()) |
54 | 0 | { |
55 | | // handle only properties that start with the desired frefix. |
56 | 0 | if (key.find(prefix) == 0) |
57 | 0 | { |
58 | | // ignore key if it contains dots after the prefix |
59 | 0 | if (key.find(0x2E /* '.' */, len + 1) != LogString::npos) |
60 | 0 | { |
61 | 0 | continue; |
62 | 0 | } |
63 | | |
64 | 0 | LogString value = OptionConverter::findAndSubst(key, properties); |
65 | 0 | key = key.substr(len); |
66 | |
|
67 | 0 | if (key == LOG4CXX_STR("layout") |
68 | 0 | && obj != 0 |
69 | 0 | && obj->instanceof(Appender::getStaticClass())) |
70 | 0 | { |
71 | 0 | continue; |
72 | 0 | } |
73 | | |
74 | 0 | setProperty(key, value, p); |
75 | 0 | } |
76 | 0 | } |
77 | |
|
78 | 0 | activate(p); |
79 | 0 | } |
80 | | |
81 | | void PropertySetter::setProperty(const LogString& option, |
82 | | const LogString& value, |
83 | | Pool&) |
84 | 0 | { |
85 | 0 | if (value.empty()) |
86 | 0 | { |
87 | 0 | return; |
88 | 0 | } |
89 | | |
90 | 0 | if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass())) |
91 | 0 | { |
92 | 0 | 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 | 0 | OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj); |
98 | 0 | handler->setOption(option, value); |
99 | 0 | } |
100 | 0 | } |
101 | | |
102 | | void PropertySetter::activate(Pool& p) |
103 | 0 | { |
104 | 0 | if (obj != 0 && obj->instanceof(OptionHandler::getStaticClass())) |
105 | 0 | { |
106 | 0 | OptionHandlerPtr handler = LOG4CXX_NS::cast<OptionHandler>(obj); |
107 | 0 | handler->activateOptions(p); |
108 | 0 | } |
109 | 0 | } |