Hi there,

I am newer in OpenOffice. Could you give me some example that use
XTextDocument?
Because I am understanding. Below theres is a pience of code that I am using
but it doesn't work.


 public OutputStream comporDocumentosDocParaDoc(List colecao)
  throws java.io.IOException, DocumentException, IOException,
IllegalArgumentException, BootstrapException
  {
    ConversorDeDocumento conversor = new ConversorDeDocumento();
    //prepare base document
    //move the document to byteArray
    InputStream docBase = (InputStream)colecao.get(0);
ByteArrayOutputStream arrayByteDocBase = new ByteArrayOutputStream();
    docBase.toString();
    IOUtils.copy(docBase,arrayByteDocBase);
    //via URL
    File arqBase = new File("M:\\Aloizio_SS\\SINF2\\DOCS\\arq0.doc");
    FileOutputStream fout = new FileOutputStream(arqBase,true);
    fout.write(arrayByteDocBase.toByteArray());
    fout.close();

    //upload the base document into open office
    XComponent docFinal =
      carregarDocumentoOpenOffice(arqBase, "DOC");

    //iterator over document list
    for(int i = 1; i < colecao.size(); i++)
    {
      InputStream arqDoc = (InputStream)colecao.get(i);
      //move the document to byte array
ByteArrayOutputStream arrayByteDoc = new ByteArrayOutputStream ();
      IOUtils.copy(arqDoc,arrayByteDoc);

      //via URL
      File arqDocAux = new
File("M:\\Aloizio_SS\\SINF2\\DOCS\\arq"+i+".doc");
      FileOutputStream foutAux = new FileOutputStream(arqDocAux);
      foutAux.write(arrayByteDoc.toByteArray());
      foutAux.close();


      //consulta a interface XTextDocument para obter o texto
      XTextDocument mxDoc =
(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, docFinal);
      XText mxDocText = mxDoc.getText();
      // create a cursor
      XTextCursor mxDocCursor = mxDocText.createTextCursor();
      mxDocCursor.gotoEnd(false);

XDocumentInsertable lXDocInsertable = (XDocumentInsertable) UnoRuntime.
      queryInterface(XDocumentInsertable.class, mxDocCursor);

      PropertyValue[] loadProps = new PropertyValue[0];
      String url = createUNOFileURL(arqDocAux.getAbsolutePath());
OOInputStream oois = new OOInputStream (arrayByteDoc.toByteArray());
      PropertyValue[] loadProps = new PropertyValue[3];
      loadProps[0] = new PropertyValue();
      loadProps[0].Name = "Hidden";
      loadProps[0].Value = new Boolean(true);
      loadProps[1] = new PropertyValue();
      loadProps[1].Name = "FilterName";
      loadProps[1].Value = new Boolean(true);
      loadProps[2] = new PropertyValue();
      loadProps[2].Name = "InputStream";
      loadProps[2].Value = oois;
lXDocInsertable.insertDocumentFromURL("private:stream", loadProps);
    }

    XStorable xstorable = ( XStorable ) UnoRuntime.queryInterface(
XStorable.class,
        docFinal );


here you query XStorable, which should work properly, but you don't use it to actually store the document.

    XComponent xComponent = ( XComponent ) UnoRuntime.queryInterface(
    XComponent.class, xstorable );
    xComponent.dispose();

Here you dispose the document and with that destroy it ... generally XCloseable.close() should work smoother :-)

    byte[] docFundido = obterDocumentoComposto(docFinal);
    InputStream fim = new ByteArrayInputStream(docFundido);
    OutputStream out = new ByteArrayOutputStream();
    IOUtils.copy(fim,out);
    return out;

mmm ... some lines above you dispose docFinal and now you try to write something related to it to a java output stream ?

Is the goal to have a Microsoft word document on disk after merging several document in one ?

I'm a bit lost here.

Regards

Stephan

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to