|
@@ -11118,10 +11118,13 @@ class CRoxieServerXmlWriteActivity : public CRoxieServerDiskWriteActivity
|
|
|
{
|
|
|
IHThorXmlWriteArg &xmlHelper;
|
|
|
StringAttr rowTag;
|
|
|
+ ThorActivityKind kind;
|
|
|
+ unsigned headerLength;
|
|
|
+ unsigned footerLength;
|
|
|
|
|
|
public:
|
|
|
- CRoxieServerXmlWriteActivity(const IRoxieServerActivityFactory *_factory, IProbeManager *_probeManager)
|
|
|
- : CRoxieServerDiskWriteActivity(_factory, _probeManager), xmlHelper(static_cast<IHThorXmlWriteArg &>(helper))
|
|
|
+ CRoxieServerXmlWriteActivity(const IRoxieServerActivityFactory *_factory, IProbeManager *_probeManager, ThorActivityKind _kind)
|
|
|
+ : CRoxieServerDiskWriteActivity(_factory, _probeManager), xmlHelper(static_cast<IHThorXmlWriteArg &>(helper)), kind(_kind), headerLength(0), footerLength(0)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -11142,11 +11145,23 @@ public:
|
|
|
|
|
|
virtual void onExecute()
|
|
|
{
|
|
|
+ StringBuffer header;
|
|
|
OwnedRoxieString suppliedHeader(xmlHelper.getHeader());
|
|
|
- const char *header = suppliedHeader;
|
|
|
- if (!header) header = "<Dataset>\n";
|
|
|
- diskout->write(strlen(header), header);
|
|
|
- CommonXmlWriter xmlOutput(xmlHelper.getXmlFlags());
|
|
|
+ if (kind==TAKjsonwrite)
|
|
|
+ {
|
|
|
+ buildJsonHeader(header, suppliedHeader, rowTag);
|
|
|
+ headerLength = header.length();
|
|
|
+ }
|
|
|
+ else if (suppliedHeader)
|
|
|
+ header.set(suppliedHeader);
|
|
|
+ else
|
|
|
+ header.set("<Dataset>\n");
|
|
|
+ diskout->write(header.length(), header.str());
|
|
|
+
|
|
|
+ Owned<IXmlWriterExt> writer = createIXmlWriterExt(xmlHelper.getXmlFlags(), 0, NULL, (kind==TAKjsonwrite) ? WTJSON : WTStandard);
|
|
|
+ writer->outputBeginArray(rowTag); //need to set this
|
|
|
+ writer->clear(); //but not output it
|
|
|
+
|
|
|
loop
|
|
|
{
|
|
|
OwnedConstRoxieRow nextrec = input->nextInGroup();
|
|
@@ -11157,15 +11172,24 @@ public:
|
|
|
break;
|
|
|
}
|
|
|
processed++;
|
|
|
- xmlOutput.clear().outputBeginNested(rowTag, false);
|
|
|
- xmlHelper.toXML((const byte *)nextrec.get(), xmlOutput);
|
|
|
- xmlOutput.outputEndNested(rowTag);
|
|
|
- diskout->write(xmlOutput.length(), xmlOutput.str());
|
|
|
+ writer->clear().outputBeginNested(rowTag, false);
|
|
|
+ xmlHelper.toXML((const byte *)nextrec.get(), *writer);
|
|
|
+ writer->outputEndNested(rowTag);
|
|
|
+ diskout->write(writer->length(), writer->str());
|
|
|
}
|
|
|
OwnedRoxieString suppliedFooter(xmlHelper.getFooter());
|
|
|
- const char * footer = suppliedFooter;
|
|
|
- if (!footer) footer = "</Dataset>\n";
|
|
|
- diskout->write(strlen(footer), footer);
|
|
|
+ StringBuffer footer;
|
|
|
+ if (kind==TAKjsonwrite)
|
|
|
+ {
|
|
|
+ buildJsonFooter(footer.newline(), suppliedFooter, rowTag);
|
|
|
+ footerLength=footer.length();
|
|
|
+ }
|
|
|
+ else if (suppliedFooter)
|
|
|
+ footer.append(suppliedFooter);
|
|
|
+ else
|
|
|
+ footer.append("</Dataset>");
|
|
|
+
|
|
|
+ diskout->write(footer.length(), footer);
|
|
|
}
|
|
|
|
|
|
virtual void reset()
|
|
@@ -11179,7 +11203,11 @@ public:
|
|
|
CRoxieServerDiskWriteActivity::setFileProperties(desc);
|
|
|
desc->queryProperties().setProp("@format","utf8n");
|
|
|
desc->queryProperties().setProp("@rowTag",rowTag.get());
|
|
|
- desc->queryProperties().setProp("@kind", "xml");
|
|
|
+ desc->queryProperties().setProp("@kind", (kind==TAKjsonwrite) ? "json" : "xml");
|
|
|
+ if (headerLength)
|
|
|
+ desc->queryProperties().setPropInt("@headerLength", headerLength);
|
|
|
+ if (footerLength)
|
|
|
+ desc->queryProperties().setPropInt("@footerLength", footerLength);
|
|
|
}
|
|
|
|
|
|
virtual bool isOutputTransformed() const { return true; }
|
|
@@ -11209,7 +11237,9 @@ public:
|
|
|
{
|
|
|
case TAKdiskwrite: return new CRoxieServerDiskWriteActivity(this, _probeManager);
|
|
|
case TAKcsvwrite: return new CRoxieServerCsvWriteActivity(this, _probeManager);
|
|
|
- case TAKxmlwrite: return new CRoxieServerXmlWriteActivity(this, _probeManager);
|
|
|
+ case TAKxmlwrite:
|
|
|
+ case TAKjsonwrite:
|
|
|
+ return new CRoxieServerXmlWriteActivity(this, _probeManager, kind);
|
|
|
};
|
|
|
throwUnexpected();
|
|
|
case 1:
|
|
@@ -19841,7 +19871,7 @@ public:
|
|
|
unsigned int writeFlags = serverContext->getXmlFlags();
|
|
|
if (response->mlFmt==MarkupFmt_JSON)
|
|
|
writeFlags |= XWFnoindent;
|
|
|
- writer.setown(createIXmlWriter(writeFlags, 1, response, (response->mlFmt==MarkupFmt_JSON) ? WTJSON : WTStandard));
|
|
|
+ writer.setown(createIXmlWriterExt(writeFlags, 1, response, (response->mlFmt==MarkupFmt_JSON) ? WTJSON : WTStandard));
|
|
|
writer->outputBeginArray("Row");
|
|
|
}
|
|
|
}
|