Merge lp:~zorba-coders/zorba/feature-fetch_binary into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Till Westmann
Approved revision: 10846
Merged at revision: 10856
Proposed branch: lp:~zorba-coders/zorba/feature-fetch_binary
Merge into: lp:zorba
Diff against target: 1359 lines (+626/-123)
45 files modified
ChangeLog (+4/-0)
include/zorba/pregenerated/diagnostic_list.h (+1/-1)
include/zorba/static_context.h (+59/-1)
include/zorba/uri_resolvers.h (+8/-2)
modules/com/zorba-xquery/www/modules/fetch.xq (+93/-46)
src/api/staticcontextimpl.cpp (+57/-1)
src/api/staticcontextimpl.h (+12/-0)
src/api/uri_resolver_wrappers.cpp (+5/-1)
src/api/uriresolverimpl.cpp (+7/-4)
src/api/uriresolverimpl.h (+9/-2)
src/capi/error.cpp (+1/-1)
src/context/default_url_resolvers.cpp (+2/-1)
src/context/static_context.cpp (+4/-0)
src/context/uri_resolver.cpp (+4/-2)
src/context/uri_resolver.h (+11/-1)
src/diagnostics/diagnostic_en.xml (+6/-2)
src/diagnostics/pregenerated/diagnostic_list.cpp (+1/-1)
src/diagnostics/pregenerated/dict_en.cpp (+2/-1)
src/functions/pregenerated/func_fetch.cpp (+25/-1)
src/functions/pregenerated/func_fetch.h (+17/-0)
src/functions/pregenerated/function_enum.h (+2/-1)
src/runtime/fetch/fetch_impl.cpp (+128/-42)
src/runtime/fetch/pregenerated/fetch.cpp (+22/-0)
src/runtime/fetch/pregenerated/fetch.h (+36/-0)
src/runtime/nodes/nodes_impl.cpp (+4/-2)
src/runtime/spec/fetch/fetch.xml (+29/-3)
src/runtime/visitors/pregenerated/planiter_visitor.h (+5/-0)
src/runtime/visitors/pregenerated/printer_visitor.cpp (+14/-0)
src/runtime/visitors/pregenerated/printer_visitor.h (+3/-0)
src/zorbaserialization/archiver.cpp (+1/-1)
test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable_binary.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/fetch/fetch_some_transcode.xml.res (+1/-0)
test/rbkt/Queries/zorba/fetch/fetch_bogus1.xq (+1/-1)
test/rbkt/Queries/zorba/fetch/fetch_bogus2.xq (+1/-1)
test/rbkt/Queries/zorba/fetch/fetch_module1.xq (+1/-1)
test/rbkt/Queries/zorba/fetch/fetch_module2.xq (+1/-1)
test/rbkt/Queries/zorba/fetch/fetch_random_file.xq (+1/-1)
test/rbkt/Queries/zorba/fetch/fetch_schema1.xq (+1/-1)
test/rbkt/Queries/zorba/fetch/fetch_seekable.xml.res (+1/-0)
test/rbkt/Queries/zorba/fetch/fetch_seekable.xq (+8/-0)
test/rbkt/Queries/zorba/fetch/fetch_seekable_binary.xq (+8/-0)
test/rbkt/Queries/zorba/fetch/fetch_some_transcode.xq (+3/-0)
test/rbkt/Queries/zorba/fetch/iso-8859-1.txt (+1/-0)
test/unit/static_context.cpp (+24/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/feature-fetch_binary
Reviewer Review Type Date Requested Status
Till Westmann Approve
Chris Hillery Approve
Matthias Brantner Approve
Review via email: mp+106300@code.launchpad.net

This proposal supersedes a proposal from 2012-05-11.

Commit message

- 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

Description of the change

- 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

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

The attempt to merge lp:~zorba-coders/zorba/feature-fetch_binary into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job feature-fetch_binary-2012-05-10T17-26-13.72Z is
  finished. The final status was:

  13 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

The attempt to merge lp:~zorba-coders/zorba/feature-fetch_binary into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job feature-fetch_binary-2012-05-10T21-26-27.53Z is
  finished. The final status was:

  13 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Matthias Brantner (matthias-brantner) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in src/context/static_context.cpp

Revision history for this message
Matthias Brantner (matthias-brantner) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job feature-fetch_binary-2012-05-11T15-47-14.061Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

Looks good except that the fetch module version should probably only be 2.1, not 3.0. I'm voting Approve now, so if you don't re-submit the proposal (and don't change anything else besides the version number) you should be able to get it merged.

review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

> Looks good except that the fetch module version should probably only be 2.1,
> not 3.0. I'm voting Approve now, so if you don't re-submit the proposal (and
> don't change anything else besides the version number) you should be able to
> get it merged.
I have changed the version 3.0 => 2.1 as suggested.

Revision history for this message
Till Westmann (tillw) wrote : Posted in a previous version of this proposal

Looks good - even the transcoding stuff seems to work :)

Some remarks (nothing blocking):
- It would be nice to keep fetch-binary functions together in the module.
- Is internal::StreamResource::create ever used with 3 parameters?
- fetch_impl.cpp:
  - 104
    Why is lEncodingStr initialized if it is always overwritten in line 115?
    Also, as the lEncodingStr is only accessed using c_str(), the zstring is
    probably not necessary at all.
  - 115
    It seems that dynamic_cast<internal::StreamResource*> and the error handling
    could be moved into getFetchResource.
- It would be great to have at least one http-Test (but of course that adds
  flakiness to the test run …)

review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

> Looks good - even the transcoding stuff seems to work :)
>
> Some remarks (nothing blocking):
> - It would be nice to keep fetch-binary functions together in the module.
fixed

> - Is internal::StreamResource::create ever used with 3 parameters?
for http stuff when coming from the api

> - fetch_impl.cpp:
> - 104
> Why is lEncodingStr initialized if it is always overwritten in line 115?
> Also, as the lEncodingStr is only accessed using c_str(), the zstring is
> probably not necessary at all.
fixed

> - 115
> It seems that dynamic_cast<internal::StreamResource*> and the error
> handling
> could be moved into getFetchResource.
fixed

> - It would be great to have at least one http-Test (but of course that adds
> flakiness to the test run …)
not fixed for this reason

Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

I'm afraid you have to review parts again. I have extended the C++ api and added the binary fetch functions to make it symmetric with the module.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in include/zorba/static_context.h

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Chris Hillery (ceejatec) wrote :

Still looks good to me.

review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-fetch_binary-2012-05-18T22-36-05.288Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 2 Approve, 1 Pending.

Revision history for this message
Till Westmann (tillw) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-fetch_binary-2012-05-19T00-09-00.993Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2012-05-16 06:45:13 +0000
3+++ ChangeLog 2012-05-18 22:05:23 +0000
4@@ -25,6 +25,10 @@
5 * Added support for NO_ICU (to not use ICU for unicode processing)
6 * Added XQJ support.
7 * Added CollectionManager and DocumentManager support for XQJ.
8+ * New API EntityKind SOME_CONTENT
9+ * API StreamResource is able to specify whether a stream is seekable
10+ * New functions in the fetch module and the StaticContext to fetch
11+ resources as binary
12
13 Optimizations:
14 * optimized insertion into a collection (don't copy it if the node was created by an element constructor
15
16=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
17--- include/zorba/pregenerated/diagnostic_list.h 2012-05-16 06:45:13 +0000
18+++ include/zorba/pregenerated/diagnostic_list.h 2012-05-18 22:05:23 +0000
19@@ -420,7 +420,7 @@
20
21 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZXQP0024_XML_DOES_NOT_MATCH_SCHEMA;
22
23-extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZXQP0025_ITEM_CREATION_FAILED;
24+extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZXQP0025_COULD_NOT_FETCH_RESOURCE;
25
26 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZXQP0026_INVALID_ENUM_VALUE;
27
28
29=== modified file 'include/zorba/static_context.h'
30--- include/zorba/static_context.h 2012-05-07 19:41:09 +0000
31+++ include/zorba/static_context.h 2012-05-18 22:05:23 +0000
32@@ -697,7 +697,8 @@
33 * registered, the built-in ones are used.
34 *
35 * The default EntityKind for resources fetched by this function
36- * is "SOME_CONTENT".
37+ * is "SOME_CONTENT". The default encoding that is used to read the
38+ * resource is "UTF-8".
39 *
40 * @param aURI the name of the resource to fetch
41 *
42@@ -712,6 +713,8 @@
43 * in this static context. If no such mappers or resolvers have been
44 * registered, the built-in ones are used.
45 *
46+ * The default encoding that is used to read the * resource is "UTF-8".
47+ *
48 * @param aURI the name of the resource to fetch
49 *
50 * @param aEntityKind the kind of the entity to fetch (i.e.
51@@ -722,6 +725,61 @@
52
53 virtual Item
54 fetch(const String& aURI, const String& aEntityKind) const = 0;
55+
56+ /** \brief Fetches an resource refered to by the given URI.
57+ *
58+ * Resolution is done using the URI mappers and resolvers registered
59+ * in this static context. If no such mappers or resolvers have been
60+ * registered, the built-in ones are used.
61+ *
62+ * @param aURI the name of the resource to fetch
63+ * @param aEncoding the encoding to use when reading the resource.
64+ *
65+ * @param aEntityKind the kind of the entity to fetch (i.e.
66+ * SOME_CONTENT, SCHEMA, MODULE, THESAURUS, or STOP_WORDS)
67+ *
68+ * @return the fetched resource
69+ */
70+ virtual Item
71+ fetch(
72+ const String& aURI,
73+ const String& aEntityKind,
74+ const String& aEncoding) const = 0;
75+
76+ /** \brief Fetches an resource refered to by the given URI
77+ * and returns it as a base64binary.
78+ *
79+ * Resolution is done using the URI mappers and resolvers registered
80+ * in this static context. If no such mappers or resolvers have been
81+ * registered, the built-in ones are used.
82+ *
83+ * The default EntityKind for resources fetched by this function
84+ * is "SOME_CONTENT".
85+ *
86+ * @param aURI the name of the resource to fetch
87+ *
88+ * @return the fetched resource
89+ */
90+ virtual Item
91+ fetchBinary(const String& aURI) const = 0;
92+
93+ /** \brief Fetches an resource refered to by the given URI
94+ * and returns it as a base64binary.
95+ *
96+ * Resolution is done using the URI mappers and resolvers registered
97+ * in this static context. If no such mappers or resolvers have been
98+ * registered, the built-in ones are used.
99+ *
100+ * @param aURI the name of the resource to fetch
101+ *
102+ * @param aEntityKind the kind of the entity to fetch (i.e.
103+ * SOME_CONTENT, SCHEMA, MODULE, THESAURUS, or STOP_WORDS)
104+ *
105+ * @return the fetched resource
106+ */
107+ virtual Item
108+ fetchBinary(const String& aURI, const String& aEntityKind) const = 0;
109+
110 /** \brief Clears the base URI and sets it to undefined state.
111 * (see http://www.w3.org/TR/xquery/#static_context)
112 */
113
114=== modified file 'include/zorba/uri_resolvers.h'
115--- include/zorba/uri_resolvers.h 2012-05-03 12:31:51 +0000
116+++ include/zorba/uri_resolvers.h 2012-05-18 22:05:23 +0000
117@@ -84,9 +84,12 @@
118 * @param aStreamReleaser A function pointer which is invoked once
119 * the StreamResource is destroyed. Normally this function will delete
120 * the std::istream object passed to it.
121+ * @param aIsStreamSeekable Determines whether the given stream is arbitrarily
122+ * seekable without throwing errors.
123 */
124 static StreamResource* create(std::istream* aStream,
125- StreamReleaser aStreamReleaser);
126+ StreamReleaser aStreamReleaser,
127+ bool aIsStreamSeekable = false);
128
129 /**
130 * @brief Retrieve the istream associated with this Resource.
131@@ -99,6 +102,8 @@
132 virtual StreamReleaser getStreamReleaser() = 0;
133
134 virtual ~StreamResource() = 0;
135+
136+ virtual bool isStreamSeekable() const = 0;
137 };
138
139 /**
140@@ -123,7 +128,8 @@
141 THESAURUS,
142 STOP_WORDS,
143 COLLECTION,
144- DOCUMENT
145+ DOCUMENT,
146+ SOME_CONTENT
147 };
148
149 /**
150
151=== modified file 'modules/com/zorba-xquery/www/modules/fetch.xq'
152--- modules/com/zorba-xquery/www/modules/fetch.xq 2012-05-03 12:31:51 +0000
153+++ modules/com/zorba-xquery/www/modules/fetch.xq 2012-05-18 22:05:23 +0000
154@@ -17,15 +17,13 @@
155 :)
156
157 (:~
158- : This module provides functions to fetch the contents or the type
159- : of the content for a resource identified by a URI.
160- : For example, it fetches content for file or http resources if Zorba
161- : allows file or http access, respectively.
162- :
163- : <p>The errors raised by functions of this module have the namespace
164- : <tt>http://www.zorba-xquery.com/errors</tt> (associated with prefix zerr).</p>
165- :
166- : @see <a href="www.zorba-xquery.com_errors.html">http://www.zorba-xquery.com/errors</a>
167+ : <p>This module provides functions to fetch the content of a resource identified
168+ : by a URI. For example, it fetches the content of file or http resources.</p>
169+ :
170+ : <p>In order to retrieve such content, the functions use the
171+ : URI resolution and URL resolver process as documented at
172+ : <a href="../../html/uriresolvers.html">
173+ : URI Resolvers</a>.</p>
174 :
175 : @author Matthias Brantner
176 :
177@@ -38,23 +36,15 @@
178 declare namespace zerr = "http://www.zorba-xquery.com/errors";
179
180 declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
181-declare option ver:module-version "2.0";
182+declare option ver:module-version "2.1";
183
184 (:~
185 : <p>Tries to fetch the resource referred to by the given URI.</p>
186 :
187- : <p>In order to retrieve the content, the functions uses the
188- : URI resolution and URL resolver process as documented at
189- : <a href="../../html/uriresolvers.html">
190- : URI Resolvers</a>. Therefore, it queries all URI mappers
191- : and resolvers with kind <tt>EntityData::SOME_CONTENT</tt>.</p>
192+ : <p>It queries all URI mappers and resolvers with kind
193+ : <tt>EntityData::SOME_CONTENT</tt>.</p>
194 :
195- : <p>The function is annotated with the <tt>an:streamable</tt>
196- : annotation, that is it returns a streamable string. A streamable
197- : string can only be consumed once. Please see section "Streamable Strings"
198- : in the <a href="../../html/options_and_annotations.html">
199- : documentation of Zorba's annotations</a>.
200- : </p>
201+ : <p>The content is assumed to be UTF-8 encoded.</p>
202 :
203 : @param $uri the resource to fetch.
204 : @return the resource referred to by the given URI as streamble string.
205@@ -73,28 +63,85 @@
206 (:~
207 : <p>Tries to fetch the resource referred to by the given URI.</p>
208 :
209- : <p>In order to retrieve the content, the functions uses the
210- : URI resolution and URL resolver process as documented at
211- : <a href="../../html/uriresolvers.html">
212- : URI Resolvers</a>. Therefore, it queries all URI mappers
213- : and resolvers with the specified entity kind.</p>
214- :
215- : <p>The function is annotated with the <tt>an:streamable</tt>
216- : annotation, that is it returns a streamable string. A streamable
217- : string can only be consumed once. Please see section "Streamable Strings"
218- : in the <a href="../../html/options_and_annotations.html">
219- : documentation of Zorba's annotations</a>.
220- : </p>
221- :
222- : @param $uri the resource to fetch.
223- : @param $entityKind the kind of resource to fetch.
224- : @return the resource referred to by the given URI as streamble string.
225- :
226- : @error zerr:ZXQP0025 if the URI could not be resolved
227- : or did not resolve to a <tt>StreamResource</tt>.
228- :
229- : @see <a href="../../html/uriresolvers.html">URI Resolvers</a>.
230- : @see <a href="../../html/options_and_annotations.html">Documentation of Zorba's annotations</a>.
231- :)
232-
233-declare %an:streamable function fetch:content($uri as xs:string, $entityKind as xs:string) as xs:string external;
234+ : <p>It queries all URI mappers and resolvers with kind the specified
235+ : entity kind.</p>
236+ :
237+ : <p>The content is assumed to be UTF-8 encoded.</p>
238+ :
239+ : @param $uri the resource to fetch.
240+ : @param $entity-kind the kind of resource to fetch.
241+ : @return the resource referred to by the given URI as streamble string.
242+ :
243+ : @error zerr:ZXQP0025 if the URI could not be resolved
244+ : or did not resolve to a <tt>StreamResource</tt>.
245+ :
246+ : @see <a href="../../html/uriresolvers.html">URI Resolvers</a>.
247+ : @see <a href="../../html/options_and_annotations.html">Documentation of Zorba's annotations</a>.
248+ :)
249+declare %an:streamable function fetch:content($uri as xs:string, $entity-kind as xs:string)
250+as xs:string
251+{
252+ fetch:content($uri, $entity-kind, "UTF-8")
253+};
254+
255+(:~
256+ : <p>Tries to fetch the resource referred to by the given URI.</p>
257+ :
258+ : <p>It queries all URI mappers and resolvers with kind the specified
259+ : entity kind.</p>
260+ :
261+ : @param $uri the resource to fetch.
262+ : @param $entity-kind the kind of resource to fetch.
263+ : @param $encoding the encoding of the content
264+ : @return the resource referred to by the given URI as streamble string.
265+ :
266+ : @error zerr:ZXQP0025 if the URI could not be resolved
267+ : or did not resolve to a <tt>StreamResource</tt>.
268+ : @error zerr:ZXQP0006 if the given encoding is invalid or not supported.
269+ :
270+ : @see <a href="../../html/uriresolvers.html">URI Resolvers</a>.
271+ : @see <a href="../../html/options_and_annotations.html">Documentation of Zorba's annotations</a>.
272+ :)
273+declare %an:streamable function fetch:content(
274+ $uri as xs:string,
275+ $entity-kind as xs:string,
276+ $encoding as xs:string)
277+as xs:string external;
278+
279+(:~
280+ : <p>Tries to fetch the resource referred to by the given URI and
281+ : returning it as base64Binary.</p>
282+ :
283+ : <p>It queries all URI mappers and resolvers with kind
284+ : <tt>EntityData::SOME_CONTENT</tt>.</p>
285+
286+ : @param $uri the resource to fetch.
287+ : @return the resource referred to by the given URI as streamble base64Binary.
288+ :
289+ : @error zerr:ZXQP0025 if the URI could not be resolved
290+ : or did not resolve to a <tt>StreamResource</tt>.
291+ :)
292+declare %an:streamable function fetch:content-binary($uri as xs:string)
293+as xs:base64Binary
294+{
295+ fetch:content-binary($uri, "SOME_CONTENT")
296+};
297+
298+(:~
299+ : <p>Tries to fetch the resource referred to by the given URI and
300+ : returning it as base64Binary.</p>
301+ :
302+ : <p>It queries all URI mappers and resolvers with kind the specified
303+ : entity kind.</p>
304+ :
305+ : @param $uri the resource to fetch.
306+ : @param $entity-kind the kind of resource to fetch.
307+ : @return the resource referred to by the given URI as streamble base64Binary.
308+ :
309+ : @error zerr:ZXQP0025 if the URI could not be resolved
310+ : or did not resolve to a <tt>StreamResource</tt>.
311+ :)
312+declare %an:streamable function fetch:content-binary(
313+ $uri as xs:string,
314+ $entity-kind as xs:string)
315+as xs:base64Binary external;
316
317=== modified file 'src/api/staticcontextimpl.cpp'
318--- src/api/staticcontextimpl.cpp 2012-05-17 00:28:51 +0000
319+++ src/api/staticcontextimpl.cpp 2012-05-18 22:05:23 +0000
320@@ -1551,7 +1551,7 @@
321 Item
322 StaticContextImpl::fetch(const String& aURI) const
323 {
324- return fetch(aURI, "SOME_CONTENT");
325+ return fetch(aURI, "SOME_CONTENT", "UTF-8");
326 }
327
328 Item
329@@ -1559,6 +1559,15 @@
330 const String& aURI,
331 const String& aEntityKind) const
332 {
333+ return fetch(aURI, aEntityKind, "UTF-8");
334+}
335+
336+Item
337+StaticContextImpl::fetch(
338+ const String& aURI,
339+ const String& aEntityKind,
340+ const String& aEncoding) const
341+{
342 ZORBA_TRY
343 {
344 Zorba* lZorba = Zorba::getInstance(0);
345@@ -1572,6 +1581,53 @@
346 lArgs.push_back(new SingletonItemSequence(lFactory->createString(aURI)));
347 lArgs.push_back(
348 new SingletonItemSequence(lFactory->createString(aEntityKind)));
349+ lArgs.push_back(
350+ new SingletonItemSequence(lFactory->createString(aEncoding)));
351+
352+ StaticContext_t lCtx = createChildContext();
353+
354+ Zorba_CompilerHints_t lHints;
355+ std::ostringstream lProlog;
356+ lProlog
357+ << "import module namespace d = '" << static_context::ZORBA_FETCH_FN_NS << "';";
358+
359+ lCtx->loadProlog(lProlog.str(), lHints);
360+
361+ ItemSequence_t lSeq = lCtx->invoke(lQName, lArgs);
362+ Iterator_t lIter = lSeq->getIterator();
363+ lIter->open();
364+ Item lRes;
365+ lIter->next(lRes);
366+ return lRes;
367+ }
368+ ZORBA_CATCH
369+ return 0;
370+}
371+
372+Item
373+StaticContextImpl::fetchBinary(const String& aURI) const
374+{
375+ return fetchBinary(aURI, "SOME_CONTENT");
376+}
377+
378+Item
379+StaticContextImpl::fetchBinary(
380+ const String& aURI,
381+ const String& aEntityKind) const
382+{
383+ ZORBA_TRY
384+ {
385+ Zorba* lZorba = Zorba::getInstance(0);
386+ ItemFactory* lFactory = lZorba->getItemFactory();
387+
388+ Item lQName = lFactory->createQName(static_context::ZORBA_FETCH_FN_NS,
389+ "content-binary");
390+
391+ // create a streamable string item
392+ std::vector<ItemSequence_t> lArgs;
393+ lArgs.push_back(new SingletonItemSequence(lFactory->createString(aURI)));
394+ lArgs.push_back(
395+ new SingletonItemSequence(lFactory->createString(aEntityKind)));
396
397 StaticContext_t lCtx = createChildContext();
398
399
400=== modified file 'src/api/staticcontextimpl.h'
401--- src/api/staticcontextimpl.h 2012-05-15 21:12:27 +0000
402+++ src/api/staticcontextimpl.h 2012-05-18 22:05:23 +0000
403@@ -304,6 +304,18 @@
404 virtual Item
405 fetch(const String& aURI, const String& aEntityKind) const;
406
407+ virtual Item
408+ fetch(
409+ const String& aURI,
410+ const String& aEntityKind,
411+ const String& aEncoding) const;
412+
413+ virtual Item
414+ fetchBinary(const String& aURI) const;
415+
416+ virtual Item
417+ fetchBinary(const String& aURI, const String& aEntityKind) const;
418+
419 protected:
420 String
421 createInvokeQuery(const Function_t&, size_t aArity) const;
422
423=== modified file 'src/api/uri_resolver_wrappers.cpp'
424--- src/api/uri_resolver_wrappers.cpp 2012-05-03 12:31:51 +0000
425+++ src/api/uri_resolver_wrappers.cpp 2012-05-18 22:05:23 +0000
426@@ -49,6 +49,8 @@
427 return new EntityDataWrapper(EntityData::COLLECTION);
428 case internal::EntityData::DOCUMENT:
429 return new EntityDataWrapper(EntityData::DOCUMENT);
430+ case internal::EntityData::SOME_CONTENT:
431+ return new EntityDataWrapper(EntityData::SOME_CONTENT);
432 default:
433 return NULL;
434 }
435@@ -146,7 +148,9 @@
436 // StreamResource, by passing the StreamReleaser to it and setting the
437 // user's StreamResource's StreamReleaser to nullptr.
438 lRetval = new internal::StreamResource(lUserStream->getStream(),
439- lUserStream->getStreamReleaser());
440+ lUserStream->getStreamReleaser(),
441+ "",
442+ lUserStream->isStreamSeekable());
443 lUserStream->setStreamReleaser(nullptr);
444 }
445 #ifndef ZORBA_NO_FULL_TEXT
446
447=== modified file 'src/api/uriresolverimpl.cpp'
448--- src/api/uriresolverimpl.cpp 2012-05-03 12:31:51 +0000
449+++ src/api/uriresolverimpl.cpp 2012-05-18 22:05:23 +0000
450@@ -43,15 +43,18 @@
451 }
452
453 StreamResource* StreamResource::create(std::istream* aStream,
454- StreamReleaser aStreamReleaser)
455+ StreamReleaser aStreamReleaser,
456+ bool aIsStreamSeekable)
457 {
458- return new StreamResourceImpl(aStream, aStreamReleaser);
459+ return new StreamResourceImpl(aStream, aStreamReleaser, aIsStreamSeekable);
460 }
461
462 StreamResourceImpl::StreamResourceImpl(std::istream* aStream,
463- StreamReleaser aStreamReleaser)
464+ StreamReleaser aStreamReleaser,
465+ bool aIsStreamSeekable)
466 : theStream(aStream),
467- theStreamReleaser(aStreamReleaser)
468+ theStreamReleaser(aStreamReleaser),
469+ theIsStreamSeekable(aIsStreamSeekable)
470 {
471 }
472
473
474=== modified file 'src/api/uriresolverimpl.h'
475--- src/api/uriresolverimpl.h 2012-05-03 12:31:51 +0000
476+++ src/api/uriresolverimpl.h 2012-05-18 22:05:23 +0000
477@@ -39,14 +39,21 @@
478
479 virtual void destroy() const;
480
481+ virtual bool isStreamSeekable() const { return theIsStreamSeekable; }
482+
483 private:
484
485- StreamResourceImpl(std::istream* aStream, StreamReleaser aStreamReleaser);
486+ StreamResourceImpl(
487+ std::istream* aStream,
488+ StreamReleaser aStreamReleaser,
489+ bool aIsStreamSeekable);
490
491 friend StreamResource* StreamResource::create(std::istream *aStream,
492- StreamReleaser aStreamReleaser);
493+ StreamReleaser aStreamReleaser,
494+ bool aIsStreamSeekable);
495 std::istream* theStream;
496 StreamReleaser theStreamReleaser;
497+ bool theIsStreamSeekable;
498
499 };
500
501
502=== modified file 'src/capi/error.cpp'
503--- src/capi/error.cpp 2012-05-03 12:31:51 +0000
504+++ src/capi/error.cpp 2012-05-18 22:05:23 +0000
505@@ -115,7 +115,7 @@
506 || error == ZXQP0013_FXCHARHEAP_EXCEPTION
507 || error == ZXQP0020_INVALID_URI
508 || error == ZXQP0021_USER_ERROR
509- || error == ZXQP0025_ITEM_CREATION_FAILED
510+ || error == ZXQP0025_COULD_NOT_FETCH_RESOURCE
511 || error == ZXQP0028_TARGET_NAMESPACE_NOT_PROVIDED
512 || error == ZXQP0029_URI_ACCESS_DENIED
513 || error == ZXQP0030_DEADLOCK
514
515=== modified file 'src/context/default_url_resolvers.cpp'
516--- src/context/default_url_resolvers.cpp 2012-05-03 12:31:51 +0000
517+++ src/context/default_url_resolvers.cpp 2012-05-18 22:05:23 +0000
518@@ -107,7 +107,8 @@
519 zstring lPath = fs::get_normalized_path(aUrl);
520 if (fs::get_type(lPath) == fs::file) {
521 std::ifstream* lStream = new std::ifstream(lPath.c_str());
522- return new StreamResource(lStream, &fileStreamReleaser);
523+ return new StreamResource(
524+ lStream, &fileStreamReleaser, "", true /* seekable */);
525 }
526 return NULL;
527 }
528
529=== modified file 'src/context/static_context.cpp'
530--- src/context/static_context.cpp 2012-05-15 21:12:27 +0000
531+++ src/context/static_context.cpp 2012-05-18 22:05:23 +0000
532@@ -512,6 +512,10 @@
533 ns == ZORBA_JSON_FN_NS ||
534 ns == ZORBA_URI_FN_NS ||
535 ns == ZORBA_RANDOM_FN_NS ||
536+ ns == ZORBA_FETCH_FN_NS ||
537+#ifndef ZORBA_NO_FULL_TEXT
538+ ns == ZORBA_FULL_TEXT_FN_NS ||
539+#endif /* ZORBA_NO_FULL_TEXT */
540 ns == ZORBA_XML_FN_NS);
541 }
542
543
544=== modified file 'src/context/uri_resolver.cpp'
545--- src/context/uri_resolver.cpp 2012-05-03 12:31:51 +0000
546+++ src/context/uri_resolver.cpp 2012-05-18 22:05:23 +0000
547@@ -46,11 +46,13 @@
548
549 StreamResource::StreamResource
550 (std::istream* aStream, StreamReleaser aStreamReleaser,
551- zstring aStreamUrl /* = "" */)
552+ zstring aStreamUrl /* = "" */,
553+ bool aIsStreamSeekable)
554 : Resource(),
555 theStream(aStream),
556 theStreamReleaser(aStreamReleaser),
557- theStreamUrl(aStreamUrl)
558+ theStreamUrl(aStreamUrl),
559+ theIsStreamSeekable(aIsStreamSeekable)
560 {}
561
562 StreamResource::~StreamResource()
563
564=== modified file 'src/context/uri_resolver.h'
565--- src/context/uri_resolver.h 2012-05-03 12:31:51 +0000
566+++ src/context/uri_resolver.h 2012-05-18 22:05:23 +0000
567@@ -97,10 +97,13 @@
568 * are certain unusual circumstances where a URLResolver may wish to
569 * return a stream over some other URL than the one passed to it. In
570 * that case, the URLResolver may pass the true URL here.
571+ * @param aIsStreamSeekable determines whether the stream passed as first
572+ * argument is arbitrarily seekable without throwing errors.
573 */
574 StreamResource(std::istream* aStream,
575 StreamReleaser aStreamReleaser,
576- zstring aStreamUrl = "");
577+ zstring aStreamUrl = "",
578+ bool aIsStreamSeekable = false);
579
580 virtual ~StreamResource();
581
582@@ -127,11 +130,18 @@
583 */
584 zstring getStreamUrl();
585
586+ /**
587+ * @brief Returns true if the stream returned by getStream is seekable,
588+ * false otherwise.
589+ */
590+ bool isStreamSeekable() const { return theIsStreamSeekable; }
591+
592 private:
593
594 std::istream* theStream;
595 StreamReleaser theStreamReleaser;
596 zstring theStreamUrl;
597+ bool theIsStreamSeekable;
598 };
599
600 /**
601
602=== modified file 'src/diagnostics/diagnostic_en.xml'
603--- src/diagnostics/diagnostic_en.xml 2012-05-16 23:04:41 +0000
604+++ src/diagnostics/diagnostic_en.xml 2012-05-18 22:05:23 +0000
605@@ -1697,8 +1697,12 @@
606 <value>XML does not match schema${: "1"}${ 2}</value>
607 </diagnostic>
608
609- <diagnostic code="ZXQP0025" name="ITEM_CREATION_FAILED">
610- <value>item creation failed</value>
611+ <diagnostic code="ZXQP0025" name="COULD_NOT_FETCH_RESOURCE">
612+ <value>"$1": could not fetch resource${; reason: 2}</value>
613+
614+ <entry key="RESOURCE_NOT_FOUND">
615+ <value>resource not found</value>
616+ </entry>
617 </diagnostic>
618
619 <diagnostic code="ZXQP0026" name="INVALID_ENUM_VALUE">
620
621=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
622--- src/diagnostics/pregenerated/diagnostic_list.cpp 2012-05-16 06:45:13 +0000
623+++ src/diagnostics/pregenerated/diagnostic_list.cpp 2012-05-18 22:05:23 +0000
624@@ -610,7 +610,7 @@
625 ZorbaErrorCode ZXQP0024_XML_DOES_NOT_MATCH_SCHEMA( "ZXQP0024" );
626
627
628-ZorbaErrorCode ZXQP0025_ITEM_CREATION_FAILED( "ZXQP0025" );
629+ZorbaErrorCode ZXQP0025_COULD_NOT_FETCH_RESOURCE( "ZXQP0025" );
630
631
632 ZorbaErrorCode ZXQP0026_INVALID_ENUM_VALUE( "ZXQP0026" );
633
634=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
635--- src/diagnostics/pregenerated/dict_en.cpp 2012-05-16 23:04:41 +0000
636+++ src/diagnostics/pregenerated/dict_en.cpp 2012-05-18 22:05:23 +0000
637@@ -411,7 +411,7 @@
638 { "ZXQP0020", "\"$1\": invalid URI${: 2}" },
639 { "ZXQP0021", "user error" },
640 { "ZXQP0024", "XML does not match schema${: \"1\"}${ 2}" },
641- { "ZXQP0025", "item creation failed" },
642+ { "ZXQP0025", "\"$1\": could not fetch resource${; reason: 2}" },
643 { "ZXQP0026", "\"$1\": invalid enumerated value for $2" },
644 { "ZXQP0028", "\"$1\": target namespace not provided by module from $2" },
645 { "ZXQP0029", "\"$1\": URI access not allowed" },
646@@ -796,6 +796,7 @@
647 { "~ZXQD0004_NON_NEGATIVE", "given value must be non-negative ($2)" },
648 { "~ZXQD0004_NOT_WITHIN_RANGE", "not within allowed range ($2)" },
649 { "~ZXQP0004_TypeOps_is_in_scope_ForFunctionItemTypes", "TypeOps::is_in_scope() for function-item types" },
650+ { "~ZXQP0025_RESOURCE_NOT_FOUND", "resource not found" },
651 { "~ZeroLenURI", "zero-length URI (and no base URI given)" },
652 { "~Zorba API error", "Zorba API error" },
653 { "~Zorba data-definition error", "Zorba data-definition error" },
654
655=== modified file 'src/functions/pregenerated/func_fetch.cpp'
656--- src/functions/pregenerated/func_fetch.cpp 2012-05-03 12:31:51 +0000
657+++ src/functions/pregenerated/func_fetch.cpp 2012-05-18 22:05:23 +0000
658@@ -41,6 +41,16 @@
659 return new FetchContentIterator(sctx, loc, argv);
660 }
661
662+PlanIter_t fn_zorba_fetch_content_binary::codegen(
663+ CompilerCB*,
664+ static_context* sctx,
665+ const QueryLoc& loc,
666+ std::vector<PlanIter_t>& argv,
667+ expr& ann) const
668+{
669+ return new FetchContentBinaryIterator(sctx, loc, argv);
670+}
671+
672 PlanIter_t fn_zorba_fetch_content_type::codegen(
673 CompilerCB*,
674 static_context* sctx,
675@@ -60,8 +70,22 @@
676 (createQName("http://www.zorba-xquery.com/modules/fetch","","content"),
677 GENV_TYPESYSTEM.STRING_TYPE_ONE,
678 GENV_TYPESYSTEM.STRING_TYPE_ONE,
679+ GENV_TYPESYSTEM.STRING_TYPE_ONE,
680 GENV_TYPESYSTEM.STRING_TYPE_ONE),
681- FunctionConsts::FN_ZORBA_FETCH_CONTENT_2);
682+ FunctionConsts::FN_ZORBA_FETCH_CONTENT_3);
683+
684+ }
685+
686+
687+ {
688+
689+
690+ DECL_WITH_KIND(sctx, fn_zorba_fetch_content_binary,
691+ (createQName("http://www.zorba-xquery.com/modules/fetch","","content-binary"),
692+ GENV_TYPESYSTEM.STRING_TYPE_ONE,
693+ GENV_TYPESYSTEM.STRING_TYPE_ONE,
694+ GENV_TYPESYSTEM.BASE64BINARY_TYPE_ONE),
695+ FunctionConsts::FN_ZORBA_FETCH_CONTENT_BINARY_2);
696
697 }
698
699
700=== modified file 'src/functions/pregenerated/func_fetch.h'
701--- src/functions/pregenerated/func_fetch.h 2012-05-03 12:31:51 +0000
702+++ src/functions/pregenerated/func_fetch.h 2012-05-18 22:05:23 +0000
703@@ -55,6 +55,23 @@
704 };
705
706
707+//fn-zorba-fetch:content-binary
708+class fn_zorba_fetch_content_binary : public function
709+{
710+public:
711+ fn_zorba_fetch_content_binary(const signature& sig, FunctionConsts::FunctionKind kind)
712+ :
713+ function(sig, kind)
714+ {
715+
716+ }
717+
718+ bool accessesDynCtx() const { return true; }
719+
720+ CODEGEN_DECL();
721+};
722+
723+
724 //fn-zorba-fetch:content-type
725 class fn_zorba_fetch_content_type : public function
726 {
727
728=== modified file 'src/functions/pregenerated/function_enum.h'
729--- src/functions/pregenerated/function_enum.h 2012-05-08 03:09:12 +0000
730+++ src/functions/pregenerated/function_enum.h 2012-05-18 22:05:23 +0000
731@@ -137,7 +137,8 @@
732 FN_TRACE_2,
733 OP_ZORBA_READ_LINE_0,
734 FN_ZORBA_UTIL_PRINT_1,
735- FN_ZORBA_FETCH_CONTENT_2,
736+ FN_ZORBA_FETCH_CONTENT_3,
737+ FN_ZORBA_FETCH_CONTENT_BINARY_2,
738 FN_ZORBA_FETCH_CONTENT_TYPE_1,
739 FN_PUT_2,
740 FULL_TEXT_CURRENT_LANG_0,
741
742=== modified file 'src/runtime/fetch/fetch_impl.cpp'
743--- src/runtime/fetch/fetch_impl.cpp 2012-05-03 12:31:51 +0000
744+++ src/runtime/fetch/fetch_impl.cpp 2012-05-18 22:05:23 +0000
745@@ -15,6 +15,8 @@
746 */
747 #include "stdafx.h"
748
749+#include <zorba/transcode_stream.h>
750+
751 #include "diagnostics/assert.h"
752 #include "diagnostics/xquery_diagnostics.h"
753
754@@ -30,33 +32,17 @@
755
756 /*******************************************************************************
757 ********************************************************************************/
758-void
759-FetchContentIterator::destroyStream(std::istream& aStream)
760-{
761- delete &aStream;
762-}
763-
764-bool
765-FetchContentIterator::nextImpl(
766- store::Item_t& result,
767- PlanState& aPlanState) const
768-{
769- store::Item_t lUri;
770- store::Item_t lEntityKind;
771+std::auto_ptr<internal::StreamResource>
772+getFetchResource(
773+ const store::Item_t& aUri,
774+ const store::Item_t& aKind,
775+ const static_context* aSctx,
776+ const QueryLoc& aLoc)
777+{
778 internal::EntityData::Kind lKind;
779- zstring lKindStr;
780- zstring lErrorMessage;
781- std::auto_ptr<internal::Resource> lRes;
782- internal::StreamResource* lStreamRes;
783-
784- PlanIteratorState* state;
785- DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
786-
787- consumeNext(lUri, theChildren[0].getp(), aPlanState);
788- consumeNext(lEntityKind, theChildren[1].getp(), aPlanState);
789+ zstring lKindStr = aKind->getStringValue();
790
791 // Figure out the EntityKind (any better way to do this?)
792- lKindStr = lEntityKind->getStringValue();
793 if ( ! lKindStr.compare("SOME_CONTENT")) {
794 lKind = internal::EntityData::SOME_CONTENT;
795 }
796@@ -78,32 +64,88 @@
797 throw XQUERY_EXCEPTION(
798 zerr::ZXQP0026_INVALID_ENUM_VALUE,
799 ERROR_PARAMS(lKindStr, "entityKind"),
800- ERROR_LOC(loc));
801+ ERROR_LOC(aLoc));
802 }
803
804 try {
805 // ask the uri mappers and resolvers to give
806 // me a resource of specified kind
807- lRes = theSctx->resolve_uri(
808- lUri->getStringValue(),
809+ zstring lErrorMessage;
810+
811+ std::auto_ptr<internal::Resource> lRes = aSctx->resolve_uri(
812+ aUri->getStringValue(),
813 lKind,
814 lErrorMessage);
815
816+ std::auto_ptr<internal::StreamResource> lStreamRes(
817+ dynamic_cast<internal::StreamResource*>(lRes.get()));
818+
819+ if ( !lStreamRes.get() )
820+ {
821+ throw XQUERY_EXCEPTION(
822+ zerr::ZXQP0025_COULD_NOT_FETCH_RESOURCE,
823+ ERROR_PARAMS(
824+ aUri->getStringValue(),
825+ ZED(ZXQP0025_RESOURCE_NOT_FOUND)
826+ ),
827+ ERROR_LOC( aLoc )
828+ );
829+ }
830+
831+ lRes.release();
832+
833+ return lStreamRes;
834+
835 } catch (ZorbaException const& e) {
836 throw XQUERY_EXCEPTION(
837- zerr::ZXQP0025_ITEM_CREATION_FAILED,
838- ERROR_PARAMS( e.what() ),
839- ERROR_LOC( loc )
840+ zerr::ZXQP0025_COULD_NOT_FETCH_RESOURCE,
841+ ERROR_PARAMS( aUri->getStringValue(), e.what() ),
842+ ERROR_LOC( aLoc )
843 );
844 }
845-
846- lStreamRes = dynamic_cast<internal::StreamResource*>(lRes.get());
847- if ( !lStreamRes ) {
848- throw XQUERY_EXCEPTION(
849- zerr::ZXQP0025_ITEM_CREATION_FAILED,
850- ERROR_PARAMS( "Resource not available." ),
851- ERROR_LOC( loc )
852- );
853+}
854+
855+/*******************************************************************************
856+********************************************************************************/
857+void
858+FetchContentIterator::destroyStream(std::istream& aStream)
859+{
860+ delete &aStream;
861+}
862+
863+bool
864+FetchContentIterator::nextImpl(
865+ store::Item_t& result,
866+ PlanState& aPlanState) const
867+{
868+ store::Item_t lUri;
869+ store::Item_t lEntityKind;
870+ store::Item_t lEncoding;
871+ zstring lEncodingStr;
872+ std::auto_ptr<internal::StreamResource> lRes;
873+
874+ PlanIteratorState* state;
875+ DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
876+
877+ consumeNext(lUri, theChildren[0].getp(), aPlanState);
878+ consumeNext(lEntityKind, theChildren[1].getp(), aPlanState);
879+ consumeNext(lEncoding, theChildren[2].getp(), aPlanState);
880+
881+ lEncodingStr = lEncoding->getStringValue();
882+
883+ lRes = getFetchResource(lUri, lEntityKind, theSctx, loc);
884+
885+ if (transcode::is_necessary(lEncodingStr.c_str()))
886+ {
887+ if (!transcode::is_supported(lEncodingStr.c_str()))
888+ {
889+ throw XQUERY_EXCEPTION(
890+ zerr::ZXQP0006_UNKNOWN_ENCODING,
891+ ERROR_PARAMS( lEncodingStr.c_str() ),
892+ ERROR_LOC( loc )
893+ );
894+ }
895+ transcode::attach(*lRes->getStream(), lEncodingStr.c_str());
896 }
897
898 // return the resource in a streamable string. This transfers memory
899@@ -111,10 +153,54 @@
900 // object, so we then remove the StreamReleaser from the StreamResource.
901 GENV_ITEMFACTORY->createStreamableString(
902 result,
903- *lStreamRes->getStream(),
904- lStreamRes->getStreamReleaser()
905- );
906- lStreamRes->setStreamReleaser(nullptr);
907+ *lRes->getStream(),
908+ lRes->getStreamReleaser(),
909+ lRes->isStreamSeekable()
910+ );
911+ lRes->setStreamReleaser(nullptr);
912+
913+ STACK_PUSH(result != NULL, state);
914+
915+ STACK_END(state);
916+}
917+
918+
919+/*******************************************************************************
920+********************************************************************************/
921+void
922+FetchContentBinaryIterator::destroyStream(std::istream& aStream)
923+{
924+ delete &aStream;
925+}
926+
927+bool
928+FetchContentBinaryIterator::nextImpl(
929+ store::Item_t& result,
930+ PlanState& aPlanState) const
931+{
932+ store::Item_t lUri;
933+ store::Item_t lEntityKind;
934+ std::auto_ptr<internal::StreamResource> lRes;
935+
936+ PlanIteratorState* state;
937+ DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
938+
939+ consumeNext(lUri, theChildren[0].getp(), aPlanState);
940+ consumeNext(lEntityKind, theChildren[1].getp(), aPlanState);
941+
942+ lRes = getFetchResource(lUri, lEntityKind, theSctx, loc);
943+
944+ // return the resource in a streamable base64. This transfers memory
945+ // ownership of the istream (via its StreamReleaser) to the StreamableBase64BinaryItem
946+ // object, so we then remove the StreamReleaser from the StreamResource.
947+ GENV_ITEMFACTORY->createStreamableBase64Binary(
948+ result,
949+ *lRes->getStream(),
950+ lRes->getStreamReleaser(),
951+ lRes->isStreamSeekable(),
952+ false
953+ );
954+ lRes->setStreamReleaser(nullptr);
955
956 STACK_PUSH(result != NULL, state);
957
958
959=== modified file 'src/runtime/fetch/pregenerated/fetch.cpp'
960--- src/runtime/fetch/pregenerated/fetch.cpp 2012-05-03 12:31:51 +0000
961+++ src/runtime/fetch/pregenerated/fetch.cpp 2012-05-18 22:05:23 +0000
962@@ -54,6 +54,28 @@
963 // </FetchContentIterator>
964
965
966+// <FetchContentBinaryIterator>
967+FetchContentBinaryIterator::class_factory<FetchContentBinaryIterator>
968+FetchContentBinaryIterator::g_class_factory;
969+
970+
971+void FetchContentBinaryIterator::accept(PlanIterVisitor& v) const {
972+ v.beginVisit(*this);
973+
974+ std::vector<PlanIter_t>::const_iterator lIter = theChildren.begin();
975+ std::vector<PlanIter_t>::const_iterator lEnd = theChildren.end();
976+ for ( ; lIter != lEnd; ++lIter ){
977+ (*lIter)->accept(v);
978+ }
979+
980+ v.endVisit(*this);
981+}
982+
983+FetchContentBinaryIterator::~FetchContentBinaryIterator() {}
984+
985+// </FetchContentBinaryIterator>
986+
987+
988 // <FetchContentTypeIterator>
989 FetchContentTypeIterator::class_factory<FetchContentTypeIterator>
990 FetchContentTypeIterator::g_class_factory;
991
992=== modified file 'src/runtime/fetch/pregenerated/fetch.h'
993--- src/runtime/fetch/pregenerated/fetch.h 2012-05-03 12:31:51 +0000
994+++ src/runtime/fetch/pregenerated/fetch.h 2012-05-18 22:05:23 +0000
995@@ -73,6 +73,42 @@
996 *
997 * Author: Matthias Brantner
998 */
999+class FetchContentBinaryIterator : public NaryBaseIterator<FetchContentBinaryIterator, PlanIteratorState>
1000+{
1001+public:
1002+ SERIALIZABLE_CLASS(FetchContentBinaryIterator);
1003+
1004+ SERIALIZABLE_CLASS_CONSTRUCTOR2T(FetchContentBinaryIterator,
1005+ NaryBaseIterator<FetchContentBinaryIterator, PlanIteratorState>);
1006+
1007+ void serialize( ::zorba::serialization::Archiver& ar)
1008+ {
1009+ serialize_baseclass(ar,
1010+ (NaryBaseIterator<FetchContentBinaryIterator, PlanIteratorState>*)this);
1011+ }
1012+
1013+ FetchContentBinaryIterator(
1014+ static_context* sctx,
1015+ const QueryLoc& loc,
1016+ std::vector<PlanIter_t>& children)
1017+ :
1018+ NaryBaseIterator<FetchContentBinaryIterator, PlanIteratorState>(sctx, loc, children)
1019+ {}
1020+
1021+ virtual ~FetchContentBinaryIterator();
1022+
1023+public:
1024+ static void destroyStream(std::istream& aStream);
1025+ void accept(PlanIterVisitor& v) const;
1026+
1027+ bool nextImpl(store::Item_t& result, PlanState& aPlanState) const;
1028+};
1029+
1030+
1031+/**
1032+ *
1033+ * Author: Matthias Brantner
1034+ */
1035 class FetchContentTypeIterator : public NaryBaseIterator<FetchContentTypeIterator, PlanIteratorState>
1036 {
1037 public:
1038
1039=== modified file 'src/runtime/nodes/nodes_impl.cpp'
1040--- src/runtime/nodes/nodes_impl.cpp 2012-05-03 12:31:51 +0000
1041+++ src/runtime/nodes/nodes_impl.cpp 2012-05-18 22:05:23 +0000
1042@@ -638,11 +638,13 @@
1043 lIterator->open();
1044 while(lIterator->next(lItem))
1045 {
1046- if(lItem->getNodeKind() == aNode->getNodeKind())
1047+ if (lItem->getNodeKind() == aNode->getNodeKind())
1048+ {
1049 if(lItem->equals(aNode))
1050 break;
1051 else
1052 count++;
1053+ }
1054 }
1055 lIterator->close();
1056 return count;
1057@@ -663,7 +665,7 @@
1058 PlanIteratorState* state;
1059 DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
1060
1061- if (consumeNext(inNode, theChildren[0], planState));
1062+ if (consumeNext(inNode, theChildren[0], planState))
1063 {
1064 do
1065 {
1066
1067=== modified file 'src/runtime/spec/fetch/fetch.xml'
1068--- src/runtime/spec/fetch/fetch.xml 2012-05-03 12:31:51 +0000
1069+++ src/runtime/spec/fetch/fetch.xml 2012-05-18 22:05:23 +0000
1070@@ -16,7 +16,8 @@
1071 <zorba:function>
1072 <zorba:signature localname="content" prefix="fn-zorba-fetch">
1073 <zorba:param>xs:string</zorba:param>
1074- <zorba:param>xs:string</zorba:param>
1075+ <zorba:param>xs:string</zorba:param> <!-- entityKind -->
1076+ <zorba:param>xs:string</zorba:param> <!-- encoding -->
1077 <zorba:output>xs:string</zorba:output>
1078 </zorba:signature>
1079
1080@@ -25,8 +26,33 @@
1081 </zorba:methods>
1082 </zorba:function>
1083
1084- <zorba:method static="true" name="destroyStream"
1085- return="void">
1086+ <zorba:method static="true" name="destroyStream" return="void">
1087+ <zorba:param type="std::istream&amp;" name="aStream"/>
1088+ </zorba:method>
1089+
1090+</zorba:iterator>
1091+
1092+<!--
1093+/*********************************************************************
1094+*********************************************************************/
1095+-->
1096+<zorba:iterator name="FetchContentBinaryIterator">
1097+
1098+ <zorba:description author="Matthias Brantner"></zorba:description>
1099+
1100+ <zorba:function>
1101+ <zorba:signature localname="content-binary" prefix="fn-zorba-fetch">
1102+ <zorba:param>xs:string</zorba:param>
1103+ <zorba:param>xs:string</zorba:param>
1104+ <zorba:output>xs:base64Binary</zorba:output>
1105+ </zorba:signature>
1106+
1107+ <zorba:methods>
1108+ <zorba:accessesDynCtx returnValue="true"/>
1109+ </zorba:methods>
1110+ </zorba:function>
1111+
1112+ <zorba:method static="true" name="destroyStream" return="void">
1113 <zorba:param type="std::istream&amp;" name="aStream"/>
1114 </zorba:method>
1115
1116
1117=== modified file 'src/runtime/visitors/pregenerated/planiter_visitor.h'
1118--- src/runtime/visitors/pregenerated/planiter_visitor.h 2012-05-17 18:16:26 +0000
1119+++ src/runtime/visitors/pregenerated/planiter_visitor.h 2012-05-18 22:05:23 +0000
1120@@ -189,6 +189,8 @@
1121
1122 class FetchContentIterator;
1123
1124+ class FetchContentBinaryIterator;
1125+
1126 class FetchContentTypeIterator;
1127
1128 class FnPutIterator;
1129@@ -900,6 +902,9 @@
1130 virtual void beginVisit ( const FetchContentIterator& ) = 0;
1131 virtual void endVisit ( const FetchContentIterator& ) = 0;
1132
1133+ virtual void beginVisit ( const FetchContentBinaryIterator& ) = 0;
1134+ virtual void endVisit ( const FetchContentBinaryIterator& ) = 0;
1135+
1136 virtual void beginVisit ( const FetchContentTypeIterator& ) = 0;
1137 virtual void endVisit ( const FetchContentTypeIterator& ) = 0;
1138
1139
1140=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.cpp'
1141--- src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-05-17 18:16:26 +0000
1142+++ src/runtime/visitors/pregenerated/printer_visitor.cpp 2012-05-18 22:05:23 +0000
1143@@ -1219,6 +1219,20 @@
1144 // </FetchContentIterator>
1145
1146
1147+// <FetchContentBinaryIterator>
1148+void PrinterVisitor::beginVisit ( const FetchContentBinaryIterator& a) {
1149+ thePrinter.startBeginVisit("FetchContentBinaryIterator", ++theId);
1150+ printCommons( &a, theId );
1151+ thePrinter.endBeginVisit( theId );
1152+}
1153+
1154+void PrinterVisitor::endVisit ( const FetchContentBinaryIterator& ) {
1155+ thePrinter.startEndVisit();
1156+ thePrinter.endEndVisit();
1157+}
1158+// </FetchContentBinaryIterator>
1159+
1160+
1161 // <FetchContentTypeIterator>
1162 void PrinterVisitor::beginVisit ( const FetchContentTypeIterator& a) {
1163 thePrinter.startBeginVisit("FetchContentTypeIterator", ++theId);
1164
1165=== modified file 'src/runtime/visitors/pregenerated/printer_visitor.h'
1166--- src/runtime/visitors/pregenerated/printer_visitor.h 2012-05-17 18:16:26 +0000
1167+++ src/runtime/visitors/pregenerated/printer_visitor.h 2012-05-18 22:05:23 +0000
1168@@ -286,6 +286,9 @@
1169 void beginVisit( const FetchContentIterator& );
1170 void endVisit ( const FetchContentIterator& );
1171
1172+ void beginVisit( const FetchContentBinaryIterator& );
1173+ void endVisit ( const FetchContentBinaryIterator& );
1174+
1175 void beginVisit( const FetchContentTypeIterator& );
1176 void endVisit ( const FetchContentTypeIterator& );
1177
1178
1179=== modified file 'src/zorbaserialization/archiver.cpp'
1180--- src/zorbaserialization/archiver.cpp 2012-05-03 12:31:51 +0000
1181+++ src/zorbaserialization/archiver.cpp 2012-05-18 22:05:23 +0000
1182@@ -125,9 +125,9 @@
1183 theCurrentLevel(0),
1184 theNonClassFieldsMap(0),
1185 theClassFieldsMap(0),
1186+ theOnlyForEval(0),
1187 all_reference_list(0),
1188 internal_archive(internal_archive),
1189- theOnlyForEval(0),
1190 theSerializeEverything(false),
1191 loading_hardcoded_objects(false),
1192 theAllowDelay2(ALLOW_DELAY),
1193
1194=== added file 'test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable.xml.res'
1195--- test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable.xml.res 1970-01-01 00:00:00 +0000
1196+++ test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable.xml.res 2012-05-18 22:05:23 +0000
1197@@ -0,0 +1,1 @@
1198+true true true
1199
1200=== added file 'test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable_binary.xml.res'
1201--- test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable_binary.xml.res 1970-01-01 00:00:00 +0000
1202+++ test/rbkt/ExpQueryResults/zorba/fetch/fetch_seekable_binary.xml.res 2012-05-18 22:05:23 +0000
1203@@ -0,0 +1,1 @@
1204+8 5Pb8Cg==
1205
1206=== added file 'test/rbkt/ExpQueryResults/zorba/fetch/fetch_some_transcode.xml.res'
1207--- test/rbkt/ExpQueryResults/zorba/fetch/fetch_some_transcode.xml.res 1970-01-01 00:00:00 +0000
1208+++ test/rbkt/ExpQueryResults/zorba/fetch/fetch_some_transcode.xml.res 2012-05-18 22:05:23 +0000
1209@@ -0,0 +1,1 @@
1210+äöü
1211
1212=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_bogus1.xq'
1213--- test/rbkt/Queries/zorba/fetch/fetch_bogus1.xq 2012-05-03 12:31:51 +0000
1214+++ test/rbkt/Queries/zorba/fetch/fetch_bogus1.xq 2012-05-18 22:05:23 +0000
1215@@ -1,4 +1,4 @@
1216 (: Fetch with unknown entity kind :)
1217-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";
1218+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1219
1220 fetch:content("http://www.zorba-xquery.com/modules/ext", "NOTHING")
1221
1222=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_bogus2.xq'
1223--- test/rbkt/Queries/zorba/fetch/fetch_bogus2.xq 2012-05-03 12:31:51 +0000
1224+++ test/rbkt/Queries/zorba/fetch/fetch_bogus2.xq 2012-05-18 22:05:23 +0000
1225@@ -1,4 +1,4 @@
1226 (: Fetch a valid module URI but as SOME_CONTENT :)
1227-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";
1228+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1229
1230 fetch:content("http://www.flworfound.org/modules/ext", "SOME_CONTENT")
1231
1232=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_module1.xq'
1233--- test/rbkt/Queries/zorba/fetch/fetch_module1.xq 2012-05-03 12:31:51 +0000
1234+++ test/rbkt/Queries/zorba/fetch/fetch_module1.xq 2012-05-18 22:05:23 +0000
1235@@ -1,4 +1,4 @@
1236 (: Fetch a module's content :)
1237-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";
1238+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1239
1240 fetch:content("http://www.zorba-xquery.com/modules/ext", "MODULE")
1241
1242=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_module2.xq'
1243--- test/rbkt/Queries/zorba/fetch/fetch_module2.xq 2012-05-03 12:31:51 +0000
1244+++ test/rbkt/Queries/zorba/fetch/fetch_module2.xq 2012-05-18 22:05:23 +0000
1245@@ -1,4 +1,4 @@
1246 (: Fetch a module's content with versioning :)
1247-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";
1248+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1249
1250 fetch:content("http://www.zorba-xquery.com/modules/ext#1.0", "MODULE")
1251
1252=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_random_file.xq'
1253--- test/rbkt/Queries/zorba/fetch/fetch_random_file.xq 2012-02-01 17:13:01 +0000
1254+++ test/rbkt/Queries/zorba/fetch/fetch_random_file.xq 2012-05-18 22:05:23 +0000
1255@@ -1,4 +1,4 @@
1256 (: Fetch a random file from the filesystem :)
1257-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";
1258+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1259
1260 fetch:content("http://www.zorba-xquery.com/random-file", "SOME_CONTENT")
1261
1262=== modified file 'test/rbkt/Queries/zorba/fetch/fetch_schema1.xq'
1263--- test/rbkt/Queries/zorba/fetch/fetch_schema1.xq 2012-05-03 12:31:51 +0000
1264+++ test/rbkt/Queries/zorba/fetch/fetch_schema1.xq 2012-05-18 22:05:23 +0000
1265@@ -1,5 +1,5 @@
1266 (: Fetch a schemas's content :)
1267-import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch#2.0";
1268+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1269
1270 fn:parse-xml(
1271 fetch:content("http://www.zorba-xquery.com/modules/theschema", "SCHEMA")
1272
1273=== added file 'test/rbkt/Queries/zorba/fetch/fetch_seekable.xml.res'
1274--- test/rbkt/Queries/zorba/fetch/fetch_seekable.xml.res 1970-01-01 00:00:00 +0000
1275+++ test/rbkt/Queries/zorba/fetch/fetch_seekable.xml.res 2012-05-18 22:05:23 +0000
1276@@ -0,0 +1,1 @@
1277+true true true
1278
1279=== added file 'test/rbkt/Queries/zorba/fetch/fetch_seekable.xq'
1280--- test/rbkt/Queries/zorba/fetch/fetch_seekable.xq 1970-01-01 00:00:00 +0000
1281+++ test/rbkt/Queries/zorba/fetch/fetch_seekable.xq 2012-05-18 22:05:23 +0000
1282@@ -0,0 +1,8 @@
1283+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1284+
1285+import module namespace s = "http://www.zorba-xquery.com/modules/string";
1286+
1287+(: make sure the returned string is streamable and can be consumed twice, i.e. is seekable :)
1288+let $x := fetch:content(fn:resolve-uri("iso-8859-1.txt"))
1289+return (s:is-streamable($x), string-length($x) gt 0, string-length($x) gt 0)
1290+
1291
1292=== added file 'test/rbkt/Queries/zorba/fetch/fetch_seekable_binary.xq'
1293--- test/rbkt/Queries/zorba/fetch/fetch_seekable_binary.xq 1970-01-01 00:00:00 +0000
1294+++ test/rbkt/Queries/zorba/fetch/fetch_seekable_binary.xq 2012-05-18 22:05:23 +0000
1295@@ -0,0 +1,8 @@
1296+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1297+
1298+import module namespace b = "http://www.zorba-xquery.com/modules/converters/base64";
1299+
1300+(: make sure the returned string is streamable and can be consumed twice, i.e. is seekable :)
1301+let $x := fetch:content-binary(fn:resolve-uri("iso-8859-1.txt"))
1302+return (string-length(xs:string($x)), $x)
1303+
1304
1305=== added file 'test/rbkt/Queries/zorba/fetch/fetch_some_transcode.xq'
1306--- test/rbkt/Queries/zorba/fetch/fetch_some_transcode.xq 1970-01-01 00:00:00 +0000
1307+++ test/rbkt/Queries/zorba/fetch/fetch_some_transcode.xq 2012-05-18 22:05:23 +0000
1308@@ -0,0 +1,3 @@
1309+import module namespace fetch = "http://www.zorba-xquery.com/modules/fetch";
1310+
1311+fetch:content(resolve-uri("iso-8859-1.txt"), "SOME_CONTENT", "ISO-8859-1")
1312
1313=== added file 'test/rbkt/Queries/zorba/fetch/iso-8859-1.txt'
1314--- test/rbkt/Queries/zorba/fetch/iso-8859-1.txt 1970-01-01 00:00:00 +0000
1315+++ test/rbkt/Queries/zorba/fetch/iso-8859-1.txt 2012-05-18 22:05:23 +0000
1316@@ -0,0 +1,1 @@
1317+äöü
1318
1319=== modified file 'test/unit/static_context.cpp'
1320--- test/unit/static_context.cpp 2012-05-07 23:43:04 +0000
1321+++ test/unit/static_context.cpp 2012-05-18 22:05:23 +0000
1322@@ -117,6 +117,27 @@
1323 }
1324
1325
1326+bool
1327+sctx_test_4(Zorba* const zorba)
1328+{
1329+ StaticContext_t lSctx = zorba->createStaticContext();
1330+
1331+ Zorba_CompilerHints_t lHints;
1332+
1333+ try
1334+ {
1335+ Item lFetched = lSctx->fetchBinary("http://www.zorba-xquery.com/modules/fetch", "MODULE");
1336+
1337+ size_t s;
1338+ return !lFetched.isNull() && lFetched.getBase64BinaryValue(s);
1339+ }
1340+ catch (ZorbaException& e)
1341+ {
1342+ std::cerr << e << std::endl;
1343+ }
1344+ return false;
1345+}
1346+
1347
1348 int static_context( int argc, char *argv[] )
1349 {
1350@@ -132,6 +153,9 @@
1351 if (!sctx_test_3(zorba))
1352 return 3;
1353
1354+ if (!sctx_test_4(zorba))
1355+ return 4;
1356+
1357 zorba->shutdown();
1358 StoreManager::shutdownStore( zstore );
1359 return 0;

Subscribers

People subscribed via source and target branches