Search in sources :

Example 31 with OLATRuntimeException

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) CPFile(org.olat.ims.cp.objects.CPFile) DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CPResource(org.olat.ims.cp.objects.CPResource) CPItem(org.olat.ims.cp.objects.CPItem) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Example 32 with OLATRuntimeException

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());
    }
}
Also used : CPOrganizations(org.olat.ims.cp.objects.CPOrganizations) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OutputFormat(org.dom4j.io.OutputFormat) DefaultDocument(org.dom4j.tree.DefaultDocument) IOException(java.io.IOException) XMLWriter(org.dom4j.io.XMLWriter) IOException(java.io.IOException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 33 with OLATRuntimeException

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();
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 34 with OLATRuntimeException

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) IOException(java.io.IOException) Properties(java.util.Properties)

Example 35 with OLATRuntimeException

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);
    }
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)268 IOException (java.io.IOException)104 File (java.io.File)50 ModuleConfiguration (org.olat.modules.ModuleConfiguration)26 ArrayList (java.util.ArrayList)22 AssertException (org.olat.core.logging.AssertException)22 FileOutputStream (java.io.FileOutputStream)20 OutputStream (java.io.OutputStream)20 Properties (java.util.Properties)20 FileInputStream (java.io.FileInputStream)18 HashMap (java.util.HashMap)18 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)18 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)18 DefaultElement (org.dom4j.tree.DefaultElement)16 Element (org.jdom.Element)16 InputStream (java.io.InputStream)14 BufferedInputStream (java.io.BufferedInputStream)12 List (java.util.List)12 Document (org.dom4j.Document)12 CPItem (org.olat.ims.cp.objects.CPItem)12