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

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Chris Hillery (ceejatec)
  Till Westmann (tillw)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/feature-fetch_binary/+merge/106300

- fetch:content-binary
- fetch:content#3 (with encoding parameter)
- StreamResource::isStreamSeekable to make sure the streamable strings returned 
by fetch are seekable.
- fixed two warnings in nodes_impl.cpp
- extended the C++ api to be symmetric to the fetch module
-- 
https://code.launchpad.net/~zorba-coders/zorba/feature-fetch_binary/+merge/106300
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-05-16 06:45:13 +0000
+++ ChangeLog	2012-05-18 02:59:20 +0000
@@ -25,6 +25,10 @@
   * Added support for NO_ICU (to not use ICU for unicode processing)
   * Added XQJ support.
   * Added CollectionManager and DocumentManager support for XQJ.
+  * New API EntityKind SOME_CONTENT
+  * API StreamResource is able to specify whether a stream is seekable
+  * New functions in the fetch module and the StaticContext to fetch
+    resources as binary
 
 Optimizations:
   * optimized insertion into a collection (don't copy it if the node was created by an element constructor

=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
--- include/zorba/pregenerated/diagnostic_list.h	2012-05-16 06:45:13 +0000
+++ include/zorba/pregenerated/diagnostic_list.h	2012-05-18 02:59:20 +0000
@@ -420,7 +420,7 @@
 
 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZXQP0024_XML_DOES_NOT_MATCH_SCHEMA;
 
-extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZXQP0025_ITEM_CREATION_FAILED;
+extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZXQP0025_COULD_NOT_FETCH_RESOURCE;
 
 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZXQP0026_INVALID_ENUM_VALUE;
 

=== modified file 'include/zorba/static_context.h'
--- include/zorba/static_context.h	2012-05-07 19:41:09 +0000
+++ include/zorba/static_context.h	2012-05-18 02:59:20 +0000
@@ -697,7 +697,8 @@
    * registered, the built-in ones are used. 
    *
    * The default EntityKind for resources fetched by this function
-   * is "SOME_CONTENT".
+   * is "SOME_CONTENT". The default encoding that is used to read the
+   * resource is "UTF-8".
    *
    * @param aURI the name of the resource to fetch
    *
@@ -712,6 +713,8 @@
    * in this static context. If no such mappers or resolvers have been
    * registered, the built-in ones are used. 
    *
+   * The default encoding that is used to read the * resource is "UTF-8".
+   *
    * @param aURI the name of the resource to fetch
    *
    * @param aEntityKind the kind of the entity to fetch (i.e.
@@ -722,12 +725,70 @@
 
   virtual Item
   fetch(const String& aURI, const String& aEntityKind) const = 0;
+<<<<<<< TREE
   /** \brief Clears the base URI and sets it to undefined state.
    *         (see http://www.w3.org/TR/xquery/#static_context)
    */
   virtual void
   clearBaseURI() = 0;
 
+=======
+
+  /** \brief Fetches an resource refered to by the given URI.
+   *
+   * Resolution is done using the URI mappers and resolvers registered
+   * in this static context. If no such mappers or resolvers have been
+   * registered, the built-in ones are used. 
+   *
+   * @param aURI the name of the resource to fetch
+   * @param aEncoding the encoding to use when reading the resource.
+   *
+   * @param aEntityKind the kind of the entity to fetch (i.e.
+   *   SOME_CONTENT, SCHEMA, MODULE, THESAURUS, or STOP_WORDS)
+   *
+   * @return the fetched resource
+   */
+  virtual Item
+  fetch(
+      const String& aURI,
+      const String& aEntityKind,
+      const String& aEncoding) const = 0;
+
+  /** \brief Fetches an resource refered to by the given URI
+   *   and returns it as a base64binary.
+   *
+   * Resolution is done using the URI mappers and resolvers registered
+   * in this static context. If no such mappers or resolvers have been
+   * registered, the built-in ones are used. 
+   *
+   * The default EntityKind for resources fetched by this function
+   * is "SOME_CONTENT".
+   *
+   * @param aURI the name of the resource to fetch
+   *
+   * @return the fetched resource
+   */
+  virtual Item
+  fetchBinary(const String& aURI) const = 0;
+
+  /** \brief Fetches an resource refered to by the given URI
+   *   and returns it as a base64binary.
+   *
+   * Resolution is done using the URI mappers and resolvers registered
+   * in this static context. If no such mappers or resolvers have been
+   * registered, the built-in ones are used. 
+   *
+   * @param aURI the name of the resource to fetch
+   *
+   * @param aEntityKind the kind of the entity to fetch (i.e.
+   *   SOME_CONTENT, SCHEMA, MODULE, THESAURUS, or STOP_WORDS)
+   *
+   * @return the fetched resource
+   */
+  virtual Item
+  fetchBinary(const String& aURI, const String& aEntityKind) const = 0;
+
+>>>>>>> MERGE-SOURCE
 };
 
 } /* namespace zorba */

=== modified file 'include/zorba/uri_resolvers.h'
--- include/zorba/uri_resolvers.h	2012-05-03 12:31:51 +0000
+++ include/zorba/uri_resolvers.h	2012-05-18 02:59:20 +0000
@@ -84,9 +84,12 @@
    * @param aStreamReleaser A function pointer which is invoked once
    *        the StreamResource is destroyed. Normally this function will delete
    *        the std::istream object passed to it.
+   * @param aIsStreamSeekable Determines whether the given stream is arbitrarily
+   *   seekable without throwing errors.
    */
   static StreamResource* create(std::istream* aStream,
-                                StreamReleaser aStreamReleaser);
+                                StreamReleaser aStreamReleaser,
+                                bool aIsStreamSeekable = false);
   
   /**
    * @brief Retrieve the istream associated with this Resource.
@@ -99,6 +102,8 @@
   virtual StreamReleaser getStreamReleaser() = 0;
 
   virtual ~StreamResource() = 0;
+
+  virtual bool isStreamSeekable() const = 0;
 };
 
 /**
@@ -123,7 +128,8 @@
     THESAURUS,
     STOP_WORDS,
     COLLECTION,
-    DOCUMENT
+    DOCUMENT,
+    SOME_CONTENT
   };
 
   /**

=== modified file 'modules/com/zorba-xquery/www/modules/fetch.xq'
--- modules/com/zorba-xquery/www/modules/fetch.xq	2012-05-03 12:31:51 +0000
+++ modules/com/zorba-xquery/www/modules/fetch.xq	2012-05-18 02:59:20 +0000
@@ -17,15 +17,13 @@
 :)
 
 (:~
- : This module provides functions to fetch the contents or the type
- : of the content for a resource identified by a URI.
- : For example, it fetches content for file or http resources if Zorba
- : allows file or http access, respectively.
- :
- : <p>The errors raised by functions of this module have the namespace
- : <tt>http://www.zorba-xquery.com/errors</tt> (associated with prefix zerr).</p>
- :
- : @see <a href="www.zorba-xquery.com_errors.html">http://www.zorba-xquery.com/errors</a>
+ : <p>This module provides functions to fetch the content of a resource identified
+ : by a URI. For example, it fetches the content of file or http resources.</p>
+ :
+ : <p>In order to retrieve such content, the functions use the
+ : URI resolution and URL resolver process as documented at
+ : <a href="../../html/uriresolvers.html">
+ : URI Resolvers</a>.</p>
  :
  : @author Matthias Brantner
  :
@@ -38,23 +36,15 @@
 declare namespace zerr = "http://www.zorba-xquery.com/errors";;
 
 declare namespace ver = "http://www.zorba-xquery.com/options/versioning";;
-declare option ver:module-version "2.0";
+declare option ver:module-version "2.1";
 
 (:~
  : <p>Tries to fetch the resource referred to by the given URI.</p>
  :
- : <p>In order to retrieve the content, the functions uses the
- : URI resolution and URL resolver process as documented at
- : <a href="../../html/uriresolvers.html">
- : URI Resolvers</a>. Therefore, it queries all URI mappers
- : and resolvers with kind <tt>EntityData::SOME_CONTENT</tt>.</p>
+ : <p>It queries all URI mappers and resolvers with kind
+ : <tt>EntityData::SOME_CONTENT</tt>.</p>
  :
- : <p>The function is annotated with the <tt>an:streamable</tt>
- : annotation, that is it returns a streamable string. A streamable
- : string can only be consumed once. Please see section "Streamable Strings"
- : in the <a href="../../html/options_and_annotations.html">
- : documentation of Zorba's annotations</a>.
- : </p>
+ : <p>The content is assumed to be UTF-8 encoded.</p>
  :
  : @param $uri the resource to fetch.
  : @return the resource referred to by the given URI as streamble string.
@@ -73,28 +63,85 @@
 (:~
  : <p>Tries to fetch the resource referred to by the given URI.</p>
  :
- : <p>In order to retrieve the content, the functions uses the
- : URI resolution and URL resolver process as documented at
- : <a href="../../html/uriresolvers.html">
- : URI Resolvers</a>. Therefore, it queries all URI mappers
- : and resolvers with the specified entity kind.</p>
- :
- : <p>The function is annotated with the <tt>an:streamable</tt>
- : annotation, that is it returns a streamable string. A streamable
- : string can only be consumed once. Please see section "Streamable Strings"
- : in the <a href="../../html/options_and_annotations.html">
- : documentation of Zorba's annotations</a>.
- : </p>
- :
- : @param $uri the resource to fetch.
- : @param $entityKind the kind of resource to fetch.
- : @return the resource referred to by the given URI as streamble string.
- :
- : @error zerr:ZXQP0025 if the URI could not be resolved
- :   or did not resolve to a <tt>StreamResource</tt>.
- :
- : @see <a href="../../html/uriresolvers.html">URI Resolvers</a>.
- : @see <a href="../../html/options_and_annotations.html">Documentation of Zorba's annotations</a>.
- :)
-
-declare %an:streamable function fetch:content($uri as xs:string, $entityKind as xs:string) as xs:string external;
+ : <p>It queries all URI mappers and resolvers with kind the specified
+ : entity kind.</p>
+ :
+ : <p>The content is assumed to be UTF-8 encoded.</p>
+ :
+ : @param $uri the resource to fetch.
+ : @param $entity-kind the kind of resource to fetch.
+ : @return the resource referred to by the given URI as streamble string.
+ :
+ : @error zerr:ZXQP0025 if the URI could not be resolved
+ :   or did not resolve to a <tt>StreamResource</tt>.
+ :
+ : @see <a href="../../html/uriresolvers.html">URI Resolvers</a>.
+ : @see <a href="../../html/options_and_annotations.html">Documentation of Zorba's annotations</a>.
+ :)
+declare %an:streamable function fetch:content($uri as xs:string, $entity-kind as xs:string)
+as xs:string
+{
+  fetch:content($uri, $entity-kind, "UTF-8")
+};
+
+(:~
+ : <p>Tries to fetch the resource referred to by the given URI.</p>
+ :
+ : <p>It queries all URI mappers and resolvers with kind the specified
+ : entity kind.</p>
+ :
+ : @param $uri the resource to fetch.
+ : @param $entity-kind the kind of resource to fetch.
+ : @param $encoding the encoding of the content
+ : @return the resource referred to by the given URI as streamble string.
+ :
+ : @error zerr:ZXQP0025 if the URI could not be resolved
+ :   or did not resolve to a <tt>StreamResource</tt>.
+ : @error zerr:ZXQP0006 if the given encoding is invalid or not supported.
+ :
+ : @see <a href="../../html/uriresolvers.html">URI Resolvers</a>.
+ : @see <a href="../../html/options_and_annotations.html">Documentation of Zorba's annotations</a>.
+ :)
+declare %an:streamable function fetch:content(
+  $uri as xs:string,
+  $entity-kind as xs:string,
+  $encoding as xs:string)
+as xs:string external;
+
+(:~
+ : <p>Tries to fetch the resource referred to by the given URI and
+ : returning it as base64Binary.</p>
+ :
+ : <p>It queries all URI mappers and resolvers with kind
+ : <tt>EntityData::SOME_CONTENT</tt>.</p>
+
+ : @param $uri the resource to fetch.
+ : @return the resource referred to by the given URI as streamble base64Binary.
+ :
+ : @error zerr:ZXQP0025 if the URI could not be resolved
+ :   or did not resolve to a <tt>StreamResource</tt>.
+ :)
+declare %an:streamable function fetch:content-binary($uri as xs:string)
+as xs:base64Binary
+{
+  fetch:content-binary($uri, "SOME_CONTENT")
+};
+
+(:~
+ : <p>Tries to fetch the resource referred to by the given URI and
+ : returning it as base64Binary.</p>
+ :
+ : <p>It queries all URI mappers and resolvers with kind the specified
+ : entity kind.</p>
+ :
+ : @param $uri the resource to fetch.
+ : @param $entity-kind the kind of resource to fetch.
+ : @return the resource referred to by the given URI as streamble base64Binary.
+ :
+ : @error zerr:ZXQP0025 if the URI could not be resolved
+ :   or did not resolve to a <tt>StreamResource</tt>.
+ :)
+declare %an:streamable function fetch:content-binary(
+  $uri as xs:string,
+  $entity-kind as xs:string)
+as xs:base64Binary external;

=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp	2012-05-17 00:28:51 +0000
+++ src/api/staticcontextimpl.cpp	2012-05-18 02:59:20 +0000
@@ -1551,7 +1551,7 @@
 Item
 StaticContextImpl::fetch(const String& aURI) const
 {
-  return fetch(aURI, "SOME_CONTENT");
+  return fetch(aURI, "SOME_CONTENT", "UTF-8");
 }
 
 Item
@@ -1559,6 +1559,15 @@
     const String& aURI,
     const String& aEntityKind) const
 {
+  return fetch(aURI, aEntityKind, "UTF-8");
+}
+
+Item
+StaticContextImpl::fetch(
+    const String& aURI,
+    const String& aEntityKind,
+    const String& aEncoding) const
+{
   ZORBA_TRY
   {
     Zorba* lZorba = Zorba::getInstance(0);
@@ -1572,6 +1581,53 @@
     lArgs.push_back(new SingletonItemSequence(lFactory->createString(aURI)));
     lArgs.push_back(
         new SingletonItemSequence(lFactory->createString(aEntityKind)));
+    lArgs.push_back(
+        new SingletonItemSequence(lFactory->createString(aEncoding)));
+
+    StaticContext_t lCtx = createChildContext();
+
+    Zorba_CompilerHints_t lHints;
+    std::ostringstream lProlog;
+    lProlog
+      << "import module namespace d = '" << static_context::ZORBA_FETCH_FN_NS  << "';";
+
+    lCtx->loadProlog(lProlog.str(), lHints);
+
+    ItemSequence_t lSeq = lCtx->invoke(lQName, lArgs);
+    Iterator_t lIter = lSeq->getIterator();
+    lIter->open();
+    Item lRes;
+    lIter->next(lRes);
+    return lRes;
+  }
+  ZORBA_CATCH
+  return 0;
+}
+
+Item
+StaticContextImpl::fetchBinary(const String& aURI) const
+{
+  return fetchBinary(aURI, "SOME_CONTENT");
+}
+
+Item
+StaticContextImpl::fetchBinary(
+    const String& aURI,
+    const String& aEntityKind) const
+{
+  ZORBA_TRY
+  {
+    Zorba* lZorba = Zorba::getInstance(0);
+    ItemFactory* lFactory = lZorba->getItemFactory();
+
+    Item lQName = lFactory->createQName(static_context::ZORBA_FETCH_FN_NS,
+                                          "content-binary");
+
+    // create a streamable string item
+    std::vector<ItemSequence_t> lArgs;
+    lArgs.push_back(new SingletonItemSequence(lFactory->createString(aURI)));
+    lArgs.push_back(
+        new SingletonItemSequence(lFactory->createString(aEntityKind)));
 
     StaticContext_t lCtx = createChildContext();
 

=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h	2012-05-15 21:12:27 +0000
+++ src/api/staticcontextimpl.h	2012-05-18 02:59:20 +0000
@@ -304,6 +304,18 @@
   virtual Item
   fetch(const String& aURI, const String& aEntityKind) const;
 
+  virtual Item
+  fetch(
+      const String& aURI,
+      const String& aEntityKind,
+      const String& aEncoding) const;
+
+  virtual Item
+  fetchBinary(const String& aURI) const;
+
+  virtual Item
+  fetchBinary(const String& aURI, const String& aEntityKind) const;
+
 protected:
   String
   createInvokeQuery(const Function_t&, size_t aArity) const;

=== modified file 'src/api/uri_resolver_wrappers.cpp'
--- src/api/uri_resolver_wrappers.cpp	2012-05-03 12:31:51 +0000
+++ src/api/uri_resolver_wrappers.cpp	2012-05-18 02:59:20 +0000
@@ -49,6 +49,8 @@
         return new EntityDataWrapper(EntityData::COLLECTION);
       case internal::EntityData::DOCUMENT:
         return new EntityDataWrapper(EntityData::DOCUMENT);
+      case internal::EntityData::SOME_CONTENT:
+        return new EntityDataWrapper(EntityData::SOME_CONTENT);
       default:
         return NULL;
       }
@@ -146,7 +148,9 @@
         // StreamResource, by passing the StreamReleaser to it and setting the
         // user's StreamResource's StreamReleaser to nullptr.
         lRetval = new internal::StreamResource(lUserStream->getStream(),
-                                           lUserStream->getStreamReleaser());
+                                           lUserStream->getStreamReleaser(),
+                                           "",
+                                           lUserStream->isStreamSeekable());
         lUserStream->setStreamReleaser(nullptr);
       }
 #ifndef ZORBA_NO_FULL_TEXT

=== modified file 'src/api/uriresolverimpl.cpp'
--- src/api/uriresolverimpl.cpp	2012-05-03 12:31:51 +0000
+++ src/api/uriresolverimpl.cpp	2012-05-18 02:59:20 +0000
@@ -43,15 +43,18 @@
   }
 
   StreamResource* StreamResource::create(std::istream* aStream,
-                                         StreamReleaser aStreamReleaser)
+                                         StreamReleaser aStreamReleaser,
+                                         bool aIsStreamSeekable)
   {
-    return new StreamResourceImpl(aStream, aStreamReleaser);
+    return new StreamResourceImpl(aStream, aStreamReleaser, aIsStreamSeekable);
   }
 
   StreamResourceImpl::StreamResourceImpl(std::istream* aStream,
-                                         StreamReleaser aStreamReleaser)
+                                         StreamReleaser aStreamReleaser,
+                                         bool aIsStreamSeekable)
     : theStream(aStream),
-      theStreamReleaser(aStreamReleaser)
+      theStreamReleaser(aStreamReleaser),
+      theIsStreamSeekable(aIsStreamSeekable)
   {
   }
 

=== modified file 'src/api/uriresolverimpl.h'
--- src/api/uriresolverimpl.h	2012-05-03 12:31:51 +0000
+++ src/api/uriresolverimpl.h	2012-05-18 02:59:20 +0000
@@ -39,14 +39,21 @@
 
   virtual void destroy() const;
 
+  virtual bool isStreamSeekable() const { return theIsStreamSeekable; }
+
 private:
 
-  StreamResourceImpl(std::istream* aStream, StreamReleaser aStreamReleaser);
+  StreamResourceImpl(
+      std::istream* aStream,
+      StreamReleaser aStreamReleaser,
+      bool aIsStreamSeekable);
 
   friend StreamResource* StreamResource::create(std::istream *aStream,
-                                                StreamReleaser aStreamReleaser);
+                                                StreamReleaser aStreamReleaser,
+                                                bool aIsStreamSeekable);
   std::istream* theStream;
   StreamReleaser theStreamReleaser;
+  bool theIsStreamSeekable;
 
 };
 

=== modified file 'src/capi/error.cpp'
--- src/capi/error.cpp	2012-05-03 12:31:51 +0000
+++ src/capi/error.cpp	2012-05-18 02:59:20 +0000
@@ -115,7 +115,7 @@
     || error == ZXQP0013_FXCHARHEAP_EXCEPTION
     || error == ZXQP0020_INVALID_URI
     || error == ZXQP0021_USER_ERROR
-    || error == ZXQP0025_ITEM_CREATION_FAILED
+    || error == ZXQP0025_COULD_NOT_FETCH_RESOURCE
     || error == ZXQP0028_TARGET_NAMESPACE_NOT_PROVIDED
     || error == ZXQP0029_URI_ACCESS_DENIED
     || error == ZXQP0030_DEADLOCK

=== modified file 'src/context/default_url_resolvers.cpp'
--- src/context/default_url_resolvers.cpp	2012-05-03 12:31:51 +0000
+++ src/context/default_url_resolvers.cpp	2012-05-18 02:59:20 +0000
@@ -107,7 +107,8 @@
   zstring lPath = fs::get_normalized_path(aUrl);
   if (fs::get_type(lPath) == fs::file) {
     std::ifstream* lStream = new std::ifstream(lPath.c_str());
-    return new StreamResource(lStream, &fileStreamReleaser);
+    return new StreamResource(
+        lStream, &fileStreamReleaser, "", true /* seekable */);
   }
   return NULL;
 }

=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp	2012-05-15 21:12:27 +0000
+++ src/context/static_context.cpp	2012-05-18 02:59:20 +0000
@@ -512,6 +512,10 @@
             ns == ZORBA_JSON_FN_NS ||
             ns == ZORBA_URI_FN_NS ||
             ns == ZORBA_RANDOM_FN_NS ||
+            ns == ZORBA_FETCH_FN_NS ||
+#ifndef ZORBA_NO_FULL_TEXT
+            ns == ZORBA_FULL_TEXT_FN_NS ||
+#endif /* ZORBA_NO_FULL_TEXT */
             ns == ZORBA_XML_FN_NS);
   }
 

=== modified file 'src/context/uri_resolver.cpp'
--- src/context/uri_resolver.cpp	2012-05-03 12:31:51 +0000
+++ src/context/uri_resolver.cpp	2012-05-18 02:59:20 +0000
@@ -46,11 +46,13 @@
 
   StreamResource::StreamResource
   (std::istream* aStream, StreamReleaser aStreamReleaser,
-   zstring aStreamUrl /* = "" */)
+   zstring aStreamUrl /* = "" */,
+   bool aIsStreamSeekable)
     : Resource(),
       theStream(aStream),
       theStreamReleaser(aStreamReleaser),
-      theStreamUrl(aStreamUrl)
+      theStreamUrl(aStreamUrl),
+      theIsStreamSeekable(aIsStreamSeekable)
   {}
   
   StreamResource::~StreamResource()

=== modified file 'src/context/uri_resolver.h'
--- src/context/uri_resolver.h	2012-05-03 12:31:51 +0000
+++ src/context/uri_resolver.h	2012-05-18 02:59:20 +0000
@@ -97,10 +97,13 @@
    * are certain unusual circumstances where a URLResolver may wish to
    * return a stream over some other URL than the one passed to it. In
    * that case, the URLResolver may pass the true URL here.
+   * @param aIsStreamSeekable determines whether the stream passed as first
+   * argument is arbitrarily seekable without throwing errors.
    */
   StreamResource(std::istream* aStream,
                  StreamReleaser aStreamReleaser,
-                 zstring aStreamUrl = "");
+                 zstring aStreamUrl = "",
+                 bool aIsStreamSeekable = false);
   
   virtual ~StreamResource();
 
@@ -127,11 +130,18 @@
    */
   zstring getStreamUrl();
 
+  /**
+   * @brief Returns true if the stream returned by getStream is seekable,
+   * false otherwise.
+   */
+  bool isStreamSeekable() const { return theIsStreamSeekable; }
+
 private:
 
   std::istream* theStream;
   StreamReleaser theStreamReleaser;
   zstring theStreamUrl;
+  bool theIsStreamSeekable;
 };
 
 /**

=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2012-05-16 23:04:41 +0000
+++ src/diagnostics/diagnostic_en.xml	2012-05-18 02:59:20 +0000
@@ -1697,8 +1697,12 @@
       <value>XML does not match schema${: "1"}${ 2}</value>
     </diagnostic>
 
-    <diagnostic code="ZXQP0025" name="ITEM_CREATION_FAILED">
-      <value>item creation failed</value>
+    <diagnostic code="ZXQP0025" name="COULD_NOT_FETCH_RESOURCE">
+      <value>"$1": could not fetch resource${; reason: 2}</value>
+
+      <entry key="RESOURCE_NOT_FOUND">
+        <value>resource not found</value>
+      </entry>
     </diagnostic>
 
     <diagnostic code="ZXQP0026" name="INVALID_ENUM_VALUE">

=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
--- src/diagnostics/pregenerated/diagnostic_list.cpp	2012-05-16 06:45:13 +0000
+++ src/diagnostics/pregenerated/diagnostic_list.cpp	2012-05-18 02:59:20 +0000
@@ -610,7 +610,7 @@
 ZorbaErrorCode ZXQP0024_XML_DOES_NOT_MATCH_SCHEMA( "ZXQP0024" );
 
 
-ZorbaErrorCode ZXQP0025_ITEM_CREATION_FAILED( "ZXQP0025" );
+ZorbaErrorCode ZXQP0025_COULD_NOT_FETCH_RESOURCE( "ZXQP0025" );
 
 
 ZorbaErrorCode ZXQP0026_INVALID_ENUM_VALUE( "ZXQP0026" );

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2012-05-16 23:04:41 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2012-05-18 02:59:20 +0000
@@ -411,7 +411,7 @@
   { "ZXQP0020", "\"$1\": invalid URI${: 2}" },
   { "ZXQP0021", "user error" },
   { "ZXQP0024", "XML does not match schema${: \"1\"}${ 2}" },
-  { "ZXQP0025", "item creation failed" },
+  { "ZXQP0025", "\"$1\": could not fetch resource${; reason: 2}" },
   { "ZXQP0026", "\"$1\": invalid enumerated value for $2" },
   { "ZXQP0028", "\"$1\": target namespace not provided by module from $2" },
   { "ZXQP0029", "\"$1\": URI access not allowed" },
@@ -796,6 +796,7 @@
   { "~ZXQD0004_NON_NEGATIVE", "given value must be non-negative ($2)" },
   { "~ZXQD0004_NOT_WITHIN_RANGE", "not within allowed range ($2)" },
   { "~ZXQP0004_TypeOps_is_in_scope_ForFunctionItemTypes", "TypeOps::is_in_scope() for function-item types" },
+  { "~ZXQP0025_RESOURCE_NOT_FOUND", "resource not found" },
   { "~ZeroLenURI", "zero-length URI (and no base URI given)" },
   { "~Zorba API error", "Zorba API error" },
   { "~Zorba data-definition error", "Zorba data-definition error" },

=== modified file 'src/functions/pregenerated/func_fetch.cpp'
--- src/functions/pregenerated/func_fetch.cpp	2012-05-03 12:31:51 +0000
+++ src/functions/pregenerated/func_fetch.cpp	2012-05-18 02:59:20 +0000
@@ -41,6 +41,16 @@
   return new FetchContentIterator(sctx, loc, argv);
 }
 
+PlanIter_t fn_zorba_fetch_content_binary::codegen(
+  CompilerCB*,
+  static_context* sctx,
+  const QueryLoc& loc,
+  std::vector<PlanIter_t>& argv,
+  expr& ann) const
+{
+  return new FetchContentBinaryIterator(sctx, loc, argv);
+}
+
 PlanIter_t fn_zorba_fetch_content_type::codegen(
   CompilerCB*,
   static_context* sctx,
@@ -60,8 +70,22 @@
         (createQName("http://www.zorba-xquery.com/modules/fetch","","content";), 
         GENV_TYPESYSTEM.STRING_TYPE_ONE, 
         GENV_TYPESYSTEM.STRING_TYPE_ONE, 
+        GENV_TYPESYSTEM.STRING_TYPE_ONE, 
         GENV_TYPESYSTEM.STRING_TYPE_ONE),
-        FunctionConsts::FN_ZORBA_FETCH_CONTENT_2);
+        FunctionConsts::FN_ZORBA_FETCH_CONTENT_3);
+
+  }
+
+
+  {
+    
+
+    DECL_WITH_KIND(sctx, fn_zorba_fetch_content_binary,
+        (createQName("http://www.zorba-xquery.com/modules/fetch","","content-binary";), 
+        GENV_TYPESYSTEM.STRING_TYPE_ONE, 
+        GENV_TYPESYSTEM.STRING_TYPE_ONE, 
+        GENV_TYPESYSTEM.BASE64BINARY_TYPE_ONE),
+        FunctionConsts::FN_ZORBA_FETCH_CONTENT_BINARY_2);
 
   }
 

=== modified file 'src/functions/pregenerated/func_fetch.h'
--- src/functions/pregenerated/func_fetch.h	2012-05-03 12:31:51 +0000
+++ src/functions/pregenerated/func_fetch.h	2012-05-18 02:59:20 +0000
@@ -55,6 +55,23 @@
 };
 
 
+//fn-zorba-fetch:content-binary
+class fn_zorba_fetch_content_binary : public function
+{
+public:
+  fn_zorba_fetch_content_binary(const signature& sig, FunctionConsts::FunctionKind kind)
+    : 
+    function(sig, kind)
+  {
+
+  }
+
+  bool accessesDynCtx() const { return true; }
+
+  CODEGEN_DECL();
+};
+
+
 //fn-zorba-fetch:content-type
 class fn_zorba_fetch_content_type : public function
 {

=== modified file 'src/functions/pregenerated/function_enum.h'
--- src/functions/pregenerated/function_enum.h	2012-05-08 03:09:12 +0000
+++ src/functions/pregenerated/function_enum.h	2012-05-18 02:59:20 +0000
@@ -137,7 +137,8 @@
   FN_TRACE_2,
   OP_ZORBA_READ_LINE_0,
   FN_ZORBA_UTIL_PRINT_1,
-  FN_ZORBA_FETCH_CONTENT_2,
+  FN_ZORBA_FETCH_CONTENT_3,
+  FN_ZORBA_FETCH_CONTENT_BINARY_2,
   FN_ZORBA_FETCH_CONTENT_TYPE_1,
   FN_PUT_2,
   FULL_TEXT_CURRENT_LANG_0,

=== modified file 'src/runtime/fetch/fetch_impl.cpp'
--- src/runtime/fetch/fetch_impl.cpp	2012-05-03 12:31:51 +0000
+++ src/runtime/fetch/fetch_impl.cpp	2012-05-18 02:59:20 +0000
@@ -15,6 +15,8 @@
  */
 #include "stdafx.h"
 
+#include <zorba/transcode_stream.h>
+
 #include "diagnostics/assert.h"
 #include "diagnostics/xquery_diagnostics.h"
 
@@ -30,33 +32,17 @@
 
 /*******************************************************************************
 ********************************************************************************/
-void
-FetchContentIterator::destroyStream(std::istream& aStream)
-{
-  delete &aStream;
-}
-
-bool
-FetchContentIterator::nextImpl(
-    store::Item_t& result,
-    PlanState& aPlanState) const
-{
-  store::Item_t lUri;
-  store::Item_t lEntityKind;
+std::auto_ptr<internal::StreamResource>
+getFetchResource(
+    const store::Item_t& aUri,
+    const store::Item_t& aKind,
+    const static_context* aSctx,
+    const QueryLoc& aLoc)
+{
   internal::EntityData::Kind lKind;
-  zstring lKindStr;
-  zstring lErrorMessage;
-  std::auto_ptr<internal::Resource> lRes;
-  internal::StreamResource* lStreamRes;
-
-  PlanIteratorState* state;
-  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
-
-  consumeNext(lUri, theChildren[0].getp(), aPlanState);
-  consumeNext(lEntityKind, theChildren[1].getp(), aPlanState);
+  zstring lKindStr = aKind->getStringValue();
 
   // Figure out the EntityKind (any better way to do this?)
-  lKindStr = lEntityKind->getStringValue();
   if ( ! lKindStr.compare("SOME_CONTENT")) {
     lKind = internal::EntityData::SOME_CONTENT;
   }
@@ -78,32 +64,88 @@
     throw XQUERY_EXCEPTION(
           zerr::ZXQP0026_INVALID_ENUM_VALUE,
           ERROR_PARAMS(lKindStr, "entityKind"),
-          ERROR_LOC(loc));
+          ERROR_LOC(aLoc));
   }
 
   try {
     // ask the uri mappers and resolvers to give
     // me a resource of specified kind
-    lRes = theSctx->resolve_uri(
-      lUri->getStringValue(),
+    zstring lErrorMessage;
+    
+    std::auto_ptr<internal::Resource> lRes = aSctx->resolve_uri(
+      aUri->getStringValue(),
       lKind,
       lErrorMessage);
 
+    std::auto_ptr<internal::StreamResource> lStreamRes(
+      dynamic_cast<internal::StreamResource*>(lRes.get()));
+
+    if ( !lStreamRes.get() )
+    {
+      throw XQUERY_EXCEPTION(
+        zerr::ZXQP0025_COULD_NOT_FETCH_RESOURCE,
+        ERROR_PARAMS(
+          aUri->getStringValue(),
+          ZED(ZXQP0025_RESOURCE_NOT_FOUND)
+        ),
+        ERROR_LOC( aLoc )
+      );
+    }
+
+    lRes.release();
+
+    return lStreamRes;
+
   } catch (ZorbaException const& e) {
     throw XQUERY_EXCEPTION(
-      zerr::ZXQP0025_ITEM_CREATION_FAILED,
-      ERROR_PARAMS( e.what() ),
-      ERROR_LOC( loc )
+      zerr::ZXQP0025_COULD_NOT_FETCH_RESOURCE,
+      ERROR_PARAMS( aUri->getStringValue(), e.what() ),
+      ERROR_LOC( aLoc )
     );
   }
-
-  lStreamRes = dynamic_cast<internal::StreamResource*>(lRes.get());
-  if ( !lStreamRes ) {
-    throw XQUERY_EXCEPTION(
-      zerr::ZXQP0025_ITEM_CREATION_FAILED,
-      ERROR_PARAMS( "Resource not available." ),
-      ERROR_LOC( loc )
-    );
+}
+
+/*******************************************************************************
+********************************************************************************/
+void
+FetchContentIterator::destroyStream(std::istream& aStream)
+{
+  delete &aStream;
+}
+
+bool
+FetchContentIterator::nextImpl(
+    store::Item_t& result,
+    PlanState& aPlanState) const
+{
+  store::Item_t lUri;
+  store::Item_t lEntityKind;
+  store::Item_t lEncoding;
+  zstring lEncodingStr;
+  std::auto_ptr<internal::StreamResource> lRes;
+
+  PlanIteratorState* state;
+  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
+
+  consumeNext(lUri, theChildren[0].getp(), aPlanState);
+  consumeNext(lEntityKind, theChildren[1].getp(), aPlanState);
+  consumeNext(lEncoding, theChildren[2].getp(), aPlanState);
+
+  lEncodingStr = lEncoding->getStringValue();
+
+  lRes = getFetchResource(lUri, lEntityKind, theSctx, loc);
+
+  if (transcode::is_necessary(lEncodingStr.c_str()))
+  {
+    if (!transcode::is_supported(lEncodingStr.c_str()))
+    {
+      throw XQUERY_EXCEPTION(
+          zerr::ZXQP0006_UNKNOWN_ENCODING,
+          ERROR_PARAMS( lEncodingStr.c_str() ),
+          ERROR_LOC( loc )
+        );
+    }
+    transcode::attach(*lRes->getStream(), lEncodingStr.c_str());
   }
 
   // return the resource in a streamable string. This transfers memory
@@ -111,10 +153,54 @@
   // object, so we then remove the StreamReleaser from the StreamResource.
   GENV_ITEMFACTORY->createStreamableString(
         result,
-        *lStreamRes->getStream(),
-        lStreamRes->getStreamReleaser()
-  );
-  lStreamRes->setStreamReleaser(nullptr);
+        *lRes->getStream(),
+        lRes->getStreamReleaser(),
+        lRes->isStreamSeekable()
+  );
+  lRes->setStreamReleaser(nullptr);
+
+  STACK_PUSH(result != NULL, state);
+
+  STACK_END(state);
+}
+
+
+/*******************************************************************************
+********************************************************************************/
+void
+FetchContentBinaryIterator::destroyStream(std::istream& aStream)
+{
+  delete &aStream;
+}
+
+bool
+FetchContentBinaryIterator::nextImpl(
+    store::Item_t& result,
+    PlanState& aPlanState) const
+{
+  store::Item_t lUri;
+  store::Item_t lEntityKind;
+  std::auto_ptr<internal::StreamResource> lRes;
+
+  PlanIteratorState* state;
+  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
+
+  consumeNext(lUri, theChildren[0].getp(), aPlanState);
+  consumeNext(lEntityKind, theChildren[1].getp(), aPlanState);
+
+  lRes = getFetchResource(lUri, lEntityKind, theSctx, loc);
+
+  // return the resource in a streamable base64. This transfers memory
+  // ownership of the istream (via its StreamReleaser) to the StreamableBase64BinaryItem
+  // object, so we then remove the StreamReleaser from the StreamResource.
+  GENV_ITEMFACTORY->createStreamableBase64Binary(
+        result,
+        *lRes->getStream(),
+        lRes->getStreamReleaser(),
+        lRes->isStreamSeekable(),
+        false
+  );
+  lRes->setStreamReleaser(nullptr);
 
   STACK_PUSH(result != NULL, state);
 

=== modified file 'src/runtime/fetch/pregenerated/fetch.cpp'
--- src/runtime/fetch/pregenerated/fetch.cpp	2012-05-03 12:31:51 +0000
+++ src/runtime/fetch/pregenerated/fetch.cpp	2012-05-18 02:59:20 +0000
@@ -54,6 +54,28 @@
 // </FetchContentIterator>
 
 
+// <FetchContentBinaryIterator>
+FetchContentBinaryIterator::class_factory<FetchContentBinaryIterator>
+FetchContentBinaryIterator::g_class_factory;
+
+
+void FetchContentBinaryIterator::accept(PlanIterVisitor& v) const {
+  v.beginVisit(*this);
+
+  std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
+  std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
+  for ( ; lIter != lEnd; ++lIter ){
+    (*lIter)->accept(v);
+  }
+
+  v.endVisit(*this);
+}
+
+FetchContentBinaryIterator::~FetchContentBinaryIterator() {}
+
+// </FetchContentBinaryIterator>
+
+
 // <FetchContentTypeIterator>
 FetchContentTypeIterator::class_factory<FetchContentTypeIterator>
 FetchContentTypeIterator::g_class_factory;

=== modified file 'src/runtime/fetch/pregenerated/fetch.h'
--- src/runtime/fetch/pregenerated/fetch.h	2012-05-03 12:31:51 +0000
+++ src/runtime/fetch/pregenerated/fetch.h	2012-05-18 02:59:20 +0000
@@ -73,6 +73,42 @@
  * 
  * Author: Matthias Brantner
  */
+class FetchContentBinaryIterator : public NaryBaseIterator<FetchContentBinaryIterator, PlanIteratorState>
+{ 
+public:
+  SERIALIZABLE_CLASS(FetchContentBinaryIterator);
+
+  SERIALIZABLE_CLASS_CONSTRUCTOR2T(FetchContentBinaryIterator,
+    NaryBaseIterator<FetchContentBinaryIterator, PlanIteratorState>);
+
+  void serialize( ::zorba::serialization::Archiver& ar)
+  {
+    serialize_baseclass(ar,
+    (NaryBaseIterator<FetchContentBinaryIterator, PlanIteratorState>*)this);
+  }
+
+  FetchContentBinaryIterator(
+    static_context* sctx,
+    const QueryLoc& loc,
+    std::vector<PlanIter_t>& children)
+    : 
+    NaryBaseIterator<FetchContentBinaryIterator, PlanIteratorState>(sctx, loc, children)
+  {}
+
+  virtual ~FetchContentBinaryIterator();
+
+public:
+  static void destroyStream(std::istream& aStream);
+  void accept(PlanIterVisitor& v) const;
+
+  bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
+};
+
+
+/**
+ * 
+ * Author: Matthias Brantner
+ */
 class FetchContentTypeIterator : public NaryBaseIterator<FetchContentTypeIterator, PlanIteratorState>
 { 
 public:

=== modified file 'src/runtime/nodes/nodes_impl.cpp'
--- src/runtime/nodes/nodes_impl.cpp	2012-05-03 12:31:51 +0000
+++ src/runtime/nodes/nodes_impl.cpp	2012-05-18 02:59:20 +0000
@@ -638,11 +638,13 @@
   lIterator->open();
   while(lIterator->next(lItem))
   {
-    if(lItem->getNodeKind() == aNode->getNodeKind())
+    if (lItem->getNodeKind() == aNode->getNodeKind())
+    {
       if(lItem->equals(aNode))
         break;
       else
         count++;
+    }
   }
   lIterator->close();
   return count;
@@ -663,7 +665,7 @@
   PlanIteratorState* state;
   DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
 
-  if (consumeNext(inNode, theChildren[0], planState));
+  if (consumeNext(inNode, theChildren[0], planState))
   {
     do
     { 

=== modified file 'src/runtime/spec/fetch/fetch.xml'
--- src/runtime/spec/fetch/fetch.xml	2012-05-03 12:31:51 +0000
+++ src/runtime/spec/fetch/fetch.xml	2012-05-18 02:59:20 +0000
@@ -16,7 +16,8 @@
   <zorba:function>
     <zorba:signature localname="content" prefix="fn-zorba-fetch">
       <zorba:param>xs:string</zorba:param>
-      <zorba:param>xs:string</zorba:param>
+      <zorba:param>xs:string</zorba:param> <!-- entityKind -->
+      <zorba:param>xs:string</zorba:param> <!-- encoding -->
       <zorba:output>xs:string</zorba:output>
     </zorba:signature>
 
@@ -25,8 +26,33 @@
     </zorba:methods>
   </zorba:function>
 
-  <zorba:method static="true" name="destroyStream"
-    return="void">
+  <zorba:method static="true" name="destroyStream" return="void">
+    <zorba:param type="std::istream&amp;" name="aStream"/>
+  </zorba:method>
+
+</zorba:iterator>
+
+<!--
+/*********************************************************************
+*********************************************************************/
+-->
+<zorba:iterator name="FetchContentBinaryIterator">
+
+  <zorba:description author="Matthias Brantner"></zorba:description>
+
+  <zorba:function>
+    <zorba:signature localname="content-binary" prefix="fn-zorba-fetch">
+      <zorba:param>xs:string</zorba:param>
+      <zorba:param>xs:string</zorba:param>
+      <zorba:output>xs:base64Binary</zorba:output>
+    </zorba:signature>
+
+    <zorba:methods>
+      <zorba:accessesDynCtx returnValue="true"/>
+    </zorba:methods>
+  </zorba:function>
+
+  <zorba:method static="true" name="destroyStream" return="void">
     <zorba:param type="std::istream&amp;" name="aStream"/>
   </zorba:method>
 

=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
--- src/runtime/visitors/pregenerated/planiter_visitor.h	2012-05-08 23:49:22 +0000
+++ src/runtime/visitors/pregenerated/planiter_visitor.h	2012-05-18 02:59:20 +0000
@@ -189,6 +189,8 @@
 
     class FetchContentIterator;
 
+    class FetchContentBinaryIterator;
+
     class FetchContentTypeIterator;
 
     class FnPutIterator;
@@ -900,6 +902,9 @@
     virtual void beginVisit ( const FetchContentIterator& ) = 0;
     virtual void endVisit   ( const FetchContentIterator& ) = 0;
 
+    virtual void beginVisit ( const FetchContentBinaryIterator& ) = 0;
+    virtual void endVisit   ( const FetchContentBinaryIterator& ) = 0;
+
     virtual void beginVisit ( const FetchContentTypeIterator& ) = 0;
     virtual void endVisit   ( const FetchContentTypeIterator& ) = 0;
 

=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
--- src/runtime/visitors/pregenerated/printer_visitor.cpp	2012-05-08 23:49:22 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.cpp	2012-05-18 02:59:20 +0000
@@ -1219,6 +1219,20 @@
 // </FetchContentIterator>
 
 
+// <FetchContentBinaryIterator>
+void PrinterVisitor::beginVisit ( const FetchContentBinaryIterator& a) {
+  thePrinter.startBeginVisit("FetchContentBinaryIterator", ++theId);
+  printCommons( &a, theId );
+  thePrinter.endBeginVisit( theId );
+}
+
+void PrinterVisitor::endVisit ( const FetchContentBinaryIterator& ) {
+  thePrinter.startEndVisit();
+  thePrinter.endEndVisit();
+}
+// </FetchContentBinaryIterator>
+
+
 // <FetchContentTypeIterator>
 void PrinterVisitor::beginVisit ( const FetchContentTypeIterator& a) {
   thePrinter.startBeginVisit("FetchContentTypeIterator", ++theId);

=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
--- src/runtime/visitors/pregenerated/printer_visitor.h	2012-05-08 23:49:22 +0000
+++ src/runtime/visitors/pregenerated/printer_visitor.h	2012-05-18 02:59:20 +0000
@@ -286,6 +286,9 @@
     void beginVisit( const FetchContentIterator& );
     void endVisit  ( const FetchContentIterator& );
 
+    void beginVisit( const FetchContentBinaryIterator& );
+    void endVisit  ( const FetchContentBinaryIterator& );
+
     void beginVisit( const FetchContentTypeIterator& );
     void endVisit  ( const FetchContentTypeIterator& );
 

=== modified file 'src/zorbaserialization/archiver.cpp'
--- src/zorbaserialization/archiver.cpp	2012-05-03 12:31:51 +0000
+++ src/zorbaserialization/archiver.cpp	2012-05-18 02:59:20 +0000
@@ -125,9 +125,9 @@
   theCurrentLevel(0),
   theNonClassFieldsMap(0),
   theClassFieldsMap(0),
+  theOnlyForEval(0),
   all_reference_list(0),
   internal_archive(internal_archive),
-  theOnlyForEval(0),
   theSerializeEverything(false),
   loading_hardcoded_objects(false),
   theAllowDelay2(ALLOW_DELAY),

=== added file 'test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable.xml.res'
--- test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable.xml.res	2012-05-18 02:59:20 +0000
@@ -0,0 +1,1 @@
+true true true

=== added file 'test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable_binary.xml.res'
--- test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable_binary.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable_binary.xml.res	2012-05-18 02:59:20 +0000
@@ -0,0 +1,1 @@
+8 5Pb8Cg==

=== added file 'test/rbkt/ExpQueryResults/zorba/fetch/fetch_some_transcode.xml.res'
--- test/rbkt/ExpQueryResults/zorba/fetch/fetch_some_transcode.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/fetch/fetch_some_transcode.xml.res	2012-05-18 02:59:20 +0000
@@ -0,0 +1,1 @@
+äöü

=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_bogus1.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_bogus1.xq	2012-05-03 12:31:51 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_bogus1.xq	2012-05-18 02:59:20 +0000
@@ -1,4 +1,4 @@
 (: Fetch with unknown entity kind :)
-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";;
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
 
 fetch:content("http://www.zorba-xquery.com/modules/ext";, "NOTHING")

=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_bogus2.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_bogus2.xq	2012-05-03 12:31:51 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_bogus2.xq	2012-05-18 02:59:20 +0000
@@ -1,4 +1,4 @@
 (: Fetch a valid module URI but as SOME_CONTENT :)
-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";;
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
 
 fetch:content("http://www.flworfound.org/modules/ext";, "SOME_CONTENT")

=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_module1.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_module1.xq	2012-05-03 12:31:51 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_module1.xq	2012-05-18 02:59:20 +0000
@@ -1,4 +1,4 @@
 (: Fetch a module's content :)
-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";;
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
 
 fetch:content("http://www.zorba-xquery.com/modules/ext";, "MODULE")

=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_module2.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_module2.xq	2012-05-03 12:31:51 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_module2.xq	2012-05-18 02:59:20 +0000
@@ -1,4 +1,4 @@
 (: Fetch a module's content with versioning :)
-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";;
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
 
 fetch:content("http://www.zorba-xquery.com/modules/ext#1.0";, "MODULE")

=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_random_file.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_random_file.xq	2012-02-01 17:13:01 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_random_file.xq	2012-05-18 02:59:20 +0000
@@ -1,4 +1,4 @@
 (: Fetch a random file from the filesystem :)
-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";;
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
 
 fetch:content("http://www.zorba-xquery.com/random-file";, "SOME_CONTENT")

=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_schema1.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_schema1.xq	2012-05-03 12:31:51 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_schema1.xq	2012-05-18 02:59:20 +0000
@@ -1,5 +1,5 @@
 (: Fetch a schemas's content :)
-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";;
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
 
 fn:parse-xml(
   fetch:content("http://www.zorba-xquery.com/modules/theschema";, "SCHEMA")

=== added file 'test/rbkt/Queries/zorba/fetch/fetch_seekable.xml.res'
--- test/rbkt/Queries/zorba/fetch/fetch_seekable.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_seekable.xml.res	2012-05-18 02:59:20 +0000
@@ -0,0 +1,1 @@
+true true true

=== added file 'test/rbkt/Queries/zorba/fetch/fetch_seekable.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_seekable.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_seekable.xq	2012-05-18 02:59:20 +0000
@@ -0,0 +1,8 @@
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
+
+import module namespace s = "http://www.zorba-xquery.com/modules/string";;
+
+(: make sure the returned string is streamable and can be consumed twice, i.e. is seekable :)
+let $x := fetch:content(fn:resolve-uri("iso-8859-1.txt"))
+return (s:is-streamable($x), string-length($x) gt 0, string-length($x) gt 0)
+

=== added file 'test/rbkt/Queries/zorba/fetch/fetch_seekable_binary.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_seekable_binary.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_seekable_binary.xq	2012-05-18 02:59:20 +0000
@@ -0,0 +1,8 @@
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
+
+import module namespace b = "http://www.zorba-xquery.com/modules/converters/base64";;
+
+(: make sure the returned string is streamable and can be consumed twice, i.e. is seekable :)
+let $x := fetch:content-binary(fn:resolve-uri("iso-8859-1.txt"))
+return (string-length(xs:string($x)), $x)
+

=== added file 'test/rbkt/Queries/zorba/fetch/fetch_some_transcode.xq'
--- test/rbkt/Queries/zorba/fetch/fetch_some_transcode.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/fetch/fetch_some_transcode.xq	2012-05-18 02:59:20 +0000
@@ -0,0 +1,3 @@
+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";;
+
+fetch:content(resolve-uri("iso-8859-1.txt"), "SOME_CONTENT", "ISO-8859-1")

=== added file 'test/rbkt/Queries/zorba/fetch/iso-8859-1.txt'
--- test/rbkt/Queries/zorba/fetch/iso-8859-1.txt	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/fetch/iso-8859-1.txt	2012-05-18 02:59:20 +0000
@@ -0,0 +1,1 @@
+

=== modified file 'test/unit/static_context.cpp'
--- test/unit/static_context.cpp	2012-05-07 23:43:04 +0000
+++ test/unit/static_context.cpp	2012-05-18 02:59:20 +0000
@@ -117,6 +117,27 @@
 }
 
 
+bool
+sctx_test_4(Zorba* const zorba)
+{
+  StaticContext_t lSctx = zorba->createStaticContext();
+
+  Zorba_CompilerHints_t lHints;
+
+  try
+  {
+    Item lFetched = lSctx->fetchBinary("http://www.zorba-xquery.com/modules/fetch";, "MODULE");
+
+    size_t s;
+    return !lFetched.isNull() && lFetched.getBase64BinaryValue(s);
+  }
+  catch (ZorbaException& e)
+  {
+    std::cerr << e << std::endl;
+  }
+  return false;
+}
+
 
 int static_context( int argc, char *argv[] ) 
 {
@@ -132,6 +153,9 @@
   if (!sctx_test_3(zorba))
     return 3;
 
+  if (!sctx_test_4(zorba))
+    return 4;
+
   zorba->shutdown();
   StoreManager::shutdownStore( zstore );
   return 0;

-- 
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