Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug905035 into 
lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)
  Hybridum (hybridum)
  Rodolfo Ochoa (rodolfo-ochoa)
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/88922

Implemented StaticContext::getNamespaceBindings to resolve bug #905035. In the 
same commit, the function getNamespaceURIByPrefix was deprecated because it's 
superseded by the new function.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug905035/+merge/88922
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-01-11 17:30:25 +0000
+++ ChangeLog	2012-01-17 19:11:32 +0000
@@ -21,6 +21,8 @@
     support.
   * zerr is not predeclared anymore to be http://www.zorba-xquery.com/errors
   * Added API method Item::getNamespaceBindings().
+  * Added API method StaticContext::getNamespaceBindings() (see bug #905035)
+  * Deprecated StaticContext:getNamespaceURIByPrefix()
 
 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-17 19:11:32 +0000
@@ -99,10 +99,21 @@
    *         could be found for the given prefix and an DiagnosticHandler has been
    *         registered.
    * @throw ZorbaException if an error occured (e.g. no URI could be found for the given prefix).
+   *
+   * @deprecated This function is deprecated. Use getNamespaceBindings instead.
    */
   virtual String
   getNamespaceURIByPrefix( const String& aPrefix ) const = 0;
 
+  /**
+   * \brief Get the list of all namespace bindings (prefix, uri)
+   *   declared in this and its parent static contexts.
+   *
+   * @param aBindings the bindings are added to this list
+   */
+  virtual void
+  getNamespaceBindings( NsBindings& aBindings ) 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-17 19:11:32 +0000
@@ -215,6 +215,37 @@
   return "";
 }
 
+/*******************************************************************************
+
+********************************************************************************/
+void
+StaticContextImpl::getNamespaceBindings( NsBindings& aBindings ) const
+{
+  try
+  {
+    store::NsBindings lBindings;
+    theCtx->get_namespace_bindings(lBindings);
+
+    for (store::NsBindings::const_iterator lIter = lBindings.begin();
+         lIter != lBindings.end(); ++lIter)
+    {
+      aBindings.push_back(
+        std::pair<zorba::String, zorba::String>(
+          lIter->first.str(),
+          lIter->second.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-17 19:11:32 +0000
@@ -78,6 +78,9 @@
 
   String getNamespaceURIByPrefix( const String& prefix ) const;
 
+  void
+  getNamespaceBindings( NsBindings& aBindings ) 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-17 19:11:32 +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-17 19:11:32 +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);
+
+  NsBindings lBindings;
+  lSctx->getNamespaceBindings(lBindings);
+
+  bool lFooFound = false;
+
+  for (NsBindings::const_iterator lIter = lBindings.begin();
+       lIter != lBindings.end(); ++lIter)
+  {
+    std::cout << "prefix: " << lIter->first << " bound to "
+      << lIter->second << std::endl;
+
+    if (lIter->first.compare("foo") == 0)
+    {
+      lFooFound = true;
+    }
+  }
+
+  return lFooFound && lBindings.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

Reply via email to