Hello, here is my code:

  public void processFile(NodeRef nodeRef) {
       SocketOpenOfficeConnection conectionToOO = new
SocketOpenOfficeConnection();
       ServiceRegistry srvResgitry = Repository.getServiceRegistry(
FacesContext.getCurrentInstance());
       FileFolderService ffService  = srvResgitry.getFileFolderService();
       ContentWriter cWriter = ffService.getWriter(nodeRef);

       try {
           // Open the input file.
           FileChannel fileChannel = cWriter.getFileChannel(false);
           InputStream is = Channels.newInputStream(fileChannel);

           //convert to OOInputStream //not sure if it's mandatory or
InputStream it's supported
           ByteArrayOutputStream bytes = new ByteArrayOutputStream();
           byte[] byteBuffer = new byte[4096];
           int byteBufferLength = 0;
           while ((byteBufferLength = is.read(byteBuffer)) > 0) {
                   bytes.write(byteBuffer,0,byteBufferLength);
           }
           OOInputStream inputStream = new
OOInputStream(bytes.toByteArray());
           //is.close();
           //fileChannel.close();

           //comnect
           conectionToOO.connect();

           PropertyValue[] loadProperties = new PropertyValue[3];
           loadProperties[0] = new PropertyValue();
           loadProperties[1] = new PropertyValue();
           loadProperties[2] = new PropertyValue();

           loadProperties[0].Name = "Hidden";
           loadProperties[0].Value = Boolean.TRUE;
           loadProperties[1].Name = "ReadOnly";
           loadProperties[1].Value = Boolean.FALSE; //I need to write
           loadProperties[2].Name = "InputStream";
           loadProperties[2].Value = new
ByteArrayToXInputStreamAdapter(IOUtils.toByteArray(inputStream));
//OOInputStream //InputStream is supported?

           //get a desktop
           XComponentLoader xComponentLoader = conectionToOO.getDesktop();

           //load file
           XComponent xComponent =
xComponentLoader.loadComponentFromURL("private:stream", "_blank", 0,
loadProperties);
           XTextDocument mxDoc = (XTextDocument)
UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
xComponent);

           //....code to relpace some text....TODO

           conectionToOO.disconnect();
           }
                catch (Exception e )
           {
               e.printStackTrace();
           }
           finally{
               conectionToOO.disconnect();
           }
     }


always get com.sun.star.lang.IllegalArgumentException: URL seems to be an
unsupported one. and I can't figure out what is the problem...
Trying to open an docx File...to do some text replacements
On a first stage I used the Apache POI library and I successfully opened the
file.

best regards

Reply via email to