[jira] [Commented] (FOP-3173) cannot include attachment whose name contains hash ('#') in the name

2024-04-16 Thread Chris Bowditch (Jira)


[ 
https://issues.apache.org/jira/browse/FOP-3173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17837666#comment-17837666
 ] 

Chris Bowditch commented on FOP-3173:
-

Based on the last comment and the description of this, this will be closed as 
not a bug, # is not legal in a URI and must be encoded

> cannot include attachment whose name contains hash ('#') in the name
> 
>
> Key: FOP-3173
> URL: https://issues.apache.org/jira/browse/FOP-3173
> Project: FOP
>  Issue Type: Bug
>  Components: fo/unqualified
>Affects Versions: 2.9
>Reporter: BlueMountain
>Priority: Major
> Attachments: PDFAttachmentTestCase.java
>
>
> hi,
> we are relying on the fop to generate PDF given data held in database + file 
> storage.
> we need to represent some ( file.name, file.data) as a pdf embedded 
> attachment.
> some users have encountered issue when the file.name value carries hash sign 
> ('#')
> upon generating the pdf, an exception is thrown about missing attachment name.
> I have added a new test to the  PDFAttachmentTestCase class (see attachment) 
> to reproduce the issue.
> The added test that generates the error is:
> @Test
> public void testAddEmbeddedFileDash () throws IFException {
> PDFDocumentHandler docHandler = new PDFDocumentHandler(new IFContext(ua));
> docHandler.setFontInfo(new FontInfo());
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> docHandler.setResult(new StreamResult(out));
> docHandler.startDocument();
> docHandler.startPage(0, "", "", new Dimension());
> docHandler.handleExtensionObject(new 
> PDFEmbeddedFileAttachment("filename#1.txt", "src", "desc"));
> // issue occurs at this line
> *docHandler.getDocumentNavigationHandler().renderLink(new Link(*
>  *new URIAction("embedded-file:filename#1.txt", false), new Rectangle()));*
> docHandler.endDocument();
> }
>  
> running the command: 
> mvn test -pl fop-core -Dtest=PDFAttachmentTestCase
> I get the following output:
> Running org.apache.fop.pdf.PDFAttachmentTestCase
> Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.15 sec <<< 
> FAILURE! - in org.apache.fop.pdf.PDFAttachmentTestCase
> testAddEmbeddedFileDash(org.apache.fop.pdf.PDFAttachmentTestCase)  Time 
> elapsed: 0.003 sec  <<< ERROR!
> {*}java.lang.IllegalStateException: No embedded file with name filename 
> present{*}.
> at org.apache.fop.pdf.PDFFactory.getActionForEmbeddedFile(PDFFactory.java:728)
> at org.apache.fop.pdf.PDFFactory.getExternalAction(PDFFactory.java:600)
> at 
> org.apache.fop.render.pdf.PDFDocumentNavigationHandler.getAction(PDFDocumentNavigationHandler.java:174)
> at 
> org.apache.fop.render.pdf.PDFDocumentNavigationHandler.renderLink(PDFDocumentNavigationHandler.java:108)
> at 
> org.apache.fop.pdf.PDFAttachmentTestCase.testAddEmbeddedFileDash(PDFAttachmentTestCase.java:119)
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (FOP-3173) cannot include attachment whose name contains hash ('#') in the name

2024-04-03 Thread BlueMountain (Jira)


[ 
https://issues.apache.org/jira/browse/FOP-3173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17833714#comment-17833714
 ] 

BlueMountain commented on FOP-3173:
---

hi peter,

thank you for your prompt reply.

i actually made the test case work using ...

```
{color:#9e880d}@Test
{color}{color:#0033b3}public void {color}{color:#00627a}testAddEmbeddedFileDash 
{color}() {color:#0033b3}throws {color}{color:#00}IFException {color}{
{color:#00}  PDFDocumentHandler docHandler {color}= {color:#0033b3}new 
{color}PDFDocumentHandler({color:#0033b3}new 
{color}IFContext({color:#871094}ua{color}));
{color:#00}  docHandler{color}.setFontInfo({color:#0033b3}new 
{color}FontInfo());
{color:#00}  ByteArrayOutputStream out {color}= {color:#0033b3}new 
{color}ByteArrayOutputStream();
{color:#00}  docHandler{color}.setResult({color:#0033b3}new 
{color}StreamResult({color:#00}out{color}));
{color:#00}  docHandler{color}.startDocument();
{color:#00}  docHandler{color}.startPage({color:#1750eb}0{color}, 
{color:#067d17}""{color}, {color:#067d17}""{color}, {color:#0033b3}new 
{color}Dimension());
{color:#00}  String unicodeFilename {color}= 
{color:#067d17}"filename#1.txt"{color};
{color:#00}  docHandler{color}.handleExtensionObject(
    {color:#0033b3}new   
{color}PDFEmbeddedFileAttachment({color:#00}unicodeFilename{color}, 
{color:#067d17}"src"{color}, {color:#067d17}"desc"{color})
  );
  *{color:#8c8c8c}// if the file name contains characters that are considered
{color}{color:#8c8c8c}  // as fragment or query, the 'embedded-file:${filename}
{color}{color:#8c8c8c}  // will fail at returning the actual file name
{color}{color:#8c8c8c}  // we are relying, here, on the URI to perform actual
{color}{color:#8c8c8c}  // character conversion
{color}{color:#8c8c8c}  {color}{color:#0033b3}final 
{color}{color:#00}String uri{color};*
  *{color:#0033b3}try {color}{*
    *{color:#00}URI tmp {color}= {color:#0033b3}new {color}URI 
({color:#067d17}"embedded-file"{color}, {color:#00}unicodeFilename{color}, 
{color:#0033b3}null{color});*
    *{color:#00}uri {color}= {color:#00}tmp{color}.toString ();*
  *}*
  *{color:#0033b3}catch {color}({color:#00}URISyntaxException e{color}) {*
    *{color:#0033b3}throw new {color}IllegalStateException 
({color:#00}e{color});*
  *}*
{color:#00}  docHandler{color}.getDocumentNavigationHandler().renderLink(
{color:#0033b3}    new {color}Link({color:#0033b3}new 
{color}URIAction({*}{color:#00}uri{color}{*}, {color:#0033b3}false{color}), 
{color:#0033b3}new {color}Rectangle())
  );
{color:#00}  docHandler{color}.endDocument();
}```

but actually, even doing some change in the original program to test the file, 
i was still getting errors.

the way embedded content was used in pdf was:
1- include it in the list of pdf attachments
2- include in the page, 1 link for each embedded attachment.

in order to allow access to these attachments either browsing the document, 
page by page ... or accessing directly the list of pdf embedded files from the 
pdf viewer application.

the fop was looking like:

```

{color:#00} {color}{color:#80}
...
{color}
{color:#00} {color}{color:#80}{color}
{color:#00} {color}{color:#80}{color}
{color:#00} {color}{color:#80}{color}
...

{color:#00} {color}{color:#80}{color}
{color:#00} {color}{color:#80}{color}{color:#00}error#1.log{color}{color:#80}{color}
{color:#00} {color}{color:#80}{color}```

the reported error was dumping stack trace that was carying:
java.lang.IllegalStateException: {+}No embedded file with name *error* 
present{+}.
    at 
org.apache.fop.pdf.PDFFactory.getActionForEmbeddedFile(PDFFactory.java:728)
    at org.apache.fop.pdf.PDFFactory.getExternalAction(PDFFactory.java:600)
    at 
org.apache.fop.render.pdf.PDFDocumentNavigationHandler.getAction(PDFDocumentNavigationHandler.java:174)
    at 
org.apache.fop.render.pdf.PDFDocumentNavigationHandler.renderLink(PDFDocumentNavigationHandler.java:108)
    at 
org.apache.fop.render.intermediate.IFRenderer.renderPage(IFRenderer.java:594)
    at org.apache.fop.area.RenderPagesModel.addPage(RenderPagesModel.java:123)

i was thinking the issue was comming from the  and it's 
filename ...
but the actual cause of the error was the link:

```

{color:#00} {color}{color:#80}{color}
{color:#00} {color}{color:#80}{color}{color:#00}error#1.log{color}{color:#80}{color}
{color:#00} {color}{color:#80}{color}```

i was able to correct the problem, by generating ...

```

{color:#00} {color}{color:#80}{color}
{color:#00} {color}{color:#80}{color}{color:#00}error#1.log{color}{color:#80}{color}
{color:#00} {color}{color:#80}{color}```

i therefore guess the issue can be closed:
{*}Q{*}: shall i close it myself ?

note: however, it would be good to keep some test 

[jira] [Commented] (FOP-3173) cannot include attachment whose name contains hash ('#') in the name

2024-04-01 Thread Peter Hull (Jira)


[ 
https://issues.apache.org/jira/browse/FOP-3173?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17832839#comment-17832839
 ] 

Peter Hull commented on FOP-3173:
-

I wonder if this is a bug actually, because the constructor for URIAction takes 
a URI (in string form) and it has correctly interpreted that as having a scheme 
of 'embedded-file', an ssp of 'filename' and a fragment of '1.txt'.

Your test will pass if you modify it a bit
{code:java}
    @Test
    public void testAddEmbeddedFileDash () throws IFException, 
java.net.URISyntaxException {
        PDFDocumentHandler docHandler = new PDFDocumentHandler(new 
IFContext(ua));
        docHandler.setFontInfo(new FontInfo());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        docHandler.setResult(new StreamResult(out));
        docHandler.startDocument();
        docHandler.startPage(0, "", "", new Dimension());
        docHandler.handleExtensionObject(new 
PDFEmbeddedFileAttachment("filename#1.txt", "src", "desc"));
        // ** MODIFY next 2 lines 
        URI uri = new URI("embedded-file", "filename#1.txt",null);
        docHandler.getDocumentNavigationHandler().renderLink(new Link(
            new URIAction(uri.toString(), false), new Rectangle()));
        docHandler.endDocument();
    }
{code}
Specifically the URI constructor will escape the hash in the filename (as 
'embedded-file:filename%231.txt')

It might be a good idea to add a constructor to URIAction which takes a URI as 
the first param, to encourage good behaviour.

> cannot include attachment whose name contains hash ('#') in the name
> 
>
> Key: FOP-3173
> URL: https://issues.apache.org/jira/browse/FOP-3173
> Project: FOP
>  Issue Type: Bug
>  Components: fo/unqualified
>Affects Versions: 2.9
>Reporter: BlueMountain
>Priority: Major
> Attachments: PDFAttachmentTestCase.java
>
>
> hi,
> we are relying on the fop to generate PDF given data held in database + file 
> storage.
> we need to represent some ( file.name, file.data) as a pdf embedded 
> attachment.
> some users have encountered issue when the file.name value carries hash sign 
> ('#')
> upon generating the pdf, an exception is thrown about missing attachment name.
> I have added a new test to the  PDFAttachmentTestCase class (see attachment) 
> to reproduce the issue.
> The added test that generates the error is:
> @Test
> public void testAddEmbeddedFileDash () throws IFException {
> PDFDocumentHandler docHandler = new PDFDocumentHandler(new IFContext(ua));
> docHandler.setFontInfo(new FontInfo());
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> docHandler.setResult(new StreamResult(out));
> docHandler.startDocument();
> docHandler.startPage(0, "", "", new Dimension());
> docHandler.handleExtensionObject(new 
> PDFEmbeddedFileAttachment("filename#1.txt", "src", "desc"));
> // issue occurs at this line
> *docHandler.getDocumentNavigationHandler().renderLink(new Link(*
>  *new URIAction("embedded-file:filename#1.txt", false), new Rectangle()));*
> docHandler.endDocument();
> }
>  
> running the command: 
> mvn test -pl fop-core -Dtest=PDFAttachmentTestCase
> I get the following output:
> Running org.apache.fop.pdf.PDFAttachmentTestCase
> Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.15 sec <<< 
> FAILURE! - in org.apache.fop.pdf.PDFAttachmentTestCase
> testAddEmbeddedFileDash(org.apache.fop.pdf.PDFAttachmentTestCase)  Time 
> elapsed: 0.003 sec  <<< ERROR!
> {*}java.lang.IllegalStateException: No embedded file with name filename 
> present{*}.
> at org.apache.fop.pdf.PDFFactory.getActionForEmbeddedFile(PDFFactory.java:728)
> at org.apache.fop.pdf.PDFFactory.getExternalAction(PDFFactory.java:600)
> at 
> org.apache.fop.render.pdf.PDFDocumentNavigationHandler.getAction(PDFDocumentNavigationHandler.java:174)
> at 
> org.apache.fop.render.pdf.PDFDocumentNavigationHandler.renderLink(PDFDocumentNavigationHandler.java:108)
> at 
> org.apache.fop.pdf.PDFAttachmentTestCase.testAddEmbeddedFileDash(PDFAttachmentTestCase.java:119)
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)