You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Cyrille37 <cy...@gmail.com> on 2006/12/21 10:02:05 UTC

reading a file in web root in a Tapestry fashion

Hello,
Sure it is a beginner question, but I'm a beginner :o)

I would like to read a file which is located in the web root folder, and 
put it in a String.
I had a look around the Internet and found some tricks :

A la "Servlet" :
ServletContext theApplicationsServletContext = (ServletContext) 
this.getExternalContext().getContext();
String realPath = 
theApplicationsServletContext.getRealPath("/resources/images");
File file = new File(realPath + File.separatorChar + justFileName);

A la "Rife" :
import com.uwyn.rife.tools.FileUtils;
URL resource = 
getClass().getClassLoader().getResource("model/WordList.txt");
final String wordlist = FileUtils.readString(resource);

Please could you tell me what are methods and usages with Tapestry ?

Thanks
cyrille

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


Re: reading a file in web root in a Tapestry fashion

Posted by Cyrille37 <cy...@gmail.com>.
More generally, I would like to know how to access Application 
environment for a service class.
So, Is there somewhere in Tapestry a Static method that could return 
some global Application information ?

For example, from a Service (Business) Class I would like to:
- get the Application Web Root to read a file
- get a key from a property file which stand in WEB-INF/

Any idea ?
Thanks
Cyrille

Cyrille37 a écrit :
> Hello,
> Sure it is a beginner question, but I'm a beginner :o)
>
> I would like to read a file which is located in the web root folder, 
> and put it in a String.
> I had a look around the Internet and found some tricks :
>
> A la "Servlet" :
> ServletContext theApplicationsServletContext = (ServletContext) 
> this.getExternalContext().getContext();
> String realPath = 
> theApplicationsServletContext.getRealPath("/resources/images");
> File file = new File(realPath + File.separatorChar + justFileName);
>
> A la "Rife" :
> import com.uwyn.rife.tools.FileUtils;
> URL resource = 
> getClass().getClassLoader().getResource("model/WordList.txt");
> final String wordlist = FileUtils.readString(resource);
>
> Please could you tell me what are methods and usages with Tapestry ?
>
> Thanks
> cyrille
>



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


Re: reading a file in web root in a Tapestry fashion

Posted by Cyrille37 <cy...@gmail.com>.
Marilen Corciovei a écrit :
> Hello,
>
> @InjectObject("service:tapestry.globals.ServletContext")
> public abstract ServletContext getServletContext();
Yes, that's it. Thanks Len.

And Please, how to without annotation ?

I'm looking in Tapestry Javadoc for some static method and I could not 
find one.

Cyrille
>
> ...
> String imageDir = getServletContext().getRealPath("images");
> ...
>
> Len
> www.len.ro <http://www.len.ro>
>
>
> On Thu, 2006-12-21 at 10:02 +0100, Cyrille37 wrote:
>> Hello,
>> Sure it is a beginner question, but I'm a beginner :o)
>>
>> I would like to read a file which is located in the web root folder, and 
>> put it in a String.
>> I had a look around the Internet and found some tricks :
>>
>> A la "Servlet" :
>> ServletContext theApplicationsServletContext = (ServletContext) 
>> this.getExternalContext().getContext();
>> String realPath = 
>> theApplicationsServletContext.getRealPath("/resources/images");
>> File file = new File(realPath + File.separatorChar + justFileName);
>>
>> A la "Rife" :
>> import com.uwyn.rife.tools.FileUtils;
>> URL resource = 
>> getClass().getClassLoader().getResource("model/WordList.txt");
>> final String wordlist = FileUtils.readString(resource);
>>
>> Please could you tell me what are methods and usages with Tapestry ?
>>
>> Thanks
>> cyrille
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org <ma...@tapestry.apache.org>
>> For additional commands, e-mail: users-help@tapestry.apache.org <ma...@tapestry.apache.org>
>>
>>     



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


Re: reading a file in web root in a Tapestry fashion

Posted by Marilen Corciovei <le...@nemesisit.rdsnet.ro>.
This only works from inside a Tapestry page because this is linked to
the servlet context which knows about the real path. To a standard class
you need to pass the information somehow. 

Without injection it can be:
getPage().getRequestCycle().getRequestContext().getServlet().getServletContext().getRealPath(fileName);

Len
www.len.ro


On Thu, 2006-12-21 at 11:38 +0100, Cyrille37 wrote:

> Marilen Corciovei a écrit :
> > Hello,
> >
> > @InjectObject("service:tapestry.globals.ServletContext")
> > public abstract ServletContext getServletContext();
> 
> I could not use an abstract class. How will I instantiate it ?
> I would not like to instantiate it with an IoC but like a normal Java 
> Object.
> 
> Cyrille.
> >
> > ...
> > String imageDir = getServletContext().getRealPath("images");
> > ...
> >
> > Len
> > www.len.ro <http://www.len.ro>
> >
> >
> > On Thu, 2006-12-21 at 10:02 +0100, Cyrille37 wrote:
> >> Hello,
> >> Sure it is a beginner question, but I'm a beginner :o)
> >>
> >> I would like to read a file which is located in the web root folder, and 
> >> put it in a String.
> >> I had a look around the Internet and found some tricks :
> >>
> >> A la "Servlet" :
> >> ServletContext theApplicationsServletContext = (ServletContext) 
> >> this.getExternalContext().getContext();
> >> String realPath = 
> >> theApplicationsServletContext.getRealPath("/resources/images");
> >> File file = new File(realPath + File.separatorChar + justFileName);
> >>
> >> A la "Rife" :
> >> import com.uwyn.rife.tools.FileUtils;
> >> URL resource = 
> >> getClass().getClassLoader().getResource("model/WordList.txt");
> >> final String wordlist = FileUtils.readString(resource);
> >>
> >> Please could you tell me what are methods and usages with Tapestry ?
> >>
> >> Thanks
> >> cyrille
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org <ma...@tapestry.apache.org>
> >> For additional commands, e-mail: users-help@tapestry.apache.org <ma...@tapestry.apache.org>
> >>
> >>     
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

Re: reading a file in web root in a Tapestry fashion

Posted by Cyrille37 <cy...@gmail.com>.
Marilen Corciovei a écrit :
> Hello,
>
> @InjectObject("service:tapestry.globals.ServletContext")
> public abstract ServletContext getServletContext();

I could not use an abstract class. How will I instantiate it ?
I would not like to instantiate it with an IoC but like a normal Java 
Object.

Cyrille.
>
> ...
> String imageDir = getServletContext().getRealPath("images");
> ...
>
> Len
> www.len.ro <http://www.len.ro>
>
>
> On Thu, 2006-12-21 at 10:02 +0100, Cyrille37 wrote:
>> Hello,
>> Sure it is a beginner question, but I'm a beginner :o)
>>
>> I would like to read a file which is located in the web root folder, and 
>> put it in a String.
>> I had a look around the Internet and found some tricks :
>>
>> A la "Servlet" :
>> ServletContext theApplicationsServletContext = (ServletContext) 
>> this.getExternalContext().getContext();
>> String realPath = 
>> theApplicationsServletContext.getRealPath("/resources/images");
>> File file = new File(realPath + File.separatorChar + justFileName);
>>
>> A la "Rife" :
>> import com.uwyn.rife.tools.FileUtils;
>> URL resource = 
>> getClass().getClassLoader().getResource("model/WordList.txt");
>> final String wordlist = FileUtils.readString(resource);
>>
>> Please could you tell me what are methods and usages with Tapestry ?
>>
>> Thanks
>> cyrille
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org <ma...@tapestry.apache.org>
>> For additional commands, e-mail: users-help@tapestry.apache.org <ma...@tapestry.apache.org>
>>
>>     



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


Re: reading a file in web root in a Tapestry fashion

Posted by Marilen Corciovei <le...@nemesisit.rdsnet.ro>.
Hello,

@InjectObject("service:tapestry.globals.ServletContext")
public abstract ServletContext getServletContext();

...
String imageDir = getServletContext().getRealPath("images");
...

Len
www.len.ro


On Thu, 2006-12-21 at 10:02 +0100, Cyrille37 wrote:

> Hello,
> Sure it is a beginner question, but I'm a beginner :o)
> 
> I would like to read a file which is located in the web root folder, and 
> put it in a String.
> I had a look around the Internet and found some tricks :
> 
> A la "Servlet" :
> ServletContext theApplicationsServletContext = (ServletContext) 
> this.getExternalContext().getContext();
> String realPath = 
> theApplicationsServletContext.getRealPath("/resources/images");
> File file = new File(realPath + File.separatorChar + justFileName);
> 
> A la "Rife" :
> import com.uwyn.rife.tools.FileUtils;
> URL resource = 
> getClass().getClassLoader().getResource("model/WordList.txt");
> final String wordlist = FileUtils.readString(resource);
> 
> Please could you tell me what are methods and usages with Tapestry ?
> 
> Thanks
> cyrille
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

Re: reading a file in web root in a Tapestry fashion

Posted by Ron Piterman <rp...@gmx.net>.
for example, you can not expect hivemind to inject IEngineService
automatically since there are many services implementing this interface
(PageService, ExternalService, DirectService and so on)


Otherwise it works fine.

Cheers,
Ron


Jiří Mareš wrote:
> Hi,
> 
> the rules are quite simple, there have to be only one service of the type ... otherwise you have to specify what service
> do you want to ...
> 
> Jirka
> 
> Cyrille37 napsal(a):
>> Ron Piterman a écrit :
>>> yes, thats it - BTW, you don't need an explicit set-service.
>>> just exposte a setter in your implementation class, and hivemind will
>>> autowire it:
>>>
>>> public void setServletContext( ServletContext ctx) {...}
>>>   
>> heuu...
>> I do not really understand.
>> Do you mean Hivemind will do that automatically ?
>> What are rules ?
>> Do you know the documentation about that ?
>>
>> Thanks a lot
>> Cyrille
>>> Cheers,
>>> Ron
>>>
>>>
>>> Cyrille37 wrote:
>>>  
>>>> Ron Piterman a écrit :
>>>>    
>>>>> On which class do you need to access the resource?
>>>>>         
>>>> I've resolved the case with Hivemind.
>>>> I pass to the ObjectFactory the ServletContext to get a root path and
>>>> the relative filename.
>>>>
>>>>    <service-point id="hangmanFactoryService"
>>>> interface="games.hangman.service.HangmanFactory">
>>>>        <invoke-factory>
>>>>            <construct class="games.hangman.service.HangmanFactory">
>>>>                <set-service property="servletContext"
>>>> service-id="tapestry.globals.ServletContext"/>
>>>>                <set property="wordsListFilename" value="WordsList.txt"/>
>>>>            </construct>
>>>>        </invoke-factory>
>>>>    </service-point>
>>>>      <contribution configuration-id="tapestry.state.ApplicationObjects">
>>>>        <state-object name="hangmanStateObject" scope="session" >
>>>>            <!-- <create-instance class="games.hangman.service.Hangman"
>>>> /> -->
>>>>            <invoke-factory object="service:hangmanFactoryService" />
>>>>        </state-object>
>>>>    </contribution>
>>>>
>>>> I would have liked only the Hivemind's contribution entry, but to pass
>>>> parameters to the instance I've understood that we have to use a
>>>> Factory. So two Hivemind's entries.
>>>>
>>>> Perhaps it could be lighter with the Hivemind's "Lightweight Instance
>>>> Initialization"
>>>> http://hivemind.apache.org/instance-initialization.html
>>>> But I do not understand how it works ...
>>>>
>>>> I would have liked something simple as:
>>>>
>>>>    <bean id="hangman" scope="session"
>>>> class="games.hangman.service.Hangman" >
>>>>               <property name="servletContext"
>>>> ref="tapestry.globals.ServletContext" />
>>>>               <property name="wordsListFilename"
>>>> value="WordsList.txt" />
>>>>    </bean>
>>>>
>>>> Cyrille
>>>>
>>>>    
>>>>> Cheers,
>>>>> Ron
>>>>>
>>>>>
>>>>>
>>>>> Cyrille37 wrote:
>>>>>  
>>>>>      
>>>>>> Hello,
>>>>>> Sure it is a beginner question, but I'm a beginner :o)
>>>>>>
>>>>>> I would like to read a file which is located in the web root
>>>>>> folder, and
>>>>>> put it in a String.
>>>>>> I had a look around the Internet and found some tricks :
>>>>>>
>>>>>> A la "Servlet" :
>>>>>> ServletContext theApplicationsServletContext = (ServletContext)
>>>>>> this.getExternalContext().getContext();
>>>>>> String realPath =
>>>>>> theApplicationsServletContext.getRealPath("/resources/images");
>>>>>> File file = new File(realPath + File.separatorChar + justFileName);
>>>>>>
>>>>>> A la "Rife" :
>>>>>> import com.uwyn.rife.tools.FileUtils;
>>>>>> URL resource =
>>>>>> getClass().getClassLoader().getResource("model/WordList.txt");
>>>>>> final String wordlist = FileUtils.readString(resource);
>>>>>>
>>>>>> Please could you tell me what are methods and usages with Tapestry ?
>>>>>>
>>>>>> Thanks
>>>>>> cyrille
>>>>>>             
>>>   
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
> 


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


Re: reading a file in web root in a Tapestry fashion

Posted by Jiří Mareš <Ji...@svt.cz>.
Hi,

the rules are quite simple, there have to be only one service of the type ... otherwise you have to specify what service
do you want to ...

Jirka

Cyrille37 napsal(a):
> 
> Ron Piterman a écrit :
>> yes, thats it - BTW, you don't need an explicit set-service.
>> just exposte a setter in your implementation class, and hivemind will
>> autowire it:
>>
>> public void setServletContext( ServletContext ctx) {...}
>>   
> heuu...
> I do not really understand.
> Do you mean Hivemind will do that automatically ?
> What are rules ?
> Do you know the documentation about that ?
> 
> Thanks a lot
> Cyrille
>> Cheers,
>> Ron
>>
>>
>> Cyrille37 wrote:
>>  
>>> Ron Piterman a écrit :
>>>    
>>>> On which class do you need to access the resource?
>>>>         
>>> I've resolved the case with Hivemind.
>>> I pass to the ObjectFactory the ServletContext to get a root path and
>>> the relative filename.
>>>
>>>    <service-point id="hangmanFactoryService"
>>> interface="games.hangman.service.HangmanFactory">
>>>        <invoke-factory>
>>>            <construct class="games.hangman.service.HangmanFactory">
>>>                <set-service property="servletContext"
>>> service-id="tapestry.globals.ServletContext"/>
>>>                <set property="wordsListFilename" value="WordsList.txt"/>
>>>            </construct>
>>>        </invoke-factory>
>>>    </service-point>
>>>      <contribution configuration-id="tapestry.state.ApplicationObjects">
>>>        <state-object name="hangmanStateObject" scope="session" >
>>>            <!-- <create-instance class="games.hangman.service.Hangman"
>>> /> -->
>>>            <invoke-factory object="service:hangmanFactoryService" />
>>>        </state-object>
>>>    </contribution>
>>>
>>> I would have liked only the Hivemind's contribution entry, but to pass
>>> parameters to the instance I've understood that we have to use a
>>> Factory. So two Hivemind's entries.
>>>
>>> Perhaps it could be lighter with the Hivemind's "Lightweight Instance
>>> Initialization"
>>> http://hivemind.apache.org/instance-initialization.html
>>> But I do not understand how it works ...
>>>
>>> I would have liked something simple as:
>>>
>>>    <bean id="hangman" scope="session"
>>> class="games.hangman.service.Hangman" >
>>>               <property name="servletContext"
>>> ref="tapestry.globals.ServletContext" />
>>>               <property name="wordsListFilename"
>>> value="WordsList.txt" />
>>>    </bean>
>>>
>>> Cyrille
>>>
>>>    
>>>> Cheers,
>>>> Ron
>>>>
>>>>
>>>>
>>>> Cyrille37 wrote:
>>>>  
>>>>      
>>>>> Hello,
>>>>> Sure it is a beginner question, but I'm a beginner :o)
>>>>>
>>>>> I would like to read a file which is located in the web root
>>>>> folder, and
>>>>> put it in a String.
>>>>> I had a look around the Internet and found some tricks :
>>>>>
>>>>> A la "Servlet" :
>>>>> ServletContext theApplicationsServletContext = (ServletContext)
>>>>> this.getExternalContext().getContext();
>>>>> String realPath =
>>>>> theApplicationsServletContext.getRealPath("/resources/images");
>>>>> File file = new File(realPath + File.separatorChar + justFileName);
>>>>>
>>>>> A la "Rife" :
>>>>> import com.uwyn.rife.tools.FileUtils;
>>>>> URL resource =
>>>>> getClass().getClassLoader().getResource("model/WordList.txt");
>>>>> final String wordlist = FileUtils.readString(resource);
>>>>>
>>>>> Please could you tell me what are methods and usages with Tapestry ?
>>>>>
>>>>> Thanks
>>>>> cyrille
>>>>>             
>>>
>>   
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
Jiří Mareš (mailto:Jiri.Mares@svt.cz)
ČSAD SVT Praha, s.r.o. (http://www.svt.cz)
Czech Republic

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


Re: reading a file in web root in a Tapestry fashion

Posted by Ron Piterman <rp...@gmx.net>.
http://hivemind.apache.org/hivemind/BuilderFactory.html#Autowiring



Cyrille37 wrote:
> Ron Piterman a écrit :
>> yes, thats it - BTW, you don't need an explicit set-service.
>> just exposte a setter in your implementation class, and hivemind will
>> autowire it:
>>
>> public void setServletContext( ServletContext ctx) {...}
>>   
> heuu...
> I do not really understand.
> Do you mean Hivemind will do that automatically ?
> What are rules ?
> Do you know the documentation about that ?
> 
> Thanks a lot
> Cyrille
>> Cheers,
>> Ron
>>
>>
>> Cyrille37 wrote:
>>  
>>> Ron Piterman a écrit :
>>>    
>>>> On which class do you need to access the resource?
>>>>         
>>> I've resolved the case with Hivemind.
>>> I pass to the ObjectFactory the ServletContext to get a root path and
>>> the relative filename.
>>>
>>>    <service-point id="hangmanFactoryService"
>>> interface="games.hangman.service.HangmanFactory">
>>>        <invoke-factory>
>>>            <construct class="games.hangman.service.HangmanFactory">
>>>                <set-service property="servletContext"
>>> service-id="tapestry.globals.ServletContext"/>
>>>                <set property="wordsListFilename" value="WordsList.txt"/>
>>>            </construct>
>>>        </invoke-factory>
>>>    </service-point>
>>>      <contribution configuration-id="tapestry.state.ApplicationObjects">
>>>        <state-object name="hangmanStateObject" scope="session" >
>>>            <!-- <create-instance class="games.hangman.service.Hangman"
>>> /> -->
>>>            <invoke-factory object="service:hangmanFactoryService" />
>>>        </state-object>
>>>    </contribution>
>>>
>>> I would have liked only the Hivemind's contribution entry, but to pass
>>> parameters to the instance I've understood that we have to use a
>>> Factory. So two Hivemind's entries.
>>>
>>> Perhaps it could be lighter with the Hivemind's "Lightweight Instance
>>> Initialization"
>>> http://hivemind.apache.org/instance-initialization.html
>>> But I do not understand how it works ...
>>>
>>> I would have liked something simple as:
>>>
>>>    <bean id="hangman" scope="session"
>>> class="games.hangman.service.Hangman" >
>>>               <property name="servletContext"
>>> ref="tapestry.globals.ServletContext" />
>>>               <property name="wordsListFilename"
>>> value="WordsList.txt" />
>>>    </bean>
>>>
>>> Cyrille
>>>
>>>    
>>>> Cheers,
>>>> Ron
>>>>
>>>>
>>>>
>>>> Cyrille37 wrote:
>>>>  
>>>>      
>>>>> Hello,
>>>>> Sure it is a beginner question, but I'm a beginner :o)
>>>>>
>>>>> I would like to read a file which is located in the web root
>>>>> folder, and
>>>>> put it in a String.
>>>>> I had a look around the Internet and found some tricks :
>>>>>
>>>>> A la "Servlet" :
>>>>> ServletContext theApplicationsServletContext = (ServletContext)
>>>>> this.getExternalContext().getContext();
>>>>> String realPath =
>>>>> theApplicationsServletContext.getRealPath("/resources/images");
>>>>> File file = new File(realPath + File.separatorChar + justFileName);
>>>>>
>>>>> A la "Rife" :
>>>>> import com.uwyn.rife.tools.FileUtils;
>>>>> URL resource =
>>>>> getClass().getClassLoader().getResource("model/WordList.txt");
>>>>> final String wordlist = FileUtils.readString(resource);
>>>>>
>>>>> Please could you tell me what are methods and usages with Tapestry ?
>>>>>
>>>>> Thanks
>>>>> cyrille
>>>>>             
>>>
>>   
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 


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


Re: reading a file in web root in a Tapestry fashion

Posted by Cyrille37 <cy...@gmail.com>.
Ron Piterman a écrit :
> yes, thats it - BTW, you don't need an explicit set-service.
> just exposte a setter in your implementation class, and hivemind will
> autowire it:
>
> public void setServletContext( ServletContext ctx) {...}
>   
heuu...
I do not really understand.
Do you mean Hivemind will do that automatically ?
What are rules ?
Do you know the documentation about that ?

Thanks a lot
Cyrille
> Cheers,
> Ron
>
>
> Cyrille37 wrote:
>   
>> Ron Piterman a écrit :
>>     
>>> On which class do you need to access the resource?
>>>   
>>>       
>> I've resolved the case with Hivemind.
>> I pass to the ObjectFactory the ServletContext to get a root path and
>> the relative filename.
>>
>>    <service-point id="hangmanFactoryService"
>> interface="games.hangman.service.HangmanFactory">
>>        <invoke-factory>
>>            <construct class="games.hangman.service.HangmanFactory">
>>                <set-service property="servletContext"
>> service-id="tapestry.globals.ServletContext"/>
>>                <set property="wordsListFilename" value="WordsList.txt"/>
>>            </construct>
>>        </invoke-factory>
>>    </service-point>
>>      <contribution configuration-id="tapestry.state.ApplicationObjects">
>>        <state-object name="hangmanStateObject" scope="session" >
>>            <!-- <create-instance class="games.hangman.service.Hangman"
>> /> -->
>>            <invoke-factory object="service:hangmanFactoryService" />
>>        </state-object>
>>    </contribution>
>>
>> I would have liked only the Hivemind's contribution entry, but to pass
>> parameters to the instance I've understood that we have to use a
>> Factory. So two Hivemind's entries.
>>
>> Perhaps it could be lighter with the Hivemind's "Lightweight Instance
>> Initialization"
>> http://hivemind.apache.org/instance-initialization.html
>> But I do not understand how it works ...
>>
>> I would have liked something simple as:
>>
>>    <bean id="hangman" scope="session"
>> class="games.hangman.service.Hangman" >
>>               <property name="servletContext"
>> ref="tapestry.globals.ServletContext" />
>>               <property name="wordsListFilename" value="WordsList.txt" />
>>    </bean>
>>
>> Cyrille
>>
>>     
>>> Cheers,
>>> Ron
>>>
>>>
>>>
>>> Cyrille37 wrote:
>>>  
>>>       
>>>> Hello,
>>>> Sure it is a beginner question, but I'm a beginner :o)
>>>>
>>>> I would like to read a file which is located in the web root folder, and
>>>> put it in a String.
>>>> I had a look around the Internet and found some tricks :
>>>>
>>>> A la "Servlet" :
>>>> ServletContext theApplicationsServletContext = (ServletContext)
>>>> this.getExternalContext().getContext();
>>>> String realPath =
>>>> theApplicationsServletContext.getRealPath("/resources/images");
>>>> File file = new File(realPath + File.separatorChar + justFileName);
>>>>
>>>> A la "Rife" :
>>>> import com.uwyn.rife.tools.FileUtils;
>>>> URL resource =
>>>> getClass().getClassLoader().getResource("model/WordList.txt");
>>>> final String wordlist = FileUtils.readString(resource);
>>>>
>>>> Please could you tell me what are methods and usages with Tapestry ?
>>>>
>>>> Thanks
>>>> cyrille
>>>>     
>>>>         
>>
>   



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


Re: reading a file in web root in a Tapestry fashion

Posted by Ron Piterman <rp...@gmx.net>.
yes, thats it - BTW, you don't need an explicit set-service.
just exposte a setter in your implementation class, and hivemind will
autowire it:

public void setServletContext( ServletContext ctx) {...}

Cheers,
Ron


Cyrille37 wrote:
> Ron Piterman a écrit :
>> On which class do you need to access the resource?
>>   
> 
> I've resolved the case with Hivemind.
> I pass to the ObjectFactory the ServletContext to get a root path and
> the relative filename.
> 
>    <service-point id="hangmanFactoryService"
> interface="games.hangman.service.HangmanFactory">
>        <invoke-factory>
>            <construct class="games.hangman.service.HangmanFactory">
>                <set-service property="servletContext"
> service-id="tapestry.globals.ServletContext"/>
>                <set property="wordsListFilename" value="WordsList.txt"/>
>            </construct>
>        </invoke-factory>
>    </service-point>
>      <contribution configuration-id="tapestry.state.ApplicationObjects">
>        <state-object name="hangmanStateObject" scope="session" >
>            <!-- <create-instance class="games.hangman.service.Hangman"
> /> -->
>            <invoke-factory object="service:hangmanFactoryService" />
>        </state-object>
>    </contribution>
> 
> I would have liked only the Hivemind's contribution entry, but to pass
> parameters to the instance I've understood that we have to use a
> Factory. So two Hivemind's entries.
> 
> Perhaps it could be lighter with the Hivemind's "Lightweight Instance
> Initialization"
> http://hivemind.apache.org/instance-initialization.html
> But I do not understand how it works ...
> 
> I would have liked something simple as:
> 
>    <bean id="hangman" scope="session"
> class="games.hangman.service.Hangman" >
>               <property name="servletContext"
> ref="tapestry.globals.ServletContext" />
>               <property name="wordsListFilename" value="WordsList.txt" />
>    </bean>
> 
> Cyrille
> 
>> Cheers,
>> Ron
>>
>>
>>
>> Cyrille37 wrote:
>>  
>>> Hello,
>>> Sure it is a beginner question, but I'm a beginner :o)
>>>
>>> I would like to read a file which is located in the web root folder, and
>>> put it in a String.
>>> I had a look around the Internet and found some tricks :
>>>
>>> A la "Servlet" :
>>> ServletContext theApplicationsServletContext = (ServletContext)
>>> this.getExternalContext().getContext();
>>> String realPath =
>>> theApplicationsServletContext.getRealPath("/resources/images");
>>> File file = new File(realPath + File.separatorChar + justFileName);
>>>
>>> A la "Rife" :
>>> import com.uwyn.rife.tools.FileUtils;
>>> URL resource =
>>> getClass().getClassLoader().getResource("model/WordList.txt");
>>> final String wordlist = FileUtils.readString(resource);
>>>
>>> Please could you tell me what are methods and usages with Tapestry ?
>>>
>>> Thanks
>>> cyrille
>>>     
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 


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


Re: reading a file in web root in a Tapestry fashion

Posted by Cyrille37 <cy...@gmail.com>.
Ron Piterman a écrit :
> On which class do you need to access the resource?
>   

I've resolved the case with Hivemind.
I pass to the ObjectFactory the ServletContext to get a root path and 
the relative filename.

    <service-point id="hangmanFactoryService" 
interface="games.hangman.service.HangmanFactory">
        <invoke-factory>
            <construct class="games.hangman.service.HangmanFactory">
                <set-service property="servletContext" 
service-id="tapestry.globals.ServletContext"/>
                <set property="wordsListFilename" value="WordsList.txt"/>
            </construct>
        </invoke-factory>
    </service-point>
   
    <contribution configuration-id="tapestry.state.ApplicationObjects">
        <state-object name="hangmanStateObject" scope="session" >
            <!-- <create-instance class="games.hangman.service.Hangman" 
/> -->
            <invoke-factory object="service:hangmanFactoryService" />
        </state-object>
    </contribution>

I would have liked only the Hivemind's contribution entry, but to pass 
parameters to the instance I've understood that we have to use a 
Factory. So two Hivemind's entries.

Perhaps it could be lighter with the Hivemind's "Lightweight Instance 
Initialization"
http://hivemind.apache.org/instance-initialization.html
But I do not understand how it works ...

I would have liked something simple as:

    <bean id="hangman" scope="session" 
class="games.hangman.service.Hangman" >
               <property name="servletContext" 
ref="tapestry.globals.ServletContext" />
               <property name="wordsListFilename" value="WordsList.txt" />
    </bean>

Cyrille

> Cheers,
> Ron
>
>
>
> Cyrille37 wrote:
>   
>> Hello,
>> Sure it is a beginner question, but I'm a beginner :o)
>>
>> I would like to read a file which is located in the web root folder, and
>> put it in a String.
>> I had a look around the Internet and found some tricks :
>>
>> A la "Servlet" :
>> ServletContext theApplicationsServletContext = (ServletContext)
>> this.getExternalContext().getContext();
>> String realPath =
>> theApplicationsServletContext.getRealPath("/resources/images");
>> File file = new File(realPath + File.separatorChar + justFileName);
>>
>> A la "Rife" :
>> import com.uwyn.rife.tools.FileUtils;
>> URL resource =
>> getClass().getClassLoader().getResource("model/WordList.txt");
>> final String wordlist = FileUtils.readString(resource);
>>
>> Please could you tell me what are methods and usages with Tapestry ?
>>
>> Thanks
>> cyrille
>>     



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


Re: reading a file in web root in a Tapestry fashion

Posted by Ron Piterman <rp...@gmx.net>.
On which class do you need to access the resource?
Cheers,
Ron



Cyrille37 wrote:
> Hello,
> Sure it is a beginner question, but I'm a beginner :o)
> 
> I would like to read a file which is located in the web root folder, and
> put it in a String.
> I had a look around the Internet and found some tricks :
> 
> A la "Servlet" :
> ServletContext theApplicationsServletContext = (ServletContext)
> this.getExternalContext().getContext();
> String realPath =
> theApplicationsServletContext.getRealPath("/resources/images");
> File file = new File(realPath + File.separatorChar + justFileName);
> 
> A la "Rife" :
> import com.uwyn.rife.tools.FileUtils;
> URL resource =
> getClass().getClassLoader().getResource("model/WordList.txt");
> final String wordlist = FileUtils.readString(resource);
> 
> Please could you tell me what are methods and usages with Tapestry ?
> 
> Thanks
> cyrille
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 


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