/* * (non-Javadoc) * @see org.xml.sax.ContentHandler#startElement(java.lang.string, java.lang.string, java.lang.string, org.xml.sax.Attributes) */ public override void startElement(string namespaceURI, string sName, string qName, Dictionary <string, string> attrs) { if (qName.Equals("assessment-rules")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("show-report-at-end")) { profile.setShowReportAtEnd(entry.Value.ToString().Equals("yes")); } if (entry.Key.Equals("send-to-email")) { if (entry.Value.ToString() == null || entry.Value.ToString().ToString().Length < 1) { profile.setEmail(""); profile.setSendByEmail(false); } else { profile.setEmail(entry.Value.ToString()); profile.setSendByEmail(true); } } if (entry.Key.Equals("scorm12")) { profile.setScorm12(entry.Value.ToString().Equals("yes")); } if (entry.Key.Equals("scorm2004")) { profile.setScorm2004(entry.Value.ToString().Equals("yes")); } } } else if (qName.Equals("smtp-config")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("smtp-ssl")) { profile.setSmtpSSL(entry.Value.ToString().Equals("yes")); } if (entry.Key.Equals("smtp-server")) { profile.setSmtpServer(entry.Value.ToString()); } if (entry.Key.Equals("smtp-port")) { profile.setSmtpPort(entry.Value.ToString()); } if (entry.Key.Equals("smtp-user")) { profile.setSmtpUser(entry.Value.ToString()); } if (entry.Key.Equals("smtp-pwd")) { profile.setSmtpPwd(entry.Value.ToString()); } } } else if (qName.Equals("assessment-rule")) { string id = null; int importance = 0; bool repeatRule = false; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } if (entry.Key.Equals("importance")) { for (int j = 0; j < AssessmentRule.N_IMPORTANCE_VALUES; j++) { if (entry.Value.ToString().Equals(AssessmentRule.IMPORTANCE_VALUES[j])) { importance = j; } } } if (entry.Key.Equals("repeatRule")) { repeatRule = entry.Value.ToString().Equals("yes"); } } currentAssessmentRule = new AssessmentRule(id, importance, repeatRule); } else if (qName.Equals("timed-assessment-rule")) { string id = null; int importance = 0; bool usesEndConditions = false; bool has = false; bool repeatRule = false; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } if (entry.Key.Equals("importance")) { for (int j = 0; j < AssessmentRule.N_IMPORTANCE_VALUES; j++) { if (entry.Value.ToString().Equals(AssessmentRule.IMPORTANCE_VALUES[j])) { importance = j; } } } if (entry.Key.Equals("usesEndConditions")) { has = true; usesEndConditions = entry.Value.ToString().Equals("yes"); } if (entry.Key.Equals("repeatRule")) { repeatRule = entry.Value.ToString().Equals("yes"); } } currentAssessmentRule = new TimedAssessmentRule(id, importance, repeatRule); if (has) { ((TimedAssessmentRule)currentAssessmentRule).setUsesEndConditions(usesEndConditions); } } else if (qName.Equals("condition") || qName.Equals("init-condition") || qName.Equals("end-condition")) { currentConditions = new Conditions(); } // If it is an either tag, create a new either conditions and switch the state else if (qName.Equals("either")) { currentEitherCondition = new Conditions(); reading = READING_EITHER; } // If it is an active tag else if (qName.Equals("active")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("flag")) { // Store the active flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new FlagCondition(entry.Value.ToString())); } if (reading == READING_EITHER) { currentEitherCondition.add(new FlagCondition(entry.Value.ToString())); } addFlag(entry.Value.ToString()); } } } // If it is an inactive tag else if (qName.Equals("inactive")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("flag")) { // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new FlagCondition(entry.Value.ToString(), FlagCondition.FLAG_INACTIVE)); } if (reading == READING_EITHER) { currentEitherCondition.add(new FlagCondition(entry.Value.ToString(), FlagCondition.FLAG_INACTIVE)); } addFlag(entry.Value.ToString()); } } } // If it is a greater-than tag else if (qName.Equals("greater-than")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.VAR_GREATER_THAN, value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.VAR_GREATER_THAN, value)); } addVar(var); } // If it is a greater-equals-than tag else if (qName.Equals("greater-equals-than")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.VAR_GREATER_EQUALS_THAN, value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.VAR_GREATER_EQUALS_THAN, value)); } addVar(var); } // If it is a less-than tag else if (qName.Equals("less-than")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.VAR_LESS_THAN, value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.VAR_LESS_THAN, value)); } addVar(var); } // If it is a less-equals-than tag else if (qName.Equals("less-equals-than")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.VAR_LESS_EQUALS_THAN, value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.VAR_LESS_EQUALS_THAN, value)); } addVar(var); } // If it is a equals-than tag else if (qName.Equals("equals")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.VAR_EQUALS, value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.VAR_EQUALS, value)); } addVar(var); } // If it is a not-equals-than tag else if (qName.Equals("not-equals")) { // The var string var = null; // The value int value = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("var")) { var = entry.Value.ToString(); } else if (entry.Key.Equals("value")) { value = int.Parse(entry.Value.ToString()); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new VarCondition(var, VarCondition.VAR_NOT_EQUALS, value)); } if (reading == READING_EITHER) { currentEitherCondition.add(new VarCondition(var, VarCondition.VAR_NOT_EQUALS, value)); } addVar(var); } // If it is a global-state-reference tag else if (qName.Equals("global-state-ref")) { // Id string id = null; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } } // Store the inactive flag in the conditions or either conditions if (reading == READING_NONE) { currentConditions.add(new GlobalStateCondition(id)); } if (reading == READING_EITHER) { currentEitherCondition.add(new GlobalStateCondition(id)); } } else if (qName.Equals("set-property")) { string id = null; string value = null; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } if (entry.Key.Equals("value")) { value = entry.Value.ToString(); } } currentAssessmentRule.addProperty(new AssessmentProperty(id, value)); } else if (qName.Equals("effect")) { if (currentAssessmentRule is TimedAssessmentRule) { int timeMin = int.MinValue; int timeMax = int.MinValue; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("time-min")) { timeMin = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("time-max")) { timeMax = int.Parse(entry.Value.ToString()); } } TimedAssessmentRule tRule = (TimedAssessmentRule)currentAssessmentRule; if (timeMin != int.MinValue && timeMax != int.MaxValue) { tRule.addEffect(timeMin, timeMax); } else { tRule.addEffect(); } } } }
public override void ParseElement(XmlElement element) { XmlNodeList smtpsconfigs = element.SelectNodes("smtp-config"), assessmentsrule = element.SelectNodes("assessment-rule"), timedsssessmentsrule = element.SelectNodes("timed-assessment-rule"), conditions, initsconditions, endsconditions, setpropertys, assessEffects; string tmpArgVal; tmpArgVal = element.GetAttribute("show-report-at-end"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setShowReportAtEnd(tmpArgVal.Equals("yes")); } tmpArgVal = element.GetAttribute("send-to-email"); if (!string.IsNullOrEmpty(tmpArgVal)) { if (tmpArgVal == null || tmpArgVal.Length < 1) { profile.setEmail(""); profile.setSendByEmail(false); } else { profile.setEmail(tmpArgVal); profile.setSendByEmail(true); } } tmpArgVal = element.GetAttribute("scorm12"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setScorm12(tmpArgVal.Equals("yes")); } tmpArgVal = element.GetAttribute("scorm2004"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setScorm2004(tmpArgVal.Equals("yes")); } tmpArgVal = element.GetAttribute("name"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setName(tmpArgVal); } foreach (XmlElement ell in smtpsconfigs) { tmpArgVal = element.GetAttribute("smtp-ssl"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setSmtpSSL(tmpArgVal.Equals("yes")); } tmpArgVal = element.GetAttribute("smtp-server"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setSmtpServer(tmpArgVal); } tmpArgVal = element.GetAttribute("smtp-port"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setSmtpPort(tmpArgVal); } tmpArgVal = element.GetAttribute("smtp-user"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setSmtpUser(tmpArgVal); } tmpArgVal = element.GetAttribute("smtp-pwd"); if (!string.IsNullOrEmpty(tmpArgVal)) { profile.setSmtpPwd(tmpArgVal); } } foreach (XmlElement ell in assessmentsrule) { string id = null; int importance = 0; bool repeatRule = false; tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { id = tmpArgVal; } tmpArgVal = element.GetAttribute("importance"); if (!string.IsNullOrEmpty(tmpArgVal)) { for (int j = 0; j < AssessmentRule.N_IMPORTANCE_VALUES; j++) { if (tmpArgVal.Equals(AssessmentRule.IMPORTANCE_VALUES[j])) { importance = j; } } } tmpArgVal = element.GetAttribute("repeatRule"); if (!string.IsNullOrEmpty(tmpArgVal)) { repeatRule = tmpArgVal.Equals("yes"); } currentAssessmentRule = new AssessmentRule(id, importance, repeatRule); conditions = element.SelectNodes("condition"); foreach (XmlElement ell_ in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell_); currentAssessmentRule.setConditions(currentConditions); } initsconditions = element.SelectNodes("init-condition"); foreach (XmlElement ell_ in initsconditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell_); ((TimedAssessmentRule)currentAssessmentRule).setInitConditions(currentConditions); } endsconditions = element.SelectNodes("end-condition"); foreach (XmlElement ell_ in endsconditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell_); ((TimedAssessmentRule)currentAssessmentRule).setEndConditions(currentConditions); } if (ell.SelectSingleNode("concept") != null) { currentAssessmentRule.setConcept(ell.SelectSingleNode("concept").InnerText.ToString().Trim()); } if (ell.SelectSingleNode("set-text") != null) { currentAssessmentRule.setText(ell.SelectSingleNode("set-text").InnerText.ToString().Trim()); } assessEffects = element.SelectNodes("assessEffect"); foreach (XmlElement ell_ in assessEffects) { int timeMin = int.MinValue; int timeMax = int.MinValue; tmpArgVal = element.GetAttribute("time-min"); if (!string.IsNullOrEmpty(tmpArgVal)) { timeMin = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("time-max"); if (!string.IsNullOrEmpty(tmpArgVal)) { timeMax = int.Parse(tmpArgVal); } TimedAssessmentRule tRule = (TimedAssessmentRule)currentAssessmentRule; if (timeMin != int.MinValue && timeMax != int.MaxValue) { tRule.addEffect(timeMin, timeMax); } else { tRule.addEffect(); } } profile.addRule(currentAssessmentRule); } foreach (XmlElement ell in timedsssessmentsrule) { string id = null; int importance = 0; bool usesEndConditions = false; bool has = false; bool repeatRule = false; tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { id = tmpArgVal; } tmpArgVal = element.GetAttribute("importance"); if (!string.IsNullOrEmpty(tmpArgVal)) { for (int j = 0; j < AssessmentRule.N_IMPORTANCE_VALUES; j++) { if (tmpArgVal.Equals(AssessmentRule.IMPORTANCE_VALUES[j])) { importance = j; } } } tmpArgVal = element.GetAttribute("usesEndConditions"); if (!string.IsNullOrEmpty(tmpArgVal)) { has = true; usesEndConditions = tmpArgVal.Equals("yes"); } tmpArgVal = element.GetAttribute("repeatRule"); if (!string.IsNullOrEmpty(tmpArgVal)) { has = true; repeatRule = tmpArgVal.Equals("yes"); } currentAssessmentRule = new TimedAssessmentRule(id, importance, repeatRule); if (has) { ((TimedAssessmentRule)currentAssessmentRule).setUsesEndConditions(usesEndConditions); } conditions = element.SelectNodes("condition"); foreach (XmlElement ell_ in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell_); currentAssessmentRule.setConditions(currentConditions); } initsconditions = element.SelectNodes("init-condition"); foreach (XmlElement ell_ in initsconditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell_); ((TimedAssessmentRule)currentAssessmentRule).setInitConditions(currentConditions); } endsconditions = element.SelectNodes("end-condition"); foreach (XmlElement ell_ in endsconditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell_); ((TimedAssessmentRule)currentAssessmentRule).setEndConditions(currentConditions); } if (ell.SelectSingleNode("concept") != null) { currentAssessmentRule.setConcept(ell.SelectSingleNode("concept").InnerText.ToString().Trim()); } if (ell.SelectSingleNode("set-text") != null) { currentAssessmentRule.setText(ell.SelectSingleNode("set-text").InnerText.ToString().Trim()); } assessEffects = element.SelectNodes("assessEffect"); foreach (XmlElement ell_ in assessEffects) { int timeMin = int.MinValue; int timeMax = int.MinValue; tmpArgVal = element.GetAttribute("time-min"); if (!string.IsNullOrEmpty(tmpArgVal)) { timeMin = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("time-max"); if (!string.IsNullOrEmpty(tmpArgVal)) { timeMax = int.Parse(tmpArgVal); } TimedAssessmentRule tRule = (TimedAssessmentRule)currentAssessmentRule; if (timeMin != int.MinValue && timeMax != int.MaxValue) { tRule.addEffect(timeMin, timeMax); } else { tRule.addEffect(); } } profile.addRule(currentAssessmentRule); } chapter.addAssessmentProfile(profile); }