@@ -79,7 +79,7 @@ public String unzipImportFile(String filename) {
79
79
if (!dir .exists ()) {
80
80
if (!dir .mkdirs ()) {
81
81
log .warn ("Unable to mkdir {}" , dir .getPath ());
82
- }
82
+ }
83
83
}
84
84
85
85
Set <String > dirsMade = new TreeSet <>();
@@ -90,19 +90,19 @@ public String unzipImportFile(String filename) {
90
90
qtiFilename = "exportAssessment.xml" ;
91
91
List <String > xmlFilenames = new ArrayList <>();
92
92
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 )) {
99
99
File d = new File (dir .getPath () + "/" + dirName );
100
100
// If it already exists as a dir, don't do anything
101
101
if (!(d .exists () && d .isDirectory ())) {
102
102
// Try to create the directory, warn if it fails
103
103
if (!d .mkdirs ()) {
104
- log .warn ("Unable to mkdir {}/{}" , dir .getPath (), dirName );
105
- }
104
+ log .warn ("unable to mkdir {}/{}" , dir .getPath (), dirName );
105
+ }
106
106
dirsMade .add (dirName );
107
107
}
108
108
}
@@ -131,25 +131,27 @@ public String unzipImportFile(String filename) {
131
131
NamedNodeMap namedNodeMap = fstNode .getAttributes ();
132
132
qtiFilename = namedNodeMap .getNamedItem ("href" ).getNodeValue ();
133
133
} 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
+ }
135
149
}
136
- } else if (entryNameTrimmed .endsWith (".xml" )) {
137
- xmlFilenames .add (entryNameTrimmed );
138
150
}
139
151
140
152
zipStream .closeEntry ();
141
153
entry = zipStream .getNextEntry ();
142
154
}
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
- }
153
155
}
154
156
} catch (IOException e ) {
155
157
log .warn (e .toString ());
@@ -165,4 +167,5 @@ public String getQtiFilename() {
165
167
public void setQtiFilename (String qtiFilename ) {
166
168
this .qtiFilename = qtiFilename ;
167
169
}
170
+
168
171
}
0 commit comments