aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2022-01-19 09:53:53 +0000
committerSimon Steiner <ssteiner@apache.org>2022-01-19 09:53:53 +0000
commitbbd7343ba13043f8f78e175363037f052d648395 (patch)
treeb3c21059a74f4f6ec7fde7d3d46e528a08e50137 /fop-core
parentc21d1426d2bf612c24127c9ba1793bcaddded917 (diff)
downloadxmlgraphics-fop-bbd7343ba13043f8f78e175363037f052d648395.tar.gz
xmlgraphics-fop-bbd7343ba13043f8f78e175363037f052d648395.zip
FOP-2839: Links to pdf files with no scheme should open in pdf viewer
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1897193 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java3
-rw-r--r--fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java34
2 files changed, 23 insertions, 14 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
index 57f8a17a9..f0456a53f 100644
--- a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
+++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
@@ -589,6 +589,9 @@ public class PDFFactory {
if (filename == null) {
filename = uri.getSchemeSpecificPart();
}
+ if (scheme == null && filename.toLowerCase().endsWith(".pdf")) {
+ scheme = "file";
+ }
if (scheme == null) {
return new PDFUri(uri.toASCIIString());
} else if (scheme.equalsIgnoreCase("embedded-file")) {
diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java
index b4c6a5239..988a14668 100644
--- a/fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFLinkTestCase.java
@@ -123,12 +123,12 @@ public class PDFLinkTestCase {
{"/foo/bar 2.pdf", quote("<< /Type /Filespec /F (/foo/bar 2.pdf)")},
// PDF, Relative paths
- {"foobar.pdf", quote("<< /URI (foobar.pdf)")}, //34
- {"foo bar.pdf", quote("<< /URI (foo%20bar.pdf)")},
- {"./foobar.pdf", quote("<< /URI (./foobar.pdf)")},
- {"./foo bar.pdf", quote("<< /URI (./foo%20bar.pdf)")},
- {"../foobar.pdf", quote("<< /URI (../foobar.pdf)")},
- {"../foo bar.pdf", quote("<< /URI (../foo%20bar.pdf)")},
+ {"foobar.pdf", quote("<< /Type /Filespec /F (foobar.pdf)")}, //34
+ {"foo bar.pdf", quote("<< /Type /Filespec /F (foo bar.pdf)")},
+ {"./foobar.pdf", quote("<< /Type /Filespec /F (./foobar.pdf)")},
+ {"./foo bar.pdf", quote("<< /Type /Filespec /F (./foo bar.pdf)")},
+ {"../foobar.pdf", quote("<< /Type /Filespec /F (../foobar.pdf)")},
+ {"../foo bar.pdf", quote("<< /Type /Filespec /F (../foo bar.pdf)")},
// PDF, Windows network paths
{"\\\\foo\\bar.pdf", quote("<< /Type /Filespec /F (\\\\\\\\foo\\\\bar.pdf)")}, //40
@@ -165,12 +165,18 @@ public class PDFLinkTestCase {
+ quote("/D [ 2 /XYZ null null null ]")},
// PDF with fragments, Relative paths
- {"foobar.pdf#dest=aa", quote("<< /URI (foobar.pdf#dest=aa)")}, //55
- {"foo bar.pdf#page=2", quote("<< /URI (foo%20bar.pdf#page=2)")},
- {"./foobar.pdf#dest=aa", quote("<< /URI (./foobar.pdf#dest=aa)")},
- {"./foo bar.pdf#page=2", quote("<< /URI (./foo%20bar.pdf#page=2)")},
- {"../foobar.pdf#dest=aa", quote("<< /URI (../foobar.pdf#dest=aa)")},
- {"../foo bar.pdf#page=2", quote("<< /URI (../foo%20bar.pdf#page=2)")},
+ {"foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (foobar.pdf)") + ".*" + quote("/S /GoToR") + ".*"
+ + quote("/D (aa)")}, //55
+ {"foo bar.pdf#page=2", quote("<< /Type /Filespec /F (foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*"
+ + quote("/D [ 2 /XYZ null null null ]")},
+ {"./foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (./foobar.pdf)") + ".*" + quote("/S /GoToR")
+ + ".*" + quote("/D (aa)")},
+ {"./foo bar.pdf#page=2", quote("<< /Type /Filespec /F (./foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*"
+ + quote("/D [ 2 /XYZ null null null ]")},
+ {"../foobar.pdf#dest=aa", quote("<< /Type /Filespec /F (../foobar.pdf)") + ".*" + quote("/S /GoToR")
+ + ".*" + quote("/D (aa)")},
+ {"../foo bar.pdf#page=2", quote("<< /Type /Filespec /F (../foo bar.pdf)") + ".*" + quote("/S /GoToR") + ".*"
+ + quote("/D [ 2 /XYZ null null null ]")},
// PDF with fragments, Windows network paths
{"\\\\foo\\bar.pdf#dest=aa", quote("<< /Type /Filespec /F (\\\\\\\\foo\\\\bar.pdf)") + ".*"
@@ -393,7 +399,7 @@ public class PDFLinkTestCase {
{"file:examples.html", quote("<< /Type /Filespec /F (examples.html)")},
// parenthesis
- {"simple_report_(version2.pdf", quote("<< /URI (simple_report_\\(version2.pdf)")}
+ {"simple_report_(version2.pdf", quote("<< /Type /Filespec /F (simple_report_\\(version2.pdf)")}
});
}
@@ -415,6 +421,6 @@ public class PDFLinkTestCase {
Pattern r = Pattern.compile(expected);
Matcher m = r.matcher(outString);
- Assert.assertTrue(m.find());
+ Assert.assertTrue(target + " " + outString, m.find());
}
}