2 * Copyright 2009-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.
20 * An Attribute whose values are serialized XML.
24 #include "attribute/XMLAttribute.h"
26 #include <xercesc/util/Base64.hpp>
29 # include <xsec/framework/XSECDefs.hpp>
32 using namespace shibsp;
36 SHIBSP_DLLLOCAL Attribute* XMLAttributeFactory(DDF& in) {
37 return new XMLAttribute(in);
41 XMLAttribute::XMLAttribute(const vector<string>& ids) : Attribute(ids)
45 XMLAttribute::XMLAttribute(DDF& in) : Attribute(in)
47 DDF val = in.first().first();
48 while (val.string()) {
49 m_values.push_back(val.string());
50 val = in.first().next();
54 XMLAttribute::~XMLAttribute()
58 vector<string>& XMLAttribute::getValues()
63 const vector<string>& XMLAttribute::getValues() const
68 size_t XMLAttribute::valueCount() const
70 return m_values.size();
73 void XMLAttribute::clearSerializedValues()
78 const char* XMLAttribute::getString(size_t index) const
80 return m_values[index].c_str();
83 void XMLAttribute::removeValue(size_t index)
85 Attribute::removeValue(index);
86 if (index < m_values.size())
87 m_values.erase(m_values.begin() + index);
90 const vector<string>& XMLAttribute::getSerializedValues() const
94 if (m_serialized.empty()) {
95 for (vector<string>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
96 XMLByte* enc = Base64::encode(reinterpret_cast<const XMLByte*>(i->data()), i->size(), &len);
98 for (pos=enc, pos2=enc; *pos2; pos2++)
102 m_serialized.push_back(reinterpret_cast<char*>(enc));
103 #ifdef SHIBSP_XERCESC_HAS_XMLBYTE_RELEASE
104 XMLString::release(&enc);
106 XMLString::release((char**)&enc);
111 return Attribute::getSerializedValues();
114 DDF XMLAttribute::marshall() const
116 DDF ddf = Attribute::marshall();
118 DDF vlist = ddf.first();
119 for (vector<string>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i)
120 vlist.add(DDF(nullptr).string(i->c_str()));