Java Doc for StringTemplateHandler.java in  » Web-Server » HttpdBase4J » net » homeip » donaldm » httpdbase4j » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » HttpdBase4J » net.homeip.donaldm.httpdbase4j 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.homeip.donaldm.httpdbase4j.StringTemplateHandler

All known Subclasses:   net.homeip.donaldm.httpdbase4j.FileStringTemplateHandler,  net.homeip.donaldm.httpdbase4j.ArchiveStringTemplateHandler,
StringTemplateHandler
abstract public class StringTemplateHandler implements HttpHandleable,Postable,Templatable(Code)
Provides a base handler class for templating based on the StringTemplate library (http://www.stringtemplate.org/) The Templates (which must have an extension of '.st') may be processed in three ways:
  • The user may specify a template processing class that implements the Templatable interface. The Templatable.processTemplate method of that class will then be called for each template.

  • If a template processing class is not specified in the constructor then the StringTemplateHandler class uses itself as a template processing class. The default Templatable handler method loads a class from the Java package in m_templateJavaPackage (which must be specified in the constructor) with the same name as the template. This class must have an empty public constructor and must implement the Templatable interface. The class name (excluding the extension) must either be exactly the same as the template (ie have the same case too) or the first letter can be uppercase. For example if the the template is listpersons.st then listpersons.class or Listpersons.class will be found.

  • The user can overide the StringTemplateHTTPD class and provide his own processTemplate method

The StringTemplate library (@see http://www.stringtemplate.org) requires stringtemplate.jar and antlr-2.7.7.jar be in the classpath.
See Also:   FileStringTemplateHandler
See Also:   ArchiveStringTemplateHandler
author:
   Donald Munro


Field Summary
protected  Httpdm_httpd
    
protected  booleanm_isCacheable
    
protected  Map<Long, File>m_postMap
    
protected  Map<Long, Object>m_resultMap
    
protected  StringTemplateGroupm_templateGroup
    
protected  Stringm_templateJavaPackage
     The package name for per-template processing and generation Java classes.
protected  Templatablem_templateProcessor
     Template processing and generation class.

Constructor Summary
public  StringTemplateHandler(Httpd httpd, String templateJavaPackage)
     Constructor with template package.
public  StringTemplateHandler(Httpd httpd, Templatable templateProcessor)
     Constructor with a template processor class that implements the Templatable interface.

Method Summary
protected  Class_instantiateTemplateClass(String className)
    
public  booleangetCacheable()
    
abstract protected  StringTemplategetTemplate(Request request)
    
abstract protected  TemplatablegetTemplateInstance(String templateName)
    
public  RequestonFileNotFound(long id, HttpExchange ex, Request request)
    
public  ObjectonHandlePost(long id, HttpExchange ex, Request request, HttpResponse response, File dir, Object... extraParameters)
    
public  StringonListDirectory(Request request)
    
public  voidonPostServe(long id, HttpExchange ex, Request request, boolean isOK)
    
public  booleanonPreServe(long id, HttpExchange ex, Request request)
    
public  InputStreamonServeBody(long id, HttpExchange ex, Request request)
    
public  HttpResponseonServeHeaders(long id, HttpExchange ex, Request request)
    
public  voidsetCacheable(boolean isCacheable)
     By default the StringTemplateHandler derived classes return m_isCacheable which defaults to false to disallow cacheing for template based resources.
public  voidsetDebug(boolean b)
    
public  FiletemplateFile(StringTemplate template, Request request, StringBuffer mimeType, File dir)
     The method processes templates and returns the file generated from the template.
public  InputStreamtemplateStream(StringTemplate template, Request request, StringBuffer mimeType)
     The method processes templates and returns the file generated from the template.
public  StringtemplateString(StringTemplate template, Request request, StringBuffer mimeType)
     The method processes templates and returns the file generated from the template.

Field Detail
m_httpd
protected Httpd m_httpd(Code)



m_isCacheable
protected boolean m_isCacheable(Code)



m_postMap
protected Map<Long, File> m_postMap(Code)



m_resultMap
protected Map<Long, Object> m_resultMap(Code)



m_templateGroup
protected StringTemplateGroup m_templateGroup(Code)
Template group for the home directory (also handles sub-dirs of the home dir



m_templateJavaPackage
protected String m_templateJavaPackage(Code)
The package name for per-template processing and generation Java classes.



m_templateProcessor
protected Templatable m_templateProcessor(Code)
Template processing and generation class.




Constructor Detail
StringTemplateHandler
public StringTemplateHandler(Httpd httpd, String templateJavaPackage) throws IOException(Code)
Constructor with template package.
Parameters:
  httpd - The Httpd instance
Parameters:
  templateJavaPackage - The Java package where template processing classes are located.
throws:
  java.io.IOException - Throws an IO exception if the homeDir directory is not accessible.



StringTemplateHandler
public StringTemplateHandler(Httpd httpd, Templatable templateProcessor) throws IOException, IllegalArgumentException(Code)
Constructor with a template processor class that implements the Templatable interface.
Parameters:
  httpd - The Httpd instance
Parameters:
  templateProcessor - A Java class that implements the Templatable interface.
throws:
  java.io.IOException - Throws an IO exception if the homeDir directory not accessible.
throws:
  java.lang.IllegalArgumentException - Throws an IllegalArgumentException exception if templateProcessor is null




Method Detail
_instantiateTemplateClass
protected Class _instantiateTemplateClass(String className)(Code)



getCacheable
public boolean getCacheable()(Code)
true if cacheing is enabled for StringTemplate resources, elsefalse



getTemplate
abstract protected StringTemplate getTemplate(Request request)(Code)



getTemplateInstance
abstract protected Templatable getTemplateInstance(String templateName)(Code)



onFileNotFound
public Request onFileNotFound(long id, HttpExchange ex, Request request)(Code)



onHandlePost
public Object onHandlePost(long id, HttpExchange ex, Request request, HttpResponse response, File dir, Object... extraParameters)(Code)



onListDirectory
public String onListDirectory(Request request)(Code)



onPostServe
public void onPostServe(long id, HttpExchange ex, Request request, boolean isOK)(Code)



onPreServe
public boolean onPreServe(long id, HttpExchange ex, Request request)(Code)



onServeBody
public InputStream onServeBody(long id, HttpExchange ex, Request request)(Code)



onServeHeaders
public HttpResponse onServeHeaders(long id, HttpExchange ex, Request request)(Code)



setCacheable
public void setCacheable(boolean isCacheable)(Code)
By default the StringTemplateHandler derived classes return m_isCacheable which defaults to false to disallow cacheing for template based resources. Use this method to enable/disable caching for this handler.
Parameters:
  isCacheable - true to enable cahceing for this handler.



setDebug
public void setDebug(boolean b)(Code)

Parameters:
  b - true to enable debug mode (Disables use of template cache)



templateFile
public File templateFile(StringTemplate template, Request request, StringBuffer mimeType, File dir)(Code)
The method processes templates and returns the file generated from the template. The default behaviour when this class is the template processor is to load a class from m_templateJavaPackage with the same name as the template. This class must have an empty public constructor and must implement the Templatable interface. Overiding classes can modify this behaviour to change the way templates content is generated.
Parameters:
  template - The template
Parameters:
  request - The Request instance. The file generated from the template.



templateStream
public InputStream templateStream(StringTemplate template, Request request, StringBuffer mimeType)(Code)
The method processes templates and returns the file generated from the template. The default behaviour when this class is the template processor is to load a class from m_templateJavaPackage with the same name as the template. This class must have an empty public constructor and must implement the Templatable interface. Overiding classes can modify this behaviour to change the way templates content is generated. Note With the current implementation only templateString (and templateFile for POST processing) is used so this method need not be implemented, although if the implementation changes for example to use chunked encoding and not to generate a string in onServeHeaders, but instead to generate a stream in onServeBody then templateStream would be required.
Parameters:
  template - The template
Parameters:
  request - The Request instance. The InputStream generated from the template.



templateString
public String templateString(StringTemplate template, Request request, StringBuffer mimeType)(Code)
The method processes templates and returns the file generated from the template. The default behaviour when this class is the template processor is to load a class from m_templateJavaPackage with the same name as the template. This class must have an empty public constructor and must implement the Templatable interface. Overiding classes can modify this behaviour to change the way templates content is generated.
Parameters:
  template - The template
Parameters:
  request - The Request instance. The String generated from the template.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.