<commit_before>/****************************************************************************
 * ubion.ORS - The Open Report Suite                                        *
 *                                                                          *
 * ------------------------------------------------------------------------ *
 *                                                                          *
 * Subproject: NOA (Nice Office Access)                                     *
 *                                                                          *
 *                                                                          *
 * The Contents of this file are made available subject to                  *
 * the terms of GNU Lesser General Public License Version 2.1.              *
 *                                                                          * 
 * GNU Lesser General Public License Version 2.1                            *
 * ======================================================================== *
 * Copyright 2003-2005 by IOn AG                                            *
 *                                                                          *
 * This library is free software; you can redistribute it and/or            *
 * modify it under the terms of the GNU Lesser General Public               *
 * License version 2.1, as published by the Free Software Foundation.       *
 *                                                                          *
 * This library is distributed in the hope that it will be useful,          *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
 * Lesser General Public License for more details.                          *
 *                                                                          *
 * You should have received a copy of the GNU Lesser General Public         *
 * License along with this library; if not, write to the Free Software      *
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,                    *
 * MA  02111-1307  USA                                                      *
 *                                                                          *
 * Contact us:                                                              *
 *  http://www.ion.ag                                                       *
 *  <EMAIL>                                                             *
 *                                                                          *
 ****************************************************************************/

/*
 * Last changes made by $Author: markus $, $Date: 2010-07-13 14:20:22 +0200 (Di, 13 Jul 2010) $
 */
package ag.ion.bion.officelayer.internal.document;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import ag.ion.bion.officelayer.application.connection.IOfficeConnection;
import ag.ion.bion.officelayer.desktop.IFrame;
import ag.ion.bion.officelayer.document.DocumentDescriptor;
import ag.ion.bion.officelayer.document.DocumentException;
import ag.ion.bion.officelayer.document.IDocument;
import ag.ion.bion.officelayer.document.IDocumentDescriptor;
import ag.ion.bion.officelayer.document.IDocumentService;
import ag.ion.bion.officelayer.runtime.IOfficeProgressMonitor;
import ag.ion.noa.NOAException;
import ag.ion.noa.db.IDatabaseDocument;
import ag.ion.noa.document.URLAdapter;
import ag.ion.noa.internal.db.DatabaseDocument;
import ag.ion.noa.service.IServiceProvider;

import com.sun.star.beans.PropertyState;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XEnumeration;
import com.sun.star.frame.FrameSearchFlag;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDesktop;
import com.sun.star.lang.XComponent;
import com.sun.star.sdb.XDocumentDataSource;
import com.sun.star.sdb.XOfficeDatabaseDocument;
import com.sun.star.uno.Any;
import com.sun.star.uno.UnoRuntime;

/**
 * Service for documents.
 * 
 * @author <NAME>
 * @version $Revision: 11756 $
 */
public class DocumentService implements IDocumentService {

  private static final String WRITER_FACTORY_URL  = "private:factory/swriter";               //$NON-NLS-1$
  private static final String CALC_FACTORY_URL    = "private:factory/scalc";                 //$NON-NLS-1$
  private static final String IMPRESS_FACTORY_URL = "private:factory/simpress";              //$NON-NLS-1$
  private static final String DRAW_FACTORY_URL    = "private:factory/sdraw";                 //$NON-NLS-1$
  private static final String MATH_FACTORY_URL    = "private:factory/smath";                 //$NON-NLS-1$
  private static final String WEB_FACTORY_URL     = "private:factory/swriter/web";           //$NON-NLS-1$
  private static final String GLOBAL_FACTORY_URL  = "private:factory/swriter/GlobalDocument"; //$NON-NLS-1$

  private IOfficeConnection   officeConnection    = null;
  private IServiceProvider    serviceProvider     = null;
  private XComponentLoader    xComponentLoader    = null;

  //----------------------------------------------------------------------------
  /**
   * Constructs new DocumentService.
   * 
   * @param officeConnection office connection to be used
   * @param serviceProvider the service provider to be used
   * 
   * @throws IllegalArgumentException if the submitted office connection is not valid
   * 
   * @author <NAME>
   */
  public DocumentService(IOfficeConnection officeConnection, IServiceProvider serviceProvider)
      throws IllegalArgumentException {
    if (officeConnection == null)
      throw new IllegalArgumentException("The submitted office connection is not valid."); //$NON-NLS-1$
    this.officeConnection = officeConnection;
    this.serviceProvider = serviceProvider;
  }

  //----------------------------------------------------------------------------
  /**
   * Constructs new document.
   * 
   * @param documentType document type to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return new constructed document
   * 
   * @throws NOAException if the new document can not be constructed
   * 
   * @author <NAME>
   */
  public IDocument constructNewDocument(String documentType, IDocumentDescriptor documentDescriptor)
      throws NOAException {
    return constructNewDocument(null, documentType, documentDescriptor);
  }

  //----------------------------------------------------------------------------
  /**
   * Constructs new document in the submitted frame.
   * 
   * <br><br>
   * Use one of the types:
   * <br><br>
   * <code>IDocument.WRITER</code><br>
   * <code>IDocument.CALC</code><br>
   * <code>IDocument.IMPRESS</code><br>
   * <code>IDocument.DRAW</code><br>
   * <code>IDocument.MATH</code><br>
   * <code>IDocument.WEB</code><br>
   * <code>IDocument.BASE</code><br>
   * <code>IDocument.GLOBAL</code>
   * 
   * @param frame frame to be used
   * @param documentType document type to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return new constructed document
   * 
   * @throws NOAException if the new document can not be constructed
   * 
   * @author <NAME>
   */
  public IDocument constructNewDocument(IFrame frame, String documentType,
      IDocumentDescriptor documentDescriptor) throws NOAException {
    try {
      if (xComponentLoader == null)
        xComponentLoader = constructComponentLoader();

      checkMaxOpenDocuments(serviceProvider);

      String factoryURL = WRITER_FACTORY_URL;
      if (documentType != null) {
        if (documentType.equals(IDocument.CALC))
          factoryURL = CALC_FACTORY_URL;
        else if (documentType.equals(IDocument.DRAW))
          factoryURL = DRAW_FACTORY_URL;
        else if (documentType.equals(IDocument.IMPRESS))
          factoryURL = IMPRESS_FACTORY_URL;
        else if (documentType.equals(IDocument.MATH))
          factoryURL = MATH_FACTORY_URL;
        else if (documentType.equals(IDocument.WEB))
          factoryURL = WEB_FACTORY_URL;
        else if (documentType.equals(IDocument.GLOBAL))
          factoryURL = GLOBAL_FACTORY_URL;
        else if (documentType.equals(IDocument.BASE))
          return constructDatabaseDocument();
      }

      XComponent xComponent = null;
      PropertyValue[] props = DocumentDescriptorTransformer.documentDescriptor2PropertyValues(documentDescriptor);
      if (frame != null) {
        xComponent = xComponentLoader.loadComponentFromURL(factoryURL,
            frame.getXFrame().getName(),
            FrameSearchFlag.ALL,
            props); //$NON-NLS-1$ //$NON-NLS-2$
      }
      else {
        xComponent = xComponentLoader.loadComponentFromURL(factoryURL, "_blank", 0, props); //$NON-NLS-1$
      }
      IDocument document = DocumentLoader.getDocument(xComponent, serviceProvider, props);
      if (document == null)
        throw new DocumentException("The new document can not be constructed."); //$NON-NLS-1$
      return document;
    }
    catch (Throwable throwable) {
      throw new NOAException(throwable);
    }
  }

  //----------------------------------------------------------------------------
  /**
   * Constructs new hidden document of the submitted type.
   * <br><br>
   * Use one of the types:
   * <br><br>
   * <code>IDocument.WRITER</code><br>
   * <code>IDocument.CALC</code><br>
   * <code>IDocument.IMPRESS</code><br>
   * <code>IDocument.DRAW</code><br>
   * <code>IDocument.MATH</code><br>
   * <code>IDocument.WEB</code><br>
   * <code>IDocument.BASE</code><br>
   * <code>IDocument.GLOBAL</code>
   * 
   * @param documentType document type to be constructed
   * 
   * @return new constructed document of the submitted type
   * 
   * @throws NOAException if the document can not be contructed
   * 
   * @author <NAME>
   * @date 16.03.2006
   */
  public IDocument constructNewHiddenDocument(String documentType) throws NOAException {
    return constructNewDocument(documentType, DocumentDescriptor.DEFAULT_HIDDEN);
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted URL.
   * 
   * @param url URL of the document
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded or the URL does
   * not locate an OpenOffice.org document
   * 
   * @author <NAME>
   */
  public IDocument loadDocument(String url) throws DocumentException {
    try {
      url = URLAdapter.adaptURL(url);
      IDocument document = DocumentLoader.loadDocument(serviceProvider, url);
      if (document != null)
        return document;
      else
        throw new DocumentException(Messages.getString("DocumentService_exception_url_invalid")); //$NON-NLS-1$
    }
    catch (Throwable throwable) {
      DocumentException documentException = new DocumentException(throwable.getMessage());
      documentException.initCause(throwable);
      throw documentException;
    }
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted URL.
   * 
   * @param url URL of the document
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   *  
   * @throws NOAException if the document can not be loaded or the URL does
   * not locate an OpenOffice.org document
   * 
   * @author <NAME>
   * @date 02.07.2006
   */
  public IDocument loadDocument(String url, IDocumentDescriptor documentDescriptor)
      throws NOAException {
    try {
      PropertyValue[] propertyValues = DocumentDescriptorTransformer.documentDescriptor2PropertyValues(documentDescriptor);
      url = URLAdapter.adaptURL(url);
      IDocument document = DocumentLoader.loadDocument(serviceProvider, url, propertyValues);
      if (document != null)
        return document;
      else
        throw new NOAException(Messages.getString("DocumentService_exception_url_invalid")); //$NON-NLS-1$
    }
    catch (Throwable throwable) {
      throw new NOAException(throwable);
    }
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted stream.
   * 
   * @param inputStream input stream to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded
   * 
   * @author <NAME>
   * @author <NAME>
   */
  public IDocument loadDocument(InputStream inputStream, IDocumentDescriptor documentDescriptor)
      throws DocumentException {
    return loadDocument(null, null, inputStream, documentDescriptor);
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted stream. 
   * 
   * <b>The document has no location and can not be stored with
   * the store() method of the <code>IPersistenceService</code>. Furthermore
   * OpenOffice.org can not recognize if the document is already open - 
   * therefore the document will be never opened in <code>ReadOnly</code> mode.</b>
   * 
   * @param frame frame to be used for the document
   * @param inputStream input stream to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded
   * 
   * @author <NAME>
   */
  public IDocument loadDocument(IFrame frame, InputStream inputStream,
      IDocumentDescriptor documentDescriptor) throws DocumentException {
    return loadDocument(null, frame, inputStream, documentDescriptor);
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted stream.
   * 
   * @param officeProgressMonitor office progress monitor to be used
   * @param inputStream input stream to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded
   * 
   * @author <NAME>
   */
  public IDocument loadDocument(IOfficeProgressMonitor officeProgressMonitor,
      InputStream inputStream, IDocumentDescriptor documentDescriptor) throws DocumentException {
    return loadDocument(officeProgressMonitor, null, inputStream, documentDescriptor);
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted stream.
   * 
   * <b>The document has no location and can not be stored with
   * the store() method of the <code>IPersistenceService</code>. Furthermore
   * OpenOffice.org can not recognize if the document is already open - 
   * therefore the document will be never opened in <code>ReadOnly</code> mode.</b>
   * 
   * @param officeProgressMonitor office progress monitor to be used
   * @param frame frame to be used for the document
   * @param inputStream input stream to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded<commit_msg>Added javadoc warning about slowness<commit_after>/****************************************************************************
 * ubion.ORS - The Open Report Suite                                        *
 *                                                                          *
 * ------------------------------------------------------------------------ *
 *                                                                          *
 * Subproject: NOA (Nice Office Access)                                     *
 *                                                                          *
 *                                                                          *
 * The Contents of this file are made available subject to                  *
 * the terms of GNU Lesser General Public License Version 2.1.              *
 *                                                                          * 
 * GNU Lesser General Public License Version 2.1                            *
 * ======================================================================== *
 * Copyright 2003-2005 by IOn AG                                            *
 *                                                                          *
 * This library is free software; you can redistribute it and/or            *
 * modify it under the terms of the GNU Lesser General Public               *
 * License version 2.1, as published by the Free Software Foundation.       *
 *                                                                          *
 * This library is distributed in the hope that it will be useful,          *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        *
 * Lesser General Public License for more details.                          *
 *                                                                          *
 * You should have received a copy of the GNU Lesser General Public         *
 * License along with this library; if not, write to the Free Software      *
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,                    *
 * MA  02111-1307  USA                                                      *
 *                                                                          *
 * Contact us:                                                              *
 *  http://www.ion.ag                                                       *
 *  <EMAIL>                                                             *
 *                                                                          *
 ****************************************************************************/

/*
 * Last changes made by $Author: markus $, $Date: 2010-07-13 14:20:22 +0200 (Di, 13 Jul 2010) $
 */
package ag.ion.bion.officelayer.internal.document;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import ag.ion.bion.officelayer.application.connection.IOfficeConnection;
import ag.ion.bion.officelayer.desktop.IFrame;
import ag.ion.bion.officelayer.document.DocumentDescriptor;
import ag.ion.bion.officelayer.document.DocumentException;
import ag.ion.bion.officelayer.document.IDocument;
import ag.ion.bion.officelayer.document.IDocumentDescriptor;
import ag.ion.bion.officelayer.document.IDocumentService;
import ag.ion.bion.officelayer.runtime.IOfficeProgressMonitor;
import ag.ion.noa.NOAException;
import ag.ion.noa.db.IDatabaseDocument;
import ag.ion.noa.document.URLAdapter;
import ag.ion.noa.internal.db.DatabaseDocument;
import ag.ion.noa.service.IServiceProvider;

import com.sun.star.beans.PropertyState;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XEnumeration;
import com.sun.star.frame.FrameSearchFlag;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDesktop;
import com.sun.star.lang.XComponent;
import com.sun.star.sdb.XDocumentDataSource;
import com.sun.star.sdb.XOfficeDatabaseDocument;
import com.sun.star.uno.Any;
import com.sun.star.uno.UnoRuntime;

/**
 * Service for documents.
 * 
 * @author <NAME>
 * @version $Revision: 11756 $
 */
public class DocumentService implements IDocumentService {

  private static final String WRITER_FACTORY_URL  = "private:factory/swriter";               //$NON-NLS-1$
  private static final String CALC_FACTORY_URL    = "private:factory/scalc";                 //$NON-NLS-1$
  private static final String IMPRESS_FACTORY_URL = "private:factory/simpress";              //$NON-NLS-1$
  private static final String DRAW_FACTORY_URL    = "private:factory/sdraw";                 //$NON-NLS-1$
  private static final String MATH_FACTORY_URL    = "private:factory/smath";                 //$NON-NLS-1$
  private static final String WEB_FACTORY_URL     = "private:factory/swriter/web";           //$NON-NLS-1$
  private static final String GLOBAL_FACTORY_URL  = "private:factory/swriter/GlobalDocument"; //$NON-NLS-1$

  private IOfficeConnection   officeConnection    = null;
  private IServiceProvider    serviceProvider     = null;
  private XComponentLoader    xComponentLoader    = null;

  //----------------------------------------------------------------------------
  /**
   * Constructs new DocumentService.
   * 
   * @param officeConnection office connection to be used
   * @param serviceProvider the service provider to be used
   * 
   * @throws IllegalArgumentException if the submitted office connection is not valid
   * 
   * @author <NAME>
   */
  public DocumentService(IOfficeConnection officeConnection, IServiceProvider serviceProvider)
      throws IllegalArgumentException {
    if (officeConnection == null)
      throw new IllegalArgumentException("The submitted office connection is not valid."); //$NON-NLS-1$
    this.officeConnection = officeConnection;
    this.serviceProvider = serviceProvider;
  }

  //----------------------------------------------------------------------------
  /**
   * Constructs new document.
   * 
   * @param documentType document type to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return new constructed document
   * 
   * @throws NOAException if the new document can not be constructed
   * 
   * @author <NAME>
   */
  public IDocument constructNewDocument(String documentType, IDocumentDescriptor documentDescriptor)
      throws NOAException {
    return constructNewDocument(null, documentType, documentDescriptor);
  }

  //----------------------------------------------------------------------------
  /**
   * Constructs new document in the submitted frame.
   * 
   * <br><br>
   * Use one of the types:
   * <br><br>
   * <code>IDocument.WRITER</code><br>
   * <code>IDocument.CALC</code><br>
   * <code>IDocument.IMPRESS</code><br>
   * <code>IDocument.DRAW</code><br>
   * <code>IDocument.MATH</code><br>
   * <code>IDocument.WEB</code><br>
   * <code>IDocument.BASE</code><br>
   * <code>IDocument.GLOBAL</code>
   * 
   * @param frame frame to be used
   * @param documentType document type to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return new constructed document
   * 
   * @throws NOAException if the new document can not be constructed
   * 
   * @author <NAME>
   */
  public IDocument constructNewDocument(IFrame frame, String documentType,
      IDocumentDescriptor documentDescriptor) throws NOAException {
    try {
      if (xComponentLoader == null)
        xComponentLoader = constructComponentLoader();

      checkMaxOpenDocuments(serviceProvider);

      String factoryURL = WRITER_FACTORY_URL;
      if (documentType != null) {
        if (documentType.equals(IDocument.CALC))
          factoryURL = CALC_FACTORY_URL;
        else if (documentType.equals(IDocument.DRAW))
          factoryURL = DRAW_FACTORY_URL;
        else if (documentType.equals(IDocument.IMPRESS))
          factoryURL = IMPRESS_FACTORY_URL;
        else if (documentType.equals(IDocument.MATH))
          factoryURL = MATH_FACTORY_URL;
        else if (documentType.equals(IDocument.WEB))
          factoryURL = WEB_FACTORY_URL;
        else if (documentType.equals(IDocument.GLOBAL))
          factoryURL = GLOBAL_FACTORY_URL;
        else if (documentType.equals(IDocument.BASE))
          return constructDatabaseDocument();
      }

      XComponent xComponent = null;
      PropertyValue[] props = DocumentDescriptorTransformer.documentDescriptor2PropertyValues(documentDescriptor);
      if (frame != null) {
        xComponent = xComponentLoader.loadComponentFromURL(factoryURL,
            frame.getXFrame().getName(),
            FrameSearchFlag.ALL,
            props); //$NON-NLS-1$ //$NON-NLS-2$
      }
      else {
        xComponent = xComponentLoader.loadComponentFromURL(factoryURL, "_blank", 0, props); //$NON-NLS-1$
      }
      IDocument document = DocumentLoader.getDocument(xComponent, serviceProvider, props);
      if (document == null)
        throw new DocumentException("The new document can not be constructed."); //$NON-NLS-1$
      return document;
    }
    catch (Throwable throwable) {
      throw new NOAException(throwable);
    }
  }

  //----------------------------------------------------------------------------
  /**
   * Constructs new hidden document of the submitted type.
   * <br><br>
   * Use one of the types:
   * <br><br>
   * <code>IDocument.WRITER</code><br>
   * <code>IDocument.CALC</code><br>
   * <code>IDocument.IMPRESS</code><br>
   * <code>IDocument.DRAW</code><br>
   * <code>IDocument.MATH</code><br>
   * <code>IDocument.WEB</code><br>
   * <code>IDocument.BASE</code><br>
   * <code>IDocument.GLOBAL</code>
   * 
   * @param documentType document type to be constructed
   * 
   * @return new constructed document of the submitted type
   * 
   * @throws NOAException if the document can not be contructed
   * 
   * @author <NAME>
   * @date 16.03.2006
   */
  public IDocument constructNewHiddenDocument(String documentType) throws NOAException {
    return constructNewDocument(documentType, DocumentDescriptor.DEFAULT_HIDDEN);
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted URL.
   * 
   * @param url URL of the document
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded or the URL does
   * not locate an OpenOffice.org document
   * 
   * @author <NAME>
   */
  public IDocument loadDocument(String url) throws DocumentException {
    try {
      url = URLAdapter.adaptURL(url);
      IDocument document = DocumentLoader.loadDocument(serviceProvider, url);
      if (document != null)
        return document;
      else
        throw new DocumentException(Messages.getString("DocumentService_exception_url_invalid")); //$NON-NLS-1$
    }
    catch (Throwable throwable) {
      DocumentException documentException = new DocumentException(throwable.getMessage());
      documentException.initCause(throwable);
      throw documentException;
    }
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted URL.
   * 
   * @param url URL of the document
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   *  
   * @throws NOAException if the document can not be loaded or the URL does
   * not locate an OpenOffice.org document
   * 
   * @author <NAME>
   * @date 02.07.2006
   */
  public IDocument loadDocument(String url, IDocumentDescriptor documentDescriptor)
      throws NOAException {
    try {
      PropertyValue[] propertyValues = DocumentDescriptorTransformer.documentDescriptor2PropertyValues(documentDescriptor);
      url = URLAdapter.adaptURL(url);
      IDocument document = DocumentLoader.loadDocument(serviceProvider, url, propertyValues);
      if (document != null)
        return document;
      else
        throw new NOAException(Messages.getString("DocumentService_exception_url_invalid")); //$NON-NLS-1$
    }
    catch (Throwable throwable) {
      throw new NOAException(throwable);
    }
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted stream.
   * May be <b>significantly slower</b> than the load* variants which take an URL String as parameter.
   * 
   * @param inputStream input stream to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded
   * 
   * @author <NAME>
   * @author <NAME>
   */
  public IDocument loadDocument(InputStream inputStream, IDocumentDescriptor documentDescriptor)
      throws DocumentException {
    return loadDocument(null, null, inputStream, documentDescriptor);
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted stream. 
   * 
   * <b>The document has no location and can not be stored with
   * the store() method of the <code>IPersistenceService</code>. Furthermore
   * OpenOffice.org can not recognize if the document is already open - 
   * therefore the document will be never opened in <code>ReadOnly</code> mode.</b>
   * 
   * May be <b>significantly slower</b> than the load* variants which take an URL String as parameter.
   * 
   * @param frame frame to be used for the document
   * @param inputStream input stream to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded
   * 
   * @author <NAME>
   */
  public IDocument loadDocument(IFrame frame, InputStream inputStream,
      IDocumentDescriptor documentDescriptor) throws DocumentException {
    return loadDocument(null, frame, inputStream, documentDescriptor);
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted stream.
   * May be <b>significantly slower</b> than the load* variants which take an URL String as parameter.
   * 
   * @param officeProgressMonitor office progress monitor to be used
   * @param inputStream input stream to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded
   * 
   * @author <NAME>
   */
  public IDocument loadDocument(IOfficeProgressMonitor officeProgressMonitor,
      InputStream inputStream, IDocumentDescriptor documentDescriptor) throws DocumentException {
    return loadDocument(officeProgressMonitor, null, inputStream, documentDescriptor);
  }

  //----------------------------------------------------------------------------
  /**
   * Loads document on the basis of the submitted stream.
   * 
   * <b>The document has no location and can not be stored with
   * the store() method of the <code>IPersistenceService</code>. Furthermore
   * OpenOffice.org can not recognize if the document is already open - 
   * therefore the document will be never opened in <code>ReadOnly</code> mode.</b>
   * 
   * May be <b>significantly slower</b> than the load* variants which take an URL String as parameter.
   * 
   * @param officeProgressMonitor office progress monitor to be used
   * @param frame frame to be used for the document
   * @param inputStream input stream to be used
   * @param documentDescriptor document descriptor to be used
   * 
   * @return loaded document
   * 
   * @throws DocumentException if the document can not be loaded
{'fraction_non_alphanumeric': 0.14780228626630174, 'fraction_numerical': 0.005796168088874577, 'mean_word_length': 2.010177377144519, 'pattern_counts': {'":': 0, '<': 167, '<?xml version=': 0, '>': 167, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 84, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2373075', 'n_tokens_mistral': 7836, 'n_tokens_neox': 7509, 'n_words': 2213}