Apache OpenOffice (AOO) Bugzilla – Issue 116753
getByName after an insertByName throws NoSuchElementException
Last modified: 2017-05-20 10:45:16 UTC
When a getByName is invoked after an insertByName a NoSuchElementException is thrown. I've tried with a code that works fine with OO 3.2.1. The same code doesn't work with OO 3.3 This is my java code: private void insertImage(XTextDocument textDocument, XTextRange searchTextRange, ImageResource imageResource) throws OfficeException { try { XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, document); Object bitmapTable = xMultiServiceFactory.createInstance("com.sun.star.drawing.BitmapTable"); XNameContainer xBitmapContainer = (XNameContainer)UnoRuntime.queryInterface(XNameContainer.class, bitmapTable); String internalName = imageResource.getUrl().getPath().replace("/", "_").replace(":", "_") + System.currentTimeMillis() + "_" + Math.random(); xBitmapContainer.insertByName(internalName, imageResource.getUrl().toExternalForm()); Object internalUrl = xBitmapContainer.getByName(internalName); Object image = xMultiServiceFactory.createInstance("com.sun.star.text.TextGraphicObject"); XTextContent xImage = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, image); XPropertySet xPropertySet = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xImage); xPropertySet.setPropertyValue("GraphicURL", internalUrl); xPropertySet.setPropertyValue("Width", imageResource.getWidth()); xPropertySet.setPropertyValue("Height", imageResource.getHeight()); textDocument.getText().insertTextContent(searchTextRange, xImage, true); } catch (Exception e) { e.printStackTrace(); throw new OfficeException("Eccezione durante l'inserimento dell'immagine", e); } } ImageResource is just a bean POJO.
@TBO: Please have a look.
.
java, not my language - anyone else can confirm this? else an attached basic macro would help me to check and verify this.
I want to make this problem clear, I have met the same problem in the following forum and mailing-list. http://www.oooforum.org/forum/viewtopic.phtml?t=115594&highlight= http://openoffice.org/projects/api/lists/dev/archive/2011-03/message/15 My code works well posted in the above thread written in Basic on OOo 3.3.0. Sub EmbedImageIntoPageBackground sURL = "file:///home/asuka/Documents/images/logo.png" sName = "Logo" oDoc = ThisComponent oBitmapTable = oDoc.createInstance("com.sun.star.drawing.BitmapTable") If NOT oBitmapTable.hasByName(sName) Then oBitmapTable.insertByName(sName, sURL) End If sInternalURL = oBitmapTable.getByName(sName) oStyleFamilies = oDoc.getStyleFamilies() oStyleFamily = oStyleFamilies.getByName("PageStyles") oStyle = oStyleFamily.getByName("Standard") oStyle.BackGraphicURL = sInternalURL End Sub I checked the problem with the above code on both 3.2.1 and 3.3.0. I have an image in the following URL and it is inserted with the following name: sURL = "file:///E:/usr/chart_1.png" sName = "section-background" If I change the sURL starting from "file:///" to "file:/" (this is illegal), NoSuchElementException raised on OOo 3.3.0, but not on 3.2.1.
Created attachment 76359 [details] Java code to explain file:/ managment I confirm my problem with Linux Distros too.
Comment on attachment 76359 [details] Java code to explain file:/ managment Output is: file:/igrue/ciao.txt file:/igrue/ciao.txt file:/igrue/ciao.txt file:/igrue/ciao.txt file:/igrue/ciao.txt http://igrue/ciao.txt http://igrue/ciao.txt http://igrue/ciao.txt http://igrue/ciao.txt http://igrue/ciao.txt I haven't control on number of slashes!
java.net.URL class has problem about it and java.net.URI has been introduced on Java 1.4.
Reset the assignee to the default "issues@openoffice.apache.org".