use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class ContentPackage method updatePage.
protected void updatePage(CPPage page) {
DefaultElement ele = cpcore.getElementByIdentifier(page.getIdentifier());
if (ele instanceof CPItem) {
CPItem item = (CPItem) ele;
item.setTitle(page.getTitle());
item.setMetadata(page.getMetadata());
String itemIdentifierRef = item.getIdentifierRef();
if (itemIdentifierRef == null || itemIdentifierRef.equals("")) {
// This item has no linked resource yet. Add one if there is a page file
// attached.
VFSLeaf pageFile = page.getPageFile();
if (pageFile != null) {
CPResource res = new CPResource();
CPFile file = new CPFile(pageFile);
res.addFile(file);
// TODO:GW Set type according to file
res.setType("text/html");
res.setHref(file.getHref());
item.setIdentifierRef(res.getIdentifier());
cpcore.getRootNode().getResources().addResource(res);
}
} else {
// this item has already a linked resource
// this is not supported, we don't change linked resources...
}
} else if (ele instanceof CPOrganization) {
CPOrganization organization = (CPOrganization) ele;
organization.setTitle(page.getTitle());
} else {
// ERROR: this shouldn't be
throw new OLATRuntimeException("Error while updating manifest with new Page-Data. Invalid identifier " + page.getIdentifier(), null);
}
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class ContentPackage method writeToFile.
/**
* writes the manifest.xml
*/
void writeToFile() {
String filename = "imsmanifest.xml";
OutputFormat format = OutputFormat.createPrettyPrint();
try {
VFSLeaf outFile;
// file may exist
outFile = (VFSLeaf) cpcore.getRootDir().resolve("/" + filename);
if (outFile == null) {
// if not, create it
outFile = cpcore.getRootDir().createChildLeaf("/" + filename);
}
DefaultDocument manifestDocument = cpcore.buildDocument();
XMLWriter writer = new XMLWriter(outFile.getOutputStream(false), format);
writer.write(manifestDocument);
} catch (Exception e) {
log.error("imsmanifest for ores " + ores.getResourceableId() + "couldn't be written to file.", e);
throw new OLATRuntimeException(CPOrganizations.class, "Error writing imsmanifest-file", new IOException());
}
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class CPResource method buildChildren.
/**
* @see org.olat.ims.cp.objects.CPNode#buildChildren()
*/
public void buildChildren() {
Iterator<DefaultElement> children = this.elementIterator();
// iterate through children
while (children.hasNext()) {
DefaultElement child = children.next();
if (child.getName().equals(CPCore.FILE)) {
CPFile file = new CPFile(child, this.xmlbase, parent.getRootDir());
file.buildChildren();
file.setParentElement(this);
files.add(file);
} else if (child.getName().equals(CPCore.DEPENDENCY)) {
CPDependency dep = new CPDependency(child);
dep.setParentElement(this);
dependencies.add(dep);
} else if (child.getName().equals(CPCore.METADATA)) {
// TODO: implement METADATA
metadata = new CPMetadata(child);
metadata.setParentElement(this);
} else {
throw new OLATRuntimeException(CPOrganizations.class, "Invalid IMS-Manifest (unallowed element under <resource>)", new Exception());
}
}
this.clearContent();
validateElement();
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class WikiManager method saveWikiPageProperties.
private void saveWikiPageProperties(OLATResourceable ores, WikiPage page) {
VFSContainer wikiContentContainer = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
VFSLeaf leaf = (VFSLeaf) wikiContentContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
if (leaf == null)
leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
Properties p = getPageProperties(page);
try {
p.store(leaf.getOutputStream(false), "wiki page meta properties");
} catch (IOException e) {
throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() + " and olatresource: " + ores.getResourceableId(), e);
}
}
use of org.olat.core.logging.OLATRuntimeException in project OpenOLAT by OpenOLAT.
the class WikiManager method generatePageId.
/**
* @param pageName
* @return
*/
public static String generatePageId(String pageName) {
try {
String encoded = new String(Base64.encodeBase64(pageName.getBytes("utf-8")), "us-ascii");
// base64 can contain "/" so we have to replace them
encoded = encoded.replace('/', '_');
return encoded;
} catch (UnsupportedEncodingException e) {
throw new OLATRuntimeException(WikiManager.class, "Encoding UTF-8 not supported by your platform!", e);
}
}
Aggregations