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.
24 * An Attribute whose values are serialized XML.
28 #include "attribute/XMLAttribute.h"
30 #include <xercesc/util/Base64.hpp>
33 # include <xsec/framework/XSECDefs.hpp>
36 using namespace shibsp;
40 SHIBSP_DLLLOCAL Attribute* XMLAttributeFactory(DDF& in) {
41 return new XMLAttribute(in);
45 XMLAttribute::XMLAttribute(const vector<string>& ids) : Attribute(ids)
49 XMLAttribute::XMLAttribute(DDF& in) : Attribute(in)
51 DDF val = in.first().first();
52 while (val.string()) {
53 m_values.push_back(val.string());
54 val = in.first().next();
58 XMLAttribute::~XMLAttribute()
62 vector<string>& XMLAttribute::getValues()
67 const vector<string>& XMLAttribute::getValues() const
72 size_t XMLAttribute::valueCount() const
74 return m_values.size();
77 void XMLAttribute::clearSerializedValues()
82 const char* XMLAttribute::getString(size_t index) const
84 return m_values[index].c_str();
87 void XMLAttribute::removeValue(size_t index)
89 Attribute::removeValue(index);
90 if (index < m_values.size())
91 m_values.erase(m_values.begin() + index);
94 const vector<string>& XMLAttribute::getSerializedValues() const
98 if (m_serialized.empty()) {
99 for (vector<string>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
100 XMLByte* enc = Base64::encode(reinterpret_cast<const XMLByte*>(i->data()), i->size(), &len);
102 for (pos=enc, pos2=enc; *pos2; pos2++)
106 m_serialized.push_back(reinterpret_cast<char*>(enc));
107 #ifdef SHIBSP_XERCESC_HAS_XMLBYTE_RELEASE
108 XMLString::release(&enc);
110 XMLString::release((char**)&enc);
115 return Attribute::getSerializedValues();
118 DDF XMLAttribute::marshall() const
120 DDF ddf = Attribute::marshall();
122 DDF vlist = ddf.first();
123 for (vector<string>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i)
124 vlist.add(DDF(nullptr).string(i->c_str()));