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

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

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/core_archive_module/+merge/112661

- added API function Item:isSeekable
- fixed a problem in the file module where all exceptions being throw in the 
body were caught and rethrown as file exception. This could have lead to 
confusing error messages if an exception was reported while evaluating the 
input sequence to file:write.
-- 
https://code.launchpad.net/~zorba-coders/zorba/core_archive_module/+merge/112661
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-06-28 19:06:27 +0000
+++ ChangeLog	2012-06-28 22:14:20 +0000
@@ -4,6 +4,7 @@
 version 2.x
 
 New Features:
+  * Item::isSeekable API extension for streamable content (xs:string and xs:base64Binary).
   * Implemented the latest W3C specification for the group by clause
   * New XQuery 3.0 functions
     - fn:parse-xml-fragment#1

=== modified file 'include/zorba/item.h'
--- include/zorba/item.h	2012-06-28 04:14:03 +0000
+++ include/zorba/item.h	2012-06-28 22:14:20 +0000
@@ -422,6 +422,14 @@
   isStreamable() const;
 
   /**
+   * Checks whether the item's streamable content is seekable.
+   *
+   * @return true only if it is.
+   */
+  bool
+  isSeekable() const;
+
+  /**
    * Gets an istream for the item's content.
    *
    * @return the stream.

=== modified file 'modules/org/expath/ns/file.xq.src/file_function.cpp'
--- modules/org/expath/ns/file.xq.src/file_function.cpp	2012-06-28 04:14:03 +0000
+++ modules/org/expath/ns/file.xq.src/file_function.cpp	2012-06-28 22:14:20 +0000
@@ -241,77 +241,79 @@
   File_t lFile = File::createFile(lFileStr.c_str());
 
   // precondition
-  if (lFile->isDirectory()) {
-    raiseFileError("FOFL0004", "The given path points to a directory", lFile->getFilePath());
+  if (lFile->isDirectory())
+  {
+    raiseFileError("FOFL0004",
+        "The given path points to a directory", lFile->getFilePath());
   }
 
   bool lBinary = isBinary();
+  // open the output stream in the desired write mode
+  std::ofstream lOutStream;
 
   // actual write
-  try {
-
-    // open the output stream in the desired write mode
-    std::ofstream lOutStream;
+  try
+  {
     lFile->openOutputStream(lOutStream, lBinary, isAppend());
-
-    // if this is a binary write
-    if (lBinary) {
-      Item lBinaryItem;
-      Iterator_t lContentSeq = aArgs[1]->getIterator();
-      lContentSeq->open();
-      while (lContentSeq->next(lBinaryItem))
-      {
-        if (lBinaryItem.isStreamable() && !lBinaryItem.isEncoded())
-        {
-          lOutStream << lBinaryItem.getStream().rdbuf();
-        }
-        else
-        {
-          Zorba_SerializerOptions lOptions;
-          lOptions.ser_method = ZORBA_SERIALIZATION_METHOD_BINARY;
-          Serializer_t lSerializer = Serializer::createSerializer(lOptions);
-          SingletonItemSequence lSeq(lBinaryItem);
-          lSerializer->serialize(&lSeq, lOutStream);
-        }
-
-      }
-    }
-    // if we only write text
-    else {
-      Item lStringItem;
-      Iterator_t lContentSeq = aArgs[1]->getIterator();
-      lContentSeq->open();
-      // for each item (string or base64Binary) in the content sequence
-      while (lContentSeq->next(lStringItem)) {
-        // if the item is streamable make use of the stream
-        if (lStringItem.isStreamable()) {
-          std::istream& lInStream = lStringItem.getStream();
-          char lBuf[1024];
-          while (!lInStream.eof()) {
-            lInStream.read(lBuf, 1024);
-            lOutStream.write(lBuf, lInStream.gcount());
-          }
-        }
-        // else write the string value
-        else {
-          zorba::String lString = lStringItem.getStringValue();
-          lOutStream.write(lString.data(), lString.size());
-        }
-      }
-      lContentSeq->close();
-    }
-
-    // close the file stream
-    lOutStream.close();
-
-  } catch (ZorbaException& ze) {
+  }
+  catch (ZorbaException& ze)
+  {
     std::stringstream lSs;
-    lSs << "An unknown error occured: " << ze.what() << "Can not read file";
+    lSs << "Can not open file for writing: " << ze.what();
     raiseFileError("FOFL9999", lSs.str(), lFile->getFilePath());
-  } catch (...) {
-    //assert(false); if this happens errors are not proprly thrown
-    raiseFileError("FOFL9999", "Can not read file", lFile->getFilePath());
-  }
+  }
+
+  // if this is a binary write
+  if (lBinary)
+  {
+    Item lBinaryItem;
+    Iterator_t lContentSeq = aArgs[1]->getIterator();
+    lContentSeq->open();
+    while (lContentSeq->next(lBinaryItem))
+    {
+      if (lBinaryItem.isStreamable() && !lBinaryItem.isEncoded())
+      {
+        lOutStream << lBinaryItem.getStream().rdbuf();
+      }
+      else
+      {
+        Zorba_SerializerOptions lOptions;
+        lOptions.ser_method = ZORBA_SERIALIZATION_METHOD_BINARY;
+        Serializer_t lSerializer = Serializer::createSerializer(lOptions);
+        SingletonItemSequence lSeq(lBinaryItem);
+        lSerializer->serialize(&lSeq, lOutStream);
+      }
+
+    }
+  }
+  // if we only write text
+  else
+  {
+    Item lStringItem;
+    Iterator_t lContentSeq = aArgs[1]->getIterator();
+    lContentSeq->open();
+    // for each item (string or base64Binary) in the content sequence
+    while (lContentSeq->next(lStringItem)) {
+      // if the item is streamable make use of the stream
+      if (lStringItem.isStreamable()) {
+        std::istream& lInStream = lStringItem.getStream();
+        char lBuf[1024];
+        while (!lInStream.eof()) {
+          lInStream.read(lBuf, 1024);
+          lOutStream.write(lBuf, lInStream.gcount());
+        }
+      }
+      // else write the string value
+      else {
+        zorba::String lString = lStringItem.getStringValue();
+        lOutStream.write(lString.data(), lString.size());
+      }
+    }
+    lContentSeq->close();
+  }
+
+  // close the file stream
+  lOutStream.close();
 
   return ItemSequence_t(new EmptySequence());
 }

=== modified file 'src/api/item.cpp'
--- src/api/item.cpp	2012-06-28 04:14:03 +0000
+++ src/api/item.cpp	2012-06-28 22:14:20 +0000
@@ -546,6 +546,17 @@
   return false;
 }
 
+bool
+Item::isSeekable() const
+{
+  ITEM_TRY
+    SYNC_CODE(AutoLock lock(GENV_STORE.getGlobalLock(), Lock::READ);)
+
+    return m_item->isSeekable();
+  ITEM_CATCH
+  return false;
+}
+
 std::istream&
 Item::getStream()
 {

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