Index: import-parsers/common-cartridge/src/java/org/sakaiproject/importer/impl/CommonCartridgeFileParser.java =================================================================== --- import-parsers/common-cartridge/src/java/org/sakaiproject/importer/impl/CommonCartridgeFileParser.java (revision 79811) +++ import-parsers/common-cartridge/src/java/org/sakaiproject/importer/impl/CommonCartridgeFileParser.java (working copy) @@ -21,6 +21,7 @@ package org.sakaiproject.importer.impl; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -34,6 +35,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.sakaiproject.archive.api.ImportMetadata; import org.sakaiproject.importer.api.ImportFileParser; import org.sakaiproject.importer.api.Importable; @@ -50,6 +53,9 @@ public class CommonCartridgeFileParser extends IMSFileParser { private static final String CC_NAMESPACE_URI = "http://www.imsglobal.org/xsd/imscc/imscp_v1p1"; + /** Our logger. */ + private static Log M_log = LogFactory.getLog(CommonCartridgeFileParser.class); + public CommonCartridgeFileParser() { // add resource translators here addResourceTranslator(new CCAssessmentTranslator()); @@ -130,8 +136,10 @@ title = XPathHelper.getNodeValue("./title", itemNode); if (title == null || "".equals(title)) { Document descriptor = getDescriptor(resourceNode); - title = XPathHelper.getNodeValue("/CONTENT/TITLE",descriptor); + if (descriptor != null) { + title = XPathHelper.getNodeValue("/CONTENT/TITLE",descriptor); } + } } return title; } @@ -145,26 +153,31 @@ } public Document getDescriptor(Node resourceNode) { - String descriptorFilename = XPathHelper.getNodeValue("./file/@href",resourceNode); + String descriptorFilename = XPathHelper.getNodeValue("./file/@href",resourceNode).replaceAll("[/\\\\]+", "\\" + File.separator); Document doc = null; DocumentBuilder docBuilder; InputStream fis = null; + + // There is no reason to attempt to parse the file for a title unless it can be parsed + String lowerFilename = descriptorFilename.toLowerCase(); + if (!lowerFilename.endsWith(".xml") && !lowerFilename.endsWith(".html") && + !lowerFilename.endsWith(".htm") && !lowerFilename.endsWith(".xhtml")) { + return doc; + } + try { - fis = new FileInputStream(pathToData + "/" + descriptorFilename); + fis = new FileInputStream(pathToData + File.separator + descriptorFilename); docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); doc = (Document) docBuilder.parse(fis); } catch (FileNotFoundException e) { - // TODO Auto-generated catch block (this is here since it is not clear what this should do in this case) - e.printStackTrace(); + M_log.warn("getDescriptor() file not found: " + pathToData + File.separator + descriptorFilename); } catch (ParserConfigurationException e) { - // TODO Auto-generated catch block (this is here since it is not clear what this should do in this case) - e.printStackTrace(); + M_log.warn("getDescriptor() parser config error: " + e.getMessage()); } catch (SAXException e) { - // TODO Auto-generated catch block (this is here since it is not clear what this should do in this case) - e.printStackTrace(); + M_log.warn("getDescriptor() SAX parse error on file " + pathToData + File.separator + + descriptorFilename + ": " + e.getMessage()); } catch (IOException e) { - // TODO Auto-generated catch block (this is here since it is not clear what this should do in this case) - e.printStackTrace(); + M_log.warn("getDescriptor() file IO exception", e); } finally { if (fis != null) { try { Index: import-impl/src/java/org/sakaiproject/importer/impl/ZipFileParser.java =================================================================== --- import-impl/src/java/org/sakaiproject/importer/impl/ZipFileParser.java (revision 79811) +++ import-impl/src/java/org/sakaiproject/importer/impl/ZipFileParser.java (working copy) @@ -65,7 +65,7 @@ public ImportDataSource parse(byte[] fileData, String unArchiveLocation) { this.localArchiveLocation = unzipArchive(fileData, unArchiveLocation); - this.pathToData = unArchiveLocation + "/" + localArchiveLocation; + this.pathToData = unArchiveLocation + File.separator + localArchiveLocation; awakeFromUnzip(pathToData); List categories = new ArrayList(); Collection items = new ArrayList();