Set fourth file version digit to signify rebuild.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractSimpleElement.cpp
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * AbstractSimpleElement.cpp
23  * 
24  * Extension of AbstractXMLObject that implements simple elements.
25  */
26
27 #include "internal.h"
28 #include "AbstractSimpleElement.h"
29
30 #include <xercesc/util/XMLChar.hpp>
31
32 using namespace xmltooling;
33 using xercesc::XMLString;
34 using xercesc::XMLChar1_0;
35 using namespace std;
36
37 // shared "empty" list of children for childless objects
38
39 list<XMLObject*> AbstractSimpleElement::m_no_children;
40
41 AbstractSimpleElement::AbstractSimpleElement() : m_value(nullptr)
42 {
43 }
44
45 AbstractSimpleElement::AbstractSimpleElement(const AbstractSimpleElement& src)
46     : AbstractXMLObject(src), m_value(XMLString::replicate(src.m_value))
47 {
48 }
49
50 AbstractSimpleElement::~AbstractSimpleElement()
51 {
52     XMLString::release(&m_value);
53 }
54
55 bool AbstractSimpleElement::hasChildren() const
56 {
57     return false;
58 }
59
60 const list<XMLObject*>& AbstractSimpleElement::getOrderedChildren() const
61 {
62     return m_no_children;
63 }
64
65 void AbstractSimpleElement::removeChild(XMLObject* child)
66 {
67     throw XMLObjectException("Cannot remove child from a childless object.");
68 }
69
70 const XMLCh* AbstractSimpleElement::getTextContent(unsigned int position) const
71 {
72     return (position==0) ? m_value : nullptr;
73 }
74
75 void AbstractSimpleElement::setTextContent(const XMLCh* value, unsigned int position)
76 {
77     if (position > 0)
78         throw XMLObjectException("Cannot set text content in simple element at position > 0.");
79
80     // We overwrite the "one" piece of Text content if:
81     //  - the new value is null
82     //  - there is no existing value
83     //  - the old value is all whitespace
84     // If there's a non-whitespace value set, we leave it alone unless we're clearing it with a null.
85
86     if (!value || !m_value || XMLChar1_0::isAllSpaces(m_value, XMLString::stringLen(m_value)))
87         m_value=prepareForAssignment(m_value, value);
88 }