X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2FAbstractSimpleElement.cpp;h=5782e3bd7f066c970e3b729298ae78fd24583e1f;hb=56a73c1c7b1e63f1ff1717b25a76ebd480594d5a;hp=a6a29e7dfac15529c1053d2cdf36b78ed4868eba;hpb=a0d768778a8f5f539b909baf5b115e70ea765f0f;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/AbstractSimpleElement.cpp b/xmltooling/AbstractSimpleElement.cpp index a6a29e7..5782e3b 100644 --- a/xmltooling/AbstractSimpleElement.cpp +++ b/xmltooling/AbstractSimpleElement.cpp @@ -1,17 +1,21 @@ -/* - * Copyright 2001-2010 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** @@ -23,8 +27,11 @@ #include "internal.h" #include "AbstractSimpleElement.h" +#include + using namespace xmltooling; using xercesc::XMLString; +using xercesc::XMLChar1_0; using namespace std; // shared "empty" list of children for childless objects @@ -69,5 +76,13 @@ void AbstractSimpleElement::setTextContent(const XMLCh* value, unsigned int posi { if (position > 0) throw XMLObjectException("Cannot set text content in simple element at position > 0."); - m_value=prepareForAssignment(m_value,value); + + // We overwrite the "one" piece of Text content if: + // - the new value is null + // - there is no existing value + // - the old value is all whitespace + // If there's a non-whitespace value set, we leave it alone unless we're clearing it with a null. + + if (!value || !m_value || XMLChar1_0::isAllSpaces(m_value, XMLString::stringLen(m_value))) + m_value=prepareForAssignment(m_value, value); }