Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug905035 into lp:zorba.
Requested reviews: Markos Zaharioudakis (markos-za) Rodolfo Ochoa (hybridum) Related bugs: Bug #905035 in Zorba: "there is no way to get the Namespace Prefixes" https://bugs.launchpad.net/zorba/+bug/905035 For more details, see: https://code.launchpad.net/~zorba-coders/zorba/bug905035/+merge/88271 implemented StaticContext::getDeclaredPrefixes to resolve bug #905035 -- https://code.launchpad.net/~zorba-coders/zorba/bug905035/+merge/88271 Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog' --- ChangeLog 2012-01-11 17:30:25 +0000 +++ ChangeLog 2012-01-11 20:46:24 +0000 @@ -21,6 +21,7 @@ support. * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors * Added API method Item::getNamespaceBindings(). + * Added API method StaticContext::getDeclaredPrefixes() (see bug #905035) version 2.1 === modified file 'include/zorba/static_context.h' --- include/zorba/static_context.h 2011-12-21 14:40:33 +0000 +++ include/zorba/static_context.h 2012-01-11 20:46:24 +0000 @@ -103,6 +103,14 @@ virtual String getNamespaceURIByPrefix( const String& aPrefix ) const = 0; + /** + * \brief Get the list of prefixes declared in this static context. + * + * @param aPrefixes the list of prefixes is added to this vector + */ + virtual void + getDeclaredPrefixes( std::vector<String>& aPrefixes ) const = 0; + /** \brief Set the default element and type namespace * (see http://www.w3.org/TR/xquery/#static_context) * === modified file 'src/api/staticcontextimpl.cpp' --- src/api/staticcontextimpl.cpp 2012-01-11 17:30:25 +0000 +++ src/api/staticcontextimpl.cpp 2012-01-11 20:46:24 +0000 @@ -215,6 +215,32 @@ return ""; } +/******************************************************************************* + +********************************************************************************/ +void +StaticContextImpl::getDeclaredPrefixes( std::vector<String>& aPrefixes ) const +{ + try + { + store::NsBindings lBindings; + theCtx->get_namespace_bindings(lBindings); + + for (store::NsBindings::const_iterator lIter = lBindings.begin(); + lIter != lBindings.end(); ++lIter) + { + aPrefixes.push_back(lIter->first.str()); + } + } + catch (ZorbaException const& e) + { + ZorbaImpl::notifyError(theDiagnosticHandler, e); + } + catch (std::exception const& e) + { + ZorbaImpl::notifyError(theDiagnosticHandler, e.what()); + } +} /******************************************************************************* === modified file 'src/api/staticcontextimpl.h' --- src/api/staticcontextimpl.h 2011-12-21 14:40:33 +0000 +++ src/api/staticcontextimpl.h 2012-01-11 20:46:24 +0000 @@ -78,6 +78,9 @@ String getNamespaceURIByPrefix( const String& prefix ) const; + void + getDeclaredPrefixes( std::vector<String>& aPrefixes ) const; + bool setDefaultElementAndTypeNamespace( const String& URI ); String getDefaultElementAndTypeNamespace( ) const; === modified file 'test/unit/CMakeLists.txt' --- test/unit/CMakeLists.txt 2012-01-11 17:30:25 +0000 +++ test/unit/CMakeLists.txt 2012-01-11 20:46:24 +0000 @@ -94,6 +94,7 @@ xquery_functions.cpp xmldatamanager.cpp staticcollectionmanager.cpp + static_context.cpp ) IF (NOT ZORBA_NO_FULL_TEXT) === added file 'test/unit/static_context.cpp' --- test/unit/static_context.cpp 1970-01-01 00:00:00 +0000 +++ test/unit/static_context.cpp 2012-01-11 20:46:24 +0000 @@ -0,0 +1,75 @@ +/* + * Copyright 2006-2012 The FLWOR Foundation. + * + * Licensed 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 <cassert> +#include <iostream> +#include <list> +#include <map> + +#include <sstream> +#include <zorba/store_manager.h> +#include <zorba/zorba.h> +#include <zorba/zorba_exception.h> + +using namespace std; +using namespace zorba; +using namespace zorba::locale; + +bool +sctx_test_1(Zorba* const zorba) +{ + StaticContext_t lSctx = zorba->createStaticContext(); + + Zorba_CompilerHints_t lHints; + + std::stringstream lProlog; + lProlog << "declare namespace foo = 'http://www.example.com';"; + + lSctx->loadProlog(lProlog.str(), lHints); + + std::vector<String> lPrefixes; + lSctx->getDeclaredPrefixes(lPrefixes); + + bool lFooFound = false; + + for (std::vector<String>::const_iterator lIter = lPrefixes.begin(); + lIter != lPrefixes.end(); ++lIter) + { + std::cout << "prefix: " << *lIter << " bound to " + << lSctx->getNamespaceURIByPrefix(*lIter) << std::endl; + + if (lIter->compare("foo") == 0) + { + lFooFound = true; + } + } + + return lFooFound && lPrefixes.size() == 6; +} + +int static_context( int argc, char *argv[] ) { + void *const zstore = StoreManager::getStore(); + Zorba *const zorba = Zorba::getInstance( zstore ); + + if (!sctx_test_1(zorba)) + return 1; + + zorba->shutdown(); + StoreManager::shutdownStore( zstore ); + return 0; +} +/* vim:set et sw=2 ts=2: */ +
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp