2 * Copyright 2001-2010 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * AbstractSimpleElement.cpp
20 * Extension of AbstractXMLObject that implements simple elements.
24 #include "AbstractSimpleElement.h"
26 #include <xercesc/util/XMLChar.hpp>
28 using namespace xmltooling;
29 using xercesc::XMLString;
30 using xercesc::XMLChar1_0;
33 // shared "empty" list of children for childless objects
35 list<XMLObject*> AbstractSimpleElement::m_no_children;
37 AbstractSimpleElement::AbstractSimpleElement() : m_value(nullptr)
41 AbstractSimpleElement::AbstractSimpleElement(const AbstractSimpleElement& src)
42 : AbstractXMLObject(src), m_value(XMLString::replicate(src.m_value))
46 AbstractSimpleElement::~AbstractSimpleElement()
48 XMLString::release(&m_value);
51 bool AbstractSimpleElement::hasChildren() const
56 const list<XMLObject*>& AbstractSimpleElement::getOrderedChildren() const
61 void AbstractSimpleElement::removeChild(XMLObject* child)
63 throw XMLObjectException("Cannot remove child from a childless object.");
66 const XMLCh* AbstractSimpleElement::getTextContent(unsigned int position) const
68 return (position==0) ? m_value : nullptr;
71 void AbstractSimpleElement::setTextContent(const XMLCh* value, unsigned int position)
74 throw XMLObjectException("Cannot set text content in simple element at position > 0.");
76 // We overwrite the "one" piece of Text content if:
77 // - the new value is null
78 // - there is no existing value
79 // - the old value is all whitespace
80 // If there's a non-whitespace value set, we leave it alone unless we're clearing it with a null.
82 if (!value || !m_value || XMLChar1_0::isAllSpaces(m_value, XMLString::stringLen(m_value)))
83 m_value=prepareForAssignment(m_value, value);