Index: lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/PrintHandler.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/PrintHandler.java (revision 322152) +++ lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/cc/PrintHandler.java (revision 322153) @@ -129,6 +129,12 @@ private static final String RESOURCE="resource"; private static final String CC_ITEM_TITLE="title"; + private static final String CC_ITEM_METADATA="metadata"; + private static final String LOM_LOM="lom"; + private static final String LOM_GENERAL="general"; + private static final String LOM_STRUCTURE="structure"; + private static final String LOM_SOURCE="source"; + private static final String LOM_VALUE="value"; private static final String CC_WEBCONTENT="webcontent"; private static final String LAR="learning-application-resource"; private static final String WEBLINK="webLink"; @@ -438,6 +444,48 @@ else title = the_xml.getChildText(CC_ITEM_TITLE, ns.cc_ns()); + // metadata is used for special Sakai data + boolean inline = false; + String mmDisplayType = null; + Element metadata = null; + if (the_xml != null) + metadata = the_xml.getChild(CC_ITEM_METADATA, ns.cc_ns()); + if (metadata != null) { + metadata = metadata.getChild(LOM_LOM, ns.lom_ns()); + } + if (metadata != null) { + metadata = metadata.getChild(LOM_GENERAL, ns.lom_ns()); + } + if (metadata != null) { + metadata = metadata.getChild(LOM_STRUCTURE, ns.lom_ns()); + } + if (metadata != null) { + Listproperties = metadata.getChildren(); + IteratorpropertiesIt = properties.iterator(); + while (propertiesIt.hasNext()) { + Element nameElt = propertiesIt.next(); + if (!propertiesIt.hasNext()) + break; + Element valueElt = propertiesIt.next(); + if (!"source".equals(nameElt.getName())) { + System.out.println("first item in structure not source " + nameElt.getName()); + break; + } + if (!"value".equals(valueElt.getName())) { + System.out.println("second item in structure not source " + valueElt.getName()); + break; + } + String name = nameElt.getText(); + String value = valueElt.getText(); + if ("inline.lessonbuilder.sakaiproject.org".equals(name) && + "true".equals(value)) + inline = true; + else if ("mmDisplayType.lessonbuilder.sakaiproject.org".equals(name)) + mmDisplayType = value; + } + } + + try { if ((type.equals(CC_WEBCONTENT) || (type.equals(UNKNOWN))) && !hide) { // note: when this code is called the actual sakai resource hasn't been created yet @@ -457,6 +505,82 @@ SimplePageItem item = simplePageToolDao.makeItem(page.getPageId(), seq, SimplePageItem.RESOURCE, sakaiId, title); item.setHtml(mime); item.setSameWindow(true); + + title = the_xml.getChildText(CC_ITEM_TITLE, ns.cc_ns()); + + boolean nofile = false; + if (inline) { + StringBuilder html = new StringBuilder(); + String htmlString = null; + // type 3 is a link, so it's handled below + // get contents of file for types where we don't need a file in contents + if (mmDisplayType == null || "1".equals(mmDisplayType)) { + nofile = true; + // read the file containing the HTML + String fileName = getFileName(resource); + InputStream fileStream = null; + + if (fileName != null) + fileStream = utils.getFile(fileName); + if (fileStream != null) { + byte[] buffer = new byte[8096]; + int n = 0; + while ((n = fileStream.read(buffer, 0, 8096)) >= 0) { + if (n > 0) + html.append(new String(buffer, 0, n, "UTF-8")); + } + } + + htmlString = html.toString(); + + // remove stuff the exporter added + int off = htmlString.indexOf(""); + if (off > 0) + htmlString = htmlString.substring(off + 7); + off = htmlString.lastIndexOf(""); + if (off > 0) + htmlString = htmlString.substring(0, off); + + // and fix relative URLs to absolute, since this is going to be inserted inline + // in a page that's not in resources. + if (htmlString.startsWith(""); + String fixString = htmlString.substring(11, fixend); + htmlString = htmlString.substring(fixend + 3); + String[] fixups = fixString.split(","); + // iterate backwards since once we fix something, offsets + // further in the string are bad + for (int i = (fixups.length-1); i >= 0; i--) { + String fixup = fixups[i]; + // these are offsets of a URL. The URL is for a file in attachments, so we need + // to map it to a full URL. The file should be attachments/item-xx.html in the + // package. relFixup will have added ../ to it to get to the base. + try { + int offset = Integer.parseInt(fixup); + htmlString = htmlString.substring(0, offset) + baseUrl + htmlString.substring(offset+3); + } catch (Exception e) { + System.out.println("exception " + e); + } + } + } + } + + // inline can be multimedia or text. If mmdisplaytype set, it's multimedia + if (mmDisplayType != null) { + // 1 -- embed code, 2 -- av type, 3 -- oembed, 4 -- iframe + // 3 is output as a link, so it's handled below + item.setType(SimplePageItem.MULTIMEDIA); + if ("1".equals(mmDisplayType)) { + item.setAttribute("multimediaEmbedCode", htmlString); + } + item.setAttribute("multimediaDisplayType", mmDisplayType); + } else { + // must be text item + item.setType(SimplePageItem.TEXT); + item.setHtml(htmlString); + } + } + if (intendedUse != null) { intendedUse = intendedUse.toLowerCase(); if (intendedUse.equals("lessonplan")) @@ -519,23 +643,34 @@ filename = filename.substring(0, filename.length()-3) + "url"; String sakaiId = baseName + filename; - if (! filesAdded.contains(filename)) { + if (!inline && ! filesAdded.contains(filename)) { // we store the URL as a text/url resource ContentResourceEdit edit = ContentHostingService.addResource(sakaiId); edit.setContentType("text/url"); edit.setResourceType("org.sakaiproject.content.types.urlResource"); edit.setContent(url.getBytes("UTF-8")); - edit.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, - Validator.escapeResourceName(filename)); + edit.getPropertiesEdit().addProperty(ResourceProperties.PROP_DISPLAY_NAME, + Validator.escapeResourceName(filename)); ContentHostingService.commitResource(edit, NotificationService.NOTI_NONE); - filesAdded.add(filename); + filesAdded.add(filename); } - if (!hide) { + if (inline && "3".equals(mmDisplayType)) { + // inline can be either oembed or youtube. Handle oembed here + SimplePageItem item = simplePageToolDao.makeItem(page.getPageId(), seq, SimplePageItem.MULTIMEDIA, sakaiId, title); + item.setAttribute("multimediaUrl", url); + item.setAttribute("multimediaDisplayType", "3"); + simplePageBean.saveItem(item); + } else if (!hide) { // now create the Sakai item SimplePageItem item = simplePageToolDao.makeItem(page.getPageId(), seq, SimplePageItem.RESOURCE, sakaiId, title); + if (inline) { + // should just be youtube. null displaytype is right for that + item.setType(SimplePageItem.MULTIMEDIA); + } else { - item.setHtml(simplePageBean.getTypeOfUrl(url)); // checks the web site to see what it actually is + item.setHtml(simplePageBean.getTypeOfUrl(url)); // checks the web site to see what it actually is item.setSameWindow(true); + } simplePageBean.saveItem(item); if (roles.size() > 0) simplePageBean.setItemGroups(item, roles.toArray(new String[0])); Index: lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/ccexport/CCExport.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/ccexport/CCExport.java (revision 322152) +++ lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/ccexport/CCExport.java (revision 322153) @@ -677,13 +677,6 @@ ZipEntry zipEntry = new ZipEntry(location); out.putNextEntry(zipEntry); - out.println(""); - out.println(""); - out.println(""); - out.print(item.getHtml()); - out.println(""); - out.println(""); - Resource res = new Resource(); res.sakaiId = ("/text/" + item.getId()); res.resourceId = getResourceId(); @@ -693,6 +686,12 @@ res.islink = false; res.isbank = false; fileMap.put(res.sakaiId, res); + out.println(""); + out.println(""); + out.println(""); + out.print(item.getHtml()); + out.println(""); + out.println(""); } } catch (Exception e) { log.error("Lessons export error outputting file, outputAllTexts " + e); @@ -866,6 +865,8 @@ ititle = messageLocator.getMessage("simplepage.importcc-texttitle"); } outputIndent(out, indent + 4); out.println("" + StringEscapeUtils.escapeXml(ititle) + ""); + // output Sakai-specific information, if any + outputItemMetadata(out, indent, item); outputIndent(out, indent + 2); out.println(""); } } @@ -876,6 +877,42 @@ return next; } + public void outputItemMetadata(ZipPrintStream out, int indent, SimplePageItem item) { + // inline types + switch (item.getType()) { + case SimplePageItem.MULTIMEDIA: + String mmDisplayType = item.getAttribute("multimediaDisplayType"); + if (mmDisplayType == null || mmDisplayType.equals("")) + mmDisplayType = "2"; + outputIndent(out, indent +4); out.println(""); + outputIndent(out, indent +6); out.println(""); + outputIndent(out, indent +8); out.println(""); + outputIndent(out, indent +10); out.println(""); + outputIndent(out, indent +12); out.println("inline.lessonbuilder.sakaiproject.org"); + outputIndent(out, indent +12); out.println("true"); + outputIndent(out, indent +12); out.println("mmDisplayType.lessonbuilder.sakaiproject.org"); + outputIndent(out, indent +12); out.println("" + mmDisplayType + ""); + outputIndent(out, indent +10); out.println(""); + outputIndent(out, indent +8); out.println(""); + outputIndent(out, indent +6); out.println(""); + outputIndent(out, indent +4); out.println(""); + break; + case SimplePageItem.TEXT: + outputIndent(out, indent +4); out.println(""); + outputIndent(out, indent +6); out.println(""); + outputIndent(out, indent +8); out.println(""); + outputIndent(out, indent +10); out.println(""); + outputIndent(out, indent +12); out.println("inline.lessonbuilder.sakaiproject.org"); + outputIndent(out, indent +12); out.println("true"); + outputIndent(out, indent +10); out.println(""); + outputIndent(out, indent +8); out.println(""); + outputIndent(out, indent +6); out.println(""); + outputIndent(out, indent +4); out.println(""); + break; + } + }; + + public boolean outputManifest(ZipPrintStream out) { String title = "Sakai"; // should never be used @@ -1281,7 +1318,8 @@ } // turns the links into relative links - public String relFixup (String s, Resource resource) { + // fixups will get a list of offsets where fixups were done, for loader to reconstitute HTML + public String relFixup (String s, Resource resource, StringBuilder fixups) { // http://lessonbuilder.sakaiproject.org/53605/ StringBuilder ret = new StringBuilder(); String sakaiIdBase = "/group/" + siteId; @@ -1342,6 +1380,13 @@ String thisref = sakaiId.substring(sakaiIdBase.length()+1); String relative = relativize(thisref, base); ret.append(s.substring(index, start)); + // we're now at start of URL. save it for fixup list + if (fixups != null) { + if (fixups.length() > 0) + fixups.append(","); + fixups.append("" + ret.length()); + } + // and now add the new relative URL ret.append(relative.toString()); index = sakaiend; // start here next time } else { // matched http://lessonbuilder.sakaiproject.org/ @@ -1365,6 +1410,13 @@ String base = getParent(resource.location); String thisref = sakaiId.substring(sakaiIdBase.length()+1); String relative = relativize(thisref, base); + // we're now at start of URL. save it for fixup list + if (fixups != null) { + if (fixups.length() > 0) + fixups.append(","); + fixups.append("" + ret.length()); + } + // and now add the new relative URL ret.append(relative); if (s.charAt(endnum) == '/') endnum++; @@ -1379,8 +1431,17 @@ } } } + if (fixups != null && fixups.length() > 0) { + + return ("" + ret.toString()); + } return ret.toString(); + } + + public String relFixup (String s, Resource resource) { + return relFixup(s, resource, null); + - } + } // return base directory of file, including trailing / // "" if it is in home directory