You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ad...@apache.org on 2005/09/28 21:37:31 UTC

svn commit: r292280 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java

Author: adelmelle
Date: Wed Sep 28 12:37:26 2005
New Revision: 292280

URL: http://svn.apache.org/viewcvs?rev=292280&view=rev
Log:
Added UA initialization from user-config

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java?rev=292280&r1=292279&r2=292280&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java Wed Sep 28 12:37:26 2005
@@ -20,6 +20,9 @@
 
 // Java
 import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -325,6 +328,12 @@
      */
     public void setUserConfig(Configuration userConfig) {
         this.userConfig = userConfig;
+        try {
+            initUserConfig();
+        } catch (ConfigurationException cfge) {
+            log.error("Error initializing User Agent configuration: "
+                    + cfge.getMessage());
+        }
     }
 
     /**
@@ -333,6 +342,51 @@
      */
     public Configuration getUserConfig() {
         return userConfig;
+    }
+    
+    /**
+     * Initializes user agent settings from the user configuration
+     * file, if present: baseURL, resolution, default page size,...
+     * 
+     * @throws ConfigurationException when there is an entry that 
+     *          misses the required attribute
+     */
+    public void initUserConfig() throws ConfigurationException {
+        log.info("Initializing User Agent Configuration");
+        Configuration cfgUserAgent = userConfig.getChild("userAgent");
+        if (cfgUserAgent.getChild("base", false) != null) {
+            try {
+                String cfgBaseDir = cfgUserAgent.getChild("base")
+                                    .getAttribute("url");
+                File dir = new File(cfgBaseDir);
+                if (dir.isDirectory()) {
+                    cfgBaseDir = "file://" + dir.getCanonicalPath() 
+                        + System.getProperty("file.separator");
+                }
+                URL cfgBaseURL = new URL(cfgBaseDir);
+                setBaseURL(cfgBaseDir);
+            } catch (MalformedURLException mue) {
+                log.error("Base URL in user config is malformed!");
+            } catch (IOException ioe) {
+                log.error("Error converting relative base directory to absolute URL.");
+            }
+            log.info("Base URL set to: " + baseURL);
+        }
+        if (cfgUserAgent.getChild("pixelToMillimeter", false) != null) {
+            this.px2mm = cfgUserAgent.getChild("pixelToMillimeter")
+                            .getAttributeAsFloat("value", DEFAULT_PX2MM);
+            log.info("pixelToMillimeter set to: " + px2mm);
+        }
+        if (cfgUserAgent.getChild("pageHeight", false) != null) {
+            setPageHeight(cfgUserAgent.getChild("pageHeight")
+                            .getAttribute("value"));
+            log.info("Default page-height set to: " + pageHeight);
+        }
+        if (cfgUserAgent.getChild("pageWidth", false) != null) {
+            setPageWidth(cfgUserAgent.getChild("pageWidth")
+                            .getAttribute("value"));
+            log.info("Default page-width set to: " + pageWidth);
+        }
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Re: svn commit: r292280 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Sep 28, 2005, at 22:29, Jeremias Maerki wrote:

>
> On 28.09.2005 22:14:29 Andreas L Delmelle wrote:
> <snip/>
>>> The fact that we let the user agent object handle the configuration,
>>> does not need to be reflected in the configuration file. I would
>>> prefer to see these configuration elements as direct children of the
>>> top level element, or perhaps some of them wrapped in an element like
>>> pagesettings.
>>
>> No objection from me.
>> Anyone with other opinions before I make this alteration?
>
> No, Simon's suggestion is fine.

Since you were the original author of the fop.xconf file, that's enough 
for me :-)

IOW: Done!

Cheers,

Andreas


Re: svn commit: r292280 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 28.09.2005 22:14:29 Andreas L Delmelle wrote:
<snip/>
> > The fact that we let the user agent object handle the configuration,
> > does not need to be reflected in the configuration file. I would
> > prefer to see these configuration elements as direct children of the
> > top level element, or perhaps some of them wrapped in an element like
> > pagesettings.
> 
> No objection from me.
> Anyone with other opinions before I make this alteration?

No, Simon's suggestion is fine.

Jeremias Maerki


Re: svn commit: r292280 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Sep 28, 2005, at 22:09, Simon Pepping wrote:

Hi Simon,

> On Wed, Sep 28, 2005 at 07:37:31PM -0000, adelmelle@apache.org wrote:
>>
>> +    public void initUserConfig() throws ConfigurationException {
>> +        log.info("Initializing User Agent Configuration");
>> +        Configuration cfgUserAgent = 
>> userConfig.getChild("userAgent");
>
> Why do you wrap these configuration elements in a userAgent element?

Well, I didn't modify the fop.xconf file myself. The general UA config 
entries were already there, and I just added the page-settings in 
there...

> The fact that we let the user agent object handle the configuration,
> does not need to be reflected in the configuration file. I would
> prefer to see these configuration elements as direct children of the
> top level element, or perhaps some of them wrapped in an element like
> pagesettings.

No objection from me.
Anyone with other opinions before I make this alteration?

Cheers,

Andreas


Re: svn commit: r292280 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java

Posted by Simon Pepping <sp...@leverkruid.nl>.
Andreas,

On Wed, Sep 28, 2005 at 07:37:31PM -0000, adelmelle@apache.org wrote:
> URL: http://svn.apache.org/viewcvs?rev=292280&view=rev
> Log:
> Added UA initialization from user-config
> 
> Modified:
>     xmlgraphics/fop/trunk/src/java/org/apache/fop/apps/FOUserAgent.java
> 
> +    public void initUserConfig() throws ConfigurationException {
> +        log.info("Initializing User Agent Configuration");
> +        Configuration cfgUserAgent = userConfig.getChild("userAgent");

Why do you wrap these configuration elements in a userAgent element?
The fact that we let the user agent object handle the configuration,
does not need to be reflected in the configuration file. I would
prefer to see these configuration elements as direct children of the
top level element, or perhaps some of them wrapped in an element like
pagesettings.

> +        if (cfgUserAgent.getChild("base", false) != null) {
> +            try {
> +                String cfgBaseDir = cfgUserAgent.getChild("base")
> +                                    .getAttribute("url");
> +                File dir = new File(cfgBaseDir);
> +                if (dir.isDirectory()) {
> +                    cfgBaseDir = "file://" + dir.getCanonicalPath() 
> +                        + System.getProperty("file.separator");
> +                }
> +                URL cfgBaseURL = new URL(cfgBaseDir);
> +                setBaseURL(cfgBaseDir);
> +            } catch (MalformedURLException mue) {
> +                log.error("Base URL in user config is malformed!");
> +            } catch (IOException ioe) {
> +                log.error("Error converting relative base directory to absolute URL.");
> +            }
> +            log.info("Base URL set to: " + baseURL);
> +        }
> +        if (cfgUserAgent.getChild("pixelToMillimeter", false) != null) {
> +            this.px2mm = cfgUserAgent.getChild("pixelToMillimeter")
> +                            .getAttributeAsFloat("value", DEFAULT_PX2MM);
> +            log.info("pixelToMillimeter set to: " + px2mm);
> +        }
> +        if (cfgUserAgent.getChild("pageHeight", false) != null) {
> +            setPageHeight(cfgUserAgent.getChild("pageHeight")
> +                            .getAttribute("value"));
> +            log.info("Default page-height set to: " + pageHeight);
> +        }
> +        if (cfgUserAgent.getChild("pageWidth", false) != null) {
> +            setPageWidth(cfgUserAgent.getChild("pageWidth")
> +                            .getAttribute("value"));
> +            log.info("Default page-width set to: " + pageWidth);
> +        }
>      }

Regards, Simon

-- 
Simon Pepping
home page: http://www.leverkruid.nl