List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * Create QTI meta data element/*from ww w . j av a 2s. co m*/ * * @param doc * @param questionType * @return */ private Element createQTIMetadataElement(Document doc, String questionType) { Element qtiMetaData = doc.createElementNS("http://www.imsglobal.org/xsd/imsqti_v2p1", "imsqti:qtiMetadata"); Element itemTemplate = doc.createElementNS("http://www.imsglobal.org/xsd/imsqti_v2p1", "imsqti:itemTemplate"); itemTemplate.setTextContent("false"); qtiMetaData.appendChild(itemTemplate); Element composite = doc.createElementNS("http://www.imsglobal.org/xsd/imsqti_v2p1", "imsqti:composite"); composite.setTextContent("false"); qtiMetaData.appendChild(composite); Element interactionType = doc.createElementNS("http://www.imsglobal.org/xsd/imsqti_v2p1", "imsqti:interactionType"); String interaction = ""; if (("mneme:MultipleChoice").equals(questionType) || ("mneme:TrueFalse").equals(questionType) || ("mneme:LikertScale").equals(questionType)) interaction = "choiceInteraction"; if (("mneme:Essay").equals(questionType)) interaction = "extendedTextInteraction"; if (("mneme:Match").equals(questionType)) interaction = "matchInteraction"; if (("mneme:FillBlanks").equals(questionType)) interaction = "textEntryInteraction"; interactionType.setTextContent(interaction); qtiMetaData.appendChild(interactionType); Element feedbackType = doc.createElementNS("http://www.imsglobal.org/xsd/imsqti_v2p1", "imsqti:feedbackType"); feedbackType.setTextContent("none"); qtiMetaData.appendChild(feedbackType); return qtiMetaData; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * Creates the assessment.xml file and writes to the zip package * //from w ww. j av a 2s . c o m * @param test * @param resourceAssessmentIdent * @param assessmentFileName * @param zip * @return */ public HashMap<String, List<Element>> createAssessmentDocument(String context, Assessment test, Document doc, String resourceAssessmentIdent, String assessmentFileName, ZipOutputStream zip, ArrayList<PoolDetails> pools) { Document assessmentTestDocument = Xml.createDocument(); Element assessmentTestElement = assessmentTestDocument.createElement("assessmentTest"); assessmentTestElement.setAttribute("xmlns", "http://www.imsglobal.org/xsd/imsqti_v2p1"); HashMap<String, List<Element>> miscellaneousItems = new HashMap<String, List<Element>>(); HashMap<String, Element> questionsList = new HashMap<String, Element>(); assessmentTestElement.setAttribute("identifier", resourceAssessmentIdent); assessmentTestElement.setAttribute("title", test.getTitle()); float pointsValue = 0; String points = "10"; String tries = ""; String navigationMode = (test.getRandomAccess()) ? "nonlinear" : "linear"; String submissionMode = "simultaneous"; String reviewOptions = "Never"; String showHints = "false"; boolean randomDraw = false; if (test.getHasTriesLimit()) tries = test.getTries().toString(); if (test.getReview() != null && test.getReview().getTiming() != null) reviewOptions = test.getReview().getTiming().toString(); if (test.getShowHints() != null) showHints = test.getShowHints().toString(); // <timeLimits maxTime="" allowLateSubmission="0 or 1"/> if (test.getHasTimeLimit()) { Element limitElement = assessmentTestDocument.createElement("timeLimits"); limitElement.setAttribute("maxTime", test.getTimeLimit().toString()); limitElement.setAttribute("allowLateSubmission", "0"); assessmentTestElement.appendChild(limitElement); } // create outcomeDeclaration Element outcomeDeclarationElement = createOutcomeElement(assessmentTestDocument, "SCORE", "float", points); if (outcomeDeclarationElement != null) assessmentTestElement.appendChild(outcomeDeclarationElement); assessmentTestElement = createOtherSettingsOutcomeElements(assessmentTestDocument, assessmentTestElement, test); // testPart AssessmentParts assessmentParts = test.getParts(); // part numbering if (!assessmentParts.getContinuousNumbering()) { Element outcomeDeclarationPartNumberingElement = createOutcomeElement(assessmentTestDocument, "PartNumbering", "string", assessmentParts.getContinuousNumbering().toString()); if (outcomeDeclarationPartNumberingElement != null) assessmentTestElement.appendChild(outcomeDeclarationPartNumberingElement); } List<Part> parts = assessmentParts.getParts(); int partsCount = 1; for (Part p : parts) { //get the master pool and questions id. for (Iterator<PartDetail> i = p.getDetails().iterator(); i.hasNext();) { PartDetail detail = i.next(); if (!detail.restoreToOriginal(null, null)) { i.remove(); } } pointsValue = pointsValue + p.getTotalPoints(); // <testPart identifier="part01" navigationMode="nonlinear" submissionMode="simultaneous"> Element testPartElement = assessmentTestDocument.createElement("testPart"); testPartElement.setAttribute("identifier", p.getId()); testPartElement.setAttribute("navigationMode", navigationMode); testPartElement.setAttribute("submissionMode", submissionMode); Element itemSession = createItemSessionElement(assessmentTestDocument, tries, reviewOptions, showHints, test.getShowModelAnswer()); testPartElement.appendChild(itemSession); // <assessmentSection identifier="sectionA" title="Section A" visible="true"> Element assessmentSectionElement = createSectionElement(assessmentTestDocument, p.getTitle(), partsCount++, p.getRandomize()); // rubricBlock Element rubricElement = assessmentTestDocument.createElement("rubricBlock"); if (p.getPresentation() != null && p.getPresentation().getText() != null) { String partDescription = p.getPresentation().getText(); ArrayList<String> mediaFiles = new ArrayList<String>(); String subFolder = test.getId() + "/Resources/"; if (zip != null && mediaFiles != null) partDescription = translateEmbedData(zip, subFolder, "Resources/", partDescription, mediaFiles); rubricElement.setTextContent(partDescription); } assessmentSectionElement.appendChild(rubricElement); // create AssessmentItem document for the question int question_count = 1; List<Question> questions = p.getQuestions(); List<PartDetail> details = p.getDetails(); List<PartDetail> drawPools = new ArrayList<PartDetail>(); assessmentSectionElement = findDrawPools(details, assessmentTestDocument, assessmentSectionElement, drawPools, p.getNumQuestions()); if (drawPools.size() > 0) randomDraw = true; for (Question question : questions) { try { String questionPoolId = question.getPool().getId(); PoolDetails questionPool = new PoolDetails(questionPoolId, question.getPool().getTitle()); if (!pools.contains(questionPool)) pools.add(questionPool); // create question.xml file ArrayList<String> mediaFiles = new ArrayList<String>(); Element assessmentItem = createAssessmentItemforQuestion(zip, context, test.getId(), mediaFiles, question, question.getPartDetail().getQuestionPoints(), question_count++); if (assessmentItem == null) continue; Element itemResourceElement = createResourceElementforQuestion(doc, test.getId(), question, mediaFiles); itemResourceElement = getAttachments(zip, test.getId(), doc, itemResourceElement, question); questionsList.put(question.getId(), itemResourceElement); // add assessmentItemRef -- <assessmentItemRef identifier="item034" href="adaptive.xml"> Element assessmentItemRefElement = assessmentTestDocument.createElement("assessmentItemRef"); assessmentItemRefElement.setAttribute("identifier", questionPoolId + ":" + question.getId()); assessmentItemRefElement.setAttribute("href", "question" + question.getId() + ".xml"); if (randomDraw && !question.getPartDetail().getType().contains("Draw")) assessmentItemRefElement.setAttribute("required", "true"); else if (randomDraw && question.getPartDetail().getType().contains("Draw")) assessmentItemRefElement.setAttribute("required", "false"); assessmentSectionElement.appendChild(assessmentItemRefElement); } catch (Exception e) { M_log.debug("Export qti2:" + e.getMessage()); } } // questions for // if random add other questions from the pool to draw from for (PartDetail pd : drawPools) { Float pdQuestionPoints = pd.getEffectivePoints() / pd.getNumQuestions(); List<Element> otherResources = addOtherPoolQuestions(doc, assessmentTestDocument, questionsList, pd.getPool(), zip, context, test.getId(), pdQuestionPoints, question_count++); for (Element r : otherResources) assessmentSectionElement.appendChild(r); question_count = question_count + otherResources.size(); } ArrayList<Element> items = new ArrayList<Element>(); for (Element e : questionsList.values()) items.add(e); miscellaneousItems.put("questionItems", items); testPartElement.appendChild(assessmentSectionElement); assessmentTestElement.appendChild(testPartElement); } // parts end if (pointsValue > 0) { NodeList value = outcomeDeclarationElement.getElementsByTagName("value"); Element valueElement = (Element) value.item(0); valueElement.setTextContent(new Float(pointsValue).toString()); } // outcomeProcessing Element outcomeProcessingElement = assessmentTestDocument.createElement("outcomeProcessing"); assessmentTestElement.appendChild(outcomeProcessingElement); // Final Message if (test.getSubmitPresentation() != null && test.getSubmitPresentation().getText() != null) { Element testFeedbackElement = createFinalFeedbackElement(assessmentTestDocument, test.getSubmitPresentation().getText()); assessmentTestElement.appendChild(testFeedbackElement); } assessmentTestDocument.appendChild(assessmentTestElement); // 4. write assessment.xml to the zip file writeDocumentToZip(zip, test.getId() + "/", assessmentFileName, assessmentTestDocument); return miscellaneousItems; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * /*from ww w .j a v a 2 s.c om*/ * @param poolDocument * @param question * @param text * @return */ public Map<String, Element> getallQuestionElements(ZipOutputStream zip, Document questionDocument, String testId, Question question, String context, List<String> mediaFiles) throws Exception { Map<String, Element> questionParts = new HashMap<String, Element>(); String text = question.getPresentation().getText(); Element itemBody = questionDocument.createElement("itemBody"); // for fill blanks text will be chopped if (!"mneme:FillBlanks".equals(question.getType())) { if (text == null) return questionParts; // process embed media and change path as Resources/xxxx.jpg // security advisor pushAdvisor(); itemBody = translateEmbedData(zip, testId + "/Resources/", text, itemBody, mediaFiles, questionDocument); popAdvisor(); if (mediaFiles.isEmpty()) { Element div = questionDocument.createElement("div"); div.setTextContent(text); itemBody.appendChild(div); } } // split the text based on <br/> if ("mneme:FillBlanks".equals(question.getType())) { FillBlanksQuestionImpl f = (FillBlanksQuestionImpl) (question.getTypeSpecificQuestion()); text = f.getText(); itemBody = getFillBlanksResponseChoices(questionDocument, itemBody, f, questionParts); } else if ("mneme:TrueFalse".equals(question.getType())) { getTFResponseChoices(questionDocument, question, questionParts); if (questionParts.containsKey("choiceInteraction")) itemBody.appendChild(questionParts.get("choiceInteraction")); } else if ("mneme:MultipleChoice".equals(question.getType())) { getMCResponseChoices(questionDocument, question, questionParts); if (questionParts.containsKey("choiceInteraction")) itemBody.appendChild(questionParts.get("choiceInteraction")); } else if ("mneme:Match".equals(question.getType())) { getMatchResponseChoices(questionDocument, question, questionParts); if (questionParts.containsKey("matchInteraction")) itemBody.appendChild(questionParts.get("matchInteraction")); } else if ("mneme:Essay".equals(question.getType())) { getEssayResponseChoices(questionDocument, question, questionParts); if (questionParts.containsKey("extendedTextInteraction")) itemBody.appendChild(questionParts.get("extendedTextInteraction")); if (questionParts.containsKey("uploadInteraction")) itemBody.appendChild(questionParts.get("uploadInteraction")); } else if ("mneme:Task".equals(question.getType())) { // no model answer and no submission type and no basetype Element responseDeclaration = questionDocument.createElement("responseDeclaration"); responseDeclaration.setAttribute("identifier", "RESPONSE"); responseDeclaration.setAttribute("cardinality", "single"); questionParts.put("responseDeclaration", responseDeclaration); } else if ("mneme:LikertScale".equals(question.getType())) { // <itemBody class="likert"> itemBody.setAttribute("class", "likert"); getLikertScaleResponseChoices(questionDocument, question, questionParts); if (questionParts.containsKey("choiceInteraction")) itemBody.appendChild(questionParts.get("choiceInteraction")); } // Hints are part of item body if (question.getHints() != null && question.getHints().length() != 0) { Element feedbackInlineElement = questionDocument.createElement("feedbackInline"); feedbackInlineElement.setAttribute("showHide", "hide"); feedbackInlineElement.setAttribute("identifier", "FB_Hints"); feedbackInlineElement.appendChild(questionDocument.createCDATASection(question.getHints())); itemBody.appendChild(feedbackInlineElement); } // question feedback if (question.getFeedback() != null && question.getFeedback().length() != 0) { Element feedbackElement = questionDocument.createElement("modalFeedback"); feedbackElement.setAttribute("showHide", "hide"); feedbackElement.setAttribute("identifier", "FB_Question"); feedbackElement.appendChild(questionDocument.createCDATASection(question.getFeedback())); questionParts.put("modalFeedback", feedbackElement); } questionParts.put("itemBody", itemBody); return questionParts; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * // w w w.j av a 2 s.co m * @param questionDocument * @param question * @param questionParts */ public void getEssayResponseChoices(Document questionDocument, Question question, Map<String, Element> questionParts) { if (question == null) return; EssayQuestionImpl essay = (EssayQuestionImpl) (question.getTypeSpecificQuestion()); String basetype = ("attachments".equals(essay.getSubmissionType().toString())) ? "file" : "string"; if ("string".equals(basetype)) { // <extendedTextInteraction responseIdentifier="RESPONSE" expectedLength="200"> Element interaction = questionDocument.createElement("extendedTextInteraction"); interaction.setAttribute("responseIdentifier", "RESPONSE"); interaction.setAttribute("expectedLength", "200"); questionParts.put("extendedTextInteraction", interaction); } else if ("file".equals(basetype)) { // <uploadInteraction responseIdentifier="RESPONSE"> Element interaction = questionDocument.createElement("uploadInteraction"); interaction.setAttribute("responseIdentifier", "RESPONSE"); questionParts.put("uploadInteraction", interaction); } // <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="string"/> Element responseDeclaration = createResponseDeclaration(questionDocument, "RESPONSE", "single", basetype); // Modal answer String answer = essay.getModelAnswer(); Element correctResponse = questionDocument.createElement("correctResponse"); responseDeclaration.appendChild(correctResponse); if (answer != null && answer.length() > 0) { answer = FormattedText.unEscapeHtml(answer); Element correctResponseValue = questionDocument.createElement("value"); correctResponseValue.setTextContent(answer); correctResponse.appendChild(correctResponseValue); } questionParts.put("responseDeclaration", responseDeclaration); return; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * /*from w w w. j a v a2s . c o m*/ * @param questionDocument * @param itemBody * @param question * @param questionParts * @return */ public Element getFillBlanksResponseChoices(Document questionDocument, Element itemBody, FillBlanksQuestionImpl question, Map<String, Element> questionParts) { if (question == null) return itemBody; // itemBody String text = question.getText(); Pattern p_fillBlanks_curly = Pattern.compile("([^{]*.?)(\\{)([^}]*.?)(\\})", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); Matcher m_fillBlanks = p_fillBlanks_curly.matcher(text); StringBuffer sb = new StringBuffer(); // in each part look for {} fill in the blank symbol and create render_fib tag int count = 1; while (m_fillBlanks.find()) { String fib = m_fillBlanks.group(1); Element textDiv = questionDocument.createElement("div"); textDiv.setTextContent(fib); itemBody.appendChild(textDiv); String fib_curly = m_fillBlanks.group(2); Element fbInteraction = questionDocument.createElement("textEntryInteraction"); fbInteraction.setAttribute("responseIdentifier", "RESPONSE" + (count++)); fbInteraction.setAttribute("expectedLength", Integer.toString(fib_curly.length())); itemBody.appendChild(fbInteraction); m_fillBlanks.appendReplacement(sb, ""); } m_fillBlanks.appendTail(sb); if (sb.length() > 0) { Element textDiv = questionDocument.createElement("div"); textDiv.setTextContent(sb.toString()); itemBody.appendChild(textDiv); } // answer List<String> correctAnswers = new ArrayList<String>(); question.parseCorrectAnswers(correctAnswers); int responseCount = 1; for (String answer : correctAnswers) { Element responseDeclaration = createResponseDeclaration(questionDocument, "RESPONSE" + responseCount, "single", "string"); Element correctResponse = questionDocument.createElement("correctResponse"); Element correctResponseValue = questionDocument.createElement("value"); answer = FormattedText.unEscapeHtml(answer); correctResponseValue.setTextContent(answer); correctResponse.appendChild(correctResponseValue); responseDeclaration.appendChild(correctResponse); questionParts.put("responseDeclaration" + responseCount, responseDeclaration); responseCount++; } Element countDiv = questionDocument.createElement("div"); countDiv.setTextContent(Integer.toString(responseCount)); questionParts.put("responseDeclarationCount", countDiv); questionParts.put("itemBody", itemBody); return itemBody; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * //from w ww . j av a 2 s . c o m * @param questionDocument * @param question * @param questionParts */ public void getLikertScaleResponseChoices(Document questionDocument, Question question, Map<String, Element> questionParts) { if (question == null) return; LikertScaleQuestionImpl likert = (LikertScaleQuestionImpl) (question.getTypeSpecificQuestion()); List<LikertScaleQuestionChoice> choices = likert.getChoices(); // <choiceInteraction responseIdentifier="RESPONSE" shuffle="false" maxChoices="1"> Element choiceInteraction = questionDocument.createElement("choiceInteraction"); choiceInteraction.setAttribute("responseIdentifier", "RESPONSE"); choiceInteraction.setAttribute("shuffle", "false"); choiceInteraction.setAttribute("maxChoices", "1"); // <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"> Element responseDeclaration = createResponseDeclaration(questionDocument, "RESPONSE", "single", "identifier"); // add scale as the correct answer Element correctResponse = questionDocument.createElement("correctResponse"); Element value = questionDocument.createElement("value"); value.setTextContent(likert.getScale()); correctResponse.appendChild(value); responseDeclaration.appendChild(correctResponse); // response choices int count = 1; for (LikertScaleQuestionChoice c : choices) { // <simpleChoice identifier="ChoiceA">You must stay with your luggage at all times.</simpleChoice> Element simpleChoice = questionDocument.createElement("simpleChoice"); simpleChoice.setAttribute("identifier", "Choice" + Integer.toString(count++) + "_" + question.getId()); String choiceText = c.getText(); choiceText = FormattedText.unEscapeHtml(choiceText); simpleChoice.setTextContent(choiceText); choiceInteraction.appendChild(simpleChoice); } questionParts.put("choiceInteraction", choiceInteraction); questionParts.put("responseDeclaration", responseDeclaration); return; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * Get the Elements needed for question.xml * /* w ww . j a v a 2 s .c o m*/ * @param questionDocument * The AssessmentItem Document * @param question * The Question * @param questionParts * Map containing different w3c dom elements */ public void getMCResponseChoices(Document questionDocument, Question question, Map<String, Element> questionParts) { if (question == null) return; MultipleChoiceQuestionImpl mc = (MultipleChoiceQuestionImpl) (question.getTypeSpecificQuestion()); // String cardinality = ("False".equalsIgnoreCase(mc.getSingleCorrect())) ? "multiple" : "single"; boolean shuffle = mc.shuffleChoicesSetting(); List<MultipleChoiceQuestionChoice> choices = mc.getChoices(); Set<Integer> correctAnswers = mc.getCorrectAnswerSet(); int maxChoice = (correctAnswers != null) ? correctAnswers.size() : 0; // <choiceInteraction responseIdentifier="RESPONSE" shuffle="false" maxChoices="1"> Element choiceInteraction = questionDocument.createElement("choiceInteraction"); choiceInteraction.setAttribute("responseIdentifier", "RESPONSE"); choiceInteraction.setAttribute("shuffle", new Boolean(shuffle).toString()); choiceInteraction.setAttribute("maxChoices", new Integer(maxChoice).toString()); // <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"> Element responseDeclaration = createResponseDeclaration(questionDocument, "RESPONSE", "single", "identifier"); Element correctResponse = questionDocument.createElement("correctResponse"); responseDeclaration.appendChild(correctResponse); // response choices int count = 1; for (MultipleChoiceQuestionChoice c : choices) { // <simpleChoice identifier="ChoiceA">You must stay with your luggage at all times.</simpleChoice> Element simpleChoice = questionDocument.createElement("simpleChoice"); simpleChoice.setAttribute("identifier", "Choice" + Integer.toString(count++) + "_" + question.getId()); String choiceText = c.getText(); choiceText = FormattedText.unEscapeHtml(choiceText); simpleChoice.setTextContent(choiceText); choiceInteraction.appendChild(simpleChoice); } // correct answers for (Integer correct : correctAnswers) { Element correctResponseValue = questionDocument.createElement("value"); correctResponseValue.setTextContent("Choice" + (correct.intValue() + 1) + "_" + question.getId()); correctResponse.appendChild(correctResponseValue); } questionParts.put("choiceInteraction", choiceInteraction); questionParts.put("responseDeclaration", responseDeclaration); return; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * Get different components of a match type question * //from ww w . j a v a 2 s . com * @param questionDocument * @param question * @param questionParts */ public void getMatchResponseChoices(Document questionDocument, Question question, Map<String, Element> questionParts) { if (question == null) return; MatchQuestionImpl mc = (MatchQuestionImpl) (question.getTypeSpecificQuestion()); String cardinality = "multiple"; boolean shuffle = true; List<MatchQuestionPair> choicePairs = mc.getPairs(); int maxChoice = (choicePairs != null) ? choicePairs.size() : 0; // <matchInteraction responseIdentifier="RESPONSE" shuffle="true" maxAssociations="4"> Element matchInteraction = questionDocument.createElement("matchInteraction"); matchInteraction.setAttribute("responseIdentifier", "RESPONSE"); matchInteraction.setAttribute("shuffle", new Boolean(shuffle).toString()); matchInteraction.setAttribute("maxAssociations", new Integer(maxChoice).toString()); // <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"> Element responseDeclaration = createResponseDeclaration(questionDocument, "RESPONSE", cardinality, "directedPair"); Element correctResponse = questionDocument.createElement("correctResponse"); responseDeclaration.appendChild(correctResponse); // response choices int count = 0; Element simpleMatchSet1 = questionDocument.createElement("simpleMatchSet"); Element simpleMatchSet2 = questionDocument.createElement("simpleMatchSet"); for (MatchQuestionPair c : choicePairs) { // <simpleAssociableChoice identifier="C" matchMax="1">Capulet</simpleAssociableChoice> Element simpleAssociableChoice = questionDocument.createElement("simpleAssociableChoice"); String id1 = "Choice" + Integer.toString(++count) + "_" + question.getId(); simpleAssociableChoice.setAttribute("identifier", id1); simpleAssociableChoice.setAttribute("matchMax", "1"); String choiceText = c.getChoice(); choiceText = FormattedText.unEscapeHtml(choiceText); simpleAssociableChoice.setTextContent(choiceText); simpleMatchSet1.appendChild(simpleAssociableChoice); // match Element simpleAssociableMatch = questionDocument.createElement("simpleAssociableChoice"); String id2 = "Choice" + Integer.toString(++count) + "_" + question.getId(); simpleAssociableMatch.setAttribute("identifier", id2); simpleAssociableMatch.setAttribute("matchMax", "1"); String matchText = c.getMatch(); matchText = FormattedText.unEscapeHtml(matchText); simpleAssociableMatch.setTextContent(matchText); simpleMatchSet2.appendChild(simpleAssociableMatch); // correct pair Element correctResponseValue = questionDocument.createElement("value"); correctResponseValue.setTextContent(id1 + " " + id2); correctResponse.appendChild(correctResponseValue); } matchInteraction.appendChild(simpleMatchSet1); matchInteraction.appendChild(simpleMatchSet2); questionParts.put("matchInteraction", matchInteraction); questionParts.put("responseDeclaration", responseDeclaration); return; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * Get True-false question elements// w ww .ja v a2 s.com * * @param questionDocument * @param question * @param questionParts */ public void getTFResponseChoices(Document questionDocument, Question question, Map<String, Element> questionParts) { if (question == null) return; TrueFalseQuestionImpl tf = (TrueFalseQuestionImpl) (question.getTypeSpecificQuestion()); String cardinality = "single"; // <choiceInteraction responseIdentifier="RESPONSE" shuffle="false" maxChoices="1"> Element choiceInteraction = questionDocument.createElement("choiceInteraction"); choiceInteraction.setAttribute("responseIdentifier", "RESPONSE"); choiceInteraction.setAttribute("shuffle", "false"); choiceInteraction.setAttribute("maxChoices", "1"); // <responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"> Element responseDeclaration = createResponseDeclaration(questionDocument, "RESPONSE", cardinality, "identifier"); Element correctResponse = questionDocument.createElement("correctResponse"); responseDeclaration.appendChild(correctResponse); Element correctResponseValue = questionDocument.createElement("value"); // response choices // <simpleChoice identifier="ChoiceA">True</simpleChoice> Element simpleChoice = questionDocument.createElement("simpleChoice"); simpleChoice.setAttribute("identifier", "ChoiceA" + "_" + question.getId()); simpleChoice.setTextContent("True"); choiceInteraction.appendChild(simpleChoice); Element simpleChoiceFalse = questionDocument.createElement("simpleChoice"); simpleChoiceFalse.setAttribute("identifier", "ChoiceB" + "_" + question.getId()); simpleChoiceFalse.setTextContent("False"); choiceInteraction.appendChild(simpleChoiceFalse); if (tf.correctAnswer) correctResponseValue.setTextContent("ChoiceA" + "_" + question.getId()); else correctResponseValue.setTextContent("ChoiceB" + "_" + question.getId()); correctResponse.appendChild(correctResponseValue); questionParts.put("choiceInteraction", choiceInteraction); questionParts.put("responseDeclaration", responseDeclaration); return; }
From source file:org.etudes.mneme.impl.ExportQtiServiceImpl.java
/** * Creates elements for all embed media with in itembody element. Use this for question text * //from w w w .j a v a 2 s . co m * @param zip * @param subFolder * @param text * @param itemBody * @param mediaFiles * @return */ private Element translateEmbedData(ZipOutputStream zip, String subFolder, String text, Element itemBody, List<String> mediaFiles, Document questionDocument) { if (text == null || text.length() == 0) return itemBody; Element media = null; try { Pattern pa = Pattern.compile("<(img|a|embed)\\s+.*?/*>", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); // TODO: write all attributes Pattern p_srcAttribute = Pattern.compile("(src|href)[\\s]*=[\\s]*\"([^#\"]*)([#\"])", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); Matcher m = pa.matcher(text); StringBuffer sb = new StringBuffer(); subFolder = (subFolder == null || subFolder.length() == 0) ? "Resources/" : subFolder; String embedSubFolder = "Resources/"; int start = 0; while (m.find()) { int startIdx = m.start(); String img_content = m.group(0); Matcher m_src = p_srcAttribute.matcher(img_content); if (m_src.find()) { String ref = m_src.group(2); if (!ref.contains("/access/mneme/content/")) continue; Element div = questionDocument.createElement("div"); if (startIdx <= text.length()) { String divText = text.substring(start, startIdx); div.setTextContent(divText); start = m.end(); } ref = ref.replaceAll("%20", " "); String resource_id = ref.replace("/access/mneme", ""); String embedFileName = ref.substring(ref.lastIndexOf("/") + 1); ref = subFolder + embedFileName; mediaFiles.add(ref); media = questionDocument.createElement(m.group(1)); if ("a".equalsIgnoreCase(m.group(1))) media.setAttribute("target", "_blank"); media.setAttribute(m_src.group(1), embedSubFolder + embedFileName); m.appendReplacement(sb, ""); String fileName = Validator.getFileName(resource_id); fileName = fileName.replaceAll("%20", " "); fileName = Validator.escapeResourceName(fileName); writeContentResourceToZip(zip, subFolder, resource_id, fileName); itemBody.appendChild(div); itemBody.appendChild(media); } } m.appendTail(sb); if (start > 0 && start < text.length()) { Element div = questionDocument.createElement("div"); div.setTextContent(text.substring(start)); itemBody.appendChild(div); } return itemBody; } catch (Exception e) { M_log.debug("error in translating embed up blank img tags:" + e.getMessage()); } return itemBody; }