[Bug 64038] New: createHyperlinkRun: duplicate generated rId

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug 64038] New: createHyperlinkRun: duplicate generated rId

Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64038

            Bug ID: 64038
           Summary: createHyperlinkRun: duplicate generated rId
           Product: POI
           Version: 4.1.1-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XWPF
          Assignee: [hidden email]
          Reporter: [hidden email]
  Target Milestone: ---

Using the new XWPFParagraph.createHyperlinkRun method (from
https://github.com/apache/poi/pull/153), I noticed that some links do not have
a valid rId: at some point, I got "rI1", which was already used in the
relations.

In more details: I was trying to add a link inside a footnote. This run was
generated in footnotes.xml:

<w:hyperlink r:id="rId1"><w:r><w:rPr><w:color w:val="0563c1"/><w:u
w:val="single"/></w:rPr><w:t>avec bien plus de
lourdeur</w:t></w:r></w:hyperlink>

However, neither in footnotes.xml.rels nor in document.xml.rels could I find
the link I just added. The worse was in document.xml.rels, where this ID
already existed:

<Relationship Id="rId1" Target="numbering.xml"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"/>

In my case, the solution was not to get the ID from getPart(), but from
getDocument(). I ended up with this code:

String rId =
paragraph.getLast().getDocument().getPackagePart().addExternalRelationship(
                    uri, XWPFRelation.HYPERLINK.getRelation()
).getId();

Thus, I think that the code of XWPFParagraph.createHyperlinkRun should be
changed to:

    public XWPFHyperlinkRun createHyperlinkRun(String uri) {
        // Create a relationship ID for this link.
        String rId = getDocument().getPackagePart().addExternalRelationship(
                uri, XWPFRelation.HYPERLINK.getRelation()
        ).getId();

        // Create the run.
        CTHyperlink ctHyperLink = getCTP().addNewHyperlink();
        ctHyperLink.setId(rId);
        ctHyperLink.addNewR();

        // Append this run to the paragraph.
        XWPFHyperlinkRun link = new XWPFHyperlinkRun(ctHyperLink,
ctHyperLink.getRArray(0), this);
        runs.add(link);
        iruns.add(link);
        return link;
    }

As I am really unsure about this, I prefer to open an issue rather than create
a pull request…

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 64038] createHyperlinkRun: duplicate generated rId

Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64038

Dominik Stadler <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All
             Status|NEW                         |NEEDINFO

--- Comment #1 from Dominik Stadler <[hidden email]> ---
Can you provide a small snippet of code or test-case which reproduces this?

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

[Bug 64038] createHyperlinkRun: duplicate generated rId

Bugzilla from bugzilla@apache.org
In reply to this post by Bugzilla from bugzilla@apache.org
https://bz.apache.org/bugzilla/show_bug.cgi?id=64038

Paul Wellner Bou <[hidden email]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[hidden email]

--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]