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.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * AbstractSimpleElement.cpp
24 * Extension of AbstractXMLObject that implements simple elements.
28 #include "AbstractSimpleElement.h"
30 #include <xercesc/util/XMLChar.hpp>
32 using namespace xmltooling;
33 using xercesc::XMLString;
34 using xercesc::XMLChar1_0;
37 // shared "empty" list of children for childless objects
39 list<XMLObject*> AbstractSimpleElement::m_no_children;
41 AbstractSimpleElement::AbstractSimpleElement() : m_value(nullptr)
45 AbstractSimpleElement::AbstractSimpleElement(const AbstractSimpleElement& src)
46 : AbstractXMLObject(src), m_value(XMLString::replicate(src.m_value))
50 AbstractSimpleElement::~AbstractSimpleElement()
52 XMLString::release(&m_value);
55 bool AbstractSimpleElement::hasChildren() const
60 const list<XMLObject*>& AbstractSimpleElement::getOrderedChildren() const
65 void AbstractSimpleElement::removeChild(XMLObject* child)
67 throw XMLObjectException("Cannot remove child from a childless object.");
70 const XMLCh* AbstractSimpleElement::getTextContent(unsigned int position) const
72 return (position==0) ? m_value : nullptr;
75 void AbstractSimpleElement::setTextContent(const XMLCh* value, unsigned int position)
78 throw XMLObjectException("Cannot set text content in simple element at position > 0.");
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.
86 if (!value || !m_value || XMLChar1_0::isAllSpaces(m_value, XMLString::stringLen(m_value)))
87 m_value=prepareForAssignment(m_value, value);