Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWPFParagraph: easier way to create a link. #153

Closed
wants to merge 4 commits into from
Closed

XWPFParagraph: easier way to create a link. #153

wants to merge 4 commits into from

Conversation

@dourouc05
Copy link

@dourouc05 dourouc05 commented Jun 4, 2019

Inspiration from https://stackoverflow.com/questions/55275241/how-to-add-a-hyperlink-to-the-footer-of-a-xwpfdocument-using-apache-poi

@asfgit
Copy link

@asfgit asfgit commented Jun 4, 2019

Can one of the admins verify this patch?

Loading

@dourouc05
Copy link
Author

@dourouc05 dourouc05 commented Jun 24, 2019

I've just added a test; is this OK to merge?

Loading

Copy link
Contributor

@pjfanning pjfanning left a comment

Test fails for me.

Testcase: testAddHyperlink took 0.007 sec
	Caused an ERROR
null
java.lang.NullPointerException
	at org.apache.poi.xwpf.usermodel.TestXWPFDocument.testAddHyperlink(TestXWPFDocument.java:194)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Loading

@dourouc05
Copy link
Author

@dourouc05 dourouc05 commented Jul 19, 2019

The DOCX always got generated as it should have, but retrieving a newly added link could not work. What I did is call initHyperlinks in XWPFDocument each time a link is requested by ID, in case a new link was added (first emptying the hyperlinks field).

Is this approach correct? From my understanding, I think so… Performancewise, it seems problematic, as the list is rebuilt each time a request for a link is made, this is why I made a second commit to rebuild this list only when the link is not found (which is already better).

Loading

@asfgit asfgit closed this in e14c9f2 Jul 19, 2019
@pjfanning
Copy link
Contributor

@pjfanning pjfanning commented Jul 19, 2019

Loading

asfgit pushed a commit that referenced this issue Oct 6, 2019
Alain-Bearez pushed a commit to cuali/poi that referenced this issue Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants