org.mentawai.template
Class TemplateServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.mentawai.template.TemplateServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
JspTemplateServlet

public abstract class TemplateServlet
extends javax.servlet.http.HttpServlet

Classe abstrata base para TemplateServlets. Possui uma implementacao padrao, que e JspTemplateServlet, porem podem ser feitas outras, como FreemarkerTemplateServlet ou VelocityTemplateServlet

Author:
Davi Luan Carneiro
See Also:
Serialized Form

Field Summary
static String CURRENT_VIEW_ATTR
           
static String PAGE_ATTR
           
protected static String TEMPLATE_MANAGER_ATTR
          Para acessar o initParam do web.xml
 
Constructor Summary
TemplateServlet()
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Redireciona para processRequest.
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Redireciona para processRequest.
static void executeListener(Page page, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
          Executa o Listener.
static String extractPagePath(javax.servlet.http.HttpServletRequest request)
          Metodo utilitario que retorna o path da pagina, sem a extensao.
static TemplateManager getTemplateManager()
          Retorna o TemplateManager.
 void init()
          O TemplateManager sera carregado no startup do container
protected  void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Processa a requisicao, obtendo o path a partir da request e redirecionando para o metodo processTemplate
 void processTemplate(String path, TemplateManager manager, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
          Processa o template, invocando o TemplateManager e redirecionando para o local adequado.
protected abstract  void putPageInResponse(Page page, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
          Responsavel por colocar o Page na camada de visao.
static void setTemplateManager(TemplateManager manager)
          Permite que o TemplateManager seja setado.
protected abstract  void showPage(Page page, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletContext application)
          Gera a saida do page no browser.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMPLATE_MANAGER_ATTR

protected static final String TEMPLATE_MANAGER_ATTR
Para acessar o initParam do web.xml

See Also:
Constant Field Values

PAGE_ATTR

public static final String PAGE_ATTR
See Also:
Constant Field Values

CURRENT_VIEW_ATTR

public static final String CURRENT_VIEW_ATTR
See Also:
Constant Field Values
Constructor Detail

TemplateServlet

public TemplateServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
O TemplateManager sera carregado no startup do container

Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

getTemplateManager

public static TemplateManager getTemplateManager()
Retorna o TemplateManager. Por ser estatico, torna o TemplateManager disponivel a outras classes. Deve-se tomar cuidado, pois o TemplateManager so sera preenchido na primeira requisicao ao TemplateServlet. Antes disso, o seu valor e null.

Returns:
TemplateManager

setTemplateManager

public static void setTemplateManager(TemplateManager manager)
Permite que o TemplateManager seja setado. Nao e usado internamente, porem para darmos maxima flexibilidade a quem for usar (incluindo outros frameworks), incluimos este metodo.

Parameters:
manager - Instancia de TemplateManager

extractPagePath

public static String extractPagePath(javax.servlet.http.HttpServletRequest request)
Metodo utilitario que retorna o path da pagina, sem a extensao. Por exemplo: WEB-INF/views/mypage

Parameters:
request -
Returns:
Path da pagina

processRequest

protected void processRequest(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              IOException
Processa a requisicao, obtendo o path a partir da request e redirecionando para o metodo processTemplate

Parameters:
request -
response -
Throws:
javax.servlet.ServletException
IOException

processTemplate

public void processTemplate(String path,
                            TemplateManager manager,
                            javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response,
                            javax.servlet.ServletContext application)
Processa o template, invocando o TemplateManager e redirecionando para o local adequado. Este metodo invoca outros metodos abstratos, tornando-o bem generico. Se fosse criado um FreemarkerTemplateServlet, por exemplo, esta metodo provavelmente continuaria igual. Eh publico porque pode ser usado na integracao com frameworks web mvc.

Parameters:
path -
request -
response -

putPageInResponse

protected abstract void putPageInResponse(Page page,
                                          javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response,
                                          javax.servlet.ServletContext application)
                                   throws Exception
Responsavel por colocar o Page na camada de visao. A classe filha devera implementar este metodo. O JspTemplateServlet, por exemplo, implementa-o setando o Page na request. Se for algo chave-valor (provavelmente sera), procure por como chave a constante PAGE_ATTR

Parameters:
page -
request -
response -
Throws:
Exception

showPage

protected abstract void showPage(Page page,
                                 javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response,
                                 javax.servlet.ServletContext application)
                          throws Exception
Gera a saida do page no browser. Cada implementacao tera a sua propria.

Parameters:
page -
request -
response -
application -
Throws:
Exception

executeListener

public static void executeListener(Page page,
                                   javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response,
                                   javax.servlet.ServletContext application)
                            throws Exception
Executa o Listener. Esta como publico e estatico porque e usado pela taglib.

Parameters:
page -
request -
response -
application -
Throws:
Exception

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     IOException
Redireciona para processRequest.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

doPost

protected void doPost(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws javax.servlet.ServletException,
                      IOException
Redireciona para processRequest.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException


Copyright © 2013. All Rights Reserved.