use of org.olat.imscp.xml.manifest.ManifestType in project OpenOLAT by OpenOLAT.
the class ExportBinderAsCPResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding("UTF-8");
} catch (Exception e) {
log.error("", e);
}
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
Binder binder = portfolioService.getBinderByKey(binderRef.getKey());
String label = binder.getTitle();
String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
String file = secureLabel + ".zip";
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
// load pages
List<Section> sections = portfolioService.getSections(binder);
List<Page> pages = portfolioService.getPages(binder, null);
// manifest
ManifestType manifest = createImsManifest(binder, sections, pages);
zout.putNextEntry(new ZipEntry("imsmanifest.xml"));
write(manifest, new ShieldOutputStream(zout));
zout.closeEntry();
// write pages
for (Section section : sections) {
exportSection(section, zout);
}
// write pages
for (Page page : pages) {
exportPage(page, zout);
}
// theme and javascripts
exportCSSAndJs(zout);
// make it readable offline
ByteArrayOutputStream manifestOut = new ByteArrayOutputStream();
write(manifest, manifestOut);
String manifestXml = new String(manifestOut.toByteArray());
String indexSrc = sectionFilename(sections.get(0));
CPOfflineReadableManager.getInstance().makeCPOfflineReadable(manifestXml, indexSrc, zout);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.imscp.xml.manifest.ManifestType in project OpenOLAT by OpenOLAT.
the class ExportBinderAsCPResource method createImsManifest.
private ManifestType createImsManifest(Binder binder, List<Section> sections, List<Page> pages) {
ManifestType manifest = cpObjectFactory.createManifestType();
manifest.setIdentifier(UUID.randomUUID().toString());
// schema
ManifestMetadataType metadataType = cpObjectFactory.createManifestMetadataType();
manifest.setMetadata(metadataType);
// organizations
OrganizationsType organizations = cpObjectFactory.createOrganizationsType();
manifest.setOrganizations(organizations);
OrganizationType organization = cpObjectFactory.createOrganizationType();
organization.setIdentifier("binder_" + binder.getKey());
organization.setTitle(binder.getTitle());
organization.setStructure("hierarchical");
organizations.getOrganization().add(organization);
organizations.setDefault(organization);
ResourcesType resources = cpObjectFactory.createResourcesType();
manifest.setResources(resources);
Map<Section, ItemType> sectionToItemMap = new HashMap<>();
for (Section section : sections) {
ItemType sectionItem = cpObjectFactory.createItemType();
String itemIdentifier = "section_" + section.getKey().toString();
String resourceIdentifier = "res_" + itemIdentifier;
sectionItem.setTitle(section.getTitle());
sectionItem.setIdentifier(itemIdentifier);
sectionItem.setIdentifierref(resourceIdentifier);
sectionItem.setIsvisible(Boolean.TRUE);
organization.getItem().add(sectionItem);
sectionToItemMap.put(section, sectionItem);
ResourceType resource = cpObjectFactory.createResourceType();
resource.setIdentifier(resourceIdentifier);
resource.setType("webcontent");
resource.setHref(sectionFilename(section));
resources.getResource().add(resource);
}
for (Page page : pages) {
ItemType sectionItem = sectionToItemMap.get(page.getSection());
if (sectionItem == null) {
continue;
}
ItemType pageItem = cpObjectFactory.createItemType();
pageItem.setTitle(page.getTitle());
String itemIdentifier = "page_" + page.getKey().toString();
String resourceIdentifier = "res_" + itemIdentifier;
pageItem.setIdentifier(itemIdentifier);
pageItem.setIdentifierref(resourceIdentifier);
pageItem.setIsvisible(Boolean.TRUE);
sectionItem.getItem().add(pageItem);
ResourceType resource = cpObjectFactory.createResourceType();
resource.setIdentifier(resourceIdentifier);
resource.setType("webcontent");
resource.setHref(pageFilename(page));
resources.getResource().add(resource);
}
return manifest;
}
use of org.olat.imscp.xml.manifest.ManifestType in project openolat by klemens.
the class ExportBinderAsCPResource method createImsManifest.
private ManifestType createImsManifest(Binder binder, List<Section> sections, List<Page> pages) {
ManifestType manifest = cpObjectFactory.createManifestType();
manifest.setIdentifier(UUID.randomUUID().toString());
// schema
ManifestMetadataType metadataType = cpObjectFactory.createManifestMetadataType();
manifest.setMetadata(metadataType);
// organizations
OrganizationsType organizations = cpObjectFactory.createOrganizationsType();
manifest.setOrganizations(organizations);
OrganizationType organization = cpObjectFactory.createOrganizationType();
organization.setIdentifier("binder_" + binder.getKey());
organization.setTitle(binder.getTitle());
organization.setStructure("hierarchical");
organizations.getOrganization().add(organization);
organizations.setDefault(organization);
ResourcesType resources = cpObjectFactory.createResourcesType();
manifest.setResources(resources);
Map<Section, ItemType> sectionToItemMap = new HashMap<>();
for (Section section : sections) {
ItemType sectionItem = cpObjectFactory.createItemType();
String itemIdentifier = "section_" + section.getKey().toString();
String resourceIdentifier = "res_" + itemIdentifier;
sectionItem.setTitle(section.getTitle());
sectionItem.setIdentifier(itemIdentifier);
sectionItem.setIdentifierref(resourceIdentifier);
sectionItem.setIsvisible(Boolean.TRUE);
organization.getItem().add(sectionItem);
sectionToItemMap.put(section, sectionItem);
ResourceType resource = cpObjectFactory.createResourceType();
resource.setIdentifier(resourceIdentifier);
resource.setType("webcontent");
resource.setHref(sectionFilename(section));
resources.getResource().add(resource);
}
for (Page page : pages) {
ItemType sectionItem = sectionToItemMap.get(page.getSection());
if (sectionItem == null) {
continue;
}
ItemType pageItem = cpObjectFactory.createItemType();
pageItem.setTitle(page.getTitle());
String itemIdentifier = "page_" + page.getKey().toString();
String resourceIdentifier = "res_" + itemIdentifier;
pageItem.setIdentifier(itemIdentifier);
pageItem.setIdentifierref(resourceIdentifier);
pageItem.setIsvisible(Boolean.TRUE);
sectionItem.getItem().add(pageItem);
ResourceType resource = cpObjectFactory.createResourceType();
resource.setIdentifier(resourceIdentifier);
resource.setType("webcontent");
resource.setHref(pageFilename(page));
resources.getResource().add(resource);
}
return manifest;
}
use of org.olat.imscp.xml.manifest.ManifestType in project openolat by klemens.
the class ExportBinderAsCPResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding("UTF-8");
} catch (Exception e) {
log.error("", e);
}
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
Binder binder = portfolioService.getBinderByKey(binderRef.getKey());
String label = binder.getTitle();
String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
String file = secureLabel + ".zip";
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
// load pages
List<Section> sections = portfolioService.getSections(binder);
List<Page> pages = portfolioService.getPages(binder, null);
// manifest
ManifestType manifest = createImsManifest(binder, sections, pages);
zout.putNextEntry(new ZipEntry("imsmanifest.xml"));
write(manifest, new ShieldOutputStream(zout));
zout.closeEntry();
// write pages
for (Section section : sections) {
exportSection(section, zout);
}
// write pages
for (Page page : pages) {
exportPage(page, zout);
}
// theme and javascripts
exportCSSAndJs(zout);
// make it readable offline
ByteArrayOutputStream manifestOut = new ByteArrayOutputStream();
write(manifest, manifestOut);
String manifestXml = new String(manifestOut.toByteArray());
String indexSrc = sectionFilename(sections.get(0));
CPOfflineReadableManager.getInstance().makeCPOfflineReadable(manifestXml, indexSrc, zout);
} catch (Exception e) {
log.error("", e);
}
}
Aggregations