Package org.olat.ims.resources

Source Code of org.olat.ims.resources.IMSLoader

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* This software is protected by the OLAT software license.<br>
* Use is subject to license terms.<br>
* See LICENSE.TXT in this distribution for details.
* <p>
* Copyright (c) JGS goodsolutions GmbH, Zurich, Switzerland. http://www.goodsolutions.ch <br>
* All rights reserved.
* <p>
*/
package org.olat.ims.resources;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.dom4j.Document;
import org.olat.core.util.vfs.VFSLeaf;
import org.olat.core.util.xml.XMLParser;

/**
* Description:<br>
*
* <P>
* Initial Date:  13.06.2006 <br>
*
* @author Felix Jost
*/
public class IMSLoader {
 
  /**
   * Reads an IMS XML Document if supported by /org/olat/ims/resources.
   * @param documentF
   * @return document
   */
  public static Document loadIMSDocument(VFSLeaf documentF) {
    InputStream in = null;
    BufferedInputStream bis = null;
    Document doc = null;
    try {
      in = documentF.getInputStream();
      bis = new BufferedInputStream(in);
      XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
      doc = xmlParser.parse(bis, false);
    catch (Exception e) { return null; }
    finally {
      try {
        if (in != nullin.close();
        if (bis != null) bis.close();
      catch (Exception e) {
        // we did our best to close the inputStream
      }
    }
    return doc;
  }
 
  /**
   * Reads an IMS XML Document if supported by /org/olat/ims/resources.
   * @param documentF
   * @return document
   */
  public static Document loadIMSDocument(File documentF) {
    FileInputStream in = null;
    BufferedInputStream bis = null;
    Document doc = null;
    try {
      in = new FileInputStream(documentF);
      bis = new BufferedInputStream(in);
      XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
      doc = xmlParser.parse(bis, false);
    catch (Exception e) { return null; }
    finally {
      try {
        if (in != nullin.close();
        if (bis != null) bis.close();
      catch (Exception e) {
        // we did our best to close the inputStream
      }
    }
    return doc;
  }
}
TOP

Related Classes of org.olat.ims.resources.IMSLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.