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::startElement(const char elem[]) 63 { 64 return this->onStartElement(elem); 65 } 66 67 bool SkXMLParser::addAttribute(const char name[], const char value[]) 68 { 69 return this->onAddAttribute(name, value); 70 } 71 72 bool SkXMLParser::endElement(const char elem[]) 73 { 74 return this->onEndElement(elem); 75 } 76 77 bool SkXMLParser::text(const char text[], int len) 78 { 79 return this->onText(text, len); 80 } 81 82 //////////////////////////////////////////////////////////////////////////////// 83 84 bool SkXMLParser::onStartElement(const char elem[]) {return false; } 85 bool SkXMLParser::onAddAttribute(const char name[], const char value[]) {return false; } 86 bool SkXMLParser::onEndElement(const char elem[]) { return false; } 87 bool SkXMLParser::onText(const char text[], int len) {return false; } 88