You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Esse <es...@widenarrow.se> on 2010/08/25 13:25:11 UTC

Relative paths when running FOP as servlet (Tomcat)

Hi fopusers!

Specs:
Latest fop (1.0)
Latest tomcat (7.x)

I’m using the fop servlet example in tomcat, with a config file. 

Right now, FOpServlet is modified like this:

protected void configureFopFactory() {
        try {
                fopFactory.setUserConfig(new File("/conf/fop.xconf"));
        } catch (SAXException e) {
                System.out.println(e);
        } catch (IOException e) {
                System.out.println(e);
        }
    }

However, the path for the config file in the above example is
C:\conf\fop.xconf . 

How to make config file path relative(in jar/war/tomcat folder?

Really anywhere would do except a hard path, like [JAVA_HOME]/conf/fop.xconf
or something like that.


Please help :)


-- 
View this message in context: http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531194.html
Sent from the FOP - Users mailing list archive at Nabble.com.


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


Re: Relative paths when running FOP as servlet (Tomcat)

Posted by Martin Jacobson <ja...@gmail.com>.
Hi Esse,

Class naming? You can call the listener anything you like -
"BarakObamaListener" if you wish! - I prefer to name classes for what
they *do* rather than what they *are*, but tastes vary. All that
matters is that it implements the "ServletContextListener" interface.

Whether you want to add the interface into an existing class is again
up to you, but I wouldn't. Webapp activation and shutdown are very
specific activities, and I like to keep them separate from classes
that do other things.

BTW, we seem to be straying off-topic.

HTH
Martin

On 26 August 2010 10:20, Esse <es...@widenarrow.se> wrote:
>
> Thanks Martin!
>
> Theoretically, i know -almost- what to do now ;)
>
> I know we really get into the basics here... How about listener naming, does
> it matter and i which ways? But the listener, should i create a separate
> WebInitializer.java for that class, or should i merge the ContextListener
> with any of the existing code? There is a
> ServletContextURIResolver.java-file(quoted below:)
>
> /**
>  * This class is a URIResolver implementation that provides access to
> resources in the WEB-INF
>  * directory of a web application using "servlet-content:" URIs.
>  */
> public class ServletContextURIResolver implements URIResolver {
>
>    /** The protocol name for the servlet context URIs. */
>    public static final String SERVLET_CONTEXT_PROTOCOL =
> "servlet-context:";
>
>    private ServletContext servletContext;
> ...
>
> Thanks again!
>
>
>
> Martin Jacobson wrote:
>>
>> Hi Esse,
>>
>> The web.xml stuff I gave you goes right at the beginning, before the
>> first <servlet> tag.
>>
>> It took me a while to get my head round the app lifecycle, so I
>> understand your confusion! The <listener>  allows you to write a class
>> that is guaranteed to be executed before any of your servlets. The
>> interface for ContextListener defines a method for when your context
>> (ie, your web app) is initialized (first loaded), and another for when
>> the context is destroyed (shut down), so this is where you open your
>> database connection, configure FOP, etc etc, at startup, and close
>> everything at shutdown.
>>
>> I hope that helps - it's late here in Helsinki, so I'm a bit sleepy!
>>
>> Martin
>>
>> On 25 August 2010 15:10, Esse <es...@widenarrow.se> wrote:
>>>
>>> Hi Martin!
>>>
>>> Thanks a lot for your help! However, i'm really a rookie and i need some
>>> clarification to understand :)
>>>
>>> How should i modify my web.xml(below)?
>>>
>>> web-app>
>>>        <!-- Servlets -->
>>>  <servlet>
>>>    <servlet-name>Fop</servlet-name>
>>>    <servlet-class>org.apache.fop.servlet.FopServlet</servlet-class>
>>>  </servlet>
>>>  <servlet>
>>>    <servlet-name>FopPrint</servlet-name>
>>>    <servlet-class>org.apache.fop.servlet.FopPrintServlet</servlet-class>
>>>  </servlet>
>>>  <!-- Servlet mappings -->
>>>  <servlet-mapping>
>>>    <servlet-name>Fop</servlet-name>
>>>    <url-pattern>/</url-pattern>
>>>  </servlet-mapping>
>>>  <servlet-mapping>
>>>    <servlet-name>FopPrint</servlet-name>
>>>    <url-pattern>/fopprint</url-pattern>
>>>  </servlet-mapping>
>>> </web-app>
>>>
>>>
>>>
>>>
>>> Martin Jacobson wrote:
>>>>
>>>> This is what I would do...
>>>>
>>>> 0) move the config file to be part of the war file, inside WEB-INF
>>>>
>>>> 1) web.xml
>>>>
>>>> <?xml version="1.0" encoding="ISO-8859-1"?>
>>>>
>>>> <!DOCTYPE web-app
>>>>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>>>>     "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
>>>>
>>>> <web-app>
>>>>     <display-name>cartoWeb - vector map server</display-name>
>>>>
>>>>       <context-param>
>>>>               <param-name>configuration-file</param-name>
>>>>               <param-value>WEB-INF/fop.xconf</param-value>
>>>>       </context-param>
>>>>
>>>>       <listener>
>>>>
>>>> <listener-class>com.emc.carto.web.servlet.WebAppInitializer</listener-class>
>>>>       </listener>
>>>> ...
>>>>
>>>> 2) Listener
>>>>
>>>> public class WebAppInitializer implements ServletContextListener
>>>> {
>>>>       ServletContext ctx = null;
>>>>
>>>>       public void contextInitialized(ServletContextEvent sce)
>>>>       {
>>>>               ctx = sce.getServletContext();
>>>>               String configFileName =
>>>> ctx.getInitParameter("configuration-file");
>>>>               String realConfigFile = ctx.getRealPath(configFileName);
>>>>                try {
>>>>                      fopFactory.setUserConfig(new File(realConfigFile));
>>>>               }
>>>> etc.
>>>>
>>>>
>>>> HTH
>>>> Martin
>>>>
>>>>
>>>>
>>>>
>>>> On 25 August 2010 14:25, Esse <es...@widenarrow.se> wrote:
>>>>>
>>>>> Hi fopusers!
>>>>>
>>>>> Specs:
>>>>> Latest fop (1.0)
>>>>> Latest tomcat (7.x)
>>>>>
>>>>> I’m using the fop servlet example in tomcat, with a config file.
>>>>>
>>>>> Right now, FOpServlet is modified like this:
>>>>>
>>>>> protected void configureFopFactory() {
>>>>>        try {
>>>>>                fopFactory.setUserConfig(new File("/conf/fop.xconf"));
>>>>>        } catch (SAXException e) {
>>>>>                System.out.println(e);
>>>>>        } catch (IOException e) {
>>>>>                System.out.println(e);
>>>>>        }
>>>>>    }
>>>>>
>>>>> However, the path for the config file in the above example is
>>>>> C:\conf\fop.xconf .
>>>>>
>>>>> How to make config file path relative(in jar/war/tomcat folder?
>>>>>
>>>>> Really anywhere would do except a hard path, like
>>>>> [JAVA_HOME]/conf/fop.xconf
>>>>> or something like that.
>>>>>
>>>>>
>>>>> Please help :)
>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531194.html
>>>>> Sent from the FOP - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>>>>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> From my MacBook Pro
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>>>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531548.html
>>> Sent from the FOP - Users mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>>
>>>
>>
>>
>>
>> --
>> From my MacBook Pro
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29539561.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>
>



-- 
>From my MacBook Pro

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


Re: Relative paths when running FOP as servlet (Tomcat)

Posted by Esse <es...@widenarrow.se>.
Thanks Martin!

Theoretically, i know -almost- what to do now ;) 

I know we really get into the basics here... How about listener naming, does
it matter and i which ways? But the listener, should i create a separate
WebInitializer.java for that class, or should i merge the ContextListener
with any of the existing code? There is a
ServletContextURIResolver.java-file(quoted below:)

/**
 * This class is a URIResolver implementation that provides access to
resources in the WEB-INF
 * directory of a web application using "servlet-content:" URIs.
 */
public class ServletContextURIResolver implements URIResolver {

    /** The protocol name for the servlet context URIs. */
    public static final String SERVLET_CONTEXT_PROTOCOL =
"servlet-context:";

    private ServletContext servletContext;
...

Thanks again! 



Martin Jacobson wrote:
> 
> Hi Esse,
> 
> The web.xml stuff I gave you goes right at the beginning, before the
> first <servlet> tag.
> 
> It took me a while to get my head round the app lifecycle, so I
> understand your confusion! The <listener>  allows you to write a class
> that is guaranteed to be executed before any of your servlets. The
> interface for ContextListener defines a method for when your context
> (ie, your web app) is initialized (first loaded), and another for when
> the context is destroyed (shut down), so this is where you open your
> database connection, configure FOP, etc etc, at startup, and close
> everything at shutdown.
> 
> I hope that helps - it's late here in Helsinki, so I'm a bit sleepy!
> 
> Martin
> 
> On 25 August 2010 15:10, Esse <es...@widenarrow.se> wrote:
>>
>> Hi Martin!
>>
>> Thanks a lot for your help! However, i'm really a rookie and i need some
>> clarification to understand :)
>>
>> How should i modify my web.xml(below)?
>>
>> web-app>
>>        <!-- Servlets -->
>>  <servlet>
>>    <servlet-name>Fop</servlet-name>
>>    <servlet-class>org.apache.fop.servlet.FopServlet</servlet-class>
>>  </servlet>
>>  <servlet>
>>    <servlet-name>FopPrint</servlet-name>
>>    <servlet-class>org.apache.fop.servlet.FopPrintServlet</servlet-class>
>>  </servlet>
>>  <!-- Servlet mappings -->
>>  <servlet-mapping>
>>    <servlet-name>Fop</servlet-name>
>>    <url-pattern>/</url-pattern>
>>  </servlet-mapping>
>>  <servlet-mapping>
>>    <servlet-name>FopPrint</servlet-name>
>>    <url-pattern>/fopprint</url-pattern>
>>  </servlet-mapping>
>> </web-app>
>>
>>
>>
>>
>> Martin Jacobson wrote:
>>>
>>> This is what I would do...
>>>
>>> 0) move the config file to be part of the war file, inside WEB-INF
>>>
>>> 1) web.xml
>>>
>>> <?xml version="1.0" encoding="ISO-8859-1"?>
>>>
>>> <!DOCTYPE web-app
>>>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>>>     "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
>>>
>>> <web-app>
>>>     <display-name>cartoWeb - vector map server</display-name>
>>>
>>>       <context-param>
>>>               <param-name>configuration-file</param-name>
>>>               <param-value>WEB-INF/fop.xconf</param-value>
>>>       </context-param>
>>>
>>>       <listener>
>>>
>>> <listener-class>com.emc.carto.web.servlet.WebAppInitializer</listener-class>
>>>       </listener>
>>> ...
>>>
>>> 2) Listener
>>>
>>> public class WebAppInitializer implements ServletContextListener
>>> {
>>>       ServletContext ctx = null;
>>>
>>>       public void contextInitialized(ServletContextEvent sce)
>>>       {
>>>               ctx = sce.getServletContext();
>>>               String configFileName =
>>> ctx.getInitParameter("configuration-file");
>>>               String realConfigFile = ctx.getRealPath(configFileName);
>>>                try {
>>>                      fopFactory.setUserConfig(new File(realConfigFile));
>>>               }
>>> etc.
>>>
>>>
>>> HTH
>>> Martin
>>>
>>>
>>>
>>>
>>> On 25 August 2010 14:25, Esse <es...@widenarrow.se> wrote:
>>>>
>>>> Hi fopusers!
>>>>
>>>> Specs:
>>>> Latest fop (1.0)
>>>> Latest tomcat (7.x)
>>>>
>>>> I’m using the fop servlet example in tomcat, with a config file.
>>>>
>>>> Right now, FOpServlet is modified like this:
>>>>
>>>> protected void configureFopFactory() {
>>>>        try {
>>>>                fopFactory.setUserConfig(new File("/conf/fop.xconf"));
>>>>        } catch (SAXException e) {
>>>>                System.out.println(e);
>>>>        } catch (IOException e) {
>>>>                System.out.println(e);
>>>>        }
>>>>    }
>>>>
>>>> However, the path for the config file in the above example is
>>>> C:\conf\fop.xconf .
>>>>
>>>> How to make config file path relative(in jar/war/tomcat folder?
>>>>
>>>> Really anywhere would do except a hard path, like
>>>> [JAVA_HOME]/conf/fop.xconf
>>>> or something like that.
>>>>
>>>>
>>>> Please help :)
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531194.html
>>>> Sent from the FOP - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>>>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> From my MacBook Pro
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531548.html
>> Sent from the FOP - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>
>>
> 
> 
> 
> -- 
> From my MacBook Pro
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29539561.html
Sent from the FOP - Users mailing list archive at Nabble.com.


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


Re: Relative paths when running FOP as servlet (Tomcat)

Posted by Martin Jacobson <ja...@gmail.com>.
Hi Esse,

The web.xml stuff I gave you goes right at the beginning, before the
first <servlet> tag.

It took me a while to get my head round the app lifecycle, so I
understand your confusion! The <listener>  allows you to write a class
that is guaranteed to be executed before any of your servlets. The
interface for ContextListener defines a method for when your context
(ie, your web app) is initialized (first loaded), and another for when
the context is destroyed (shut down), so this is where you open your
database connection, configure FOP, etc etc, at startup, and close
everything at shutdown.

I hope that helps - it's late here in Helsinki, so I'm a bit sleepy!

Martin

On 25 August 2010 15:10, Esse <es...@widenarrow.se> wrote:
>
> Hi Martin!
>
> Thanks a lot for your help! However, i'm really a rookie and i need some
> clarification to understand :)
>
> How should i modify my web.xml(below)?
>
> web-app>
>        <!-- Servlets -->
>  <servlet>
>    <servlet-name>Fop</servlet-name>
>    <servlet-class>org.apache.fop.servlet.FopServlet</servlet-class>
>  </servlet>
>  <servlet>
>    <servlet-name>FopPrint</servlet-name>
>    <servlet-class>org.apache.fop.servlet.FopPrintServlet</servlet-class>
>  </servlet>
>  <!-- Servlet mappings -->
>  <servlet-mapping>
>    <servlet-name>Fop</servlet-name>
>    <url-pattern>/</url-pattern>
>  </servlet-mapping>
>  <servlet-mapping>
>    <servlet-name>FopPrint</servlet-name>
>    <url-pattern>/fopprint</url-pattern>
>  </servlet-mapping>
> </web-app>
>
>
>
>
> Martin Jacobson wrote:
>>
>> This is what I would do...
>>
>> 0) move the config file to be part of the war file, inside WEB-INF
>>
>> 1) web.xml
>>
>> <?xml version="1.0" encoding="ISO-8859-1"?>
>>
>> <!DOCTYPE web-app
>>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>>     "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
>>
>> <web-app>
>>     <display-name>cartoWeb - vector map server</display-name>
>>
>>       <context-param>
>>               <param-name>configuration-file</param-name>
>>               <param-value>WEB-INF/fop.xconf</param-value>
>>       </context-param>
>>
>>       <listener>
>>
>> <listener-class>com.emc.carto.web.servlet.WebAppInitializer</listener-class>
>>       </listener>
>> ...
>>
>> 2) Listener
>>
>> public class WebAppInitializer implements ServletContextListener
>> {
>>       ServletContext ctx = null;
>>
>>       public void contextInitialized(ServletContextEvent sce)
>>       {
>>               ctx = sce.getServletContext();
>>               String configFileName = ctx.getInitParameter("configuration-file");
>>               String realConfigFile = ctx.getRealPath(configFileName);
>>                try {
>>                      fopFactory.setUserConfig(new File(realConfigFile));
>>               }
>> etc.
>>
>>
>> HTH
>> Martin
>>
>>
>>
>>
>> On 25 August 2010 14:25, Esse <es...@widenarrow.se> wrote:
>>>
>>> Hi fopusers!
>>>
>>> Specs:
>>> Latest fop (1.0)
>>> Latest tomcat (7.x)
>>>
>>> I’m using the fop servlet example in tomcat, with a config file.
>>>
>>> Right now, FOpServlet is modified like this:
>>>
>>> protected void configureFopFactory() {
>>>        try {
>>>                fopFactory.setUserConfig(new File("/conf/fop.xconf"));
>>>        } catch (SAXException e) {
>>>                System.out.println(e);
>>>        } catch (IOException e) {
>>>                System.out.println(e);
>>>        }
>>>    }
>>>
>>> However, the path for the config file in the above example is
>>> C:\conf\fop.xconf .
>>>
>>> How to make config file path relative(in jar/war/tomcat folder?
>>>
>>> Really anywhere would do except a hard path, like
>>> [JAVA_HOME]/conf/fop.xconf
>>> or something like that.
>>>
>>>
>>> Please help :)
>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531194.html
>>> Sent from the FOP - Users mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>>
>>>
>>
>>
>>
>> --
>> From my MacBook Pro
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531548.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>
>



-- 
>From my MacBook Pro

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


Re: Relative paths when running FOP as servlet (Tomcat)

Posted by Esse <es...@widenarrow.se>.
Hi Martin!

Thanks a lot for your help! However, i'm really a rookie and i need some
clarification to understand :)

How should i modify my web.xml(below)? 

web-app>
	<!-- Servlets -->
  <servlet>
    <servlet-name>Fop</servlet-name>
    <servlet-class>org.apache.fop.servlet.FopServlet</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>FopPrint</servlet-name>
    <servlet-class>org.apache.fop.servlet.FopPrintServlet</servlet-class>
  </servlet>
  <!-- Servlet mappings -->
  <servlet-mapping>
    <servlet-name>Fop</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>FopPrint</servlet-name>
    <url-pattern>/fopprint</url-pattern>
  </servlet-mapping>
</web-app>




Martin Jacobson wrote:
> 
> This is what I would do...
> 
> 0) move the config file to be part of the war file, inside WEB-INF
> 
> 1) web.xml
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> 
> <!DOCTYPE web-app
>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>     "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
> 
> <web-app>
>     <display-name>cartoWeb - vector map server</display-name>
> 
> 	<context-param>
> 		<param-name>configuration-file</param-name>
> 		<param-value>WEB-INF/fop.xconf</param-value>
> 	</context-param>
> 
> 	<listener>
> 	
> <listener-class>com.emc.carto.web.servlet.WebAppInitializer</listener-class>
> 	</listener>
> ...
> 
> 2) Listener
> 
> public class WebAppInitializer implements ServletContextListener
> {
> 	ServletContext ctx = null;
> 
> 	public void contextInitialized(ServletContextEvent sce)
> 	{
> 		ctx = sce.getServletContext();
> 		String configFileName = ctx.getInitParameter("configuration-file");
> 		String realConfigFile = ctx.getRealPath(configFileName);
>                try {
>                      fopFactory.setUserConfig(new File(realConfigFile));
>               }
> etc.
> 
> 
> HTH
> Martin
> 
> 
> 
> 
> On 25 August 2010 14:25, Esse <es...@widenarrow.se> wrote:
>>
>> Hi fopusers!
>>
>> Specs:
>> Latest fop (1.0)
>> Latest tomcat (7.x)
>>
>> I’m using the fop servlet example in tomcat, with a config file.
>>
>> Right now, FOpServlet is modified like this:
>>
>> protected void configureFopFactory() {
>>        try {
>>                fopFactory.setUserConfig(new File("/conf/fop.xconf"));
>>        } catch (SAXException e) {
>>                System.out.println(e);
>>        } catch (IOException e) {
>>                System.out.println(e);
>>        }
>>    }
>>
>> However, the path for the config file in the above example is
>> C:\conf\fop.xconf .
>>
>> How to make config file path relative(in jar/war/tomcat folder?
>>
>> Really anywhere would do except a hard path, like
>> [JAVA_HOME]/conf/fop.xconf
>> or something like that.
>>
>>
>> Please help :)
>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531194.html
>> Sent from the FOP - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>
>>
> 
> 
> 
> -- 
> From my MacBook Pro
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531548.html
Sent from the FOP - Users mailing list archive at Nabble.com.


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


Re: Relative paths when running FOP as servlet (Tomcat)

Posted by Martin Jacobson <ja...@gmail.com>.
This is what I would do...

0) move the config file to be part of the war file, inside WEB-INF

1) web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">

<web-app>
    <display-name>cartoWeb - vector map server</display-name>

	<context-param>
		<param-name>configuration-file</param-name>
		<param-value>WEB-INF/fop.xconf</param-value>
	</context-param>

	<listener>
		<listener-class>com.emc.carto.web.servlet.WebAppInitializer</listener-class>
	</listener>
...

2) Listener

public class WebAppInitializer implements ServletContextListener
{
	ServletContext ctx = null;

	public void contextInitialized(ServletContextEvent sce)
	{
		ctx = sce.getServletContext();
		String configFileName = ctx.getInitParameter("configuration-file");
		String realConfigFile = ctx.getRealPath(configFileName);
               try {
                     fopFactory.setUserConfig(new File(realConfigFile));
              }
etc.


HTH
Martin




On 25 August 2010 14:25, Esse <es...@widenarrow.se> wrote:
>
> Hi fopusers!
>
> Specs:
> Latest fop (1.0)
> Latest tomcat (7.x)
>
> I’m using the fop servlet example in tomcat, with a config file.
>
> Right now, FOpServlet is modified like this:
>
> protected void configureFopFactory() {
>        try {
>                fopFactory.setUserConfig(new File("/conf/fop.xconf"));
>        } catch (SAXException e) {
>                System.out.println(e);
>        } catch (IOException e) {
>                System.out.println(e);
>        }
>    }
>
> However, the path for the config file in the above example is
> C:\conf\fop.xconf .
>
> How to make config file path relative(in jar/war/tomcat folder?
>
> Really anywhere would do except a hard path, like [JAVA_HOME]/conf/fop.xconf
> or something like that.
>
>
> Please help :)
>
>
> --
> View this message in context: http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29531194.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>
>



-- 
>From my MacBook Pro

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


Re: Relative paths when running FOP as servlet (Tomcat)

Posted by Esse <es...@widenarrow.se>.
Hi Martin! 

Thanks a lot for your help! However, i'm really a rookie and i need some
clarification to understand :) 

How should i modify my web.xml(below)? Should i just add the
<context-param>- and <listener>-part to the web.xml? 

I do not fully understand what to do with the listener and how to do it...
where do i put the listener? 

Im not really used to Java, so all of this is sort of new to me. 

web-app> 
        <!-- Servlets --> 
  <servlet> 
    <servlet-name>Fop</servlet-name> 
    <servlet-class>org.apache.fop.servlet.FopServlet</servlet-class> 
  </servlet> 
  <servlet> 
    <servlet-name>FopPrint</servlet-name> 
    <servlet-class>org.apache.fop.servlet.FopPrintServlet</servlet-class> 
  </servlet> 
  <!-- Servlet mappings --> 
  <servlet-mapping> 
    <servlet-name>Fop</servlet-name> 
    <url-pattern>/</url-pattern> 
  </servlet-mapping> 
  <servlet-mapping> 
    <servlet-name>FopPrint</servlet-name> 
    <url-pattern>/fopprint</url-pattern> 
  </servlet-mapping> 
</web-app> 




Martin Jacobson wrote:
This is what I would do... 

0) move the config file to be part of the war file, inside WEB-INF 

1) web.xml 

<?xml version="1.0" encoding="ISO-8859-1"?> 

<!DOCTYPE web-app 
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
    "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd"> 

<web-app> 
    <display-name>cartoWeb - vector map server</display-name> 

        <context-param> 
                <param-name>configuration-file</param-name> 
                <param-value>WEB-INF/fop.xconf</param-value> 
        </context-param> 

        <listener> 
               
<listener-class>com.emc.carto.web.servlet.WebAppInitializer</listener-class> 
        </listener> 
... 

2) Listener 

public class WebAppInitializer implements ServletContextListener 
{ 
        ServletContext ctx = null; 

        public void contextInitialized(ServletContextEvent sce) 
        { 
                ctx = sce.getServletContext(); 
                String configFileName =
ctx.getInitParameter("configuration-file"); 
                String realConfigFile = ctx.getRealPath(configFileName); 
               try { 
                     fopFactory.setUserConfig(new File(realConfigFile)); 
              } 
etc. 


HTH 
Martin 

-- 
View this message in context: http://old.nabble.com/Relative-paths-when-running-FOP-as-servlet-%28Tomcat%29-tp29531194p29533202.html
Sent from the FOP - Users mailing list archive at Nabble.com.


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