1 2 /* 3 * Copyright 2006 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #include "SkXMLParser.h" 11 12 static char const* const gErrorStrings[] = { 13 "empty or missing file ", 14 "unknown element ", 15 "unknown attribute name ", 16 "error in attribute value ", 17 "duplicate ID ", 18 "unknown error " 19 }; 20 21 SkXMLParserError::SkXMLParserError() : fCode(kNoError), fLineNumber(-1), 22 fNativeCode(-1) 23 { 24 reset(); 25 } 26 27 SkXMLParserError::~SkXMLParserError() 28 { 29 // need a virtual destructor for our subclasses 30 } 31 32 void SkXMLParserError::getErrorString(SkString* str) const 33 { 34 SkASSERT(str); 35 SkString temp; 36 if (fCode != kNoError) { 37 if ((unsigned)fCode < SK_ARRAY_COUNT(gErrorStrings)) 38 temp.set(gErrorStrings[fCode - 1]); 39 temp.append(fNoun); 40 } else 41 SkXMLParser::GetNativeErrorString(fNativeCode, &temp); 42 str->append(temp); 43 } 44 45 void SkXMLParserError::reset() { 46 fCode = kNoError; 47 fLineNumber = -1; 48 fNativeCode = -1; 49 } 50 51 52 //////////////// 53 54 SkXMLParser::SkXMLParser(SkXMLParserError* parserError) : fParser(NULL), fError(parserError) 55 { 56 } 57 58 SkXMLParser::~SkXMLParser() 59 { 60 } 61 62 bool SkXMLParser::parse(SkStream& docStream) 63 { 64 return false; 65 } 66 67 bool SkXMLParser::parse(const char doc[], size_t len) 68 { 69 return false; 70 } 71 72 void SkXMLParser::GetNativeErrorString(int error, SkString* str) 73 { 74 75 } 76 77 bool SkXMLParser::startElement(const char elem[]) 78 { 79 return this->onStartElement(elem); 80 } 81 82 bool SkXMLParser::addAttribute(const char name[], const char value[]) 83 { 84 return this->onAddAttribute(name, value); 85 } 86 87 bool SkXMLParser::endElement(const char elem[]) 88 { 89 return this->onEndElement(elem); 90 } 91 92 bool SkXMLParser::text(const char text[], int len) 93 { 94 return this->onText(text, len); 95 } 96 97 //////////////////////////////////////////////////////////////////////////////// 98 99 bool SkXMLParser::onStartElement(const char elem[]) {return false; } 100 bool SkXMLParser::onAddAttribute(const char name[], const char value[]) {return false; } 101 bool SkXMLParser::onEndElement(const char elem[]) { return false; } 102 bool SkXMLParser::onText(const char text[], int len) {return false; } 103