2 * Copyright 2009 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 * shibsp/attribute/ExtensibleAttribute.cpp
20 * An Attribute whose values are arbitrary structures.
25 #include "attribute/ExtensibleAttribute.h"
26 #include "util/SPConstants.h"
28 using namespace shibsp;
29 using namespace xmltooling;
32 const vector<string>& ExtensibleAttribute::getSerializedValues() const
34 if (m_serialized.empty()) {
35 const char* formatter = m_obj["_formatter"].string();
37 string msg = formatter;
38 DDF val = m_obj.first().first();
39 while (!val.isnull()) {
41 static const char* legal="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_.[]";
43 m_serialized.push_back(string());
44 string& processed = m_serialized.back();
46 string::size_type i=0,start=0;
47 while (start!=string::npos && start<msg.length() && (i=msg.find("$",start))!=string::npos) {
49 processed += msg.substr(start,i-start); // append everything in between
50 start=i+1; // move start to the beginning of the token name
51 i=msg.find_first_not_of(legal,start); // find token delimiter
52 if (i==start) { // append a non legal character
53 processed+=msg[start++];
57 string tag = msg.substr(start,(i==string::npos) ? i : i-start);
58 if (tag == "_string" && val.string()) {
59 processed += val.string();
63 DDF child = val.getmember(tag.c_str());
65 processed += child.string();
66 else if (child.isstruct() && child["_string"].string())
67 processed += child["_string"].string();
71 if (start!=string::npos && start<msg.length())
72 processed += msg.substr(start,i); // append rest of string
74 val = m_obj.first().next();
78 return Attribute::getSerializedValues();