/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/
package org.olat.fileresource.types;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.Element;
import org.olat.core.util.vfs.LocalFileImpl;
import org.olat.core.util.vfs.LocalFolderImpl;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.core.util.vfs.VFSItem;
import org.olat.ims.qti.process.AssessmentInstance;
import org.olat.ims.qti.process.QTIHelper;
/**
* Initial Date: Apr 6, 2004
*
* @author Mike Stock
*/
public class SurveyFileResource extends FileResource {
/**
* IMS QTI Survey file resource identifier.
*/
public static final String TYPE_NAME = "FileResource.SURVEY";
/**
* Standard constructor.
*/
public SurveyFileResource() { super.setTypeName(TYPE_NAME); }
/**
* @param unzippedDir
* @return True if is of type.
*/
public static boolean validate(File unzippedDir) {
//with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedDir);
VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
//getDocument(..) ensures that InputStream is closed in every case.
Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
//if doc is null an error loading the document occured
if (doc == null) return false;
List metas = doc.selectNodes("questestinterop/assessment/qtimetadata/qtimetadatafield");
for (Iterator iter = metas.iterator(); iter.hasNext();) {
Element el_metafield = (Element) iter.next();
Element el_label = (Element) el_metafield.selectSingleNode("fieldlabel");
String label = el_label.getText();
if (label.equals(AssessmentInstance.QMD_LABEL_TYPE)) { // type meta
Element el_entry = (Element) el_metafield.selectSingleNode("fieldentry");
String entry = el_entry.getText();
return entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY);
}
}
return false;
}
}