void Executive::executeCommands(ConfigParseToConsole configure) { //demonstrating each requirment one by one Display dp; XmlProcessing::XmlDocument doc(configure.getRepository()->getRoot()); std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstarting Requirement 3 and 10 by parsing and thereby writing an XML File/String to corresponding Tree representation"; std::cout << "\n" << std::string(150, '='); dp.displayToConsole(configure.getRepository()->getRoot(), true); dp.writeToOutputXML(configure.getRepository()->getRoot(), true); //Execute Functions:If TA supplies any new XML then he can make neccesary changes demonstrateAddRoot(dp, doc, "NewRoot"); demonstrateFindByTag(dp, doc, "title"); demonstrateFindByTag(dp, doc, "HelloWorld"); demonstrateFindByNameValue(dp, doc, "tagName", "Tester"); demonstrateFindByNameValue(dp, doc, "InvalidName", "InvalidValue"); demonstrateShowAttribute(dp, doc, "LectureNote"); demonstrateShowChildren(dp, doc, "LectureNote"); demonstrateAddAttribute(dp, doc, "title", "name", "ojas"); demonstrateAddChild(dp, doc, "LectureNote", "comment"); demonstrateAddChild(dp, doc, "LectureNote", "tag"); demonstrateAddChild(dp, doc, "LectureNote", "text"); demonstrateRemoveAttribute(dp, doc, "GreatChildTestTag", "tagName", "Tester"); demonstrateRemoveChild(dp, doc, "author", "TestTag"); doc.findById("").removeChild("LectureNote"); //removing the root from the docElement so that addRoot Functionality can be tested demonstrateAddRoot(dp, doc, "NewRoot"); demonstrateMoveOperation(dp, doc); }
void Executive::demonstrateShowChildren(Display dp, XmlProcessing::XmlDocument &doc, const std::string parent) { //demonstrates requirment and then send the output to display class std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 8 provide a facility to return a std::vector of pointers to all the children of a specified element."; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Input is Pointer to Element: " << parent << "\n"; std::vector<std::shared_ptr<AbstractXmlElement>> vectorSharedPtr; vectorSharedPtr = doc.findById(parent).select(); if (vectorSharedPtr.size() > 0) { dp.displayToConsole(doc.getChildrenVector(vectorSharedPtr[0])); dp.displayToConsole(doc.getChildrenVector(vectorSharedPtr[0]), parent); } else std::cout << "\n"<<"Tag: " << parent << " is not found in XML"; }
void Executive::demonstrateAddChild(Display dp, XmlProcessing::XmlDocument &doc, const std::string parent, const std::string option) { bool displayFlag = false; std::shared_ptr<AbstractXmlElement> sharedPtr; if (option == "comment") { //demonstrates requirment of add child by adding comment element std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 7 by adding Child Element to any Element in the tree that can hold child references found by ID or Tag."; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Query is: Add Comment Element: 'My Comment' to the parent tag: " + parent + "" << "\n"; sharedPtr = makeCommentElement("My Comment"); //making the pointer of comment element displayFlag = doc.findById(parent).addChild(sharedPtr); dp.displayToConsole(pDocElement_, displayFlag, parent); dp.writeToOutputXML(pDocElement_, displayFlag); } else if (option == "tag") { //demonstrates requirment of add child by adding tagged element std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n"<< "Demonstrating Requirement 7 by adding Child Element to any Element in the tree that can hold child references found by ID or Tag."; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Query is: Add Tagged Element with tag: 'NewChild' and Name,Value Pair:'NewChildName = NewChildValue' to the parent tag: " + parent + "." << "\n"; sharedPtr = makeTaggedElement("NewChild"); sharedPtr->addAttrib("NewChildName", "NewChildValue");//making the pointer of tagged element displayFlag = doc.findById(parent).addChild(sharedPtr); dp.displayToConsole(pDocElement_, displayFlag, parent); dp.writeToOutputXML(pDocElement_, displayFlag); } else if (option == "text") { //demonstrates requirment of add child by adding text element std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 7 by adding Child Element to any Element in the tree that can hold child references found by ID or Tag."; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Query is: Add Text Element with Text: 'NewChildText' to the parent tag: "+ parent +"."<<"\n"; sharedPtr = makeTextElement("NewChildText");//making the pointer of text element displayFlag = doc.findById(parent).addChild(sharedPtr); dp.displayToConsole(pDocElement_, displayFlag, parent); dp.writeToOutputXML(pDocElement_, displayFlag); } }
void Executive::demonstrateFindByTag( Display dp, XmlProcessing::XmlDocument &doc, const std::string tag) { //demonstrates requirment by finding element using ID/Tag std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n"<< "Demonstrating Requirement 6 by finding pointers to the a collection of elements that have the tag: "+ tag +""; std::cout << "\n" << std::string(150, '='); std::vector<std::shared_ptr<AbstractXmlElement>> vectorSharedPtr; vectorSharedPtr = doc.findById(tag).select(); dp.displayToConsole(vectorSharedPtr, tag); }
void Executive::demonstrateFindByNameValue(Display dp, XmlProcessing::XmlDocument &doc, const std::string name, const std::string value) { //demonstrates requirment by finding element using name value pair std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 5 by finding pointer to the element that have the specified name and value pair"; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Query is: Find with name and value pair as: '" + name + " = " + value + "'"<<"\n"; std::vector<std::shared_ptr<AbstractXmlElement>> vectorSharedPtr; vectorSharedPtr = doc.findByNameAndValue(name, value).select(); dp.displayToConsole(vectorSharedPtr, name, value); }
void Executive::demonstrateRemoveChild(Display dp, XmlProcessing::XmlDocument &doc, const std::string parent, const std::string elementToBeDeleted) { //demonstrates requirment of remove child and then send the output to display class bool displayFlag = false; std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 7 by removing Child Element from any Element in the tree that can hold child references found by ID or Tag."; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Query is: :Remove Child Element with Tag: " + elementToBeDeleted + " from the parent tag: "+parent+"."<<"\n"; displayFlag = doc.findById(parent).removeChild(elementToBeDeleted); dp.displayToConsole(pDocElement_, displayFlag, parent); dp.writeToOutputXML(pDocElement_, displayFlag); }
void Executive::demonstrateAddAttribute(Display dp, XmlProcessing::XmlDocument &doc, const std::string parent, std::string name, const std::string value) { //demonstrates requirment of add child by adding attribute bool displayFlag = false; std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 9 by adding name and value pair that supports attributes"; std::cout << "\n" << std::string(150, '='); std::cout << "\n""\n" << "Query is: Add Name-Value Pair: '" << name << " = " << value << "' to Tag: " << parent << "\n"; displayFlag = doc.findById(parent).addAttribute(name,value); dp.displayToConsole(pDocElement_, displayFlag, parent); dp.writeToOutputXML(pDocElement_, displayFlag); }
void Executive::demonstrateRemoveAttribute(Display dp, XmlProcessing::XmlDocument &doc, const std::string parent, const std::string name, const std::string value) { //demonstrates requirment of remove attribute and then send the output to display class bool displayFlag = false; std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 9 by removing name and value pair that supports attributes"; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Query is: Remove Child Attribute with Name-Value Pair: '" + name + " = " + value + "' from the tag: " + parent + "." << "\n"; displayFlag = doc.findById(parent).removeAttribute(name, value); dp.displayToConsole(pDocElement_, displayFlag, parent); dp.writeToOutputXML(pDocElement_, displayFlag); }
void Executive::demonstrateShowAttribute(Display dp, XmlProcessing::XmlDocument &doc,const std::string tag) { //demonstrates requirment and then send the output to display class std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 8 provide a facility to return a std::vector containing all the name-value attribute pairs attached to that element"; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Input is Pointer to Element: " << tag << "\n"; std::vector<std::shared_ptr<AbstractXmlElement>> vectorSharedPtr; vectorSharedPtr = doc.findById(tag).select(); if (vectorSharedPtr.size() > 0) dp.displayToConsole(doc.getAttributePairVector(vectorSharedPtr[0]), tag); else std::cout <<"\n"<< "Tag: "<<tag<<" is not found in XML"; }
void Executive::demonstrateAddRoot(Display dp, XmlProcessing::XmlDocument &doc,const std::string root) { //demonstartes add Root requirement bool displayFlag = false; std::cout << "\n""\n""\n" << std::string(150, '='); std::cout << "\n" << "Demonstrating Requirement 7 by providing the ability to add a root element to an empty document tree"; std::cout << "\n" << std::string(150, '='); std::cout << "\n" << "Query is:: Add Tagged Element: '" + root + "'id the root is empty." << "\n"; displayFlag = doc.addRoot(root); if (displayFlag) { dp.displayToConsole(doc.getRoot(), displayFlag); dp.writeToRootXML(doc.getRoot(), displayFlag); } else { std::cout << "\n""\n" << "Cannot Form New Root because Childrens are already Present" << "\n"; } }