void ActionRegisterUserParser::text(const QString &text) { if (currentTag() == "login") { k->data["login"] = text; } else if (currentTag() == "email") { k->data["email"] = text; } }
void TupProjectParser::text(const QString &text) { if (currentTag() == "users") k->users = text.split(","); if (currentTag() == "data") k->data = QByteArray::fromBase64(text.toLocal8Bit()); }
void ProjectActionParser::text(const QString &text) { if (currentTag() == "user") { k->users.insert(k->type, text); } else if (currentTag() == "name") { k->name = text; } else if (currentTag() == "author") { k->author = text; } else if (currentTag() == "description") { k->description = text; } }
void DatabaseParser::text(const QString &text) { if (currentTag() == "user") { m_users << text; if (m_loadProject) { if (m_project) m_project->addUser(text, m_typeUser); } } }
bool ofXML::pushTag(string lbl,int which) { bool ret=false; if(getNumTag(lbl)){ ret=true; prevLevel.push(currentLevel); currentLevel=&getTag(lbl, which); } else ofLog(OF_LOG_WARNING, "Tag not found: "+lbl+". Current level is "+currentTag()); return ret; }
bool FormulaComputability::checkComputability( const CNode& rootNode ) { CNode currentNode = rootNode.first_child(); while ( !currentNode.empty() ) { CTag& currentTag = CTagContainer::getTag(currentNode.name()); CNode nextNode = currentTag.checkSignature( currentNode ); currentTag(currentNode); currentNode = nextNode; } return true; }
void ofXML::loadFile(string file) { nodes.clear(); while (prevLevel.size()) prevLevel.pop(); currentLevel=0; filename=file; ifstream input(ofToDataPath(file).c_str()); string buffer; bool tagOpen=false; while (input.peek()!=EOF) { getline(input, buffer); for (unsigned int i=0; i<buffer.length(); i++) { if(buffer[0]=='#') i=buffer.length(); else if(!tagOpen&&buffer[i]=='<'){ tagOpen=true; i++; try { if(buffer[i]=='/'){ i++; string close=getWord(buffer, i, " >"); if(!currentTag().compare(close)){ popTag(); i--; } else ofLog(OF_LOG_WARNING, "Tags don't match: "+close+" and " +currentTag()); } else { string newLabel=getWord(buffer, i, " >"); i--; int n=addTag(newLabel); pushTag(newLabel, n); } } catch (string except) { ofLog(OF_LOG_WARNING, except); } } else if(tagOpen){ i=buffer.find_first_not_of(" ",i); if(buffer[i]=='>'){ //writeOut(); tagOpen=false; } else if(buffer[i]=='/'&&i<buffer.length()-1&&buffer[i+1]=='>'){ popTag(); } else { string aName=getWord(buffer, i, " ="); i=buffer.find_first_not_of("=\"",i); string aValue=getWord(buffer, i, "\""); addAttribute(aName,aValue); } } else if(!tagOpen&&buffer[i]!='\t'&&buffer[i]!='\r'&&buffer[i]!='\n'){ string val=getWord(buffer,i,"<"); i--; currentLevel->setValue(val); } } } }
void TupRequestParser::text(const QString &ch) { if (currentTag() == "data") k->response->setData(QByteArray::fromBase64(QByteArray(ch.toLocal8Bit()))); }
void TupNotificationParser::text(const QString &text) { if (currentTag() == "message") package.message = text; }
void ActionRegisterUserParser::text(const QString &txt) { d->data[currentTag()] = txt; }
int libhdfsconnector::readXMLOffset(const char * filename, unsigned long seekPos, unsigned long readlen, const char * rowTag, const char * headerText, const char * footerText, unsigned long bufferSize) { string xmlizedxpath; string elementname; string rootelement; xpath2xml(&xmlizedxpath, rowTag, true); getLastXPathElement(&elementname, rowTag); hdfsFile readFile = hdfsOpenFile(fs, filename, O_RDONLY, 0, 0, 0); if (!readFile) { fprintf(stderr, "Failed to open %s for reading!\n", filename); return EXIT_FAILURE; } if (hdfsSeek(fs, readFile, seekPos)) { fprintf(stderr, "Failed to seek %s for reading!\n", filename); return EXIT_FAILURE; } unsigned char buffer[bufferSize + 1]; bool firstRowfound = false; string openRowTag("<"); openRowTag.append(elementname).append(1, '>'); string closeRowTag("</"); closeRowTag.append(elementname).append(1, '>'); string closeRootTag("</"); getLastXMLElement(&closeRootTag, footerText); closeRootTag.append(1, '>'); unsigned long currentPos = seekPos + openRowTag.size(); string currentTag(""); bool withinRecord = false; bool stopAtNextClosingTag = false; bool parsingTag = false; fprintf(stderr, "--Start looking <%s>: %ld--\n", elementname.c_str(), currentPos); fprintf(stdout, "%s", xmlizedxpath.c_str()); unsigned long bytesLeft = readlen; while (hdfsAvailable(fs, readFile) && bytesLeft > 0) { tSize numOfBytesRead = hdfsRead(fs, readFile, (void*) buffer, bufferSize); if (numOfBytesRead <= 0) { fprintf(stderr, "\n--Hard Stop at: %ld--\n", currentPos); break; } for (int buffIndex = 0; buffIndex < numOfBytesRead;) { char currChar = buffer[buffIndex]; if (currChar == '<' || parsingTag) { if (!parsingTag) currentTag.clear(); int tagpos = buffIndex; while (tagpos < numOfBytesRead) { currentTag.append(1, buffer[tagpos++]); if (buffer[tagpos - 1] == '>') break; } if (tagpos == numOfBytesRead && buffer[tagpos - 1] != '>') { fprintf(stderr, "\nTag accross buffer reads...\n"); currentPos += tagpos - buffIndex; bytesLeft -= tagpos - buffIndex; buffIndex = tagpos; parsingTag = true; if (bytesLeft <= 0) { bytesLeft = readlen; //not sure how much longer til next EOL read up readlen; stopAtNextClosingTag = true; } break; } else parsingTag = false; if (!firstRowfound) { firstRowfound = strcmp(currentTag.c_str(), openRowTag.c_str()) == 0; if (firstRowfound) fprintf(stderr, "--start piping tag %s at %lu--\n", currentTag.c_str(), currentPos); } if (strcmp(currentTag.c_str(), closeRootTag.c_str()) == 0) { bytesLeft = 0; break; } if (strcmp(currentTag.c_str(), openRowTag.c_str()) == 0) withinRecord = true; else if (strcmp(currentTag.c_str(), closeRowTag.c_str()) == 0) withinRecord = false; else if (firstRowfound && !withinRecord) { bytesLeft = 0; fprintf(stderr, "Unexpected Tag found: %s at position %lu\n", currentTag.c_str(), currentPos); break; } currentPos += tagpos - buffIndex; bytesLeft -= tagpos - buffIndex; buffIndex = tagpos; if (bytesLeft <= 0 && !withinRecord) stopAtNextClosingTag = true; if (stopAtNextClosingTag && strcmp(currentTag.c_str(), closeRowTag.c_str()) == 0) { fprintf(stdout, "%s", currentTag.c_str()); fprintf(stderr, "--stop piping at %s %lu--\n", currentTag.c_str(), currentPos); bytesLeft = 0; break; } if (firstRowfound) fprintf(stdout, "%s", currentTag.c_str()); else fprintf(stderr, "skipping tag %s\n", currentTag.c_str()); if (buffIndex < numOfBytesRead) currChar = buffer[buffIndex]; else break; } if (firstRowfound) fprintf(stdout, "%c", currChar); buffIndex++; currentPos++; bytesLeft--; if (bytesLeft <= 0) { if (withinRecord) { fprintf(stderr, "\n--Looking for last closing row tag: %ld--\n", currentPos); bytesLeft = readlen; //not sure how much longer til next EOL read up readlen; stopAtNextClosingTag = true; } else break; } } } xmlizedxpath.clear(); xpath2xml(&xmlizedxpath, rowTag, false); fprintf(stdout, "%s", xmlizedxpath.c_str()); return EXIT_SUCCESS; }