After further investigation I nailed the problem to the XStorable.storeAsUrl() method. It seems, that the method ist not executing properly but isn't throwing an exception either. The debugging messages are exactly the same for all executes , except for the crashing one where logger.debug("Store as URL finished") is not executed. But the surrounding catch block to get the com.sun.star.io.IOException is not executed either. So no error message for me :/ .

       try
       {
           if (changeIdentity)
           {
logger.debug("Store as URL. Property is:"+property[0]); // property[0] = new PropertyValue(); property[0].Name = "Overwrite"; property[0].Value = new Boolean(true); logger.debug("Filename ist: "+fileName); // generated file name logger.debug("has Location "+this.xStoreable.hasLocation()); // false logger.debug("is read only "+this.xStoreable.isReadonly()); // false
               this.xStoreable.storeAsURL(fileName, property);
logger.debug("Store as URL finished"); // on crash, this line is not beeing executed, but the catch block is neither executed
           }
           else
           {
               logger.debug("Store to URL");
// storeTo behält die Identität des Dokuments bei, entspricht
               // also dem Export
               this.xStoreable.storeToURL(fileName, property);
               logger.debug("Store to URL finished");
           }
       }
       catch (IOException ioe)
       {
throw new OpenOfficeException(ioe); // is never thrown even tough storeAsURL seems not to execute properly.
       }


The file is indeed saved at the specified location given to storeAsUrl(), but it contains absolultely no data. I've also noticed, that the problem only arises if I did embed a graphic into the document at the last(crashing) try. Even though tests like the above NEVER failed what would suggest, that the embedGraphic-Method and the saveAs-method are alright. And in my application the embedGraphic-Method is beeing executed properly as well before the crash.

Quick-Test for embedGraphic and saveAs method:
           for(int i = 0; i < 500; i ++)
           {
           con = fac.createOpenOfficeConnection();
doc = new TextDocument(con, "file:///m/quark/steb/s3/tmp/PB.odt"); doc.embedGraphic("file:///m/quark/steb/s3/tmp/test2.jpg", doc.getCursorByPlaceHolder("hier", false));
           doc.appendDocument("file:///m/quark/steb/s3/tmp/test2.odt");
           doc.appendDocument("file:///m/quark/steb/s3/tmp/test2.odt");
doc.saveAs("file:///m/quark/steb/s3/tmp/append"+i+".odt"); // calls the above posted code
           doc.close();
           con.close();
           }

the embedGraphic Method:
   public void embedGraphic2(String graphicURL, XTextCursor cursor)
   {
       logger.debug("embedding graphic "+graphicURL);
       XText xText = cursor.getText();
       // 1st step: Insert graphic object into the document as a link
       //

       try
       {
           XTextContent xImage = (XTextContent) UnoRuntime
                   .queryInterface(
                           XTextContent.class,
                           xMultiServiceFactory
.createInstance("com.sun.star.text.TextGraphicObject"));
           // Querying for the interface XTextContent on the GraphicObject
           XTextContent xTextContent = (XTextContent) UnoRuntime
                   .queryInterface(XTextContent.class, xImage);
           // Replace the selected text with the image content
           xText
                   .insertTextContent(cursor, xTextContent,
                           true);
           // Querying for the interface XPropertySet on GraphicObject
// http://api.openoffice.org/docs/common/ref/com/sun/star/text/TextContent.html XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(
                   XPropertySet.class, xImage);
           // Setting the anchor type
           xPropSet.setPropertyValue("AnchorType",
                   TextContentAnchorType.AS_CHARACTER);
           // Setting the graphic url
// http://api.openoffice.org/docs/common/ref/com/sun/star/text/TextGraphicObject.html
           xPropSet.setPropertyValue("GraphicURL", graphicURL);

// 2nd step: create a bitmap container to hold graphic permanently
           // inside the document
           //
           XNameContainer xBitmapContainer = (XNameContainer) UnoRuntime
.queryInterface(XNameContainer.class, xMultiServiceFactory .createInstance("com.sun.star.drawing.BitmapTable")); // helper-stuff to let OOo create an internal name of the graphic
           // that can be used later (internal name consists of various
           // checksums)
           MessageDigest md = MessageDigest.getInstance("MD5");
           md.update(graphicURL.getBytes(), 0, graphicURL.length());
String internalName = new BigInteger(1, md.digest()).toString(16);
           xBitmapContainer.insertByName(internalName, graphicURL);
           String internalURL = (String) (xBitmapContainer
                   .getByName(internalName));
           // replace external URL with internal URL
           xPropSet.setPropertyValue("GraphicURL", internalURL);
           // remove unnecessary object reference
           xBitmapContainer.removeByName(internalName);
           logger.debug("Finished embedding graphic");
       }
       catch (IllegalArgumentException e)
       {
           e.printStackTrace();
       }
       catch (UnknownPropertyException e)
       {
           e.printStackTrace();
       }
       catch (PropertyVetoException e)
       {
           e.printStackTrace();
       }
       catch (WrappedTargetException e)
       {
           e.printStackTrace();
       }
       catch (NoSuchAlgorithmException e)
       {
           e.printStackTrace();
       }
       catch (ElementExistException e)
       {
           e.printStackTrace();
       }
       catch (NoSuchElementException e)
       {
           e.printStackTrace();
       }
       catch (Exception e)
       {
           e.printStackTrace();
       }

   }

Did anyone ever encounter such a problem with storeAsUrl()? Or could you think of any circumstances where it could fail without throwing the IOException?

Regards,
Steffen

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to