diff options
Diffstat (limited to 'include/xml')
-rw-r--r-- | include/xml/SkBML_WXMLParser.h | 54 | ||||
-rw-r--r-- | include/xml/SkBML_XMLParser.h | 39 | ||||
-rw-r--r-- | include/xml/SkDOM.h | 100 | ||||
-rw-r--r-- | include/xml/SkJS.h | 47 | ||||
-rw-r--r-- | include/xml/SkXMLParser.h | 161 | ||||
-rw-r--r-- | include/xml/SkXMLWriter.h | 93 |
6 files changed, 494 insertions, 0 deletions
diff --git a/include/xml/SkBML_WXMLParser.h b/include/xml/SkBML_WXMLParser.h new file mode 100644 index 0000000..faa127d --- /dev/null +++ b/include/xml/SkBML_WXMLParser.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkBML_WXMLParser_DEFINED +#define SkBML_WXMLParser_DEFINED + +#include "SkString.h" +#include "SkXMLParser.h" + +class SkStream; +class SkWStream; + +class BML_WXMLParser : public SkXMLParser { +public: + BML_WXMLParser(SkWStream& writer); + virtual ~BML_WXMLParser(); + static void Write(SkStream& s, const char filename[]); + + /** @cond UNIT_TEST */ + SkDEBUGCODE(static void UnitTest();) + /** @endcond */ +private: + virtual bool onAddAttribute(const char name[], const char value[]); + virtual bool onEndElement(const char name[]); + virtual bool onStartElement(const char name[]); + BML_WXMLParser& operator=(const BML_WXMLParser& src); +#ifdef SK_DEBUG + int fElemsCount, fElemsReused; + int fAttrsCount, fNamesReused, fValuesReused; +#endif + SkWStream& fWriter; + char* fElems[256]; + char* fAttrNames[256]; + char* fAttrValues[256]; + + // important that these are U8, so we get automatic wrap-around + U8 fNextElem, fNextAttrName, fNextAttrValue; +}; + +#endif // SkBML_WXMLParser_DEFINED + diff --git a/include/xml/SkBML_XMLParser.h b/include/xml/SkBML_XMLParser.h new file mode 100644 index 0000000..f056bca --- /dev/null +++ b/include/xml/SkBML_XMLParser.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkBML_XMLParser_DEFINED +#define SkBML_XMLParser_DEFINED + +class SkStream; +class SkWStream; +class SkXMLParser; +class SkXMLWriter; + +class BML_XMLParser { +public: + /** Read the byte XML stream and write the decompressed XML. + */ + static void Read(SkStream& s, SkXMLWriter& writer); + /** Read the byte XML stream and write the decompressed XML into a writable stream. + */ + static void Read(SkStream& s, SkWStream& output); + /** Read the byte XML stream and write the decompressed XML into an XML parser. + */ + static void Read(SkStream& s, SkXMLParser& output); +}; + +#endif // SkBML_XMLParser_DEFINED + diff --git a/include/xml/SkDOM.h b/include/xml/SkDOM.h new file mode 100644 index 0000000..74e2492 --- /dev/null +++ b/include/xml/SkDOM.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkDOM_DEFINED +#define SkDOM_DEFINED + +#include "SkChunkAlloc.h" +#include "SkMath.h" +#include "SkScalar.h" +#include "SkTemplates.h" + +struct SkDOMNode; +struct SkDOMAttr; + +class SkDOM { +public: + SkDOM(); + ~SkDOM(); + + typedef SkDOMNode Node; + typedef SkDOMAttr Attr; + + /** Returns null on failure + */ + const Node* build(const char doc[], size_t len); + const Node* copy(const SkDOM& dom, const Node* node); + + const Node* getRootNode() const; + + enum Type { + kElement_Type, + kText_Type + }; + Type getType(const Node*) const; + + const char* getName(const Node*) const; + const Node* getFirstChild(const Node*, const char elem[] = NULL) const; + const Node* getNextSibling(const Node*, const char elem[] = NULL) const; + + const char* findAttr(const Node*, const char attrName[]) const; + const Attr* getFirstAttr(const Node*) const; + const Attr* getNextAttr(const Node*, const Attr*) const; + const char* getAttrName(const Node*, const Attr*) const; + const char* getAttrValue(const Node*, const Attr*) const; + + // helpers for walking children + int countChildren(const Node* node, const char elem[] = NULL) const; + + // helpers for calling SkParse + bool findS32(const Node*, const char name[], int32_t* value) const; + bool findScalars(const Node*, const char name[], SkScalar value[], int count) const; + bool findHex(const Node*, const char name[], uint32_t* value) const; + bool findBool(const Node*, const char name[], bool*) const; + int findList(const Node*, const char name[], const char list[]) const; + + bool findScalar(const Node* node, const char name[], SkScalar value[]) const + { + return this->findScalars(node, name, value, 1); + } + + bool hasAttr(const Node*, const char name[], const char value[]) const; + bool hasS32(const Node*, const char name[], int32_t value) const; + bool hasScalar(const Node*, const char name[], SkScalar value) const; + bool hasHex(const Node*, const char name[], uint32_t value) const; + bool hasBool(const Node*, const char name[], bool value) const; + + class AttrIter { + public: + AttrIter(const class SkDOM&, const Node*); + const char* next(const char** value); + private: + const Attr* fAttr; + const Attr* fStop; + }; + + SkDEBUGCODE(void dump(const Node* node = NULL, int tabLevel = 0) const;) + SkDEBUGCODE(static void UnitTest();) + +private: + SkChunkAlloc fAlloc; + Node* fRoot; + friend class AttrIter; + friend class SkDOMParser; +}; + +#endif + diff --git a/include/xml/SkJS.h b/include/xml/SkJS.h new file mode 100644 index 0000000..fe76352 --- /dev/null +++ b/include/xml/SkJS.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SkTypes.h" +#include "SkWindow.h" + +extern "C" { + typedef long JSWord; + typedef JSWord jsword; + typedef jsword jsval; + typedef struct JSRuntime JSRuntime; + typedef struct JSContext JSContext; + typedef struct JSObject JSObject; +} + +class SkString; + +class SkJS : public SkOSWindow { +public: + SkJS(void* hwnd); + ~SkJS(); + SkBool EvaluateScript(const char* script, jsval* rVal); + SkBool ValueToString(jsval value, SkString* string); +#ifdef SK_DEBUG + static void Test(void* hwnd); +#endif +protected: + void InitializeDisplayables(const SkBitmap& , JSContext *, JSObject *, JSObject *); + void DisposeDisplayables(); + JSRuntime *fRuntime; + JSContext *fContext; + JSObject *fGlobal; +}; + diff --git a/include/xml/SkXMLParser.h b/include/xml/SkXMLParser.h new file mode 100644 index 0000000..ddad273 --- /dev/null +++ b/include/xml/SkXMLParser.h @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkXMLParser_DEFINED +#define SkXMLParser_DEFINED + +#include "SkMath.h" +#include "SkString.h" + +class SkStream; + +class SkDOM; +struct SkDOMNode; + +class SkXMLParserError { +public: + enum ErrorCode { + kNoError, + kEmptyFile, + kUnknownElement, + kUnknownAttributeName, + kErrorInAttributeValue, + kDuplicateIDs, + kUnknownError + }; + + SkXMLParserError(); + virtual ~SkXMLParserError(); + ErrorCode getErrorCode() const { return fCode; } + virtual void getErrorString(SkString* str) const; + int getLineNumber() const { return fLineNumber; } + int getNativeCode() const { return fNativeCode; } + bool hasError() const { return fCode != kNoError || fNativeCode != -1; } + bool hasNoun() const { return fNoun.size() > 0; } + void reset(); + void setCode(ErrorCode code) { fCode = code; } + void setNoun(const SkString& str) { fNoun.set(str); } + void setNoun(const char* ch) { fNoun.set(ch); } + void setNoun(const char* ch, size_t len) { fNoun.set(ch, len); } +protected: + ErrorCode fCode; +private: + int fLineNumber; + int fNativeCode; + SkString fNoun; + friend class SkXMLParser; +}; + +class SkXMLParser { +public: + SkXMLParser(SkXMLParserError* parserError = NULL); + virtual ~SkXMLParser(); + + /** Returns true for success + */ + bool parse(const char doc[], size_t len); + bool parse(SkStream& docStream); + bool parse(const SkDOM&, const SkDOMNode*); + + static void GetNativeErrorString(int nativeErrorCode, SkString* str); + +protected: + // override in subclasses; return true to stop parsing + virtual bool onStartElement(const char elem[]); + virtual bool onAddAttribute(const char name[], const char value[]); + virtual bool onEndElement(const char elem[]); + virtual bool onText(const char text[], int len); + +public: + // public for ported implementation, not meant for clients to call + virtual bool startElement(const char elem[]); + virtual bool addAttribute(const char name[], const char value[]); + virtual bool endElement(const char elem[]); + virtual bool text(const char text[], int len); + void* fParser; +protected: + SkXMLParserError* fError; +private: + void reportError(void* parser); +}; + +class SkXMLPullParser { +public: + SkXMLPullParser(); + explicit SkXMLPullParser(SkStream*); + virtual ~SkXMLPullParser(); + + SkStream* getStream() const { return fStream; } + SkStream* setStream(SkStream* stream); + + enum EventType { + ERROR = -1, + START_DOCUMENT, + END_DOCUMENT, + START_TAG, + END_TAG, + TEXT, + CDSECT, + ENTITY_REF, + IGNORABLE_WHITESPACE, + PROCESSING_INSTRUCTION, + COMMENT, + DOCDECL + }; + + EventType nextToken(); + EventType getEventType() const { return fCurr.fEventType; } + + struct AttrInfo { + const char* fName; + const char* fValue; + }; + + int getDepth() const { return fDepth; } + const char* getName(); + int getAttributeCount(); + void getAttributeInfo(int, AttrInfo*); + const char* getText(); + bool isWhitespace(); + +protected: + virtual bool onEntityReplacement(const char name[], + SkString* replacement); + +public: + struct Curr { + EventType fEventType; + const char* fName; + AttrInfo* fAttrInfos; + int fAttrInfoCount; + bool fIsWhitespace; + }; + +private: + // implemented in the porting layer + bool onInit(); // return false on failure + EventType onNextToken(); + void onExit(); + + SkStream* fStream; + Curr fCurr; + int fDepth; + + struct Impl; + Impl* fImpl; +}; + +#endif diff --git a/include/xml/SkXMLWriter.h b/include/xml/SkXMLWriter.h new file mode 100644 index 0000000..742e7f1 --- /dev/null +++ b/include/xml/SkXMLWriter.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SkXMLWriter_DEFINED +#define SkXMLWriter_DEFINED + +#include "SkTDArray.h" +#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); + 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; + virtual void onEndElement() = 0; + + struct Elem { + SkString fName; + bool fHasChildren; + }; + 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(); + virtual void writeHeader(); + SkDEBUGCODE(static void UnitTest();) +protected: + virtual void onStartElementLen(const char elem[], size_t length); + virtual void onEndElement(); + virtual void onAddAttributeLen(const char name[], const char value[], size_t length); +private: + SkWStream& fStream; +}; + +class SkXMLParserWriter : public SkXMLWriter { +public: + SkXMLParserWriter(SkXMLParser*); + virtual ~SkXMLParserWriter(); +protected: + virtual void onStartElementLen(const char elem[], size_t length); + virtual void onEndElement(); + virtual void onAddAttributeLen(const char name[], const char value[], size_t length); +private: + SkXMLParser& fParser; +}; + + +#endif + |