Merge lp:~zorba-coders/zorba/mz-htlm-module into lp:zorba/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
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 :

Validation queue starting for the following merge proposals:
https://code.launchpad.net/~zorba-coders/zorba/mz-htlm-module/+merge/178585

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

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://code.launchpad.net/~zorba-coders/zorba/mz-htlm-module/+merge/178585

Progress dashboard at http://jenkins.lambda.nu/view/ValidationQueue

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

Validation queue result for https://code.launchpad.net/~zorba-coders/zorba/mz-htlm-module/+merge/178585

Stage "ZorbaVQ" failed.

Check console output at http://jenkins.lambda.nu/job/ZorbaVQ/213/console to view the results.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/html.xq.src/html.cpp'
--- src/html.xq.src/html.cpp 2011-10-06 07:40:17 +0000
+++ src/html.xq.src/html.cpp 2013-08-05 15:23:31 +0000
@@ -25,8 +25,8 @@
2525
26namespace zorba26namespace zorba
27{27{
28 namespace htmlmodule28namespace htmlmodule
29 {29{
3030
31//*****************************************************************************31//*****************************************************************************
32//*****************************************************************************32//*****************************************************************************
@@ -36,72 +36,80 @@
36{36{
37}37}
3838
39
39ItemSequence_t40ItemSequence_t
40ParseFunction::evaluate(41ParseFunction::evaluate(
41 const ExternalFunction::Arguments_t& aArgs,42 const ExternalFunction::Arguments_t& aArgs,
42 const StaticContext* aSctxCtx,43 const StaticContext* aSctxCtx,
43 const DynamicContext* aDynCtx) const44 const DynamicContext* aDynCtx) const
44 {45{
45 std::auto_ptr<std::istringstream> iss;46 std::auto_ptr<std::istringstream> iss;
46 std::istream *is;47 std::istream *is;
47 String docString;48 String docString;
48 Item lStringItem, lOptionsItem;49 Item lStringItem, lOptionsItem;
4950
50 if (aArgs.size() >= 1)51 if (aArgs.size() >= 1)
51 {52 {
52 Iterator_t lArg0Iter = aArgs[0]->getIterator();53 Iterator_t lArg0Iter = aArgs[0]->getIterator();
53 lArg0Iter->open();54 lArg0Iter->open();
54 lArg0Iter->next(lStringItem);55 lArg0Iter->next(lStringItem);
55 lArg0Iter->close();56 lArg0Iter->close();
56 }57 }
5758
58 if ( lStringItem.isStreamable() )59 if ( lStringItem.isStreamable() )
59 {60 {
60 //61 //
61 // The "iss" auto_ptr can NOT be used since it will delete the stream that,62 // The "iss" auto_ptr can NOT be used since it will delete the stream that,
62 // in this case, is a data member inside another object and not dynamically63 // in this case, is a data member inside another object and not dynamically
63 // allocated.64 // allocated.
64 //65 //
65 // We can't replace "iss" with "is" since we still need the auto_ptr for66 // We can't replace "iss" with "is" since we still need the auto_ptr for
66 // the case when the result is not streamable.67 // the case when the result is not streamable.
67 //68 //
68 is = &lStringItem.getStream();69 is = &lStringItem.getStream();
69 }70 }
70 else71 else
71 {72 {
72 docString = lStringItem.getStringValue();73 docString = lStringItem.getStringValue();
73 iss.reset (new std::istringstream(docString.c_str()));74 iss.reset (new std::istringstream(docString.c_str()));
74 is = iss.get();75 is = iss.get();
75 }76 }
7677
77 if (aArgs.size() == 2)78 if (aArgs.size() == 2)
78 {79 {
79 Iterator_t lArg1Iter = aArgs[1]->getIterator();80 Iterator_t lArg1Iter = aArgs[1]->getIterator();
80 lArg1Iter->open();81 lArg1Iter->open();
81 lArg1Iter->next(lOptionsItem);82 lArg1Iter->next(lOptionsItem);
82 lArg1Iter->close();83 lArg1Iter->close();
83 }84 }
8485
85 return ItemSequence_t(new SingletonItemSequence(86 return ItemSequence_t(
86 createHtmlItem( *is , lOptionsItem )));87 new SingletonItemSequence(createHtmlItem(*is, lOptionsItem)));
87 }88}
8889
89//*****************************************************************************90
90//*****************************************************************************91//*****************************************************************************
9192//*****************************************************************************
92ItemFactory* HtmlModule::theFactory = 0;93HtmlModule::HtmlModule()
94{
95 Zorba* engine = Zorba::getInstance(0);
96
97 theFactory = engine->getItemFactory();
98}
99
93100
94HtmlModule::~HtmlModule()101HtmlModule::~HtmlModule()
95{102{
96 for ( FuncMap_t::const_iterator lIter = theFunctions.begin();103 for ( FuncMap_t::const_iterator lIter = theFunctions.begin();
97 lIter != theFunctions.end();104 lIter != theFunctions.end();
98 ++lIter)105 ++lIter)
99 {106 {
100 delete lIter->second;107 delete lIter->second;
101 }108 }
102 theFunctions.clear();109 theFunctions.clear();
103}110}
104111
112
105ExternalFunction*113ExternalFunction*
106HtmlModule::getExternalFunction(const String& aLocalname)114HtmlModule::getExternalFunction(const String& aLocalname)
107{115{
@@ -127,6 +135,8 @@
127 }135 }
128 delete this;136 delete this;
129}137}
138
139
130//*****************************************************************************140//*****************************************************************************
131//*****************************************************************************141//*****************************************************************************
132142
133143
=== modified file 'src/html.xq.src/html.h'
--- src/html.xq.src/html.h 2011-10-06 07:40:17 +0000
+++ src/html.xq.src/html.h 2013-08-05 15:23:31 +0000
@@ -26,87 +26,85 @@
26{26{
27 namespace htmlmodule27 namespace htmlmodule
28 {28 {
29//*****************************************************************************29
30//*****************************************************************************30//*****************************************************************************
31 class HtmlModule : public ExternalModule31//*****************************************************************************
32 {32class HtmlModule : public ExternalModule
33 private:33{
34 static ItemFactory* theFactory;34protected:
3535 class ltstr
36 protected:36 {
37 class ltstr37 public:
38 {38 bool operator()(const String& s1, const String& s2) const
39 public:39 {
40 bool operator()(const String& s1, const String& s2) const40 return s1.compare(s2) < 0;
41 {41 }
42 return s1.compare(s2) < 0;42 };
43 }43
44 };44 typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;
4545
46 typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;46protected:
4747 ItemFactory * theFactory;
48 FuncMap_t theFunctions;48 XmlDataManager_t theDataMgr;
4949 FuncMap_t theFunctions;
50 public:50
51 virtual ~HtmlModule();51public:
5252 HtmlModule();
53 virtual String53
54 getURI() const { return "http://www.zorba-xquery.com/modules/converters/html"; }54 virtual ~HtmlModule();
5555
56 virtual ExternalFunction*56 virtual String
57 getExternalFunction(const String& aLocalname);57 getURI() const { return "http://www.zorba-xquery.com/modules/converters/html"; }
5858
59 virtual void59 virtual ExternalFunction*
60 destroy();60 getExternalFunction(const String& aLocalname);
6161
62 static ItemFactory*62 virtual void
63 getItemFactory()63 destroy();
64 {64
65 if(!theFactory)65 ItemFactory* getItemFactory() const { return theFactory; }
66 {66
67 theFactory = Zorba::getInstance(0)->getItemFactory();67 XmlDataManager* getDataMgr() const { return theDataMgr.get(); }
68 }68};
69 return theFactory;69
70 }70
71 };71//*****************************************************************************
7272//*****************************************************************************
73//*****************************************************************************73class HtmlFunction : public ContextualExternalFunction
74//*****************************************************************************74{
75 class HtmlFunction : public ContextualExternalFunction75protected:
76 {76 const HtmlModule* theModule;
77 protected:77
78 const HtmlModule* theModule;78public:
79 public:79 HtmlFunction(const HtmlModule* aModule) : theModule(aModule) {};
80 HtmlFunction(const HtmlModule* aModule)80
81 : theModule(aModule) {};81 ~HtmlFunction() {};
8282
83 ~HtmlFunction() {};83 virtual String
8484 getURI() const { return theModule->getURI(); }
85 virtual String85};
86 getURI() const { return theModule->getURI(); }86
8787
88 };88//*****************************************************************************
8989//*****************************************************************************
90//*****************************************************************************90class ParseFunction : public HtmlFunction
91//*****************************************************************************91{
92 class ParseFunction : public HtmlFunction92public:
93 {93 ParseFunction(const HtmlModule* aModule);
94 public:94
95 ParseFunction(const HtmlModule* aModule);95 virtual String
9696 getLocalName() const { return "parse-internal"; }
97 virtual String97
98 getLocalName() const { return "parse-internal"; }98 virtual ItemSequence_t
9999 evaluate(const ExternalFunction::Arguments_t& args,
100 virtual ItemSequence_t100 const StaticContext* aSctxCtx,
101 evaluate(const ExternalFunction::Arguments_t& args,101 const DynamicContext* aDynCtx) const;
102 const StaticContext* aSctxCtx,102};
103 const DynamicContext* aDynCtx) const;103
104 };104
105105
106106
107107} /* namespace htmlmodule */
108
109 } /* namespace htmlmodule */
110} /* namespace zorba */108} /* namespace zorba */
111109
112#endif /* ZORBA_HTMLMODULE_HTML_H */110#endif /* ZORBA_HTMLMODULE_HTML_H */
113111
=== modified file 'src/html.xq.src/tidy_wrapper.h'
--- src/html.xq.src/tidy_wrapper.h 2011-08-18 23:42:49 +0000
+++ src/html.xq.src/tidy_wrapper.h 2013-08-05 15:23:31 +0000
@@ -35,166 +35,176 @@
3535
36namespace zorba36namespace zorba
37{37{
38 namespace htmlmodule38namespace htmlmodule
39 {39{
40 class TidyReader {40
41 private:41class TidyReader
42 std::istream* theStream;42{
43 // We need a buffer to support the unget function43private:
44 std::vector<unsigned int> theBuffer;44 std::istream* theStream;
45 public:45 // We need a buffer to support the unget function
46 TidyReader(std::istream* aStream) : theStream(aStream) {}46 std::vector<unsigned int> theBuffer;
47 TidyInputSource getInputSource()47
48 {48public:
49 TidyInputSource lResult;49 TidyReader(std::istream* aStream) : theStream(aStream) {}
50 lResult.sourceData = this;50
51 lResult.getByte = &getByte;51 TidyInputSource getInputSource()
52 lResult.ungetByte = &ungetByte;52 {
53 lResult.eof = &isEof;53 TidyInputSource lResult;
54 return lResult;54 lResult.sourceData = this;
55 }55 lResult.getByte = &getByte;
56 56 lResult.ungetByte = &ungetByte;
57 public: // callback functions57 lResult.eof = &isEof;
58 static int TIDY_CALL getByte(void* aData)58 return lResult;
59 {59 }
60 TidyReader* lReader = static_cast<TidyReader*>(aData);60
61 if (lReader->theBuffer.empty())61public: // callback functions
62 return lReader->theStream->get();62 static int TIDY_CALL getByte(void* aData)
63 else63 {
64 {64 TidyReader* lReader = static_cast<TidyReader*>(aData);
65 int lResult = lReader->theBuffer.back();65 if (lReader->theBuffer.empty())
66 lReader->theBuffer.pop_back();66 return lReader->theStream->get();
67 return lResult;67 else
68 }68 {
69 }69 int lResult = lReader->theBuffer.back();
70 70 lReader->theBuffer.pop_back();
71 static void TIDY_CALL ungetByte(void* aData, byte aByte)71 return lResult;
72 {72 }
73 TidyReader* lReader = static_cast<TidyReader*>(aData);73 }
74 lReader->theBuffer.push_back(aByte);74
75 }75 static void TIDY_CALL ungetByte(void* aData, byte aByte)
76 76 {
77 static Bool TIDY_CALL isEof(void* aData)77 TidyReader* lReader = static_cast<TidyReader*>(aData);
78 {78 lReader->theBuffer.push_back(aByte);
79 TidyReader* lReader = static_cast<TidyReader*>(aData);79 }
80 return lReader->theStream->eof() ? yes : no;80
81 }81 static Bool TIDY_CALL isEof(void* aData)
82 };82 {
83 83 TidyReader* lReader = static_cast<TidyReader*>(aData);
84 static void checkRC(int rc, const char* errMsg)84 return lReader->theStream->eof() ? yes : no;
85 {85 }
86 if (rc > 1)86};
87 {87
88 zorba::Item lError = Zorba::getInstance(0)->getItemFactory()88
89 ->createQName(89static void checkRC(int rc, const char* errMsg)
90 "http://www.zorba-xquery.com/modules/converters/html",90{
91 "InternalError");91 if (rc > 1)
92 throw USER_EXCEPTION(lError, errMsg );92 {
93 }93 zorba::Item lError = Zorba::getInstance(0)->getItemFactory()->
94 }94 createQName("http://www.zorba-xquery.com/modules/converters/html",
95 95 "InternalError");
96 static Bool setTidyOption(TidyDoc doc, const char* option, const char* value)96
97 {97 throw USER_EXCEPTION(lError, errMsg );
98 Bool ok = yes;98 }
99 TidyOptionId toID = tidyOptGetIdForName(option);99}
100 if(toID < N_TIDY_OPTIONS)100
101 {101
102 ok = tidyOptSetValue(doc, toID, value);102static Bool setTidyOption(TidyDoc doc, const char* option, const char* value)
103 if (ok != yes)103{
104 {104 Bool ok = yes;
105 zorba::Item lError = Zorba::getInstance(0)->getItemFactory()105 TidyOptionId toID = tidyOptGetIdForName(option);
106 ->createQName(106 if(toID < N_TIDY_OPTIONS)
107 "http://www.zorba-xquery.com/modules/converters/html",107 {
108 "TidyOption");108 ok = tidyOptSetValue(doc, toID, value);
109 std::ostringstream lErrorMsg;109 if (ok != yes)
110 lErrorMsg << "Error setting tidy option '" << option 110 {
111 << "' with value '" << value << "'";111 zorba::Item lError = Zorba::getInstance(0)->getItemFactory()->
112 throw USER_EXCEPTION(lError, lErrorMsg.str());112 createQName("http://www.zorba-xquery.com/modules/converters/html",
113 }113 "TidyOption");
114 }114
115 else115 std::ostringstream lErrorMsg;
116 {116 lErrorMsg << "Error setting tidy option '" << option
117 return no;117 << "' with value '" << value << "'";
118 }118 throw USER_EXCEPTION(lError, lErrorMsg.str());
119 return ok;119 }
120 }120 }
121121 else
122 static Bool applyOptions(TidyDoc aDoc, zorba::Item &aOptions)122 {
123 {123 return no;
124 zorba::Iterator_t lAttributes, lElements;124 }
125 zorba::Item lAttr, lElementItem, lAttrName;125 return ok;
126 zorba::String lStrName, lStrValue;126}
127 Bool lRet = yes;127
128128
129 if(!aOptions.isNull())129static Bool applyOptions(TidyDoc aDoc, zorba::Item &aOptions)
130 {130{
131 lElements = aOptions.getChildren();131 zorba::Iterator_t lAttributes, lElements;
132 lElements->open();132 zorba::Item lAttr, lElementItem, lAttrName;
133 while (lElements->next(lElementItem)133 zorba::String lStrName, lStrValue;
134 && lElementItem.getNodeKind () == store::StoreConsts::elementNode)134 Bool lRet = yes;
135 {135
136 lAttributes = lElementItem.getAttributes();136 if(!aOptions.isNull())
137 lAttributes->open();137 {
138 while (lAttributes->next(lAttr))138 lElements = aOptions.getChildren();
139 {139 lElements->open();
140 lAttr.getNodeName(lAttrName);140 while (lElements->next(lElementItem)
141 if(lAttrName.getLocalName() == "name")141 && lElementItem.getNodeKind () == store::StoreConsts::elementNode)
142 lStrName = lAttr.getStringValue();142 {
143 else if(lAttrName.getLocalName() == "value")143 lAttributes = lElementItem.getAttributes();
144 lStrValue = lAttr.getStringValue();144 lAttributes->open();
145 }145 while (lAttributes->next(lAttr))
146 setTidyOption(aDoc, lStrName.c_str(), lStrValue.c_str());146 {
147 lAttributes->close();147 lAttr.getNodeName(lAttrName);
148 }148 if(lAttrName.getLocalName() == "name")
149 lElements->close();149 lStrName = lAttr.getStringValue();
150 }150 else if(lAttrName.getLocalName() == "value")
151 return lRet;151 lStrValue = lAttr.getStringValue();
152 }152 }
153153 setTidyOption(aDoc, lStrName.c_str(), lStrValue.c_str());
154 static zorba::Item createHtmlItem( std::istream& aStream , zorba::Item &aOptions)154 lAttributes->close();
155 {155 }
156 TidyReader lReader(&aStream);156 lElements->close();
157 TidyInputSource lInputSource = lReader.getInputSource();157 }
158 158 return lRet;
159 TidyBuffer output;159}
160 tidyBufInit(&output);160
161 TidyBuffer errbuf;161
162 tidyBufInit(&errbuf);162static zorba::Item createHtmlItem(std::istream& aStream , zorba::Item& aOptions)
163 TidyDoc tDoc = tidyCreate();163{
164164 TidyReader lReader(&aStream);
165 applyOptions(tDoc, aOptions);165 TidyInputSource lInputSource = lReader.getInputSource();
166166
167 int rc = -1;167 TidyBuffer output;
168 rc = tidySetErrorBuffer(tDoc, &errbuf);168 tidyBufInit(&output);
169 checkRC(rc, "Could not set error buffer");169 TidyBuffer errbuf;
170 rc = tidyParseSource(tDoc, &lInputSource);170 tidyBufInit(&errbuf);
171 checkRC(rc, "Could not parse the source");171 TidyDoc tDoc = tidyCreate();
172 rc = tidyCleanAndRepair(tDoc);172
173 checkRC(rc, "Could not clean and repair");173 applyOptions(tDoc, aOptions);
174 rc = tidyRunDiagnostics(tDoc);174
175 if ( rc > 1 )175 int rc = -1;
176 rc = ( tidyOptSetBool(tDoc, TidyForceOutput, yes) ? rc : -1 );176 rc = tidySetErrorBuffer(tDoc, &errbuf);
177177 checkRC(rc, "Could not set error buffer");
178 // Tidy does not support streaming for output, it only supports178 rc = tidyParseSource(tDoc, &lInputSource);
179 // something they call a "sink". Therefore we buffer it in a string.179 checkRC(rc, "Could not parse the source");
180 rc = tidySaveBuffer(tDoc, &output);180 rc = tidyCleanAndRepair(tDoc);
181 checkRC(rc, "Could not save the buffer");181 checkRC(rc, "Could not clean and repair");
182 std::string lResult((char*) output.bp, output.size);182 rc = tidyRunDiagnostics(tDoc);
183 std::istringstream lStream(lResult);183 if ( rc > 1 )
184184 rc = ( tidyOptSetBool(tDoc, TidyForceOutput, yes) ? rc : -1 );
185 tidyBufFree(&output);185
186 tidyBufFree(&errbuf);186 // Tidy does not support streaming for output, it only supports
187 tidyRelease(tDoc);187 // something they call a "sink". Therefore we buffer it in a string.
188 XmlDataManager* lDM = Zorba::getInstance(0)->getXmlDataManager();188 rc = tidySaveBuffer(tDoc, &output);
189 try189 checkRC(rc, "Could not save the buffer");
190 {190 std::string lResult((char*) output.bp, output.size);
191 return lDM->parseXML(lStream);191 std::istringstream lStream(lResult);
192 } catch (ZorbaException&)192
193 {193 tidyBufFree(&output);
194 return NULL;//Zorba::getInstance(0)->getItemFactory()->createString(lResult);194 tidyBufFree(&errbuf);
195 }195 tidyRelease(tDoc);
196 }196 XmlDataManager_t lDM = Zorba::getInstance(0)->getXmlDataManager();
197 } /* namespace htmlmodule */197 try
198 {
199 return lDM->parseXML(lStream);
200 }
201 catch (ZorbaException&)
202 {
203 return NULL;//Zorba::getInstance(0)->getItemFactory()->createString(lResult);
204 }
205}
206
207} /* namespace htmlmodule */
198} /* namespace zorba */208} /* namespace zorba */
199209
200#endif //ZORBA_HTMLMODULE_TIDY_WRAPPER_H210#endif //ZORBA_HTMLMODULE_TIDY_WRAPPER_H

Subscribers

People subscribed via source and target branches

to all changes: