2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkXMLWriter_DEFINED
|
|
|
|
#define SkXMLWriter_DEFINED
|
|
|
|
|
2016-02-18 16:53:33 +00:00
|
|
|
#include "../private/SkTDArray.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkDOM.h"
|
|
|
|
|
|
|
|
class SkWStream;
|
|
|
|
class SkXMLParser;
|
|
|
|
|
|
|
|
class SkXMLWriter {
|
|
|
|
public:
|
|
|
|
SkXMLWriter(bool doEscapeMarkup = true);
|
|
|
|
virtual ~SkXMLWriter();
|
|
|
|
|
|
|
|
void addS32Attribute(const char name[], int32_t value);
|
|
|
|
void addAttribute(const char name[], const char value[]);
|
|
|
|
void addAttributeLen(const char name[], const char value[], size_t length);
|
|
|
|
void addHexAttribute(const char name[], uint32_t value, int minDigits = 0);
|
|
|
|
void addScalarAttribute(const char name[], SkScalar value);
|
2015-02-05 02:29:27 +00:00
|
|
|
void addText(const char text[], size_t length);
|
2008-12-17 15:59:43 +00:00
|
|
|
void endElement() { this->onEndElement(); }
|
|
|
|
void startElement(const char elem[]);
|
|
|
|
void startElementLen(const char elem[], size_t length);
|
|
|
|
void writeDOM(const SkDOM&, const SkDOM::Node*, bool skipRoot);
|
|
|
|
void flush();
|
|
|
|
virtual void writeHeader();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void onStartElementLen(const char elem[], size_t length) = 0;
|
|
|
|
virtual void onAddAttributeLen(const char name[], const char value[], size_t length) = 0;
|
2015-02-05 02:29:27 +00:00
|
|
|
virtual void onAddText(const char text[], size_t length) = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual void onEndElement() = 0;
|
|
|
|
|
|
|
|
struct Elem {
|
2015-02-04 01:47:12 +00:00
|
|
|
Elem(const char name[], size_t len)
|
|
|
|
: fName(name, len)
|
|
|
|
, fHasChildren(false)
|
|
|
|
, fHasText(false) {}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkString fName;
|
|
|
|
bool fHasChildren;
|
2015-02-04 01:47:12 +00:00
|
|
|
bool fHasText;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
void doEnd(Elem* elem);
|
|
|
|
bool doStart(const char name[], size_t length);
|
|
|
|
Elem* getEnd();
|
|
|
|
const char* getHeader();
|
|
|
|
SkTDArray<Elem*> fElems;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fDoEscapeMarkup;
|
|
|
|
// illegal
|
|
|
|
SkXMLWriter& operator=(const SkXMLWriter&);
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkXMLStreamWriter : public SkXMLWriter {
|
|
|
|
public:
|
|
|
|
SkXMLStreamWriter(SkWStream*);
|
|
|
|
virtual ~SkXMLStreamWriter();
|
2015-07-13 13:18:39 +00:00
|
|
|
void writeHeader() override;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkDEBUGCODE(static void UnitTest();)
|
2015-02-05 02:29:27 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void onStartElementLen(const char elem[], size_t length) override;
|
|
|
|
void onEndElement() override;
|
|
|
|
void onAddAttributeLen(const char name[], const char value[], size_t length) override;
|
|
|
|
void onAddText(const char text[], size_t length) override;
|
2015-02-04 01:47:12 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
SkWStream& fStream;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkXMLParserWriter : public SkXMLWriter {
|
|
|
|
public:
|
|
|
|
SkXMLParserWriter(SkXMLParser*);
|
|
|
|
virtual ~SkXMLParserWriter();
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void onStartElementLen(const char elem[], size_t length) override;
|
|
|
|
void onEndElement() override;
|
|
|
|
void onAddAttributeLen(const char name[], const char value[], size_t length) override;
|
|
|
|
void onAddText(const char text[], size_t length) override;
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
SkXMLParser& fParser;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|