From 77272458e7a8906d871b241b5385bbd0f783d861 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 30 Jul 2009 08:36:12 +0000 Subject: Removed the term 'course' everywhere, and replaced it by 'template'. This reduced/simplified the Template class structure a bit. --- server/src/Makefile.am | 2 ++ server/src/journal_commit.cc | 34 +++++++++++++++--------------- server/src/journal_commit.h | 2 +- server/src/macrotool_dump.cc | 26 +++++++++++------------ server/src/saxparser.cc | 8 +++---- server/src/server.cc | 28 ++++++++++++------------ server/src/template.h | 8 +------ server/src/templateheaderparser.cc | 2 +- server/src/templateparser.cc | 33 +++++++++++++---------------- server/src/templateparser.h | 4 ++-- server/src/transaction.h | 4 ++-- server/src/transactionparser.cc | 10 ++++----- server/xml/templates/amd_behandling.xml | 6 +++--- server/xml/templates/amd_forunders.xml | 4 ++-- server/xml/templates/amd_kontrolunders.xml | 6 +++--- server/xml/templates/example.xml | 4 ++-- server/xml/templates/test.xml | 4 ++-- 17 files changed, 89 insertions(+), 96 deletions(-) (limited to 'server') diff --git a/server/src/Makefile.am b/server/src/Makefile.am index 5516458..c8e1c51 100644 --- a/server/src/Makefile.am +++ b/server/src/Makefile.am @@ -225,6 +225,8 @@ test_macroparser: $(TEST_MACROPARSER_FILES) TEST_SERVER_FILES = \ server.cc \ templateparser.cc \ + templatelist.cc \ + templateheaderparser.cc \ queryparser.cc \ queryhandlerpentominos.cc \ journal_commit.cc \ diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc index 4992545..21d40c3 100644 --- a/server/src/journal_commit.cc +++ b/server/src/journal_commit.cc @@ -207,46 +207,46 @@ JournalWriter::JournalWriter(std::string host, unsigned short int port) } void JournalWriter::addEntry(Transaction &transaction, Commit &commit, - std::string resume, std::string course) + std::string resume, std::string templname) { - TemplateParser tp(course); + TemplateParser tp(templname); tp.parse(); Template *templ = tp.getTemplate(); size_t index = 0; - std::vector< Macro >::iterator i = templ->course.macros.begin(); - while(i != templ->course.macros.end()) { + std::vector< Macro >::iterator i = templ->macros.begin(); + while(i != templ->macros.end()) { Macro &m = *i; if(commit.macro == m.attributes["name"]) break; index++; i++; } - if(index >= templ->course.macros.size()) { - PRACRO_ERR(journal, "Could not find macro %s in course %s\n", - commit.macro.c_str(), course.c_str()); + if(index >= templ->macros.size()) { + PRACRO_ERR(journal, "Could not find macro %s in template %s\n", + commit.macro.c_str(), templname.c_str()); // return; } else { - PRACRO_DEBUG(journal, "Found macro %s as index %u in course %s\n", - commit.macro.c_str(), index, course.c_str()); + PRACRO_DEBUG(journal, "Found macro %s as index %u in template %s\n", + commit.macro.c_str(), index, templname.c_str()); } // First run - initialize username and cpr. if(currentuser == "" && entrylist.size() == 0) currentuser = transaction.user; if(currentcpr == "" && entrylist.size() == 0) currentcpr = transaction.cpr; - PRACRO_DEBUG(journal, "addEntry: course(%s)\n", course.c_str()); + PRACRO_DEBUG(journal, "addEntry: template(%s)\n", templname.c_str()); - // Add the course resume as the header (ie. first entry) of the journal entry. - if(entrylist.size() == 0 && course != "") { - std::string course_resume = templ->course.attributes["resume"]; + // Add the template resume as the header (ie. first entry) of the journal entry. + if(entrylist.size() == 0 && templname != "") { + std::string template_resume = templ->attributes["resume"]; - PRACRO_DEBUG(journal, "CourseResume: %s\n", course_resume.c_str()); + PRACRO_DEBUG(journal, "TemplateResume: %s\n", template_resume.c_str()); - if(course_resume != "") { + if(template_resume != "") { ResumeEntry re; - re.resume = course_resume; - re.macro = "course_header"; + re.resume = template_resume; + re.macro = "template_header"; entrylist[-1] = re; // Make sure it comes first. } } diff --git a/server/src/journal_commit.h b/server/src/journal_commit.h index 0565f34..9122703 100644 --- a/server/src/journal_commit.h +++ b/server/src/journal_commit.h @@ -43,7 +43,7 @@ public: JournalWriter(std::string host, unsigned short int port); void addEntry(Transaction &transaction, Commit &commit, - std::string resume, std::string course_resume); + std::string resume, std::string template_resume); void commit(); diff --git a/server/src/macrotool_dump.cc b/server/src/macrotool_dump.cc index 3f9cfd7..71bc690 100644 --- a/server/src/macrotool_dump.cc +++ b/server/src/macrotool_dump.cc @@ -89,14 +89,14 @@ static std::map macroList() std::vector templatefiles = getTemplates(); std::vector::iterator tfs = templatefiles.begin(); while(tfs != templatefiles.end()) { - std::string course = tfs->substr(0, tfs->length() - 4); - TemplateParser parser(course); + std::string templ = tfs->substr(0, tfs->length() - 4); + TemplateParser parser(templ); parser.parse(); Template *t = parser.getTemplate(); - std::vector::iterator ms = t->course.macros.begin(); - while(ms != t->course.macros.end()) { + std::vector::iterator ms = t->macros.begin(); + while(ms != t->macros.end()) { if(ms->attributes.find("header") == ms->attributes.end()) - macros[ms->attributes["name"]].templates.insert(course); + macros[ms->attributes["name"]].templates.insert(templ); ms++; } tfs++; @@ -154,20 +154,20 @@ static std::map templateList() std::vector templatefiles = getTemplates(); std::vector::iterator tfs = templatefiles.begin(); while(tfs != templatefiles.end()) { - std::string course = tfs->substr(0, tfs->length() - 4); - TemplateParser parser(course); + std::string templ = tfs->substr(0, tfs->length() - 4); + TemplateParser parser(templ); parser.parse(); Template *t = parser.getTemplate(); - std::string key = t->course.attributes["name"]; + std::string key = t->attributes["name"]; templates[key].file = *tfs; - templates[key].name = t->course.attributes["name"]; - templates[key].title = t->course.attributes["title"]; - templates[key].version = t->course.attributes["version"]; + templates[key].name = t->attributes["name"]; + templates[key].title = t->attributes["title"]; + templates[key].version = t->attributes["version"]; - std::vector::iterator ms = t->course.macros.begin(); - while(ms != t->course.macros.end()) { + std::vector::iterator ms = t->macros.begin(); + while(ms != t->macros.end()) { if(ms->attributes.find("header") == ms->attributes.end()) templates[key].macros.push_back(ms->attributes["name"]); ms++; diff --git a/server/src/saxparser.cc b/server/src/saxparser.cc index ee03de1..8455593 100644 --- a/server/src/saxparser.cc +++ b/server/src/saxparser.cc @@ -182,7 +182,7 @@ unsigned int SAXParser::usedBytes() static char xml[] = "\n" "\n" -" \n" +" \n" " \n" " \n" " \n" @@ -193,7 +193,7 @@ static char xml[] = static char xml_notrailingwhitespace[] = "\n" "\n" -" \n" +" \n" " \n" " \n" " \n" @@ -204,14 +204,14 @@ static char xml_notrailingwhitespace[] = static char xml_fail[] = "\n" "\n" -" \n" +" \n" "\n" ; static char xml_fail2[] = "\n" "\n" -" \n" +" \n" "\n" "this is junk\n" ; diff --git a/server/src/server.cc b/server/src/server.cc index 924ad84..f75aeab 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -63,13 +63,13 @@ static std::string error_box(std::string message) std::string errorbox = "\n" "\n" - " \n" + " \n" "\n"; return errorbox; } @@ -77,7 +77,7 @@ static std::string error_box(std::string message) class NotFoundException : public Exception { public: NotFoundException(Request &r) - : Exception("Macro " + r.macro + " not found in course " + r.course) {} + : Exception("Macro " + r.macro + " not found in template " + r.templ) {} }; @@ -99,7 +99,7 @@ static std::string handleCommits(Transaction *transaction, Database &db, db.commitTransaction(transaction->user, transaction->cpr, *macro, commit.fields); if(resume != "") { - journalwriter.addEntry(*transaction, commit, resume, commit.course); + journalwriter.addEntry(*transaction, commit, resume, commit.templ); } i++; @@ -122,26 +122,26 @@ static std::string handleRequest(Transaction *transaction, while(i != transaction->requests.end()) { Request &request = *i; - PRACRO_DEBUG(server, "Handling request - macro: %s, course: %s\n", - request.macro.c_str(), request.course.c_str()); + PRACRO_DEBUG(server, "Handling request - macro: %s, template: %s\n", + request.macro.c_str(), request.templ.c_str()); // Read and parse the template file. - TemplateParser tp(templatelist.getLatestVersion(request.course)); + TemplateParser tp(templatelist.getLatestVersion(request.templ)); tp.parse(); Template *templ = tp.getTemplate(); - answer += " course.attributes["name"]; + answer += " \n"; i++; } @@ -432,7 +432,7 @@ bool pracro_is_running = true; char request[] = "\n" "\n" - " \n" + " \n" "\n"; int main() diff --git a/server/src/template.h b/server/src/template.h index ac5900f..c14577e 100644 --- a/server/src/template.h +++ b/server/src/template.h @@ -68,15 +68,9 @@ public: bool isHeader; }; -class Course { -public: - std::vector< Macro > macros; - std::map< std::string, std::string > attributes; -}; - class Template { public: - Course course; + std::vector< Macro > macros; std::map< std::string, std::string > attributes; }; diff --git a/server/src/templateheaderparser.cc b/server/src/templateheaderparser.cc index ee93381..8b0f162 100644 --- a/server/src/templateheaderparser.cc +++ b/server/src/templateheaderparser.cc @@ -95,7 +95,7 @@ TemplateHeaderParser::~TemplateHeaderParser() void TemplateHeaderParser::startTag(std::string name, std::map< std::string, std::string> attributes) { // Create template and enable parsing of queries, maps and window - if(name == "course") { + if(name == "template") { assert(!t); // A Template has already been allocated, cannot create template! t = new Template(); t->attributes = attributes; diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc index 8ddf6d2..62be9c7 100644 --- a/server/src/templateparser.cc +++ b/server/src/templateparser.cc @@ -63,7 +63,7 @@ TemplateParser::TemplateParser(std::string templatefile) t = new Template(); current_macro = NULL; - file = templatefile;//Conf::xml_basedir + "/templates/" + course + ".xml"; + file = templatefile; PRACRO_DEBUG(macro, "Using template file: %s\n", file.c_str()); @@ -84,20 +84,20 @@ void TemplateParser::characterData(std::string &data) void TemplateParser::startTag(std::string name, std::map< std::string, std::string> attributes) { // Enable macro parsing - if(name == "course") { - if(state != UNDEFINED) error("course found not a root node."); - state = COURSE; + if(name == "template") { + if(state != UNDEFINED) error("Template found not a root node."); + state = TEMPLATE; - assert(t); // A Template has not yet been allocated, cannot create course! + assert(t); // A Template has not yet been allocated, cannot create template! - t->course.attributes = attributes; + t->attributes = attributes; return; } // Create macro and enable parsing of queries, maps and window if(name == "macro" || name == "header") { - if(state != COURSE) error("macro found outside course."); + if(state != TEMPLATE) error("macro found outside template."); state = MACRO; assert(t); // A Template has not yet been allocated, cannot create macro! @@ -105,8 +105,8 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri Macro m; m.attributes = attributes; m.isHeader = name == "header"; - t->course.macros.push_back(m); - current_macro = &(t->course.macros.back()); + t->macros.push_back(m); + current_macro = &(t->macros.back()); return; } @@ -116,10 +116,10 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri void TemplateParser::endTag(std::string name) { - if(name == "course") state = UNDEFINED; + if(name == "template") state = UNDEFINED; if(name == "macro" || name == "header") { current_macro = NULL; - state = COURSE; + state = TEMPLATE; } } @@ -173,16 +173,13 @@ int main() Template *t = parser.getTemplate(); - printf("[Template]:\n"); - print_attributes("\t-", t->attributes); - - printf("\t[Course]:\n"); - print_attributes("\t\t-", t->course.attributes); + printf("\t[Template]:\n"); + print_attributes("\t\t-", t->attributes); printf("\t\t[Macros]:\n"); - std::vector< Macro >::iterator i = t->course.macros.begin(); + std::vector< Macro >::iterator i = t->macros.begin(); - while(i != t->course.macros.end()) { + while(i != t->macros.end()) { printf("\t\t\t[Macro]:\n"); print_attributes("\t\t\t\t-", (*i).attributes); diff --git a/server/src/templateparser.h b/server/src/templateparser.h index 845e605..61f4d0b 100644 --- a/server/src/templateparser.h +++ b/server/src/templateparser.h @@ -32,13 +32,13 @@ typedef enum { UNDEFINED, - COURSE, + TEMPLATE, MACRO, } ParserState; class TemplateParser : public SAXParser { public: - TemplateParser(std::string course); + TemplateParser(std::string templ); ~TemplateParser(); void characterData(std::string &data); diff --git a/server/src/transaction.h b/server/src/transaction.h index 07f7e10..2cca49c 100644 --- a/server/src/transaction.h +++ b/server/src/transaction.h @@ -34,7 +34,7 @@ class Request { public: std::string macro; - std::string course; + std::string templ; }; typedef std::vector< Request > Requests; @@ -42,7 +42,7 @@ typedef std::map< std::string, std::string > Fields; class Commit { public: - std::string course; + std::string templ; std::string macro; std::string version; Fields fields; diff --git a/server/src/transactionparser.cc b/server/src/transactionparser.cc index 3135929..d4f7c76 100644 --- a/server/src/transactionparser.cc +++ b/server/src/transactionparser.cc @@ -78,14 +78,14 @@ void TransactionParser::startTag(std::string name, std::map< std::string, std::s if(name == "request") { Request r; - r.course = attributes["course"]; + r.templ = attributes["template"]; r.macro = attributes["macro"]; transaction->requests.push_back(r); } if(name == "commit") { Commit c; - c.course = attributes["course"]; + c.templ = attributes["template"]; c.macro = attributes["macro"]; c.version = attributes["version"]; transaction->commits.push_back(c); @@ -124,14 +124,14 @@ static char xml_minimal[] = static char xml_request[] = "\n" "\n" -" \n" +" \n" "\n" ; static char xml_commit[] = "\n" "\n" -" \n" +" \n" " \n" " \n" " \n" @@ -142,7 +142,7 @@ static char xml_commit[] = static char xml_fail[] = "\n" "\n" -" \n" +" \n" "\n" ; diff --git a/server/xml/templates/amd_behandling.xml b/server/xml/templates/amd_behandling.xml index 7be6361..58393b3 100644 --- a/server/xml/templates/amd_behandling.xml +++ b/server/xml/templates/amd_behandling.xml @@ -1,6 +1,6 @@ - + diff --git a/server/xml/templates/amd_forunders.xml b/server/xml/templates/amd_forunders.xml index 9201e3f..31f7d7e 100644 --- a/server/xml/templates/amd_forunders.xml +++ b/server/xml/templates/amd_forunders.xml @@ -1,5 +1,5 @@ - + diff --git a/server/xml/templates/amd_kontrolunders.xml b/server/xml/templates/amd_kontrolunders.xml index 2606743..818c472 100644 --- a/server/xml/templates/amd_kontrolunders.xml +++ b/server/xml/templates/amd_kontrolunders.xml @@ -1,6 +1,6 @@ - + diff --git a/server/xml/templates/example.xml b/server/xml/templates/example.xml index b6a3f6d..23e54a3 100644 --- a/server/xml/templates/example.xml +++ b/server/xml/templates/example.xml @@ -1,6 +1,6 @@ - + diff --git a/server/xml/templates/test.xml b/server/xml/templates/test.xml index dd4c093..0947bec 100644 --- a/server/xml/templates/test.xml +++ b/server/xml/templates/test.xml @@ -1,5 +1,5 @@ - + -- cgit v1.2.3