[jira] [Commented] (FOP-2146) Wrong FontCache-Directory used for not existing userHome in FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)

2021-01-12 Thread Christopher Watford (Jira)


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

Christopher Watford commented on FOP-2146:
--

I was able to fake this out for AWS Lambda with the following:
{code:java}
String oldUserHome = System.getProperty("user.home");
System.setProperty("user.home", 
System.getProperty("java.io.tmpdir"));
try {
exporter.exportToFile(book, pageFormat, 
tempFile.getAbsolutePath());
} finally {
System.setProperty("user.home", oldUserHome);
}
{code}


> Wrong FontCache-Directory used for not existing userHome in 
> FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)
> ---
>
> Key: FOP-2146
> URL: https://issues.apache.org/jira/browse/FOP-2146
> Project: FOP
>  Issue Type: Bug
>  Components: font/unqualified
>Affects Versions: 1.1
> Environment: Operating System: All
> Platform: All
>Reporter: mg
>
> Method getDefaultCacheFile() returns an invalid file name if the user has no 
> home directory set. In that case the name of the fop user directory 
> (FOP_USER_DIR!) is returned and not the name of the cache file 
> (DEFAULT_CACHE_FILENAME).
> Wrong Code:
> public static File getDefaultCacheFile(boolean forWriting) {
> File userHome = getUserHome();
> if (userHome != null) {
> File fopUserDir = new File(userHome, FOP_USER_DIR);
> if (forWriting) {
> boolean writable = fopUserDir.canWrite();
> if (!fopUserDir.exists()) {
> writable = fopUserDir.mkdir();
> }
> if (!writable) {
> userHome = getTempDirectory();
> fopUserDir = new File(userHome, FOP_USER_DIR);
> fopUserDir.mkdir();
> }
> }
> return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
> }
> return new File(FOP_USER_DIR);
> }
> If getUserHome() does not return a directory the default name must be 
> returned (and not the name of the directory):
> return new File(DEFAULT_CACHE_FILENAME);



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (FOP-2146) Wrong FontCache-Directory used for not existing userHome in FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)

2021-01-12 Thread Christopher Watford (Jira)


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

Christopher Watford commented on FOP-2146:
--

When you use the PDFTranscoder, it is not possible to disable the font cache or 
change the font cache file:
{code:java}
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = 
cfgBuilder.build(getClass().getResourceAsStream("fop-config.xml"));

PDFTranscoder transcoder = new PDFTranscoder(); 
transcoder.configure(cfg);

TranscoderInput input = new TranscoderInput(getSVGDocument());
ByteArrayOutputStream output = new ByteArrayOutputStream();
TranscoderOutput transOutput = new TranscoderOutput(output);
transcoder.transcode(input, transOutput);
{code}
This is because when you dive into the guts:
 # PDFDocumentGraphics2DConfigurator gets created and configures itself using 
the configuration passed to the transcoder.
 # A new FontManager is created within PDFDocumentGraphics2DConfigurator, which 
DOES NOT use the configuration passed to the transcoder.
 # This FontManager is then used in DefaultFontConfigurator, and if there were 
any system fonts, they are saved.
 # The FontManager at this point is configured to use a relative directory 
called ".fop" which ends up being local to a read-only file system.

This is in spite of either use-cache being false, or cache-file pointing to 
another location.

The FontManager created within the PDFDocumentGraphics2DConfigurator needs to 
get its cache location from the FOP configuration.

> Wrong FontCache-Directory used for not existing userHome in 
> FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)
> ---
>
> Key: FOP-2146
> URL: https://issues.apache.org/jira/browse/FOP-2146
> Project: FOP
>  Issue Type: Bug
>  Components: font/unqualified
>Affects Versions: 1.1
> Environment: Operating System: All
> Platform: All
>Reporter: mg
>
> Method getDefaultCacheFile() returns an invalid file name if the user has no 
> home directory set. In that case the name of the fop user directory 
> (FOP_USER_DIR!) is returned and not the name of the cache file 
> (DEFAULT_CACHE_FILENAME).
> Wrong Code:
> public static File getDefaultCacheFile(boolean forWriting) {
> File userHome = getUserHome();
> if (userHome != null) {
> File fopUserDir = new File(userHome, FOP_USER_DIR);
> if (forWriting) {
> boolean writable = fopUserDir.canWrite();
> if (!fopUserDir.exists()) {
> writable = fopUserDir.mkdir();
> }
> if (!writable) {
> userHome = getTempDirectory();
> fopUserDir = new File(userHome, FOP_USER_DIR);
> fopUserDir.mkdir();
> }
> }
> return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
> }
> return new File(FOP_USER_DIR);
> }
> If getUserHome() does not return a directory the default name must be 
> returned (and not the name of the directory):
> return new File(DEFAULT_CACHE_FILENAME);



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (FOP-2146) Wrong FontCache-Directory used for not existing userHome in FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)

2020-05-27 Thread Simon Steiner (Jira)


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

Simon Steiner commented on FOP-2146:


I think you use EnvironmentalProfileFactory.createRestrictedIO to disable font 
caching
{code:java}
String fopxconf = "";
ResourceResolver cloudResourceResolver = 
ResourceResolverFactory.createDefaultResourceResolver();
FopFactoryBuilder confBuilder = new FopConfParser(new 
ByteArrayInputStream(fopxconf.getBytes()),
EnvironmentalProfileFactory.createRestrictedIO(new 
File(".").toURI(), cloudResourceResolver)).getFopFactoryBuilder();
FopFactory fopFactory = confBuilder.build();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
FileOutputStream fos = new FileOutputStream("out.png");
Fop fop = fopFactory.newFop("image/png", foUserAgent, fos);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Source src = new StreamSource(new ByteArrayInputStream(fo.getBytes()));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
fos.close();

{code}

> Wrong FontCache-Directory used for not existing userHome in 
> FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)
> ---
>
> Key: FOP-2146
> URL: https://issues.apache.org/jira/browse/FOP-2146
> Project: FOP
>  Issue Type: Bug
>  Components: font/unqualified
>Affects Versions: 1.1
> Environment: Operating System: All
> Platform: All
>Reporter: mg
>
> Method getDefaultCacheFile() returns an invalid file name if the user has no 
> home directory set. In that case the name of the fop user directory 
> (FOP_USER_DIR!) is returned and not the name of the cache file 
> (DEFAULT_CACHE_FILENAME).
> Wrong Code:
> public static File getDefaultCacheFile(boolean forWriting) {
> File userHome = getUserHome();
> if (userHome != null) {
> File fopUserDir = new File(userHome, FOP_USER_DIR);
> if (forWriting) {
> boolean writable = fopUserDir.canWrite();
> if (!fopUserDir.exists()) {
> writable = fopUserDir.mkdir();
> }
> if (!writable) {
> userHome = getTempDirectory();
> fopUserDir = new File(userHome, FOP_USER_DIR);
> fopUserDir.mkdir();
> }
> }
> return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
> }
> return new File(FOP_USER_DIR);
> }
> If getUserHome() does not return a directory the default name must be 
> returned (and not the name of the directory):
> return new File(DEFAULT_CACHE_FILENAME);



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (FOP-2146) Wrong FontCache-Directory used for not existing userHome in FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)

2020-05-05 Thread Jukka Matilainen (Jira)


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

Jukka Matilainen commented on FOP-2146:
---

FontCache.g{{etUserHome()}} method returns {{null}} if the {{user.home}} system 
property is unset or the directory pointed to by it does not exist. The latter 
seems to be the case on the AWS Lambda Java runtime.

> Wrong FontCache-Directory used for not existing userHome in 
> FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)
> ---
>
> Key: FOP-2146
> URL: https://issues.apache.org/jira/browse/FOP-2146
> Project: FOP
>  Issue Type: Bug
>  Components: font/unqualified
>Affects Versions: 1.1
> Environment: Operating System: All
> Platform: All
>Reporter: mg
>
> Method getDefaultCacheFile() returns an invalid file name if the user has no 
> home directory set. In that case the name of the fop user directory 
> (FOP_USER_DIR!) is returned and not the name of the cache file 
> (DEFAULT_CACHE_FILENAME).
> Wrong Code:
> public static File getDefaultCacheFile(boolean forWriting) {
> File userHome = getUserHome();
> if (userHome != null) {
> File fopUserDir = new File(userHome, FOP_USER_DIR);
> if (forWriting) {
> boolean writable = fopUserDir.canWrite();
> if (!fopUserDir.exists()) {
> writable = fopUserDir.mkdir();
> }
> if (!writable) {
> userHome = getTempDirectory();
> fopUserDir = new File(userHome, FOP_USER_DIR);
> fopUserDir.mkdir();
> }
> }
> return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
> }
> return new File(FOP_USER_DIR);
> }
> If getUserHome() does not return a directory the default name must be 
> returned (and not the name of the directory):
> return new File(DEFAULT_CACHE_FILENAME);



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (FOP-2146) Wrong FontCache-Directory used for not existing userHome in FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)

2020-01-13 Thread Chris Bowditch (Jira)


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

Chris Bowditch commented on FOP-2146:
-

I know this is an old bug, but I'm wondering what situation can user.home 
environment variable be unset? If that only on a specific operating system?

> Wrong FontCache-Directory used for not existing userHome in 
> FontCache.getDefaultCacheFile() (Bug 47786 was not fixed correctly)
> ---
>
> Key: FOP-2146
> URL: https://issues.apache.org/jira/browse/FOP-2146
> Project: FOP
>  Issue Type: Bug
>  Components: font/unqualified
>Affects Versions: 1.1
> Environment: Operating System: All
> Platform: All
>Reporter: mg
>
> Method getDefaultCacheFile() returns an invalid file name if the user has no 
> home directory set. In that case the name of the fop user directory 
> (FOP_USER_DIR!) is returned and not the name of the cache file 
> (DEFAULT_CACHE_FILENAME).
> Wrong Code:
> public static File getDefaultCacheFile(boolean forWriting) {
> File userHome = getUserHome();
> if (userHome != null) {
> File fopUserDir = new File(userHome, FOP_USER_DIR);
> if (forWriting) {
> boolean writable = fopUserDir.canWrite();
> if (!fopUserDir.exists()) {
> writable = fopUserDir.mkdir();
> }
> if (!writable) {
> userHome = getTempDirectory();
> fopUserDir = new File(userHome, FOP_USER_DIR);
> fopUserDir.mkdir();
> }
> }
> return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
> }
> return new File(FOP_USER_DIR);
> }
> If getUserHome() does not return a directory the default name must be 
> returned (and not the name of the directory):
> return new File(DEFAULT_CACHE_FILENAME);



--
This message was sent by Atlassian Jira
(v8.3.4#803005)