Author: tabish Date: Wed Jan 24 07:50:47 2007 New Revision: 499448 URL: http://svn.apache.org/viewvc?view=rev&rev=499448 Log: http://issues.apache.org/activemq/browse/AMQCPP-30
Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.cpp (with props) incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.h (with props) Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.cpp?view=auto&rev=499448 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.cpp (added) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.cpp Wed Jan 24 07:50:47 2007 @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 + * + * 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. + */ + +#include "URISupport.h" +#include "StringTokenizer.h" + +#include <activemq/exceptions/IllegalArgumentException.h> + +using namespace activemq; +using namespace activemq::util; +using namespace activemq::exceptions; + +//////////////////////////////////////////////////////////////////////////////// +SimpleProperties URISupport::parseQuery( std::string query ) + throw ( IllegalArgumentException ) +{ + try { + + SimpleProperties map; + + // strip the initial "?" + size_t pos = query.find_first_of( "?" ); + if( pos != std::string::npos ) { + query = query.substr(pos+1); + } + + // split the query into parameters + StringTokenizer tokenizer( query, "&" ); + std::vector<std::string> options; + tokenizer.toArray( options ); + + std::vector<std::string>::const_iterator iter = options.begin(); + + for( ; iter != options.end(); ++iter ) { + + tokenizer.reset( *iter, "=" ); + + std::string key = ""; + std::string value = ""; + + if( tokenizer.countTokens() != 2 ) { + throw IllegalArgumentException( + __FILE__, + __LINE__, + "URISupport::parseQuery - Invalid URI Option." ); + } + + // Get the Key + if( tokenizer.hasMoreTokens() != false ) { + key = tokenizer.nextToken(); + } + + // Get the Value + if( tokenizer.hasMoreTokens() != false ) { + value = tokenizer.nextToken(); + } + + // Store them. + map.setProperty( key, value ); + } + + return map; + } + AMQ_CATCH_RETHROW( IllegalArgumentException ) + AMQ_CATCH_EXCEPTION_CONVERT( NoSuchElementException, IllegalArgumentException ) + AMQ_CATCHALL_THROW( IllegalArgumentException ) +} + Propchange: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.h URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.h?view=auto&rev=499448 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.h (added) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.h Wed Jan 24 07:50:47 2007 @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 + * + * 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. + */ + +#ifndef _ACTIVEMQ_UTIL_URISUPPORT_H_ +#define _ACTIVEMQ_UTIL_URISUPPORT_H_ + +#include <activemq/util/SimpleProperties.h> +#include <activemq/exceptions/IllegalArgumentException.h> + +namespace activemq{ +namespace util{ + + class URISupport + { + public: + + virtual ~URISupport(); + + /** + * Parse the Query portion of a URI String and return a Simple + * Properties object containing the parameter names as keys, and + * the parameter values and values of the Properties. + * @param query. the query string to parse. + * @returns SimpleProperties object with the parsed output. + */ + static SimpleProperties parseQuery( std::string query ) + throw ( exceptions::IllegalArgumentException ); + + }; + +}} + +#endif /*_ACTIVEMQ_UTIL_URISUPPORT_H_*/ Propchange: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/URISupport.h ------------------------------------------------------------------------------ svn:eol-style = native