[cpp-xmltooling COMMIT] in /branches/REL_1/xmltooling/io: GenericRequest.h HTTPRequest.cpp HTTPRequest.h
noreply at shibboleth.net
noreply at shibboleth.net
Mon Jan 23 21:46:48 GMT 2012
Author: scantor
Date: Mon Jan 23 21:46:48 2012
New Revision: 955
URL: http://svn.shibboleth.net/view/cpp-xmltooling?rev=955&view=rev
Log:
Language matching support in request API
Modified:
branches/REL_1/xmltooling/io/GenericRequest.h
branches/REL_1/xmltooling/io/HTTPRequest.cpp
branches/REL_1/xmltooling/io/HTTPRequest.h
Modified: branches/REL_1/xmltooling/io/GenericRequest.h
URL: http://svn.shibboleth.net/view/cpp-xmltooling/branches/REL_1/xmltooling/io/GenericRequest.h?rev=955&r1=954&r2=955&view=diff
==============================================================================
--- branches/REL_1/xmltooling/io/GenericRequest.h (original)
+++ branches/REL_1/xmltooling/io/GenericRequest.h Mon Jan 23 21:46:48 2012
@@ -27,8 +27,9 @@
#ifndef __xmltooling_genreq_h__
#define __xmltooling_genreq_h__
-#include <xmltooling/base.h>
-
+#include <xmltooling/unicode.h>
+
+#include <map>
#include <string>
#include <vector>
@@ -37,6 +38,11 @@
#endif
namespace xmltooling {
+
+#if defined (_MSC_VER)
+ #pragma warning( push )
+ #pragma warning( disable : 4251 )
+#endif
/**
* Interface to generic protocol requests that transport XML messages.
@@ -157,7 +163,69 @@
std::vector<std::string>&
#endif
getClientCertificates() const=0;
+
+ /**
+ * Returns a language range to use in selecting language-specific
+ * content for this request.
+ * <p>The syntax is that of the HTTP 1.1 Accept-Language header, even
+ * if the underlying request is not HTTP.
+ *
+ * @return an HTTP 1.1 syntax language range specifier
+ */
+ virtual std::string getLanguageRange() const {
+ return "";
+ }
+
+ /**
+ * Initializes the language matching process; call this method to begin the
+ * matching process by calling the matchLang method.
+ * <p>The language matching process is not thread-safe and must be externally
+ * syncronized.
+ *
+ * @return true iff language matching is possible
+ */
+ bool startLangMatching() const;
+
+ /**
+ * Continues the language matching process; additional calls to matchLang can
+ * be done as long as this method returns true.
+ * <p>The language matching process is not thread-safe and must be externally
+ * syncronized.
+ *
+ * @return true iff more ranges are available to match against
+ */
+ bool continueLangMatching() const;
+
+ /**
+ * Matches a language tag against the currently active range.
+ * <p>The language matching process is not thread-safe and must be externally
+ * syncronized.
+ *
+ * @param tag a language tag (e.g., an xml:lang value)
+ * @return true iff the tag matches the active range
+ */
+ bool matchLang(const XMLCh* tag) const;
+
+ /**
+ * Establish default handling of language ranges.
+ *
+ * @param langFromClient honor client's language preferences if any
+ * @param defaultRange priority list of space-delimited language tags to use by default
+ */
+ static void setLangDefaults(bool langFromClient, const XMLCh* defaultRange);
+
+ private:
+ typedef std::multimap< float,std::vector<xstring> > langrange_t;
+ mutable langrange_t m_langRange;
+ mutable langrange_t::const_reverse_iterator m_langRangeIter;
+ static langrange_t m_defaultRange;
+ static bool m_langFromClient;
};
+
+#if defined (_MSC_VER)
+ #pragma warning( pop )
+#endif
+
};
#endif /* __xmltooling_genreq_h__ */
Modified: branches/REL_1/xmltooling/io/HTTPRequest.cpp
URL: http://svn.shibboleth.net/view/cpp-xmltooling/branches/REL_1/xmltooling/io/HTTPRequest.cpp?rev=955&r1=954&r2=955&view=diff
==============================================================================
--- branches/REL_1/xmltooling/io/HTTPRequest.cpp (original)
+++ branches/REL_1/xmltooling/io/HTTPRequest.cpp Mon Jan 23 21:46:48 2012
@@ -26,16 +26,24 @@
#include "internal.h"
#include "HTTPRequest.h"
-
+#include "util/Threads.h"
+
+#include <cstring>
#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
+#include <boost/lexical_cast.hpp>
#include <boost/tokenizer.hpp>
+#include <xercesc/util/XMLStringTokenizer.hpp>
using namespace xmltooling;
+using namespace xercesc;
using namespace boost;
using namespace std;
-GenericRequest::GenericRequest()
+bool GenericRequest::m_langFromClient = true;
+GenericRequest::langrange_t GenericRequest::m_defaultRange;
+
+GenericRequest::GenericRequest() : m_langRangeIter(m_langRange.crend())
{
}
@@ -43,6 +51,126 @@
{
}
+void GenericRequest::setLangDefaults(bool langFromClient, const XMLCh* defaultRange)
+{
+ m_langFromClient = langFromClient;
+ m_defaultRange.clear();
+ if (!defaultRange)
+ return;
+ float q = 0.0f;
+ XMLStringTokenizer tokens(defaultRange);
+ while (tokens.hasMoreTokens()) {
[... 150 lines stripped ...]
More information about the commits
mailing list