Issue 116753 - getByName after an insertByName throws NoSuchElementException
Summary: getByName after an insertByName throws NoSuchElementException
Status: UNCONFIRMED
Alias: None
Product: Writer
Classification: Application
Component: programming (show other issues)
Version: OOO330m20
Hardware: PC Windows XP
: P3 Trivial with 2 votes (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords: needhelp
Depends on:
Blocks:
 
Reported: 2011-02-01 13:18 UTC by lzu
Modified: 2017-05-20 10:45 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Java code to explain file:/ managment (768 bytes, text/plain)
2011-04-12 14:12 UTC, lzu
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description lzu 2011-02-01 13:18:31 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.
Comment 1 eric.savary 2011-02-01 13:52:31 UTC
@TBO: Please have a look.
Comment 2 Oliver Brinzing 2011-02-02 11:48:41 UTC
.
Comment 3 Oliver Brinzing 2011-02-02 11:49:00 UTC
.
Comment 4 b.osi.ooo 2011-02-03 16:42:22 UTC
java, not my language - anyone else can confirm this?
else an attached basic macro would help me to check and verify this.
Comment 5 hanya 2011-03-10 08:01:33 UTC
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.
Comment 6 lzu 2011-04-12 14:12:53 UTC
Created attachment 76359 [details]
Java code to explain file:/ managment

I confirm my problem with Linux Distros too.
Comment 7 lzu 2011-04-12 14:14:27 UTC
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!
Comment 8 hanya 2011-04-12 15:15:42 UTC
java.net.URL class has problem about it and java.net.URI has been introduced on Java 1.4.
Comment 9 Marcus 2017-05-20 10:45:16 UTC
Reset the assignee to the default "issues@openoffice.apache.org".