Index: lams_build/lib/lams/lams.jar =================================================================== RCS file: /usr/local/cvsroot/lams_build/lib/lams/lams.jar,v diff -u -r1.358 -r1.359 Binary files differ Index: lams_central/conf/language/lams/ApplicationResources.properties =================================================================== RCS file: /usr/local/cvsroot/lams_central/conf/language/lams/ApplicationResources.properties,v diff -u -r1.113 -r1.114 --- lams_central/conf/language/lams/ApplicationResources.properties 12 Feb 2013 16:42:45 -0000 1.113 +++ lams_central/conf/language/lams/ApplicationResources.properties 19 Feb 2013 13:56:23 -0000 1.114 @@ -395,7 +395,7 @@ label.tab.conditions.enable =Enable label.tab.conditions.dependencies.desc =Select a lesson that students will need to complete before they can see the lesson you are about to create. label.questions.file.title =Choose IMS QTI file -label.questions.file.missing =Please select a ZIP file with questions in IMS QTI format. +label.questions.file.missing =Please select a ZIP or XML file with questions in IMS QTI format. label.questions.choice.title =Choose questions label.questions.choice.select.all =Select all label.questions.choice.missing =Please check at least one question. Index: lams_central/src/java/org/lamsfoundation/lams/web/QuestionsAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/QuestionsAction.java,v diff -u -r1.2 -r1.3 --- lams_central/src/java/org/lamsfoundation/lams/web/QuestionsAction.java 12 Feb 2013 16:42:45 -0000 1.2 +++ lams_central/src/java/org/lamsfoundation/lams/web/QuestionsAction.java 19 Feb 2013 13:56:23 -0000 1.3 @@ -43,7 +43,8 @@ String returnURL = null; String limitTypeParam = null; - InputStream packageFileStream = null; + InputStream uploadedFileStream = null; + String packageName = null; for (FileItem formField : formFields) { String fieldName = formField.getFieldName(); if ("returnURL".equals(fieldName)) { @@ -52,15 +53,16 @@ } else if ("limitType".equals(fieldName)) { limitTypeParam = formField.getString(); } else if ("file".equals(fieldName) && !StringUtils.isBlank(formField.getName())) { - packageFileStream = formField.getInputStream(); + packageName = formField.getName().toLowerCase(); + uploadedFileStream = formField.getInputStream(); } } request.setAttribute("returnURL", returnURL); request.setAttribute("limitType", limitTypeParam); // user did not choose a file - if (packageFileStream == null) { + if ((uploadedFileStream == null) || !(packageName.endsWith(".zip") || packageName.endsWith(".xml"))) { ActionMessages errors = new ActionMessages(); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("label.questions.file.missing")); request.setAttribute(Globals.ERROR_KEY, errors); @@ -74,7 +76,9 @@ Collections.addAll(limitType, limitTypeParam.split(",")); } - Question[] questions = QuestionParser.parseQTIPackage(packageFileStream, limitType); + Question[] questions = packageName.endsWith(".xml") ? QuestionParser + .parseQTIFile(uploadedFileStream, limitType) : QuestionParser.parseQTIPackage(uploadedFileStream, + limitType); request.setAttribute("questions", questions); return mapping.findForward("questionChoice"); Index: lams_common/src/java/org/lamsfoundation/lams/questions/QuestionParser.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/questions/QuestionParser.java,v diff -u -r1.3 -r1.4 --- lams_common/src/java/org/lamsfoundation/lams/questions/QuestionParser.java 12 Feb 2013 16:42:43 -0000 1.3 +++ lams_common/src/java/org/lamsfoundation/lams/questions/QuestionParser.java 19 Feb 2013 13:56:25 -0000 1.4 @@ -87,14 +87,21 @@ } else { // extract from every XML file; usually there is just one for (File resourceFile : resourceFiles) { - Question[] fileQuestions = QuestionParser.parseQTIFile(resourceFile, limitType); + FileInputStream xmlFileStream = new FileInputStream(resourceFile); + Question[] fileQuestions = null; + try { + fileQuestions = QuestionParser.parseQTIFile(xmlFileStream, limitType); + } finally { + xmlFileStream.close(); + } if (fileQuestions != null) { Collections.addAll(result, fileQuestions); } } } } finally { // clean up + packageFileStream.close(); ZipFileUtil.deleteDirectory(tempPackageDirPath); } @@ -104,11 +111,11 @@ /** * Extracts questions from IMS QTI xml file. */ - public static Question[] parseQTIFile(File xmlFile, Set limitType) throws ParserConfigurationException, - SAXException, IOException { + public static Question[] parseQTIFile(InputStream xmlFileStream, Set limitType) + throws ParserConfigurationException, SAXException, IOException { List result = new ArrayList(); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = docBuilder.parse(xmlFile); + Document doc = docBuilder.parse(xmlFileStream); NodeList questionItems = doc.getElementsByTagName("item"); // yes, a label here for convenience