Merge lp:~zorba-coders/zorba/mz-htlm-module into lp:zorba/html-module
- mz-htlm-module
- Merge into html-module
Proposed by
Markos Zaharioudakis
Status: | Merged |
---|---|
Merged at revision: | 91 |
Proposed branch: | lp:~zorba-coders/zorba/mz-htlm-module |
Merge into: | lp:zorba/html-module |
Diff against target: |
672 lines (+317/-299) 3 files modified
src/html.xq.src/html.cpp (+68/-58) src/html.xq.src/html.h (+79/-81) src/html.xq.src/tidy_wrapper.h (+170/-160) |
To merge this branch: | bzr merge lp:~zorba-coders/zorba/mz-htlm-module |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Markos Zaharioudakis | Approve | ||
Review via email: mp+178585@code.launchpad.net |
Commit message
XmlDataManager is not a singleton any more
Description of the change
XmlDataManager is not a singleton any more
To post a comment you must log in.
Revision history for this message
Markos Zaharioudakis (markos-za) : | # |
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 succeeded - proposal merged!
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for the following merge proposals:
https:/
Progress dashboard at http://
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue result for https:/
Stage "ZorbaVQ" failed.
Check console output at http://
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/html.xq.src/html.cpp' |
2 | --- src/html.xq.src/html.cpp 2011-10-06 07:40:17 +0000 |
3 | +++ src/html.xq.src/html.cpp 2013-08-05 15:23:31 +0000 |
4 | @@ -25,8 +25,8 @@ |
5 | |
6 | namespace zorba |
7 | { |
8 | - namespace htmlmodule |
9 | - { |
10 | +namespace htmlmodule |
11 | +{ |
12 | |
13 | //***************************************************************************** |
14 | //***************************************************************************** |
15 | @@ -36,72 +36,80 @@ |
16 | { |
17 | } |
18 | |
19 | + |
20 | ItemSequence_t |
21 | ParseFunction::evaluate( |
22 | - const ExternalFunction::Arguments_t& aArgs, |
23 | - const StaticContext* aSctxCtx, |
24 | - const DynamicContext* aDynCtx) const |
25 | - { |
26 | - std::auto_ptr<std::istringstream> iss; |
27 | - std::istream *is; |
28 | - String docString; |
29 | - Item lStringItem, lOptionsItem; |
30 | - |
31 | - if (aArgs.size() >= 1) |
32 | - { |
33 | - Iterator_t lArg0Iter = aArgs[0]->getIterator(); |
34 | - lArg0Iter->open(); |
35 | - lArg0Iter->next(lStringItem); |
36 | - lArg0Iter->close(); |
37 | - } |
38 | - |
39 | - if ( lStringItem.isStreamable() ) |
40 | - { |
41 | - // |
42 | - // The "iss" auto_ptr can NOT be used since it will delete the stream that, |
43 | - // in this case, is a data member inside another object and not dynamically |
44 | - // allocated. |
45 | - // |
46 | - // We can't replace "iss" with "is" since we still need the auto_ptr for |
47 | - // the case when the result is not streamable. |
48 | - // |
49 | - is = &lStringItem.getStream(); |
50 | - } |
51 | - else |
52 | - { |
53 | - docString = lStringItem.getStringValue(); |
54 | - iss.reset (new std::istringstream(docString.c_str())); |
55 | - is = iss.get(); |
56 | - } |
57 | - |
58 | - if (aArgs.size() == 2) |
59 | - { |
60 | - Iterator_t lArg1Iter = aArgs[1]->getIterator(); |
61 | - lArg1Iter->open(); |
62 | - lArg1Iter->next(lOptionsItem); |
63 | - lArg1Iter->close(); |
64 | - } |
65 | - |
66 | - return ItemSequence_t(new SingletonItemSequence( |
67 | - createHtmlItem( *is , lOptionsItem ))); |
68 | - } |
69 | - |
70 | -//***************************************************************************** |
71 | -//***************************************************************************** |
72 | - |
73 | -ItemFactory* HtmlModule::theFactory = 0; |
74 | + const ExternalFunction::Arguments_t& aArgs, |
75 | + const StaticContext* aSctxCtx, |
76 | + const DynamicContext* aDynCtx) const |
77 | +{ |
78 | + std::auto_ptr<std::istringstream> iss; |
79 | + std::istream *is; |
80 | + String docString; |
81 | + Item lStringItem, lOptionsItem; |
82 | + |
83 | + if (aArgs.size() >= 1) |
84 | + { |
85 | + Iterator_t lArg0Iter = aArgs[0]->getIterator(); |
86 | + lArg0Iter->open(); |
87 | + lArg0Iter->next(lStringItem); |
88 | + lArg0Iter->close(); |
89 | + } |
90 | + |
91 | + if ( lStringItem.isStreamable() ) |
92 | + { |
93 | + // |
94 | + // The "iss" auto_ptr can NOT be used since it will delete the stream that, |
95 | + // in this case, is a data member inside another object and not dynamically |
96 | + // allocated. |
97 | + // |
98 | + // We can't replace "iss" with "is" since we still need the auto_ptr for |
99 | + // the case when the result is not streamable. |
100 | + // |
101 | + is = &lStringItem.getStream(); |
102 | + } |
103 | + else |
104 | + { |
105 | + docString = lStringItem.getStringValue(); |
106 | + iss.reset (new std::istringstream(docString.c_str())); |
107 | + is = iss.get(); |
108 | + } |
109 | + |
110 | + if (aArgs.size() == 2) |
111 | + { |
112 | + Iterator_t lArg1Iter = aArgs[1]->getIterator(); |
113 | + lArg1Iter->open(); |
114 | + lArg1Iter->next(lOptionsItem); |
115 | + lArg1Iter->close(); |
116 | + } |
117 | + |
118 | + return ItemSequence_t( |
119 | + new SingletonItemSequence(createHtmlItem(*is, lOptionsItem))); |
120 | +} |
121 | + |
122 | + |
123 | +//***************************************************************************** |
124 | +//***************************************************************************** |
125 | +HtmlModule::HtmlModule() |
126 | +{ |
127 | + Zorba* engine = Zorba::getInstance(0); |
128 | + |
129 | + theFactory = engine->getItemFactory(); |
130 | +} |
131 | + |
132 | |
133 | HtmlModule::~HtmlModule() |
134 | { |
135 | for ( FuncMap_t::const_iterator lIter = theFunctions.begin(); |
136 | lIter != theFunctions.end(); |
137 | ++lIter) |
138 | - { |
139 | - delete lIter->second; |
140 | - } |
141 | - theFunctions.clear(); |
142 | + { |
143 | + delete lIter->second; |
144 | + } |
145 | + theFunctions.clear(); |
146 | } |
147 | |
148 | + |
149 | ExternalFunction* |
150 | HtmlModule::getExternalFunction(const String& aLocalname) |
151 | { |
152 | @@ -127,6 +135,8 @@ |
153 | } |
154 | delete this; |
155 | } |
156 | + |
157 | + |
158 | //***************************************************************************** |
159 | //***************************************************************************** |
160 | |
161 | |
162 | === modified file 'src/html.xq.src/html.h' |
163 | --- src/html.xq.src/html.h 2011-10-06 07:40:17 +0000 |
164 | +++ src/html.xq.src/html.h 2013-08-05 15:23:31 +0000 |
165 | @@ -26,87 +26,85 @@ |
166 | { |
167 | namespace htmlmodule |
168 | { |
169 | -//***************************************************************************** |
170 | -//***************************************************************************** |
171 | - class HtmlModule : public ExternalModule |
172 | - { |
173 | - private: |
174 | - static ItemFactory* theFactory; |
175 | - |
176 | - protected: |
177 | - class ltstr |
178 | - { |
179 | - public: |
180 | - bool operator()(const String& s1, const String& s2) const |
181 | - { |
182 | - return s1.compare(s2) < 0; |
183 | - } |
184 | - }; |
185 | - |
186 | - typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t; |
187 | - |
188 | - FuncMap_t theFunctions; |
189 | - |
190 | - public: |
191 | - virtual ~HtmlModule(); |
192 | - |
193 | - virtual String |
194 | - getURI() const { return "http://www.zorba-xquery.com/modules/converters/html"; } |
195 | - |
196 | - virtual ExternalFunction* |
197 | - getExternalFunction(const String& aLocalname); |
198 | - |
199 | - virtual void |
200 | - destroy(); |
201 | - |
202 | - static ItemFactory* |
203 | - getItemFactory() |
204 | - { |
205 | - if(!theFactory) |
206 | - { |
207 | - theFactory = Zorba::getInstance(0)->getItemFactory(); |
208 | - } |
209 | - return theFactory; |
210 | - } |
211 | - }; |
212 | - |
213 | -//***************************************************************************** |
214 | -//***************************************************************************** |
215 | - class HtmlFunction : public ContextualExternalFunction |
216 | - { |
217 | - protected: |
218 | - const HtmlModule* theModule; |
219 | - public: |
220 | - HtmlFunction(const HtmlModule* aModule) |
221 | - : theModule(aModule) {}; |
222 | - |
223 | - ~HtmlFunction() {}; |
224 | - |
225 | - virtual String |
226 | - getURI() const { return theModule->getURI(); } |
227 | - |
228 | - }; |
229 | - |
230 | -//***************************************************************************** |
231 | -//***************************************************************************** |
232 | - class ParseFunction : public HtmlFunction |
233 | - { |
234 | - public: |
235 | - ParseFunction(const HtmlModule* aModule); |
236 | - |
237 | - virtual String |
238 | - getLocalName() const { return "parse-internal"; } |
239 | - |
240 | - virtual ItemSequence_t |
241 | - evaluate(const ExternalFunction::Arguments_t& args, |
242 | - const StaticContext* aSctxCtx, |
243 | - const DynamicContext* aDynCtx) const; |
244 | - }; |
245 | - |
246 | - |
247 | - |
248 | - |
249 | - } /* namespace htmlmodule */ |
250 | + |
251 | +//***************************************************************************** |
252 | +//***************************************************************************** |
253 | +class HtmlModule : public ExternalModule |
254 | +{ |
255 | +protected: |
256 | + class ltstr |
257 | + { |
258 | + public: |
259 | + bool operator()(const String& s1, const String& s2) const |
260 | + { |
261 | + return s1.compare(s2) < 0; |
262 | + } |
263 | + }; |
264 | + |
265 | + typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t; |
266 | + |
267 | +protected: |
268 | + ItemFactory * theFactory; |
269 | + XmlDataManager_t theDataMgr; |
270 | + FuncMap_t theFunctions; |
271 | + |
272 | +public: |
273 | + HtmlModule(); |
274 | + |
275 | + virtual ~HtmlModule(); |
276 | + |
277 | + virtual String |
278 | + getURI() const { return "http://www.zorba-xquery.com/modules/converters/html"; } |
279 | + |
280 | + virtual ExternalFunction* |
281 | + getExternalFunction(const String& aLocalname); |
282 | + |
283 | + virtual void |
284 | + destroy(); |
285 | + |
286 | + ItemFactory* getItemFactory() const { return theFactory; } |
287 | + |
288 | + XmlDataManager* getDataMgr() const { return theDataMgr.get(); } |
289 | +}; |
290 | + |
291 | + |
292 | +//***************************************************************************** |
293 | +//***************************************************************************** |
294 | +class HtmlFunction : public ContextualExternalFunction |
295 | +{ |
296 | +protected: |
297 | + const HtmlModule* theModule; |
298 | + |
299 | +public: |
300 | + HtmlFunction(const HtmlModule* aModule) : theModule(aModule) {}; |
301 | + |
302 | + ~HtmlFunction() {}; |
303 | + |
304 | + virtual String |
305 | + getURI() const { return theModule->getURI(); } |
306 | +}; |
307 | + |
308 | + |
309 | +//***************************************************************************** |
310 | +//***************************************************************************** |
311 | +class ParseFunction : public HtmlFunction |
312 | +{ |
313 | +public: |
314 | + ParseFunction(const HtmlModule* aModule); |
315 | + |
316 | + virtual String |
317 | + getLocalName() const { return "parse-internal"; } |
318 | + |
319 | + virtual ItemSequence_t |
320 | + evaluate(const ExternalFunction::Arguments_t& args, |
321 | + const StaticContext* aSctxCtx, |
322 | + const DynamicContext* aDynCtx) const; |
323 | +}; |
324 | + |
325 | + |
326 | + |
327 | + |
328 | +} /* namespace htmlmodule */ |
329 | } /* namespace zorba */ |
330 | |
331 | #endif /* ZORBA_HTMLMODULE_HTML_H */ |
332 | |
333 | === modified file 'src/html.xq.src/tidy_wrapper.h' |
334 | --- src/html.xq.src/tidy_wrapper.h 2011-08-18 23:42:49 +0000 |
335 | +++ src/html.xq.src/tidy_wrapper.h 2013-08-05 15:23:31 +0000 |
336 | @@ -35,166 +35,176 @@ |
337 | |
338 | namespace zorba |
339 | { |
340 | - namespace htmlmodule |
341 | - { |
342 | - class TidyReader { |
343 | - private: |
344 | - std::istream* theStream; |
345 | - // We need a buffer to support the unget function |
346 | - std::vector<unsigned int> theBuffer; |
347 | - public: |
348 | - TidyReader(std::istream* aStream) : theStream(aStream) {} |
349 | - TidyInputSource getInputSource() |
350 | - { |
351 | - TidyInputSource lResult; |
352 | - lResult.sourceData = this; |
353 | - lResult.getByte = &getByte; |
354 | - lResult.ungetByte = &ungetByte; |
355 | - lResult.eof = &isEof; |
356 | - return lResult; |
357 | - } |
358 | - |
359 | - public: // callback functions |
360 | - static int TIDY_CALL getByte(void* aData) |
361 | - { |
362 | - TidyReader* lReader = static_cast<TidyReader*>(aData); |
363 | - if (lReader->theBuffer.empty()) |
364 | - return lReader->theStream->get(); |
365 | - else |
366 | - { |
367 | - int lResult = lReader->theBuffer.back(); |
368 | - lReader->theBuffer.pop_back(); |
369 | - return lResult; |
370 | - } |
371 | - } |
372 | - |
373 | - static void TIDY_CALL ungetByte(void* aData, byte aByte) |
374 | - { |
375 | - TidyReader* lReader = static_cast<TidyReader*>(aData); |
376 | - lReader->theBuffer.push_back(aByte); |
377 | - } |
378 | - |
379 | - static Bool TIDY_CALL isEof(void* aData) |
380 | - { |
381 | - TidyReader* lReader = static_cast<TidyReader*>(aData); |
382 | - return lReader->theStream->eof() ? yes : no; |
383 | - } |
384 | - }; |
385 | - |
386 | - static void checkRC(int rc, const char* errMsg) |
387 | - { |
388 | - if (rc > 1) |
389 | - { |
390 | - zorba::Item lError = Zorba::getInstance(0)->getItemFactory() |
391 | - ->createQName( |
392 | - "http://www.zorba-xquery.com/modules/converters/html", |
393 | - "InternalError"); |
394 | - throw USER_EXCEPTION(lError, errMsg ); |
395 | - } |
396 | - } |
397 | - |
398 | - static Bool setTidyOption(TidyDoc doc, const char* option, const char* value) |
399 | - { |
400 | - Bool ok = yes; |
401 | - TidyOptionId toID = tidyOptGetIdForName(option); |
402 | - if(toID < N_TIDY_OPTIONS) |
403 | - { |
404 | - ok = tidyOptSetValue(doc, toID, value); |
405 | - if (ok != yes) |
406 | - { |
407 | - zorba::Item lError = Zorba::getInstance(0)->getItemFactory() |
408 | - ->createQName( |
409 | - "http://www.zorba-xquery.com/modules/converters/html", |
410 | - "TidyOption"); |
411 | - std::ostringstream lErrorMsg; |
412 | - lErrorMsg << "Error setting tidy option '" << option |
413 | - << "' with value '" << value << "'"; |
414 | - throw USER_EXCEPTION(lError, lErrorMsg.str()); |
415 | - } |
416 | - } |
417 | - else |
418 | - { |
419 | - return no; |
420 | - } |
421 | - return ok; |
422 | - } |
423 | - |
424 | - static Bool applyOptions(TidyDoc aDoc, zorba::Item &aOptions) |
425 | - { |
426 | - zorba::Iterator_t lAttributes, lElements; |
427 | - zorba::Item lAttr, lElementItem, lAttrName; |
428 | - zorba::String lStrName, lStrValue; |
429 | - Bool lRet = yes; |
430 | - |
431 | - if(!aOptions.isNull()) |
432 | - { |
433 | - lElements = aOptions.getChildren(); |
434 | - lElements->open(); |
435 | - while (lElements->next(lElementItem) |
436 | - && lElementItem.getNodeKind () == store::StoreConsts::elementNode) |
437 | - { |
438 | - lAttributes = lElementItem.getAttributes(); |
439 | - lAttributes->open(); |
440 | - while (lAttributes->next(lAttr)) |
441 | - { |
442 | - lAttr.getNodeName(lAttrName); |
443 | - if(lAttrName.getLocalName() == "name") |
444 | - lStrName = lAttr.getStringValue(); |
445 | - else if(lAttrName.getLocalName() == "value") |
446 | - lStrValue = lAttr.getStringValue(); |
447 | - } |
448 | - setTidyOption(aDoc, lStrName.c_str(), lStrValue.c_str()); |
449 | - lAttributes->close(); |
450 | - } |
451 | - lElements->close(); |
452 | - } |
453 | - return lRet; |
454 | - } |
455 | - |
456 | - static zorba::Item createHtmlItem( std::istream& aStream , zorba::Item &aOptions) |
457 | - { |
458 | - TidyReader lReader(&aStream); |
459 | - TidyInputSource lInputSource = lReader.getInputSource(); |
460 | - |
461 | - TidyBuffer output; |
462 | - tidyBufInit(&output); |
463 | - TidyBuffer errbuf; |
464 | - tidyBufInit(&errbuf); |
465 | - TidyDoc tDoc = tidyCreate(); |
466 | - |
467 | - applyOptions(tDoc, aOptions); |
468 | - |
469 | - int rc = -1; |
470 | - rc = tidySetErrorBuffer(tDoc, &errbuf); |
471 | - checkRC(rc, "Could not set error buffer"); |
472 | - rc = tidyParseSource(tDoc, &lInputSource); |
473 | - checkRC(rc, "Could not parse the source"); |
474 | - rc = tidyCleanAndRepair(tDoc); |
475 | - checkRC(rc, "Could not clean and repair"); |
476 | - rc = tidyRunDiagnostics(tDoc); |
477 | - if ( rc > 1 ) |
478 | - rc = ( tidyOptSetBool(tDoc, TidyForceOutput, yes) ? rc : -1 ); |
479 | - |
480 | - // Tidy does not support streaming for output, it only supports |
481 | - // something they call a "sink". Therefore we buffer it in a string. |
482 | - rc = tidySaveBuffer(tDoc, &output); |
483 | - checkRC(rc, "Could not save the buffer"); |
484 | - std::string lResult((char*) output.bp, output.size); |
485 | - std::istringstream lStream(lResult); |
486 | - |
487 | - tidyBufFree(&output); |
488 | - tidyBufFree(&errbuf); |
489 | - tidyRelease(tDoc); |
490 | - XmlDataManager* lDM = Zorba::getInstance(0)->getXmlDataManager(); |
491 | - try |
492 | - { |
493 | - return lDM->parseXML(lStream); |
494 | - } catch (ZorbaException&) |
495 | - { |
496 | - return NULL;//Zorba::getInstance(0)->getItemFactory()->createString(lResult); |
497 | - } |
498 | - } |
499 | - } /* namespace htmlmodule */ |
500 | +namespace htmlmodule |
501 | +{ |
502 | + |
503 | +class TidyReader |
504 | +{ |
505 | +private: |
506 | + std::istream* theStream; |
507 | + // We need a buffer to support the unget function |
508 | + std::vector<unsigned int> theBuffer; |
509 | + |
510 | +public: |
511 | + TidyReader(std::istream* aStream) : theStream(aStream) {} |
512 | + |
513 | + TidyInputSource getInputSource() |
514 | + { |
515 | + TidyInputSource lResult; |
516 | + lResult.sourceData = this; |
517 | + lResult.getByte = &getByte; |
518 | + lResult.ungetByte = &ungetByte; |
519 | + lResult.eof = &isEof; |
520 | + return lResult; |
521 | + } |
522 | + |
523 | +public: // callback functions |
524 | + static int TIDY_CALL getByte(void* aData) |
525 | + { |
526 | + TidyReader* lReader = static_cast<TidyReader*>(aData); |
527 | + if (lReader->theBuffer.empty()) |
528 | + return lReader->theStream->get(); |
529 | + else |
530 | + { |
531 | + int lResult = lReader->theBuffer.back(); |
532 | + lReader->theBuffer.pop_back(); |
533 | + return lResult; |
534 | + } |
535 | + } |
536 | + |
537 | + static void TIDY_CALL ungetByte(void* aData, byte aByte) |
538 | + { |
539 | + TidyReader* lReader = static_cast<TidyReader*>(aData); |
540 | + lReader->theBuffer.push_back(aByte); |
541 | + } |
542 | + |
543 | + static Bool TIDY_CALL isEof(void* aData) |
544 | + { |
545 | + TidyReader* lReader = static_cast<TidyReader*>(aData); |
546 | + return lReader->theStream->eof() ? yes : no; |
547 | + } |
548 | +}; |
549 | + |
550 | + |
551 | +static void checkRC(int rc, const char* errMsg) |
552 | +{ |
553 | + if (rc > 1) |
554 | + { |
555 | + zorba::Item lError = Zorba::getInstance(0)->getItemFactory()-> |
556 | + createQName("http://www.zorba-xquery.com/modules/converters/html", |
557 | + "InternalError"); |
558 | + |
559 | + throw USER_EXCEPTION(lError, errMsg ); |
560 | + } |
561 | +} |
562 | + |
563 | + |
564 | +static Bool setTidyOption(TidyDoc doc, const char* option, const char* value) |
565 | +{ |
566 | + Bool ok = yes; |
567 | + TidyOptionId toID = tidyOptGetIdForName(option); |
568 | + if(toID < N_TIDY_OPTIONS) |
569 | + { |
570 | + ok = tidyOptSetValue(doc, toID, value); |
571 | + if (ok != yes) |
572 | + { |
573 | + zorba::Item lError = Zorba::getInstance(0)->getItemFactory()-> |
574 | + createQName("http://www.zorba-xquery.com/modules/converters/html", |
575 | + "TidyOption"); |
576 | + |
577 | + std::ostringstream lErrorMsg; |
578 | + lErrorMsg << "Error setting tidy option '" << option |
579 | + << "' with value '" << value << "'"; |
580 | + throw USER_EXCEPTION(lError, lErrorMsg.str()); |
581 | + } |
582 | + } |
583 | + else |
584 | + { |
585 | + return no; |
586 | + } |
587 | + return ok; |
588 | +} |
589 | + |
590 | + |
591 | +static Bool applyOptions(TidyDoc aDoc, zorba::Item &aOptions) |
592 | +{ |
593 | + zorba::Iterator_t lAttributes, lElements; |
594 | + zorba::Item lAttr, lElementItem, lAttrName; |
595 | + zorba::String lStrName, lStrValue; |
596 | + Bool lRet = yes; |
597 | + |
598 | + if(!aOptions.isNull()) |
599 | + { |
600 | + lElements = aOptions.getChildren(); |
601 | + lElements->open(); |
602 | + while (lElements->next(lElementItem) |
603 | + && lElementItem.getNodeKind () == store::StoreConsts::elementNode) |
604 | + { |
605 | + lAttributes = lElementItem.getAttributes(); |
606 | + lAttributes->open(); |
607 | + while (lAttributes->next(lAttr)) |
608 | + { |
609 | + lAttr.getNodeName(lAttrName); |
610 | + if(lAttrName.getLocalName() == "name") |
611 | + lStrName = lAttr.getStringValue(); |
612 | + else if(lAttrName.getLocalName() == "value") |
613 | + lStrValue = lAttr.getStringValue(); |
614 | + } |
615 | + setTidyOption(aDoc, lStrName.c_str(), lStrValue.c_str()); |
616 | + lAttributes->close(); |
617 | + } |
618 | + lElements->close(); |
619 | + } |
620 | + return lRet; |
621 | +} |
622 | + |
623 | + |
624 | +static zorba::Item createHtmlItem(std::istream& aStream , zorba::Item& aOptions) |
625 | +{ |
626 | + TidyReader lReader(&aStream); |
627 | + TidyInputSource lInputSource = lReader.getInputSource(); |
628 | + |
629 | + TidyBuffer output; |
630 | + tidyBufInit(&output); |
631 | + TidyBuffer errbuf; |
632 | + tidyBufInit(&errbuf); |
633 | + TidyDoc tDoc = tidyCreate(); |
634 | + |
635 | + applyOptions(tDoc, aOptions); |
636 | + |
637 | + int rc = -1; |
638 | + rc = tidySetErrorBuffer(tDoc, &errbuf); |
639 | + checkRC(rc, "Could not set error buffer"); |
640 | + rc = tidyParseSource(tDoc, &lInputSource); |
641 | + checkRC(rc, "Could not parse the source"); |
642 | + rc = tidyCleanAndRepair(tDoc); |
643 | + checkRC(rc, "Could not clean and repair"); |
644 | + rc = tidyRunDiagnostics(tDoc); |
645 | + if ( rc > 1 ) |
646 | + rc = ( tidyOptSetBool(tDoc, TidyForceOutput, yes) ? rc : -1 ); |
647 | + |
648 | + // Tidy does not support streaming for output, it only supports |
649 | + // something they call a "sink". Therefore we buffer it in a string. |
650 | + rc = tidySaveBuffer(tDoc, &output); |
651 | + checkRC(rc, "Could not save the buffer"); |
652 | + std::string lResult((char*) output.bp, output.size); |
653 | + std::istringstream lStream(lResult); |
654 | + |
655 | + tidyBufFree(&output); |
656 | + tidyBufFree(&errbuf); |
657 | + tidyRelease(tDoc); |
658 | + XmlDataManager_t lDM = Zorba::getInstance(0)->getXmlDataManager(); |
659 | + try |
660 | + { |
661 | + return lDM->parseXML(lStream); |
662 | + } |
663 | + catch (ZorbaException&) |
664 | + { |
665 | + return NULL;//Zorba::getInstance(0)->getItemFactory()->createString(lResult); |
666 | + } |
667 | +} |
668 | + |
669 | +} /* namespace htmlmodule */ |
670 | } /* namespace zorba */ |
671 | |
672 | #endif //ZORBA_HTMLMODULE_TIDY_WRAPPER_H |
Validation queue starting for the following merge proposals: /code.launchpad .net/~zorba- coders/ zorba/mz- htlm-module/ +merge/ 178585
https:/
Progress dashboard at http:// jenkins. lambda. nu/view/ ValidationQueue