Skip to content

Commit e98a355

Browse files
authored
SAK-48104 Samigo add logic to help detect the qti filename when importing a zip (sakaiproject#11040)
1 parent b6b0f01 commit e98a355

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

samigo/samigo-app/src/webapp/jsf/qti/xmlDisplay.jsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
55
<% response.setHeader("Cache-Control", "private"); %>
66
<% response.setHeader("Pragma", "cache"); %>
7-
<% response.setHeader("Content-Disposition", "attachment; filename=exported-assessment.xml"); %>
7+
<% response.setHeader("Content-Disposition", "attachment; filename=exportAssessment.xml"); %>
88

99
<%--
1010
***********************************************************************************

samigo/samigo-cp/src/java/org/sakaiproject/tool/assessment/contentpackaging/ImportService.java

+25-22
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public String unzipImportFile(String filename) {
7979
if (!dir.exists()) {
8080
if (!dir.mkdirs()) {
8181
log.warn("Unable to mkdir {}", dir.getPath());
82-
}
82+
}
8383
}
8484

8585
Set<String> dirsMade = new TreeSet<>();
@@ -90,19 +90,19 @@ public String unzipImportFile(String filename) {
9090
qtiFilename = "exportAssessment.xml";
9191
List<String> xmlFilenames = new ArrayList<>();
9292
while (entry != null) {
93-
String entryName = entry.getName();
94-
String entryNameTrimmed = entryName.trim();
95-
int ix = entryName.lastIndexOf('/');
96-
if (ix > 0) {
97-
String dirName = entryName.substring(0, ix);
98-
if (!dirsMade.contains(dirName)) {
93+
String entryName = entry.getName();
94+
String entryNameTrimmed = entryName.trim();
95+
int ix = entryName.lastIndexOf('/');
96+
if (ix > 0) {
97+
String dirName = entryName.substring(0, ix);
98+
if (!dirsMade.contains(dirName)) {
9999
File d = new File(dir.getPath() + "/" + dirName);
100100
// If it already exists as a dir, don't do anything
101101
if (!(d.exists() && d.isDirectory())) {
102102
// Try to create the directory, warn if it fails
103103
if (!d.mkdirs()) {
104-
log.warn("Unable to mkdir {}/{}", dir.getPath(), dirName);
105-
}
104+
log.warn("unable to mkdir {}/{}", dir.getPath(), dirName);
105+
}
106106
dirsMade.add(dirName);
107107
}
108108
}
@@ -131,25 +131,27 @@ public String unzipImportFile(String filename) {
131131
NamedNodeMap namedNodeMap = fstNode.getAttributes();
132132
qtiFilename = namedNodeMap.getNamedItem("href").getNodeValue();
133133
} catch (Exception e) {
134-
log.warn("Could not parse imsmanifest.xml: {}", e.toString());
134+
log.warn("Could not parse imsmanifest.xml: {}", e.toString());
135+
}
136+
} else if (entryNameTrimmed.endsWith(".xml")) {
137+
xmlFilenames.add(entryNameTrimmed);
138+
// If the QTI file doesn't exist in the zip,
139+
// we guess the name might be either exportAssessment.xml or the same as the zip or other
140+
// file name
141+
if (!xmlFilenames.contains(qtiFilename.trim())) {
142+
if (xmlFilenames.contains("exportAssessment.xml")) {
143+
qtiFilename = "exportAssessment.xml";
144+
} else if (xmlFilenames.contains(tmpName.substring(0, tmpName.lastIndexOf("_")) + ".xml")) {
145+
qtiFilename = tmpName.substring(0, tmpName.lastIndexOf("_")) + ".xml";
146+
} else {
147+
qtiFilename = entryNameTrimmed;
148+
}
135149
}
136-
} else if (entryNameTrimmed.endsWith(".xml")) {
137-
xmlFilenames.add(entryNameTrimmed);
138150
}
139151

140152
zipStream.closeEntry();
141153
entry = zipStream.getNextEntry();
142154
}
143-
// If the QTI file doesn't exist in the zip,
144-
// we guess the name might be either exportAssessment.xml or the same as the zip
145-
// file name
146-
if (!xmlFilenames.contains(qtiFilename.trim())) {
147-
if (xmlFilenames.contains("exportAssessment.xml")) {
148-
qtiFilename = "exportAssessment.xml";
149-
} else {
150-
qtiFilename = tmpName.substring(0, tmpName.lastIndexOf("_")) + ".xml";
151-
}
152-
}
153155
}
154156
} catch (IOException e) {
155157
log.warn(e.toString());
@@ -165,4 +167,5 @@ public String getQtiFilename() {
165167
public void setQtiFilename(String qtiFilename) {
166168
this.qtiFilename = qtiFilename;
167169
}
170+
168171
}

0 commit comments

Comments
 (0)