diff --git a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/Parser.java b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/Parser.java index 82b10e7d5a67..5d97d08ebb21 100755 --- a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/Parser.java +++ b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/Parser.java @@ -123,6 +123,7 @@ public class Parser extends AbstractParser { private static final String CC_RESOURCES="resources"; private static final String CC_RES_TYPE="type"; + private static final String CANVAS_MODULE_META = "course_settings/module_meta.xml"; private Parser(CartridgeLoader the_cu) { super(); @@ -131,9 +132,17 @@ public class Parser extends AbstractParser { public void parse(DefaultHandler the_handler) throws FileNotFoundException, ParseException { + Element canvas_module_meta = null; + try { + canvas_module_meta = this.getXML(utils, CANVAS_MODULE_META); + log.debug("Found - {} {}", CANVAS_MODULE_META, canvas_module_meta); + } catch (Exception e) { + log.debug("{} not found, {}", CANVAS_MODULE_META, e.toString()); + } + try { Element manifest=this.getXML(utils, IMS_MANIFEST); - processManifest(manifest, the_handler); + processManifest(manifest, canvas_module_meta, the_handler); } catch (Exception e) { the_handler.getSimplePageBean().setErrKey("simplepage.cc-error", ""); log.info("parse error, stack trace follows " + e); @@ -141,7 +150,8 @@ public class Parser extends AbstractParser { } private void - processManifest(Element the_manifest, DefaultHandler the_handler) throws ParseException { + processManifest(Element the_manifest, Element the_canvas_module_meta, DefaultHandler the_handler) throws ParseException { + log.debug("the_manifest {} the_canvas_module_meta {} the_handler", the_manifest, the_canvas_module_meta, the_handler); ns = new Ns(); the_handler.setNs(ns); // figure out which version we have, and set up ns to know about it @@ -170,6 +180,9 @@ else if (the_manifest.getNamespace().equals(ns.cp_ns())) { the_handler.startManifest(); the_handler.setManifestXml(the_manifest); + if ( the_canvas_module_meta != null && the_handler instanceof org.sakaiproject.lessonbuildertool.cc.PrintHandler) { + ((org.sakaiproject.lessonbuildertool.cc.PrintHandler)the_handler).setCanvasModuleMetaXml(the_canvas_module_meta); + } if (processAuthorization(the_manifest, the_handler)) return; // don't process CCs with authorization processManifestMetadata(the_manifest, the_handler); diff --git a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/PrintHandler.java b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/PrintHandler.java index 49a481a1ea6f..3a5be455081b 100755 --- a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/PrintHandler.java +++ b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/PrintHandler.java @@ -11,7 +11,7 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License. + * limitations under the Licensee. */ package org.sakaiproject.lessonbuildertool.cc; @@ -79,8 +79,11 @@ import org.jdom2.Element; import org.jdom2.Namespace; import org.jdom2.filter.ElementFilter; +import org.jdom2.filter.Filters; import org.jdom2.output.DOMOutputter; import org.jdom2.output.XMLOutputter; +import org.jdom2.xpath.XPathExpression; +import org.jdom2.xpath.XPathFactory; import org.jsoup.Jsoup; @@ -158,6 +161,9 @@ public class PrintHandler extends DefaultHandler implements AssessmentHandler, D private static final String BLTI="basiclti"; private static final String UNKNOWN="unknown"; private static final int MAX_ATTEMPTS = 100; + private static final String CANVAS_MODULE_META_NAMESPACE = "http://canvas.instructure.com/xsd/cccv1p0"; + private static final String CANVAS_MODULE_NEW_TAB = "new_tab"; + private static final String CANVAS_MODULE_NEW_TAB_FALSE = "false"; private List pages = new ArrayList(); // list parallel to pages containing sequence of last item on the page @@ -181,6 +187,7 @@ public class PrintHandler extends DefaultHandler implements AssessmentHandler, D boolean importtop = false; Integer assignmentNumber = 1; Element manifestXml = null; + Element canvasModuleMeta = null; boolean forceInline; // this is the CC file name for all files added @@ -552,12 +559,14 @@ public void setCCItemXml(Element itemXml, Element resourceXml, AbstractParser pa int seq = (isBank || noPage) ? 0 : sequences.get(top); String title; + String identifier = null; + String identifierRef = null; if (itemXml == null) title = "Question Pool"; else { - String identifier = itemXml.getAttributeValue(IDENTIFIER); - String identifierRef = itemXml.getAttributeValue(IDENTIFIERREF); + identifier = itemXml.getAttributeValue(IDENTIFIER); + identifierRef = itemXml.getAttributeValue(IDENTIFIERREF); title = itemXml.getChildText(CC_ITEM_TITLE, ns.getNs()); // metadata is used for special Sakai data String id = StringUtils.defaultIfBlank(identifierRef, identifier); // prefer identifierref if exists on item @@ -569,6 +578,28 @@ public void setCCItemXml(Element itemXml, Element resourceXml, AbstractParser pa boolean inline = false; String mmDisplayType = null; String resourceId = resourceXml.getAttributeValue(IDENTIFIER); + log.debug("identifier {} identifierRef {} resourceId {} resourceXml {}", identifier, identifierRef, resourceId, resourceXml); + + // Check if there is any Canvas module metadata in the import + Element canvas_module_item = null; + boolean open_same_window = true; + if ( identifier != null && canvasModuleMeta != null ) { + + Namespace namespace = Namespace.getNamespace("cccv1p0", CANVAS_MODULE_META_NAMESPACE); + + String xpathExpression = "//cccv1p0:item[@identifier='" + identifier + "']"; + + List items = XPathFactory.instance().compile(xpathExpression, Filters.element(), null, namespace).evaluate(canvasModuleMeta); + + log.debug("Found {} items whilst looking for {}", items.size(), xpathExpression); + if ( items.size() >= 1 ) { + canvas_module_item = items.get(0); + String new_tab = canvas_module_item.getChildText(CANVAS_MODULE_NEW_TAB, namespace); + open_same_window = CANVAS_MODULE_NEW_TAB_FALSE.equals(new_tab); + log.debug("new_tab {} open_same_window {}", new_tab, open_same_window); + } + } + Map itemsMetaData = itemsMetaDataAdded.get(resourceId); if (itemsMetaData != null) { inline = BooleanUtils.toBoolean(itemsMetaData.get("inline.lessonbuilder.sakaiproject.org")); @@ -594,7 +625,7 @@ public void setCCItemXml(Element itemXml, Element resourceXml, AbstractParser pa String intendedUse = resourceXml.getAttributeValue(INTENDEDUSE); SimplePageItem item = simplePageToolDao.makeItem(page.getPageId(), seq, SimplePageItem.RESOURCE, sakaiId, title); item.setHtml(mime); - item.setSameWindow(true); + item.setSameWindow(open_same_window); // only text type files can be inlined, see addFile if ((inline || forceInline) && StringUtils.startsWith(mime, "text/")) { @@ -726,7 +757,7 @@ else if (assigntool != null && intendedUse.equals("assignment")) { item.setType(SimplePageItem.MULTIMEDIA); } else { item.setHtml(simplePageBean.getTypeOfUrl(url)); // checks the web site to see what it actually is - item.setSameWindow(true); + item.setSameWindow(open_same_window); } simplePageBean.saveItem(item); if (!roles.isEmpty()) simplePageBean.setItemGroups(item, roles.toArray(new String[0])); @@ -931,7 +962,7 @@ else if (assigntool != null && intendedUse.equals("assignment")) { String sakaiId = null; if (bltitool != null) { - sakaiId = ((BltiInterface) bltitool).doImportTool(launchUrl, bltiTitle, strXml, custom); + sakaiId = ((BltiInterface) bltitool).doImportTool(launchUrl, bltiTitle, strXml, custom, open_same_window); } if (sakaiId != null) { @@ -1089,9 +1120,12 @@ public void checkCurriculum(Element the_xml) { public void setManifestXml(Element the_xml) { manifestXml = the_xml; + log.debug("manifest xml: {}", the_xml); + } - log.debug("manifest xml: "+the_xml); - + public void setCanvasModuleMetaXml(Element the_xml) { + canvasModuleMeta = the_xml; + log.debug("canvas_meta_module xml: {}", the_xml); } public void endManifest() { diff --git a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/BltiEntity.java b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/BltiEntity.java index 97b6283f14b7..37e9f186cdfc 100644 --- a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/BltiEntity.java +++ b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/BltiEntity.java @@ -509,7 +509,7 @@ public void setGroups(Collection groups) { // not group aware } - public String doImportTool(String launchUrl, String bltiTitle, String strXml, String custom) + public String doImportTool(String launchUrl, String bltiTitle, String strXml, String custom, boolean open_same_window) { if ( ltiService == null ) return null; @@ -536,6 +536,7 @@ public String doImportTool(String launchUrl, String bltiTitle, String strXml, St props.setProperty(LTIService.LTI_ALLOWOUTCOMES, "1"); props.setProperty(LTIService.LTI_SENDNAME, "1"); props.setProperty(LTIService.LTI_SENDEMAILADDR, "1"); + props.setProperty(LTIService.LTI_NEWPAGE, (open_same_window ? "0" : "1")); props.setProperty(LTIService.LTI_XMLIMPORT,strXml); if (custom != null) props.setProperty(LTIService.LTI_CUSTOM, custom); @@ -554,6 +555,7 @@ public String doImportTool(String launchUrl, String bltiTitle, String strXml, St props.setProperty(LTIService.LTI_TITLE, bltiTitle); props.setProperty( LTI_PAGETITLE, bltiTitle); props.setProperty(LTIService.LTI_LAUNCH,launchUrl); + props.setProperty(LTIService.LTI_NEWPAGE, (open_same_window ? "0" : "1")); props.setProperty(LTIService.LTI_XMLIMPORT,strXml); if ( custom != null ) props.setProperty(LTIService.LTI_CUSTOM,custom); Object result = ltiService.insertContent(props, simplePageBean.getCurrentSiteId()); diff --git a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/BltiInterface.java b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/BltiInterface.java index 1eaefdd20b46..aac60374cd57 100644 --- a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/BltiInterface.java +++ b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/BltiInterface.java @@ -19,7 +19,7 @@ public interface BltiInterface { public boolean servicePresent(); public boolean isPopUp(); public int frameSize(); - public String doImportTool(String launchUrl, String bltiTitle, String strXml, String custom); + public String doImportTool(String launchUrl, String bltiTitle, String strXml, String custom, boolean open_same_window); public String getIcon(); } diff --git a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/tool/beans/SimplePageBean.java b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/tool/beans/SimplePageBean.java index f0335953c6ef..3b0d68fcafb1 100644 --- a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/tool/beans/SimplePageBean.java +++ b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/tool/beans/SimplePageBean.java @@ -7103,6 +7103,7 @@ private long importCcFromStream(InputStream fis) { try { cc = File.createTempFile("ccloader", "file"); root = File.createTempFile("ccloader", "root"); + log.debug("cc = {} root={}", cc.getAbsoluteFile(), root.getAbsoluteFile()); if (root.exists()) { if (!root.delete()) { setErrMessage("unable to delete temp file for load"); @@ -7150,6 +7151,7 @@ private long importCcFromStream(InputStream fis) { topicobject = q; } + log.debug("parser.parse {} {} {} {} {} {} {}", this, cartridgeLoader, simplePageToolDao, quizobject, topicobject, bltiEntity, assignobject); parser.parse(new PrintHandler(this, cartridgeLoader, simplePageToolDao, quizobject, topicobject, bltiEntity, assignobject, importtop)); } catch (Exception e) { setErrKey("simplepage.cc-error", "");